10.7 Regressão de Poisson

10.7.1 Clássica

## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
data.frame(treatment, outcome, counts) # showing data
##   treatment outcome counts
## 1         1       1     18
## 2         1       2     17
## 3         1       3     15
## 4         2       1     20
## 5         2       2     10
## 6         2       3     20
## 7         3       1     25
## 8         3       2     13
## 9         3       3     12
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
anova(glm.D93)
## Analysis of Deviance Table
## 
## Model: poisson, link: log
## 
## Response: counts
## 
## Terms added sequentially (first to last)
## 
## 
##           Df Deviance Resid. Df Resid. Dev
## NULL                          8    10.5814
## outcome    2   5.4523         6     5.1291
## treatment  2   0.0000         4     5.1291
summary(glm.D93)
## 
## Call:
## glm(formula = counts ~ outcome + treatment, family = poisson())
## 
## Coefficients:
##               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  3.045e+00  1.709e-01  17.815   <2e-16 ***
## outcome2    -4.543e-01  2.022e-01  -2.247   0.0246 *  
## outcome3    -2.930e-01  1.927e-01  -1.520   0.1285    
## treatment2   1.398e-16  2.000e-01   0.000   1.0000    
## treatment3  -2.416e-16  2.000e-01   0.000   1.0000    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 10.5814  on 8  degrees of freedom
## Residual deviance:  5.1291  on 4  degrees of freedom
## AIC: 56.761
## 
## Number of Fisher Scoring iterations: 4

10.7.2 Bayesiana

# library(rstanarm)
# ### Poisson regression (example from help("glm")) 
# count_data <- data.frame(
#  counts = c(18,17,15,20,10,20,25,13,12),
#  outcome = gl(3,1,9),
#  treatment = gl(3,3)
# )
# fit3 <- stan_glm(
#   counts ~ outcome + treatment, 
#   data = count_data, 
#   family = poisson(link="log"),
#   prior = normal(0, 2),
#   refresh = 0,
#   # for speed of example only
#   chains = 2, iter = 250 
# ) 
# print(fit3)
# 
# bayesplot::color_scheme_set("viridis")
# plot(fit3)
# plot(fit3, regex_pars = c("outcome", "treatment"))
# plot(fit3, plotfun = "combo", regex_pars = "treatment") # ?bayesplot::mcmc_combo
# posterior_vs_prior(fit3, regex_pars = c("outcome", "treatment"))