我想用abline(lm(...))
来绘制一个最小二乘回归线,并使其通过特定的点。我看到这个问题与此相关,但并不完全符合我的需求。以下是一个例子:
test <- structure(list(x = c(0, 9, 27, 40, 52, 59, 76), y = c(50, 68,
79, 186, 175, 271, 281)), .Names = c("x", "y"))
# set up an example plot
plot(test,pch=19,ylim=c(0,300),
panel.first=abline(h=c(0,50),v=c(0,10),lty=3,col="gray"))
# standard line of best fit - black line
abline(lm(y ~ x, data=test))
# force through [0,0] - blue line
abline(lm(y ~ x + 0, data=test), col="blue")
这看起来像:
现在我该如何强制通过标记的任意点 (x=10,y=50)
的一条线,并同时最小化到其他点的距离?
# force through [10,50] - red line
??