[R] Anova

Gavin Simpson gavin.simpson at ucl.ac.uk
Sun Mar 16 12:39:28 CET 2008


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 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list