[R] Example of cell means model

Douglas Bates bates at stat.wisc.edu
Thu Oct 16 15:38:35 CEST 2003


"Francisco Vergara" <gerifalte28 at hotmail.com> writes:

> Thanks a lot for your reply. This helps a lot!
> Just to confirm, using lm this model will give me the mean yield value
> for each cell in the two way array.  Now if I want to obtain the mean
> of group means (like a SS type III approach) using LME (since I have
> random effects in the model) how can I parametrize this?

Didn't I just answer that?

> I could definitivelly use xtabs in a two-way case but in my case I
> have 2 other (continuous) covariates that are potential confounders in
> the model so I need to keep them to obtain the corrected means.
> I added a continuous variable (NewVar) to the dataset Newxmp11.07 and
> obtaned a model with the covariate (fm4) and another without it (fm3)

I think you misinterpreted what I wrote.  I used xtabs to show an
alternative, direct calculation of the cell means.  The purpose was to
to compare the result with the coefficients in the model fit with the
new factor constructed as I described.

> >Newxmp11.07<-fix(xmp11.07)
> >str(Newxmp11.07)
> `data.frame':   36 obs. of  4 variables:
> $ Yield  : num  10.5 9.2 7.9 12.8 11.2 13.3 12.1 12.6 14 10.8 ...
> $ Variety: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
> $ Density: Factor w/ 4 levels "1","2","3","4": 1 1 1 2 2 2 3 3 3 4 ...
> $ NewVar : num  10 9 7 12 11 11 12 11 15 16 ...
> 
> >fm3<-gls(Yield~-1+Variety + Density, xmp11.07)
> >fm4<-gls(Yield~-1+Variety + Density+NewVar, Newxmp11.07)

Why are you using gls for these models?

Why do you not generate a factor to achieve the cell means model that
(apparently) you want?

> >fm3
> Coefficients:
> Variety1  Variety2  Variety3  Density2  Density3  Density4
> 8.922222  9.797222 15.713889  2.911111  4.300000  2.433333
> 
> Degrees of freedom: 36 total; 30 residual
> Residual standard error: 1.239243
> 
> >fm4
> Coefficients:
>    Variety1    Variety2    Variety3    Density2    Density3    Density4
> 8.75757265  9.70589316 15.43347009  2.88152564  4.32186752  2.40117521
>      NewVar
> 0.01157692
> 
> Degrees of freedom: 36 total; 29 residual
> Residual standard error: 1.252991
> 
> fm4 gives me the mean of the group means for all the varieties but
> apparently it gives me the treatment contrasts for the densities.  If
> I change the order of the factors in the model specification I get

Please read what I wrote.

> >coef(fm5<-gls(Yield~-1+ Density+Variety+NewVar, Newxmp11.07))
>    Density1    Density2    Density3    Density4    Variety2    Variety3
> 8.75757265 11.63909829 13.07944017 11.15874786  0.94832051  6.67589744
>      NewVar
> 0.01157692
> 
> This, just like fm4 will include the original intercept value in
> Density 1 which is not the actual density 1 mean.  What am I missing? 
> I am sorry if these questions are very basic but I want to make sure
> that I understand what I am doing. I guess that this is the price that
> I am paying for having used in the past packages like SAS where you
> just ask for lsmeans and the software will give you a "black box"
> answer!

Yes.  I think it would be interesting to ask people who use the
results from lsmeans to explain what the results represent.  My guess
is that less than 1% of the people who use lsmeans know what they in
fact are.

I won't be able to continue this conversation.  I am very busy right
putting new facilities into R.  Perhaps others on the list will be
able to respond to your questions.




More information about the R-help mailing list