Error in effect() function in effects package

When I try to use effects::effect, it throws the following error:

Error in Effect.lm(predictors, mod, vcov. = vcov., ...) : 
  could not find function "vcov."

This error can be reproduced with this code:

lm_mtcars <- lm(mpg ~ wt, mtcars)

library(effects)
effect("wt", lm_mtcars, list(wt = seq(2, 3, 0.1)))

How can I fix this?

The error arises because you did not name the xlevels argument. Older versions of effects::effect might have had a different third argument that could be positionally matched but the current version does not.

This will probably deliver what you were expecting:

lm_mtcars <- lm(mpg ~ wt, mtcars)

library(effects)
effect("wt", lm_mtcars, xlevels=list(wt = seq(2, 3, 0.1)))

猜你喜欢

转载自blog.csdn.net/zhaozhn5/article/details/79634544