x <- c(rep(0,4),rep(1,3),rep(0,2),
rep(1,3),rep(0,2),rep(1,3),0,1,0)
n <- c(4,3,4,6,10,14,12,2,3,4,5,10,4,
5,9,5,10,4,7,4)
nx <- data.frame(n,x)
nx.glm <- glm(n ~ x, family="poisson", data=nx)
summary(nx.glm)
Call:
glm(formula = n ~ x, family = "poisson", data = nx)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.75393 -0.49739 0.05042 0.46525 1.68649
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.3610 0.1601 8.499 < 2e-16 ***
x 0.7908 0.1931 4.096 4.2e-05 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 32.616 on 19 degrees of freedom
Residual deviance: 14.502 on 18 degrees of freedom
AIC: 89.951
Number of Fisher Scoring iterations: 4
##自行计算AIC
AIC = -2*sum(dpois(nx.glm$y, nx.glm$fitted.values, log=TRUE)*nx.glm$prior.weights)+2*nx.glm$rank
AIC # 89.95149