BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Clara
Calcite | Level 5

Hi,

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

How could I calculate it?

Thanks

Clara

1 ACCEPTED SOLUTION

Accepted Solutions
StatsMan
SAS Super FREQ

Not GLM, but MIXED can do fixed effect models too.  Look at the PDIFF option on the LSMEANS statement and look at the new LSMESTIMATE statement that allows you to frame statistical estimates in terms of LS-means instead of parameter estimates.  That statement allows you to get the SE of some complicated combinations of LS-means.

View solution in original post

6 REPLIES 6
1zmm
Quartz | Level 8

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.

PGStats
Opal | Level 21

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
RonLev
Calcite | Level 5

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

SteveDenham
Jade | Level 19

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

StatsMan
SAS Super FREQ

Not GLM, but MIXED can do fixed effect models too.  Look at the PDIFF option on the LSMEANS statement and look at the new LSMESTIMATE statement that allows you to frame statistical estimates in terms of LS-means instead of parameter estimates.  That statement allows you to get the SE of some complicated combinations of LS-means.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 13677 views
  • 4 likes
  • 6 in conversation