turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Reproducing stderr of difference of lsmeans

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-19-2010 03:27 PM

Hi,

I am trying to reproduce lsmeans from proc GLM in R and with the help of the online docs and through matrix algebra I can recreate everything but the standard error of the difference of lsmeans.

From the SAS doc:

for LS-means defined by the linear combinations li'b and lj'b of the parameter estimates, Sij^2=MSE*li'*inv(X'X)*lj

This is giving me a negative number.

For balanced data I could get the standard error by taking the square root of the sum of the variances (or sqrt(2)*se of the individual lsmean) but most of the time my data will be unbalanced so this does not hold.

Is there a nice closed form of the relationship between the se for individual lsmeans and their contrasts?

Thanks for your help,

Rick Message was edited by: RickM

I am trying to reproduce lsmeans from proc GLM in R and with the help of the online docs and through matrix algebra I can recreate everything but the standard error of the difference of lsmeans.

From the SAS doc:

for LS-means defined by the linear combinations li'b and lj'b of the parameter estimates, Sij^2=MSE*li'*inv(X'X)*lj

This is giving me a negative number.

For balanced data I could get the standard error by taking the square root of the sum of the variances (or sqrt(2)*se of the individual lsmean) but most of the time my data will be unbalanced so this does not hold.

Is there a nice closed form of the relationship between the se for individual lsmeans and their contrasts?

Thanks for your help,

Rick Message was edited by: RickM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-19-2010 05:33 PM

Ok I figured out how to get it. Really simple too. Instead of li and lj I needed L=li-lj and then do Sij^2=MSE*L'*inv(X'X)*L

Have a nice weekend.

Have a nice weekend.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-19-2010 06:59 PM

Yes, because using the vector li on the left and lj on the right of inv(X'X) just returns the covariance of the two lsmeans that are obtained from li*beta and lj*beta. But the standard error of the difference is the sum of the variances of the lsmeans minus 2 times the covariance of the lsmeans. By using the matrix L, you get all the necessary terms for computing the variance of the difference.