我制作了这个函数,旨在输出 ANCOVA 的摘要并绘制结果:
statAncova <- function (dataframe, response, covariate, Factor) {
library(ggplot2)
mod <- aov(response ~ covariate + Factor, data=dataframe)
pred <- predict(mod)
plotMod <- ggplot(data = cbind(mod$model, pred), aes(covariate, response, color=Factor)) +
geom_point() +
facet_grid(. ~ Factor) +
geom_line(aes(y=pred))
return(list(mod, plotMod))
}
如果我尝试使用这样的功能:
statAncova(mtcars, drat, hp, cyl)
我收到此错误:
Error in eval(expr, envir, enclos) : object 'drat' not found
我究竟做错了什么?