Reputation: 61
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)
?
Upvotes: 4
Views: 2011
Reputation: 685
In my understanding of the question, you are looking for
mod$residuals
Check also
names(mod)
resulting in
[1] "coefficients" "residuals" "effects" "rank" "fitted.values" "assign" "qr"
[8] "df.residual" "contrasts" "xlevels" "call" "terms" "model"
You can obtain the list of residuals, the list of coefficients (mod$coefficients) etc. In akrun's example:
mod$residuals
1 2 3 4 5 6 7 8 9 10 11
-0.9000000 -8.6250000 -4.6250000 -1.9000000 1.1000000 -2.9000000 4.7500000 -3.2500000 4.1000000 3.1000000 -3.2500000
12 13 14 15 16 17 18 19 20 21 22
0.3750000 -1.9000000 1.7500000 -3.6250000 11.3750000 -2.9000000 -5.6250000 10.3750000 0.3750000 -0.9000000 3.1000000
23 24 25 26 27 28 29 30 31 32 33
7.1428571 -2.2727273 3.6000000 -2.8571429 5.6000000 -4.8571429 2.7272727 -0.2727273 -0.8571429 1.7272727 -2.4000000
34 35 36 37 38 39 40 41 42 43 44
5.7272727 -6.2727273 -5.4000000 2.1428571 -0.2727273 2.7272727 -7.2727273 2.7272727 1.1428571 -1.4000000 -1.8571429
45
0.7272727
and
mod$coefficients
(Intercept) fcategory1 fcategory2 partner.status1
12.0508117 0.1902597 1.0991883 2.4591450
fcategory1:partner.status1 fcategory2:partner.status1
-2.8430736 1.7908550
Upvotes: 0
Reputation: 887128
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
Upvotes: 3