Programming the statistical procedures from SAS

How to get standard error of difference of ls-means in Proc GLM?

Reply
Occasional Contributor
Posts: 12

How to get standard error of difference of ls-means in Proc GLM?

Hi,

how to get the SE of difference of lsmeans in Proc GLM?

How could I calculate it?

Thanks

Clara

Regular Contributor
Posts: 152

Re: How to get standard error of difference of ls-means in Proc GLM?

The standard error of the difference in two least-square means equals the square root of the sum of the squared standard errors of these two least-square means.  The following LSMEANS statement in PROC GLM displays the values of the least-square means and their standard errors:

    LSMEANS effect / stderr;

You can check this by adding the option, TDIFF, to the LSMEANS statement so that the t-statistic is displayed for all pairwise differences between two least-square means.  For each pair, these t-statistics equal the difference between these least-square means divided by the standard error of this difference.

If you want to calculate these standard errors of differences, you can use the ODS statement to write out the LSMEANS and their standard errors to an output SAS data set and to use a subsequent DATA step to perform these calculations.

Occasional Contributor
Posts: 12

Re: How to get standard error of difference of ls-means in Proc GLM?

Merci !

Respected Advisor
Posts: 4,606

Re: How to get standard error of difference of ls-means in Proc GLM?

Here is an example of how you can implement 1zmm's advice :

title 'Unbalanced Two-Way Analysis of Variance';
data a;
   input drug disease @;
   do i=1 to 6;
      input y @;
      output;
   end;
   datalines;
1 1 42 44 36 13 19 22
1 2 33  . 26  . 33 21
1 3 31 -3  . 25 25 24
2 1 28  . 23 34 42 13
2 2  . 34 33 31  . 36
2 3  3 26 28 32  4 16
3 1  .  .  1 29  . 19
3 2  . 11  9  7  1 -6
3 3 21  1  .  9  3  .
4 1 24  .  9 22 -2 15
4 2 27 12 12 -5 16 15
4 3 22  7 25  5 12  .
;

proc glm data=a plots=none;
   class drug disease;
   model y=drug disease drug*disease;
   lsmeans drug / pdiff=all tdiff CL;
   ods output Diff=aDiff LSMeanDiffCL=aCL;
run;
quit;

proc transpose data=aDiff out=aDiffT;
by RowName;
var _:;
run;

proc sql;
select
     aCL.*,
     Difference/COL1 as diffStdErr label="Difference Std Err"
from
     aCL inner join
     aDiffT on i = input(RowName,4.) and j = input(_LABEL_, 4.);
quit;

PG

PG
Occasional Contributor
Posts: 13

Re: How to get standard error of difference of ls-means in Proc GLM?

PGStats,

Coincidentally, my more recent question this week touches on this same subject:   Please refer to the question:  "How to compute a std err for LSM differences".   It appears that the standard error of the LSM difference is much smaller than the standard errors of the two individual LSM's, at least the way SAS computes it (the output came from the LSMEANS statement in PROC GLIMMIX).    Steve Denham also computes a higher std err for the LSM diff than the std err of the individual LSM's.   Can you account for this discrepancy?    Is SAS computing something entirely different?

Ron Levine

Respected Advisor
Posts: 2,655

Re: How to get standard error of difference of ls-means in Proc GLM?

I think 1zmm gave the correct answer on the other question.  It has to do with the covariance between estimates.  My earlier method assumes that this value is zero (I assumed independence), and in mixed models, this is almost never the situation.

Steve Denham

Ask a Question
Discussion stats
  • 5 replies
  • 1496 views
  • 3 likes
  • 5 in conversation