我想用R中的lm()函数计算线性回归.另外我想得到一个回归的斜率,我明确地给出了截距lm().
我在互联网上找到了一个例子,我试图阅读R-help"?lm"(不幸的是我无法理解它),但我没有成功.谁能告诉我我的错误在哪里?
lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2))
plot (lin$x, lin$y)
regImp = lm(formula = lin$x ~ lin$y)
abline(regImp, col="blue")
# Does not work:
# Use 1 as intercept
explicitIntercept = rep(1, length(lin$x))
regExp = lm(formula = lin$x ~ lin$y + explicitIntercept)
abline(regExp, col="green")
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助.