当在用户定义的函数中使用时,来自lm的“ExtractVars中的无效模型公式”出错

时间:2014-01-17 17:48:45

标签: r error-handling statistics linear-regression linear

我构建了一个名为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)

}

0 个答案:

没有答案