【问题标题】:qqplot against theoretical quantilesqqplot对理论分位数
【发布时间】:2014-02-06 18:37:15
【问题描述】:

我希望能够针对理论分位数进行 qqplots。我已经知道qqnorm() 会为正态分布做到这一点,但这对我来说是一个非常有限的工具。另外,我注意到有些人从给定的分布中模拟随机过程,并用它来与样本数据进行比较,这并不完全严格,因为它取决于模拟的方法。所以我的例子是将样本数据与几何分布进行比较:

#sample data
var=rgeom(prob=0.3, n=100)

#QQplot against a theoretical geometric distribution with prob=0.5

【问题讨论】:

    标签: r plot statistics


    【解决方案1】:

    您可以使用ggplot2 包轻松制作这样的图:

    library(ggplot2)
    qplot(sample = var, geom = "point", stat = "qq", 
          distribution = qgeom, dparams = list(prob = 0.5))
    

    理论分位数(x 轴)来自概率为 0.5 的几何分布。

    更新(基于评论中的问题):

    可以通过以下方式添加一条线,尽管它不太适合几何分布。该方法基于this answer

    qv <- quantile(var, c(.25, .75))
    qt <- qgeom(prob = 0.5, c(.25, .75))
    slope <- diff(qv)/diff(qt)
    int <- qv[1] - slope * qt[1]
    
    qplot(sample = var, geom = "point", stat = "qq", 
          distribution = qgeom, dparams = list(prob = 0.5)) + 
      geom_abline(slope = slope, intercept = int)
    

    【讨论】:

    • 很好,如何添加经典的二等分线?
    • @user3083324 此行对您的发行版没有多大意义。但是,请查看更新。
    • OP 的 var 取自 rgeom(...),prob=0.3,您的地块 prob=0.5。
    • @jlhoward 看看这个问题(特别是最后一行)。
    • 当你降低理论概率参数时,线越接近点。
    【解决方案2】:

    QQ 图是随机样本的分位数与测试分布的分位数的图。所以,

    plot(qgeom(seq(0,1,length=100),.3),quantile(var,seq(0,1,length=100)))
    

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 2019-06-02
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      相关资源
      最近更新 更多