我正在介绍如何拟合最合适的线条。我有一条简单的直线:y = 1x + 0。我正在尝试获得分散的数据点,我可以放在散点图中,这将使我的最佳拟合线保持相同的等式:y = 1x + b。
我很乐意在R或Excel中学习这种技术 - 无论哪种更容易。
谢谢!
答案 0 :(得分:0)
First generate a set of points x and y that fit your equation exactly. Then, add an error vector to y that is orthogonal to x. To do this, generate a vector r, that is same length as y. Then compute the residuals from the least squares fit of r to x, e = r - rhat, where rhat = bhat + x*ahat. (bhat and ahat are the least squares fit to this r, not your original b). Add e to y.