【发布时间】:2014-01-27 11:10:02
【问题描述】:
我有想要拟合回归线的 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]])))
【讨论】: