gpt4 book ai didi

r - 绘制与回归线的偏差

转载 作者:行者123 更新时间:2023-12-04 16:29:50 25 4
gpt4 key购买 nike

我想用 (a = 0 and b = 1) 绘制一条回归线,并添加与此相关的各个点的偏差以及用名称标识数据点。

set.seed(123)
namelab <- paste ("ET", 1:10, sep = "")
xvar <- 1:10
yvar <- rnorm(10, 5, 5)
myd <- data.frame(namelab, xvar, yvar)
plot(xvar, yvar)
abline (a= 0, b = 1, col = "red", lty = 2)

只是我意图的手动草图,我只是标记了一个点,例如。绘制的线条需要细长。
enter image description here

最佳答案

dev.new(width=4, height=4)
plot(xvar, yvar, asp=1)

a = 0
b = 1

abline (a, b, col = "red", lty = 2)

myd$xint = with(myd, (b*yvar + xvar - b*a) / (b^2 + 1))
myd$yint = with(myd, (b*yvar + b*xvar + a) / (b^2 + 1))

with(myd, segments(xvar, yvar, xint, yint))
with(myd, text(xvar, yvar, labels=namelab, pos=3, cex=0.5))

enter image description here

关于r - 绘制与回归线的偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075109/

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