gpt4 book ai didi

来自 1 :1 line 的残差

转载 作者:行者123 更新时间:2023-12-01 12:43:10 25 4
gpt4 key购买 nike

我想测量一组点和 1:1 线之间的距离。我可以建立一个线性模型并从最佳拟合中获取残差,但我无法从 1:1 的直线中获取度量。有什么有用的提示吗?

#build a df of random numbers     
x=runif(100, 0, 100)
y=runif (100, 0, 100)
df=cbind (x,y)
df=as.data.frame(df)
#build a linear model
lm1<-lm(y~x, data=df)
summary (lm1)
#plot the data, lm best fit and 1:1 (red) line)
plot (y~x, data=df, pch=16)
line (lm1)
abline abline(0,1, col="red")
#get residulas for the linear model
y.resid= resid (lm1)

最佳答案

我建议使用 y-x,就像@vpipkt 建议的那样。只是为了完整性:您还可以创建一个具有固定系数 y-x ~ 0 的线性模型,并在那里取残差。

resid(lm(y-x ~ 0))

当然,这只是更复杂,并给出与 y-x 相同的结果,但它明确指出您正在计算残差而不是计算到直线的最小距离(参见@user3969377 的回答)。

关于来自 1 :1 line 的残差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26673733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com