我正在尝试使用它来绘制一条最小二乘回归线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
??