Re: [R] Anova

From: Gavin Simpson <>
Date: Sun, 16 Mar 2008 11:39:28 +0000

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


> 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:

> Thanks in advance,
> Dan.


 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e]
 Gower Street, London          [w]
 UK. WC1E 6BT.                 [w]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 16 Mar 2008 - 11:42:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Mar 2008 - 19:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive