[R] covariates in lm

Liaw, Andy andy_liaw at merck.com
Fri May 14 17:06:27 CEST 2004


>From the output you've shown, Minitab and R give the same thing when you ask
for the same thing.  In Minitab,

> Source         DF     Seq SS     Adj SS     Adj MS       F      P
> sector          6     9.0605     2.9989     0.4998    1.21  0.297
> depth           1    34.2072    11.9973    11.9973   29.16  0.000
> sector*depth    6     1.5364     1.5364     0.2561    0.62  0.712
> Error         578   237.7830   237.7830     0.4114
> Total         591   282.5871  

In R:

> Response: Expr1
>               Df Sum Sq Mean Sq F value Pr(>F)    
> sector         6    9.1     1.5    3.67 0.0014 ** 
> depth          1   34.2    34.2   83.15 <2e-16 ***
> sector:depth   6    1.5     0.3    0.62 0.7124    
> Residuals    578  237.8     0.4                   

Note the R output matches the `Seq SS' in Minitab, because that's what R
says it does: sequential tests.  By `Adj. SS' and associated tests, I guess
Minitab meant `adjusting for other terms in the model'.  If so, use drop1().

HTH,
Andy

> From: mrufino at cmima.csic.es
> 
> Dear R list,
> 
> I have been trying to do a linear model, extracting the effect of a 
> covariate.... and the results do not match, when I do it with 
> other programs 
> (e.g. minitab).... so it is obvious that I was doing something wrong.
> 
> Whan  I do it with minitab, I have this results: (sector is a 
> factor and depth 
> is the covariate):
> 
> Source         DF     Seq SS     Adj SS     Adj MS       F      P
> sector          6     9.0605     2.9989     0.4998    1.21  0.297
> depth           1    34.2072    11.9973    11.9973   29.16  0.000
> sector*depth    6     1.5364     1.5364     0.2561    0.62  0.712
> Error         578   237.7830   237.7830     0.4114
> Total         591   282.5871  
> 
> 
> If I do with R, I have been trying everything it occurrs to 
> me and looked 
> everywhere and I could not obtain the same results and 
> nothing is clear to 
> me... (I am so sorry... probably it is lack of statistical knowledge):
> 
> If I do:
> > anova(lm(Expr1~depth*sector))
> Analysis of Variance Table
> 
> Response: Expr1
>               Df Sum Sq Mean Sq F value Pr(>F)    
> depth          1   38.2    38.2   92.76 <2e-16 ***
> sector         6    5.1     0.9    2.07  0.055 .  
> depth:sector   6    1.5     0.3    0.62  0.712    
> Residuals    578  237.8     0.4                   
> 
> I am simply fitting a crossed anova, or because depth is 
> continuos ... what is 
> it doing?
> 
> then, as it was not right, I went to look in the manuals, and in 'an 
> introduction to R' states:
> y ~ A + x Single classification analysis of covariance model 
> of y, with classes 
> determined by A, and with covariate x. Is it like this?
> > anova(lm(Expr1~sector+depth)) #I don't think so...
> 
> But I interpreted this as a additive model... and besides it 
> did not work as 
> well, so I tried what a friend recomended, i.e. x:z, whereas 
> we are extacting 
> the effect of x (covariate) on y... but it does not work as well...
> > anova(lm(Expr1~sector+depth+depth:sector)) # Would it be like this?
> Analysis of Variance Table
> 
> Response: Expr1
>               Df Sum Sq Mean Sq F value Pr(>F)    
> sector         6    9.1     1.5    3.67 0.0014 ** 
> depth          1   34.2    34.2   83.15 <2e-16 ***
> sector:depth   6    1.5     0.3    0.62 0.7124    
> Residuals    578  237.8     0.4                   
> -
> or like:  anova(lm(Expr1~depth:depth*sector))
> 
> 
> I am lost... in the other times I just did with minitab, but 
> I realy wanted to 
> do it with R... can someone give me some lights?
> Is it very difficult to do it with R?
> Sorry for the long and messy email,
> 
> thank you very much in advance,
> Marta
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list