如何用泊松作为理论分布创建Q-Q图

时间:2016-10-17 09:40:52

标签: r plot quantile poisson

我需要创建一个Q-Q图,以检查我观察到的数据是否符合泊松分布。

这是我的data.frame:

df = read.table(text = 'Var1 Freq
 1975   10
 1976   12
 1977    9
 1978   14
 1979   14
 1980   11
 1981    8
 1982    7
 1983   10
 1984    8
 1985   12
 1986    9
 1987   10
 1988    9
 1989   10
 1990    9
 1991   11
 1992   12
 1993    9
 1994   10', header = TRUE)

df$Freq列是我感兴趣的列,因为观察结果代表了每年的事件数量。

我知道我必须使用qqplot函数和qpois函数来创建理论分位数,但是如何?

3 个答案:

答案 0 :(得分:2)

ggplot2有一个很好的界面来做这件事。这是一张QQ图,红色的协议步骤线。 QQ图是使用stat_qq并更改distribution参数。您需要在lambda参数中提供dparams

ggplot(data = df,
       mapping = aes(sample = Freq)) + 
  stat_qq(distribution = stats::qpois,
          dparams = list(lambda = mean(df$Freq))) + 
  geom_step(data = data.frame(x = 6:16,
                              Freq = 6:16),
            mapping = aes(x = x,
                          y = Freq),
            colour = "red",
            alpha = 0.5) 

答案 1 :(得分:2)

此外,fitdistrplus包可以用更少的代码完成此操作。比较经验和理论密度和CDF。

library('fitdistrplus')
plot(fitdist(df$Freq,"pois"))

你可以获得你的lambda等,并检查其他发行版。不像ggplot方法那样灵活,但有助于快速检查。

答案 2 :(得分:1)

这是我可能的答案:

spring-security-oauth2

如果您发现任何错误,请告诉我。感谢

相关问题