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")
あなたの助けに感謝します。