[R] extracting p-values from Anova objects (from the car library)

David Winsemius dwinsemius at comcast.net
Mon Aug 23 21:56:27 CEST 2010


On Aug 23, 2010, at 3:01 PM, Johan Steen wrote:

> Dear all,
>
> is there anyone who can help me extracting p-values from an Anova  
> object from the car library? I can't seem to locate the p-values  
> using str(result) or str(summary(result)) in the example below
>
> > A <- factor( rep(1:2,each=3) )
> > B <- factor( rep(1:3,times=2) )
> > idata <- data.frame(A,B)
> > fit <- lm( cbind(a1_b1,a1_b2,a1_b3,a2_b1,a2_b2,a2_b3) ˜ sex,  
> data=Data.wide)
> > result <- Anova(fit, type="III", test="Wilks", idata=idata,  
> idesign=˜A*B)


# you forgot require(car)

 > A <- factor( rep(1:2,each=3) )
 >  B <- factor( rep(1:3,times=2) )
 >  idata <- data.frame(A,B)
 >  fit <- lm( cbind(a1_b1,a1_b2,a1_b3,a2_b1,a2_b2,a2_b3)~sex,  
data=Data.wide)

Error in inherits(x, "data.frame") : object 'Data.wide' not found

I am guessing that you have an object Data.wide and you are not giving  
us any look at it.

Using the lm help page example:

It appears that the print method for Anova is what would return the p- 
values:

prtAnova <- Anova(lm.D9 <- lm(weight ~ group), type="III")
 > str(prtAnova  )
Classes ‘anova’ and 'data.frame':	3 obs. of  4 variables:
  $ Sum Sq : num  253.21 0.688 8.729
  $ Df     : num  1 1 18
  $ F value: num  522.13 1.42 NA
  $ Pr(>F) : num  9.55e-15 2.49e-01 NA
  - attr(*, "heading")= chr  "Anova Table (Type III tests)\n"  
"Response: weight"

So htis is one way:

 > prtAnova$'Pr(>F)'
[1] 9.547128e-15 2.490232e-01           NA


Further examination makes me wonder why you decided that the summary  
method did not produce a p-value?

 > sumryAnova <- summary(Anova(lm.D9 <- lm(weight ~ group), type="III"))
 > str(sumryAnova)
  'table' chr [1:7, 1:4] "Min.   :  0.6882  " "1st Qu.:  4.7087  "  
"Median :  8.7293  " ...
  - attr(*, "dimnames")=List of 2
   ..$ : chr [1:7] "" "" "" "" ...
   ..$ : chr [1:4] "    Sum Sq" "      Df" "   F value" "    Pr(>F)"

Perhaps perhaps you didn't realize that Pr(>F) was the p-value? (It  
would be a bit more difficult to get the p-value from the summary  
object since it needs to be extracted with attribute functions.
--

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list