0
我有我想要擬合迴歸線的3d數據(我使用lm(x1 ~ x2+x3)
)。 要計算線路上每個點的距離,我使用residuals(fit)
。擬合多個線性迴歸線並計算來自另一個數據的殘差R
問題是如何計算距離之前擬合線的另一組點的距離(殘差)?
我有我想要擬合迴歸線的3d數據(我使用lm(x1 ~ x2+x3)
)。 要計算線路上每個點的距離,我使用residuals(fit)
。擬合多個線性迴歸線並計算來自另一個數據的殘差R
問題是如何計算距離之前擬合線的另一組點的距離(殘差)?
飛度迴歸平面和打印殘差:
用新的數據data(trees)
fit <- lm(Volume ~ Girth + Height, data=trees)
(res <- with(trees, Volume - (fit$coefficients[[3]]*Height + fit$coefficients[[2]]*Girth + fit$coefficients[[1]]))) # = residuals(fit)
現在:
trees_new <- trees * runif(nrow(trees))
(res_new <- with(trees_new, Volume - (fit$coefficients[[3]]*Height + fit$coefficients[[2]]*Girth + fit$coefficients[[1]])))
你嘗試過什麼?那麼請把你的代碼放在這裏 –