R中散点图标准差的计算

发布于 2024-10-09 00:14:36 字数 131 浏览 0 评论 0原文

我使用 R 与代表 x=y 对角线的线(使用 abline)结合创建了两个向量的散点图。我希望计算点与对角线的标准偏差,并对第一和第三分位数之间找到的区域进行着色。
我不知道该怎么做,非常感谢所有帮助! 提前致谢。 朝觐。

I have created a scatter plot of two vectors, using R, combined with a line (using abline) which represents the x=y diagonal. I wish to calculate the standard deviation of the dots from the diagonal, and color the area which is found between the first and third quantiles.
I have no idea how to do this, and would appreciate all help!!!
Thanks in advance.
Haj.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澜川若宁 2024-10-16 00:14:36

好吧,你想要做的是这样的:

# sample data
x <- rnorm(50,0,2)
y <- x+rnorm(50,0,2)

# construct polygons
div <- quantile(y-x,c(0.25,0.75))
x1 <- min(c(x,y))
x2 <- max(c(x,y))


plot(x,y,type="n")
polygon(x=c(x1,x1,x2,x2),y=c(x1+div,(x2+div)[c(2,1)]),col="grey")
abline(0,1)
points(x,y)

我会做的是这样的:

qplot(x,y,geom="point") + stat_smooth(method="lm")

你想要计算的标准偏差是

sd(y-x)

你可能正在寻找的正确度量是:

sd(residuals(lm(y~x)))

你应该根据 y 的线性模型来思考x 以获得任何有意义的结果,除非您有充分的理由不这样做。如果 x 和 y 之间的关系不是 1 on 1,那么假设正确的模型是没有意义的。如果 x 与 y 的关系不是 1 on 1,则 yx 将不是正态分布,因此 sd 将难以以有意义的方式解释。

Well, what you want to do is this :

# sample data
x <- rnorm(50,0,2)
y <- x+rnorm(50,0,2)

# construct polygons
div <- quantile(y-x,c(0.25,0.75))
x1 <- min(c(x,y))
x2 <- max(c(x,y))


plot(x,y,type="n")
polygon(x=c(x1,x1,x2,x2),y=c(x1+div,(x2+div)[c(2,1)]),col="grey")
abline(0,1)
points(x,y)

What I would do is this :

qplot(x,y,geom="point") + stat_smooth(method="lm")

The standard deviation you'd like to calculate is

sd(y-x)

The correct measure you're probably looking for is:

sd(residuals(lm(y~x)))

You should think in terms of a linear model of y on x to get any meaningful result, unless you have very good reasons not to do so. If the relation between x and y is not 1 on 1, then assuming the correct model is so won't make sense. And if the relation of x on y is not 1 on 1, y-x will not be normally distributed and hence the sd will be difficult to interprete in a meaningful way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文