我构建了一个名为regcomp的函数(用于比较回归),当我调用函数时,代码给出了一个错误。当它不在函数中时,完全相同的lm代码可以工作。有谁知道为什么我会收到这个错误:
Error in terms.formula(formula, data = data) :
invalid model formula in ExtractVars
运行代码时:
regressioncomp <- function(mdx,mdy,nmdx,nmdy){
# Calculate and summarize the regressions for sites with and without dams.
mdreg.lm = lm(mdy ~ mdx + 0)
summary(mdreg.lm)
nmdreg.lm = lm(nmdy ~ nmdx + 0)
summary(nmdreg.lm)
# ===============================
# In order to test the difference between regressions, I ran an ANCOVA and then ANOVA
allx <- c(mdx,nmdx)
ally <- c(mdy,nmdy)
all <-c('md','md','md','md','md','md','md','md','md','md','md','md','md','md',"nmd", "nmd", "nmd", "nmd", "nmd", "nmd", "nmd", "nmd", "nmd", "nmd", "nmd")
compslope <- aov(ally~allx*all+0); summary(compslope)
compint <- aov(ally~allx+all+0); summary(compslope)
compreg <- anova(compslope,compslope2); summary(compreg)
}