簡體   English   中英

擬合多元線性回歸線並從R中的另一個數據計算殘差

[英]Fit Multiple Linear Regression line and calculate residuals from another data in R

我有想要擬合回歸線的3d數據(我使用lm(x1 ~ x2+x3) )。 為了計算直線上每個點的距離,我使用了residuals(fit)

問題是如何從之前的擬合線計算另一組點的距離(殘差)?

擬合回歸平面並打印殘差:

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]])))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM