Reputation: 391
I am trying to run a marginal (also called type-III) ANOVA using the following code. Unfortunately, I get "Error: $ operator is invalid for atomic vectors". A google search turned up another person getting the same error (see here), but unfortunately no solutions.
rm(list = ls())
data(iris)
iris.lm <- lm(formula = Sepal.Length ~ Sepal.Width + Petal.Length , data = iris)
print(anova(object = iris.lm))
print(anova(object = iris.lm , type = "marginal"))
Upvotes: 2
Views: 3475
Reputation: 391
For future reference, the function Anova
from the package car
accepts a type
argument (such as "III"
or 3
). This function is not to be confused with the function anova
from the standard R
library, which does not accept a type
argument.
Upvotes: 4
Reputation: 121568
Using a traceback
you can localize the error:
print(anova(object = iris.lm , type = "marginal"))
Error: $ operator is invalid for atomic vectors
> traceback()
7: deparse(x$terms[[2L]])
6: FUN(X[[2L]], ...)
5: lapply(objects, function(x) deparse(x$terms[[2L]]))
4: anova.lmlist(object, ...)
3: anova.lm(object = iris.lm, type = "marginal")
2: anova(object = iris.lm, type = "marginal")
1: print(anova(object = iris.lm, type = "marginal"))
So you get the error because you try to call terms
on an object that not support it. This reproduce the error:
lapply(list(iris.lm,type='marginal'),terms)
Error: $ operator is invalid for atomic vectors
Or just :
terms('marginal')
But Why do you expect that this works? Maybe I miss something, but I think it is not mentioned that anova can take type
as an argument.
Upvotes: 2