set.seed(1)
n <- 500
x <- cbind(1, matrix(rnorm(n * 2), n, 2))
mu <- exp(x %*% c(0.3, 0.4, -0.2))
y <- rpois(n, lambda = mu * rgamma(n, shape = 2, rate = 2)) # NB(theta=2)
fit <- fastglm(x, y, family = negbin(theta = 2, link = "log"))
coef(fit)
Run the code above in your browser using DataLab