零膨胀泊松分布的经验和理论分布图

问题描述

以下是我正在处理的一种数据集:

data <- c(0,1,11,2,3,8,7,5,6,9,21,16,25,12,14,15,13,4,10,33,22,19,17,36,40,39,26,20,24,29,56,28,35,87,66,60,58,34,18,41,38,77,31,12)

我已使用 fitdistrplus 包通过泊松分布拟合此数据。

library(fitdistrplus)
x <- fitdist(data,"pois")

一旦我在 plot() 上使用 x 函数:

plot(x)

默认情况下构建两个并排图。一张图由经验与理论分布图组成,另一张图包含 CDF。

数据集有 (29/244)=12% 零值,因此我关心的是我想使用零膨胀泊松分布拟合数据,并希望拥有使用 fitdistrplus 包生成的相同类型的图(如我在前面提到过:plot(x))

解决方法

您可以使用 lambda 的估计值并将其代入 VGAM::dzipoisVGAM::pzipois

library(VGAM)
distr1 <- dzipois(0:max(data),lambda=x$estimate,pstr0=mean(data == 0))
distr2 <- pzipois(0:max(data),pstr0=mean(data == 0))

然后手工制作情节。

op <- par(mfrow=c(1,2))
plot(proportions(table(data)),ylim=c(0,max(proportions(table(data)))),main="Empirical and \ntheoretical distribution",ylab='Density')
lines((0:max(data)) + 0.2,distr1,type="h",lwd=2,col=2)
legend("topright",c("empirical","theoretical"),col=1:2,cex=0.8)
plot(ecdf(data),pch=1,col.hor=0,main="Empirical and \ntheoretial CDFs")
lines(0:max(data),distr2,type="s",col=2)
legend("bottomright",cex=0.8)
par(op)

enter image description here

注意: VGAM 中还有一些其他发行版值得一看。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...