我一直在尝试将零截断负二项式拟合到一些计数数据。在某些情况下,它可以很好地工作,例如:
library(ggplot2)
library(VGAM)
df <- data.frame(n = 1:7, freq = c(0.32, 0.286, 0.19, 0.10, 0.05, 0.02, 0.01))
fit = vglm(df$n ~ 1, posnegbinomial, weights=df$freq)
ggplot(df, aes(x = n, y = freq)) +
geom_point(colour= "red") +
geom_point(aes(x = n,
y = dnbinom(n, size=Coef(fit)[2],
mu = Coef(fit)[1])/(1-dnbinom(0, size=Coef(fit)[2],
mu = Coef(fit)[1]))),
colour = "blue")
但是,在其他情况下,它会失败:
df2 <- data.frame(n = 1:4, freq = c(0.87, 0.11, 0.01, 0.0005))
fit2 = vglm(df2$n ~ 1, posnegbinomial, weights=df2$freq)
ggplot(df2, aes(x = n, y = freq)) +
geom_point(colour= "red") +
geom_point(aes(x = n,
y = dnbinom(n, size=Coef(fit2)[2],
mu = Coef(fit2)[1])/(1-dnbinom(0, size=Coef(fit2)[2],
mu = Coef(fit2)[1]))),
colour = "blue")
在这种情况下,泊松拟合效果很好:
fit_p = vglm(df2$n ~ 1, pospoisson, weights=df2$freq)
ggplot(df2, aes(x = n, y = freq)) +
geom_point(colour= "red") +
geom_point(aes(x = n,
y = dpois(n, Coef(fit_p)[1])/(1-dpois(0, Coef(fit_p)[1]))),
colour = "blue")
有什么办法可以解决这个问题吗?
谢谢!