x = runif(nn <- 2000)
y1 = rnbinom(nn, mu=exp(0+2*x), size=exp(1)) # k is size in rnbinom()
y2 = rnbinom(nn, mu=exp(1+2*x), size=exp(3))
fit = vglm(cbind(y1,y2) ~ 1, posnegbinomial, subset=(y1>0)&(y2>1),
trace=TRUE)
coef(fit, matrix=TRUE)
dim(fit@y)
fitted(fit)[1:5,]
predict(fit)[1:5,]
# Another artificial data example
munb = exp(2); k = exp(3); n = 1000
y = rposnegbin(n, munb=munb, k=k)
table(y)
fit = vglm(y ~ 1, posnegbinomial, trace=TRUE)
coef(fit, matrix=TRUE)
mean(y) # Sample mean
munb / (1 - (k/(k+munb))^k) # Population mean
fitted(fit)[1:5,]
predict(fit)[1:5,]
Run the code above in your browser using DataLab