使用 R 进行逆向统计

发布于 2024-10-09 15:15:11 字数 95 浏览 0 评论 0原文

我想做的事情听起来很简单。我想用 R 绘制一条平均值为 100、标准差为 15 的正常 IQ 曲线。然后,我希望能够在其上叠加数据散点图。

有人知道该怎么做吗?

What I want to do sounds simple. I want to plot a normal IQ curve with R with a mean of 100 and a standard deviation of 15. Then, I'd like to be able to overlay a scatter plot of data on top of it.

Anybody know how to do this?

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

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

发布评论

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

评论(4

就像说晚安 2024-10-16 15:15:11

我猜您想要做的是这样的:您想要绘制平均值为 100 且 sd = 15 的模型正态密度,并且您想要在其上覆盖经验密度 一些据称遵循模型正态密度的观察值,以便您可以直观地看到模型密度与经验密度的拟合程度。下面的代码应该做到这一点(这里,x将是实际观察的向量,但为了说明目的,我用混合正态分布 N(100,15) + 15*N(0,1) 生成它,即所谓的N(100,15) 分布加上噪声)。

require(ggplot2)
x <- round( rnorm( 1000, 100, 15 )) + rnorm(1000)*15
dens.x <- density(x)
empir.df <- data.frame( type = 'empir', x = dens.x$x, density = dens.x$y )
norm.df <-  data.frame( type = 'normal', x = 50:150, density = dnorm(50:150,100,15))
df <- rbind(empir.df, norm.df)
m <- ggplot(data = df, aes(x,density))
m + geom_line( aes(linetype = type, colour = type))

替代文本

I'm guessing what you want to do is this: you want to plot the model normal density with mean 100 and sd = 15, and you want to overlay on top of that the empirical density of some set of observations that purportedly follow the model normal density, so that you can visualize how well the model density fits the empirical density. The code below should do this (here, x would be the vector of actual observations but for illustration purposes I'm generating it with a mixed normal distribution N(100,15) + 15*N(0,1), i.e. the purported N(100,15) distribution plus noise).

require(ggplot2)
x <- round( rnorm( 1000, 100, 15 )) + rnorm(1000)*15
dens.x <- density(x)
empir.df <- data.frame( type = 'empir', x = dens.x$x, density = dens.x$y )
norm.df <-  data.frame( type = 'normal', x = 50:150, density = dnorm(50:150,100,15))
df <- rbind(empir.df, norm.df)
m <- ggplot(data = df, aes(x,density))
m + geom_line( aes(linetype = type, colour = type))

alt text

眼前雾蒙蒙 2024-10-16 15:15:11

好吧,它更像是一个直方图,因为我认为您期望它们更像是一个整数舍入过程:

x<-round(rnorm(1000, 100, 15))
y<-table(x)
plot(y)
par(new=TRUE)
plot(density(x), yaxt="n", ylab="", xlab="", xaxt="n")

如果您想要叠加 dnorm 的理论值,请使用其中之一:

lines(sort(x), dnorm(sort(x), 100, 15), col="red")

替代文字
-或者

points(x, dnorm(x, 100, 15))

Well, it's more like a histogram, since I think you are expecting these to be more like an integer rounded process:

x<-round(rnorm(1000, 100, 15))
y<-table(x)
plot(y)
par(new=TRUE)
plot(density(x), yaxt="n", ylab="", xlab="", xaxt="n")

If you want the theoretic value of dnorm superimposed, then use one of these:

lines(sort(x), dnorm(sort(x), 100, 15), col="red")

alt text
-or

points(x, dnorm(x, 100, 15))
思念绕指尖 2024-10-16 15:15:11

您可以使用以下方法生成 IQ 分数 PDF:

curve(dnorm(x, 100, 15), 50, 150)

但是为什么要在密度曲线上叠加散点图呢?恕我直言,这很不寻常......

You can generate IQ scores PDF with:

curve(dnorm(x, 100, 15), 50, 150)

But why would you like to overlay scatter over density curve? IMHO, that's very unusual...

欢你一世 2024-10-16 15:15:11

除了其他好的答案之外,您可能有兴趣绘制多个面板,每个面板都有自己的图表。 类似的东西

In addition to the other good answers, you might be interested in plotting a number of panels, each with its own graph. Something like this.

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