编写QQ情节

发布于 2024-12-15 13:06:43 字数 79 浏览 0 评论 0原文

我有男女学生的数学考试成绩样本。我想为每个性别绘制QQ图,看看每个性别是否服从正态分布。我知道如何绘制整体样本的 QQ 图,但如何单独绘制它们?

I have a sample of math test scores for male and female students. I want to draw QQ plot for each gender to see if each of them is normally distributed. I know how to draw the QQ plot for the overall sample, but how can I draw them separately?

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

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

发布评论

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

评论(2

独留℉清风醉 2024-12-22 13:06:43

这是一个使用base图形的简单解决方案:

scores <- rnorm(200, mean=12, sd=2)
gender <- gl(2, 50, labels=c("M","F"))
opar <- par(mfrow=c(1,2))
for (g in levels(gender))
  qqnorm(scores[gender==g], main=paste("Gender =", g))
par(opar)

然后是一个更优雅的lattice解决方案:

qqmath(~ scores | gender, data=data.frame(scores, gender), type=c("p", "g"))

请参阅qqmath的在线帮助以获取更多讨论和示例可能的定制。

Here is a simple solution using base graphics:

scores <- rnorm(200, mean=12, sd=2)
gender <- gl(2, 50, labels=c("M","F"))
opar <- par(mfrow=c(1,2))
for (g in levels(gender))
  qqnorm(scores[gender==g], main=paste("Gender =", g))
par(opar)

A more elegant lattice solution then:

qqmath(~ scores | gender, data=data.frame(scores, gender), type=c("p", "g"))

See the on-line help for qqmath for more discussion and example of possible customization.

笔落惊风雨 2024-12-22 13:06:43

在Python中,您有OpenTURNS库提供的QQplot方法 请参阅此处的文档。这是一个例子。

第一步,我们从均匀分布中生成大小为 300 的随机样本。

第二步,我们认为我们不知道这个样本来自哪里,并尝试拟合正态分布和均匀分布。

第三步,我们针对每个拟合分布绘制样本的 QQ 图,以便“查看”哪一个是最好的

第一步:

import openturns as ot
from openturns.viewer import View
    
distribution = ot.Uniform(-1, 1)
sample = distribution.getSample(300)

第二步:

fitted_normal = ot.NormalFactory().build(sample)
fitted_uniform = ot.UniformFactory().build(sample)

第三步:

QQ_plot1 = ot.VisualTest.DrawQQplot(sample, fitted_normal)
QQ_plot2 = ot.VisualTest.DrawQQplot(sample,fitted_uniform)
    
View(QQ_plot1)
View(QQ_plot2)

正如预期的那样,拟合的均匀分布更适合对域两端误差较大的法线进行采样。

输入图片此处描述
输入图片此处描述

In Python, you have a QQplot method offered by the OpenTURNS Library see doc here. Here is an example.

In a first step, we generate a random sample of size 300 from a Uniform distribution.

In a second step, we consider that we do not know where this sample comes from and try to fit a Normal distribution and a Uniform distribution.

In a third step, we draw the QQPlot of ;the sample against each of the fitted distributions in order to "see" which one is the best

1st step:

import openturns as ot
from openturns.viewer import View
    
distribution = ot.Uniform(-1, 1)
sample = distribution.getSample(300)

2nd step:

fitted_normal = ot.NormalFactory().build(sample)
fitted_uniform = ot.UniformFactory().build(sample)

3rd step:

QQ_plot1 = ot.VisualTest.DrawQQplot(sample, fitted_normal)
QQ_plot2 = ot.VisualTest.DrawQQplot(sample,fitted_uniform)
    
View(QQ_plot1)
View(QQ_plot2)

As expected, the fitted Uniform is more adapted to the sample the Normal which has bigger error at both ends of the domain.

enter image description here
enter image description here

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