2014-02-06 29 views
0

我想能夠對理論分位數進行qqplots。我已經知道qqnorm()這是正常分佈的,但這對我來說是一個相當有限的工具。另外,我注意到有些人模擬了給定分佈的隨機過程,並將其用於與樣本數據進行比較,這並不完全嚴格,因爲它取決於仿真方法。所以,我的例子是將樣本數據比較幾何分佈:qqplot與理論分位數

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

#QQplot against a theoretical geometric distribution with prob=0.5 

回答

1

可以容易地與ggplot2包產生這樣一個情節:

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

理論分位數(x軸)是從幾何分佈導出用的概率0.5。 enter image description here

更新(基於評論問題):

一條線可以通過以下方式添加,雖然它不是非常適合幾何分佈。該方法基於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) 

enter image description here

+0

尼斯,怎麼辦我補充一點,古典平分線? – user3083324

+0

@ user3083324此行對您的發行版沒有多大意義。但是,看看更新。 –

+0

OP的'var'取自'rgeom(...)',prob = 0.3,你的圖有prob = 0.5。 – jlhoward

0

一個QQ圖是針對測試分佈分位數一ramdom樣本分位數的情節。所以,

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