Programming the statistical procedures from SAS

Bugs in LSMEANS

Reply
Occasional Contributor
Posts: 18

Bugs in LSMEANS

I think I found two undesirable features in LSMEANS.

 

First, it is calculating the means of the covariates on the set of cases where the outcome is not missing. For predictive margins, we really want the means on the set of cases where none of the covariates are missing.  As it is, LSMEANS is projecting to an uninteresting population.

 

Second, LSMEANS is rounding the population-wide averages of the covariates before taking their inner product with the beta coefficients.  (Or it is rounding the beta coefficients.  Maybe both?)  This can cause the LSMEAN for the reference group to be different than the empirical mean for the reference group.  This makes for awkward presentations.

Super User
Posts: 13,563

Re: Bugs in LSMEANS


@polarjud wrote:

I think I found two undesirable features in LSMEANS.

 

First, it is calculating the means of the covariates on the set of cases where the outcome is not missing. For predictive margins, we really want the means on the set of cases where none of the covariates are missing.  As it is, LSMEANS is projecting to an uninteresting population.

 

Second, LSMEANS is rounding the population-wide averages of the covariates before taking their inner product with the beta coefficients.  (Or it is rounding the beta coefficients.  Maybe both?)  This can cause the LSMEAN for the reference group to be different than the empirical mean for the reference group.  This makes for awkward presentations.


Since LSMEANS is not unique to a single procedure you should provide some more details. Specifically example code that you are running.

 

First, it is calculating the means of the covariates on the set of cases where the outcome is not missing.

It is pretty well documented that the models are build this way. To predict results for the records with the model dependent missing varies a bit by procedure and option used.

 

You should provide some example data code to address why you think the second issue 1) exists and 2) why it makes for awkward presentations. It may be that some of the explanation would be available with additional options or perhaps just changes in display formats. Without a concrete example, preferably using one of the SAS supplied training sets found in the SASHELP library, code and interpretation it is awkward to address a likely mobile target in verbiage only.

 

 

Occasional Contributor
Posts: 18

Re: Bugs in LSMEANS

I found the first problem in both GLM and MIXED.  The second one may only impact MIXED.  Not sure.

 

It is extremely easy to reproduce.  

 

Let Y be some outcome variable with some missing data.

Let D1 and D2 be binary indicators for population domains of interest (no missing data).

Let X be a binary or continuous covariate (no missing data).

Let Z be a categorical variable labeling clusters (no missing data).

 

Proc Mixed data=;

  Class D1 D2 Z;

  Model Y = D1 D2 D1*D2 X/solution;

  Random intercept/subject=Z;

  LSMEANS D1 D2 D1*D2/E;

run;

 

proc means data= means;

  var X;

run;

 

You will immediately see that the means used by LMEANS to estimate predictive margins are different from those produced by proc means.  

 

 

 

 

Super User
Posts: 23,752

Re: Bugs in LSMEANS

Check your PROC MIXED results, the first sets of tables will include one that shows the number of observations used. That will not match the PROC MEANS. If they N matches they would match and none of this seems unexpected to me.

I wouldn't want the LSMEANS to calculate the means using data it did not use to fit the model in the first place.
Occasional Contributor
Posts: 18

Re: Bugs in LSMEANS

Even with no missing data, they do not match because of rounding.  MIXED rounds more than MEANS.

 

But as for the desired behavior in the case of missing outcome data, I think you are missing the point of predictive margins.  They are supposed to present estimates on a well defined population.

Respected Advisor
Posts: 3,040

Re: Bugs in LSMEANS


@polarjud wrote:

But as for the desired behavior in the case of missing outcome data, I think you are missing the point of predictive margins.  They are supposed to present estimates on a well defined population.


LSMEANS can only work on the data you give it, and if the data has missings, that data can't be used.

 

Even with no missing data, they do not match because of rounding.  MIXED rounds more than MEANS.

 

Even if you had the same rounding, LSMEANS would not match MEANS.

--
Paige Miller
Ask a Question
Discussion stats
  • 5 replies
  • 121 views
  • 0 likes
  • 4 in conversation