[R] help_aov

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Oct 31 00:00:26 CET 2006


"Thanjavur Bragadeesh" <bragadeesh02 at hotmail.com> writes:

> Hi,
> 
> I am trying to run an analysis of variance using R.
> in my data table "x" is a continuous variable lengthof 200 and "p" is a 
> categorical variable also of length 200 and p is anyone of three categories 
> 1,2 or ,3.
> if I run
> summary(aov(x~p,data=test))
> I get
> Response: x
>              Df  Sum Sq Mean Sq F value    Pr(>F)
> p           1  3174.7  3174.7  42.749 5.175e-10 ***
> Residuals 198 14704.2    74.3


If you get 1 DF for a variable with three different values, then it is
not a categorical variable from R's point of view, but a quantitative
one.  So you need x~factor(p) here like you have below. Or convert "p"
to a factor before the analysis.

> and if I run
> summary(aov(x~as.factor(p), data=test)) # I get
> 
> Response: x
>                     Df  Sum Sq  Mean Sq  F value   Pr(>F)
> as.factor(p)      2  3175.7  1587.8   21.275  4.31e-09 ***
> Residuals       197  14703.2    74.6
> 
> 
> Can anyone kindly explain the difference. How will it affect -correct way to 
> run - if it is a two-way anova where I have a second categorical variable 
> "sex" - male or female.
> 
> Many Thanks
> 
> 
> Yours sincerely,
> 
> Bragadeesh
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list