[R] Learning ANOVA

Liaw, Andy andy_liaw at merck.com
Mon Aug 16 14:22:33 CEST 2010


From: Stephen Liu
> 
> Hi JesperHybel,
> 
> Thanks for your advice.
> 
> >If you're trying to follow the youtube video you have a 
> typing mistake here:
> 
> >InsectSprays.aov <-(test01$count ~ test01$spray)
> 
> >I think this should be:
> 
> >InsectSprays.aov <-aov(test01$count ~ test01$spray)
> 
> 
> Your advice works for me.  Sorry I missed "aov" before(test01$count ~ 
> test01$spray)

I just want to offer another point:  If you see any
tutorial/document/book advising you to use model formula as above; e.g.,
anything like

  df$var1 ~ df$var2 + df$var3

Just run away from it as fast as you can, and try to wipe it from your
memory.  That's about the worst way to use a model formula, and very
likely to give you what may seem to be strange problems down the road.
Well-written model fitting functions should be called like this:

   modelfn(var1 ~ var2 + var3, data=df, ...)

Andy
 
> > InsectSprays.aov <- aov(test01$count ~ test01$spray)
> > summary(InsectSprays.aov)
>              Df Sum Sq Mean Sq F value    Pr(>F)    
> test01$spray  5 2668.8  533.77  34.702 < 2.2e-16 ***
> Residuals    66 1015.2   15.38                      
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
> 
> 
> > TukeyHSD(InsectSprays.aov)
>   Tukey multiple comparisons of means
>     95% family-wise confidence level
> 
> Fit: aov(formula = test01$count ~ test01$spray)
> 
> $`test01$spray`
>            diff        lwr       upr     p adj
> B-A   0.8333333  -3.866075  5.532742 0.9951810
> C-A -12.4166667 -17.116075 -7.717258 0.0000000
> D-A  -9.5833333 -14.282742 -4.883925 0.0000014
> E-A -11.0000000 -15.699409 -6.300591 0.0000000
> F-A   2.1666667  -2.532742  6.866075 0.7542147
> C-B -13.2500000 -17.949409 -8.550591 0.0000000
> D-B -10.4166667 -15.116075 -5.717258 0.0000002
> E-B -11.8333333 -16.532742 -7.133925 0.0000000
> F-B   1.3333333  -3.366075  6.032742 0.9603075
> D-C   2.8333333  -1.866075  7.532742 0.4920707
> E-C   1.4166667  -3.282742  6.116075 0.9488669
> F-C  14.5833333   9.883925 19.282742 0.0000000
> E-D  -1.4166667  -6.116075  3.282742 0.9488669
> F-D  11.7500000   7.050591 16.449409 0.0000000
> F-E  13.1666667   8.467258 17.866075 0.0000000
> 
> 
> I made a comparison of my result with "example(InsectSprays). 
>  They looks the 
> same.
> 
> I also compared "plot(InsectSprays.aov)".
> 
> 
> A further question how to plot 4 graphs simultaneously?  
> Instead of reading 
> them, individually.  I read ?plot but unable to resolve.
> 
> Also how to save InsectSprays.aov?  I think I can only save it as 
> InsectSprays.csv.  I can't find "write.aov" command. 
> 
> 
> Thanks
> 
> 
> TIA
> 
> B.R.
> satimis
> 
> 
> 
> 
> 
> 
> ----- Original Message ----
> From: JesperHybel <jesperhybel at hotmail.com>
> To: r-help at r-project.org
> Sent: Sat, August 14, 2010 2:09:48 AM
> Subject: Re: [R] Learning ANOVA
> 
> 
> If you're trying to follow the youtube video you have a 
> typing mistake here:
> 
> InsectSprays.aov <-(test01$count ~ test01$spray)
> 
> I think this should be:
> 
> InsectSprays.aov <-aov(test01$count ~ test01$spray)
> 
> 
> youre missing the functioncall "aov" on the right hand side of the
> assignment operator '<-'.
> 
> the results of the application of function aov() is stored in
> InsectSprays.aov and is accessed through
> 
> summary(InsectSprays.aov)
> 
> since you missed the functioncall you cannot apply TukeyHSD() to
> InsectSprays.aov
> 
> I think
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Learning-ANOVA-tp2323660p2324590.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
> 
> 
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}



More information about the R-help mailing list