[R] Anova
Douglas Bates
bates at stat.wisc.edu
Mon Mar 17 20:11:03 CET 2008
On Sun, Mar 16, 2008 at 6:39 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> On Sat, 2008-03-15 at 12:48 -0500, daniel jupiter wrote:
> > Hi all,
> >
> > I apologize for what might be a silly question.
> >
> > I am interested in doing a one way anova.
> > This is not too hard in and of itself, either with anova, aov or oneway.test
> > .
> >
> > However, I need to
> > 1) get pvalues,
>
> if obj is the result of anova, aov, oneway.test, then
>
> str(obj) ## for anova
> str(summary(obj)) ## for aov
> str(obj) ## for oneway.test
>
> to find the names of the elements of obj that contain the p-values of
> the various tests/models. In the first two you are looking for the
> component "Pr(>F)" and the latter is obvious ("p.value")
>
> For summary(aov) objects, the result is a list so this gets the p-value
> you need:
>
> obj[[1]]$`Pr(>F)` or obj[[1]][,5]]
>
> for anova then this:
>
> obj$`Pr(>F)` or obj[,5]
>
> note the quoting of the component name using backticks.
>
> For oneway.test
>
> obj$p.value
>
>
> > 2) do a posthoc analysis with Tukey HSD,
>
> ?TukeyHSD for the results of aov
>
>
> > 3) and have (sometimes) an unbalanced design.
>
> See ?lme in package nlme
>
>
> >
> > I just can't seem to put all the pieces together.
> >
> > Any suggestions?
>
> I'm not sure what the problem is here - you don't say. All of what I say
> above is documented in the relevant help pages for the various functions
> and using str() is a basic tenet of using R and looking at returned
> objects.
>
> Ok, you might have needed help with getting the p-values for some of
> those tests/models, but 2) and 3) are answered on ?aov
>
> For what you describe, stick with aov for balanced designs if you want
> to do TukeyHSD as there is a method for aov objects (otherwise) you'll
> need to refit the model.
>
> For unbalanced designs, check out lme and for that you may need to
> get/borrow the book by Pinhiero and Bates, reference details of which
> are given in item [7] on:
>
> http://www.r-project.org/doc/bib/R-books.html
Thanks for the plug, Gavin, but lme and my book with Jose are for
linear *mixed-effects* models. I think the question here is about
unbalanced fixed-effects models and those can be fit quite simply by
lm, aov and friends.
Users, quite reasonably, expect that model fitting in R is done using
the formulas that they saw in an introductory textbook. In fact, that
is almost never the case. Functions like lm and aov use computational
methods that do not depend on balance in the data.
>
> >
> > Thanks in advance,
> >
> > Dan.
> >
>
> HTH
>
> G
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> Dr. Gavin Simpson [t] +44 (0)20 7679 0522
> ECRC, UCL Geography, [f] +44 (0)20 7679 0565
> Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
> Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
> UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list