Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract residuals and read coefficients from the function Anova()?

I use the function Anova() in package car to perform a test with type III. But I have no idea how to extract the residuals or how to get the information of parameter estimates.

Is there some way to do these like residuals(model) and summary.lm(model)?

like image 626
A. Caikov Avatar asked Oct 12 '25 05:10

A. Caikov


1 Answers

The output of Anova is of class anova and data.frame.

So, if we use the extraction with row/column names, it should work. Using a reproducible example from the ?Anova documentation

library(car)
mod <- lm(conformity ~ fcategory*partner.status, data=Moore,
     contrasts=list(fcategory=contr.sum, partner.status=contr.sum))
out <- Anova(mod, type = 3)
str(out)
#Classes ‘anova’ and 'data.frame':  5 obs. of  4 variables:
# $ Sum Sq : num  5753 36 240 175 818
# $ Df     : num  1 2 1 2 39
# $ F value: num  274.359 0.859 11.425 4.185 NA
# $ Pr(>F) : num  3.05e-19 4.31e-01 1.66e-03 2.26e-02 NA
# - attr(*, "heading")= chr  "Anova Table (Type III tests)\n" "Response: conformity"

The print method changes the way how it is printing the output. But, if we just strip off the anova class. The "Residuals" are also in the row names

row.names(out)
#[1] "(Intercept)"              "fcategory"              "partner.status"           
#[4] "fcategory:partner.status" "Residuals"     

So, using the row/column names for extraction

out["Residuals","Sum Sq"]
#[1] 817.764
like image 130
akrun Avatar answered Oct 14 '25 19:10

akrun