生成用于测试几何分布样本的 QQ 图 [英] Generate a QQ Plot for testing a geometrically distributed sample

查看:25
本文介绍了生成用于测试几何分布样本的 QQ 图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 R 中生成的 n 个元素的样本

I have a sample of n elements generated in R with

sim.geometric <- function(n)
{
    u <- runif(n)
    10*u/log(0.5)
}

我想测试它的分布,特别是如果它确实遵循几何分布.我想生成一个 QQ Plot 但不知道怎么做.你能帮忙吗?

for which i want to test its distribution, specifically if it indeed follows a geometric distribution. I want to generate a QQ PLot but have no idea how to. Can you help?

提前致谢.

推荐答案

与从几何分布中以相同概率抽取的真实"样本相比,QQ 图应该是一条直线范围.一个函数给出了两个向量,这些向量本质上比较了它们在每个分位数上的逆 ECDF.这个特定的采样不完全是直线的事实并不是存在问题的好信号.一方面,重复的点没有得到足够的权重,因为它们是重叠的.这意味着右尾的点得到了它们不应该得到的额外重视.

A QQ-plot should be a straight line when compared to a "true" sample drawn from a geometric distribution with the same probability parameter. One gives two vectors to the functions which essentially compares their inverse ECDF's at each quantile. The fact that this particular sampling wasn't exactly straight is not a good signal that there is a problem. For one thing the duplicated points are not given enough weight because they are overlapping. This means the points in the right tail are getting extra importance that they don't deserve.

sim.res <- sim.geometric(100)
sim.rgeom <- rgeom(100, 0.3)
qqplot(sim.res, sim.rgeom)

在这里,我遵循 qqplot 帮助页面的作者的指导(这会导致围绕身份线翻转上部曲线):

Here I follow the lead of the authors of qqplot's help page (which results in flipping that upper curve around the line of identity):

png("QQ.png")
qqplot(qgeom(ppoints(100),prob=0.3), sim.res,
       main = expression("Q-Q plot for" ~~ {G}[n == 100]))
dev.off()

您可以通过为每个分布绘制一条穿过第 25 个和第 75 个百分位点的线来添加良好拟合线".(我为此添加了一个抖动功能,以便更好地了解概率质量"的位置:)

You can add a "line of good fit" by plotting a line through through the 25th and 75th percentile points for each distribution. (I added a jittering feature to this to get a better idea where the "probability mass" was located:)

sim.res <- sim.geometric(500)
qqplot(jitter(qgeom(ppoints(500),prob=0.3)), jitter(sim.res),
       main = expression("Q-Q plot for" ~~ {G}[n == 100]), ylim=c(0,max( qgeom(ppoints(500),prob=0.3),sim.res )),
xlim=c(0,max( qgeom(ppoints(500),prob=0.3),sim.res )))
 qqline(sim.res, distribution = function(p) qgeom(p, 0.3),
       prob = c(0.25, 0.75), col = "red")

这篇关于生成用于测试几何分布样本的 QQ 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆