R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > # Data from table 2.6 in Agresti > # we compare logistic regression and Poisson regression and show that they > # are the same > > victim <- factor(rep(c("white", "black"), each = 2)) > defendant <- factor(rep(c("white", "black"), times = 2)) > deathpenalty <- matrix(c(53, 11, 0, 4, 414, 37, 16, 139), + ncol = 2, dimnames = list(NULL, c("yes", "no"))) > > data.frame(victim, defendant, deathpenalty) victim defendant yes no 1 white white 53 414 2 white black 11 37 3 black white 0 16 4 black black 4 139 > > # logistic regression (binomial glm with logit link) > # same analysis as was done in mcmc-too.R > > bout <- glm(deathpenalty ~ victim + defendant, family = binomial) > summary(bout) Call: glm(formula = deathpenalty ~ victim + defendant, family = binomial) Deviance Residuals: 1 2 3 4 0.02660 -0.06232 -0.60535 0.09379 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.5961 0.5069 -7.094 1.30e-12 *** victimwhite 2.4044 0.6006 4.003 6.25e-05 *** defendantwhite -0.8678 0.3671 -2.364 0.0181 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 22.26591 on 3 degrees of freedom Residual deviance: 0.37984 on 1 degrees of freedom AIC: 19.3 Number of Fisher Scoring iterations: 4 > > # Now try to do the same thing assuming cells are independent poisson > # have to stretch data out into a vector > > resp <- as.vector(deathpenalty) > > # then have to make all the predictors twice as long > victim <- rep(victim, times = 2) > defendant <- rep(defendant, times = 2) > deathpenalty <- factor(rep(colnames(deathpenalty), each = 4)) > > data.frame(victim, defendant, deathpenalty, resp) victim defendant deathpenalty resp 1 white white yes 53 2 white black yes 11 3 black white yes 0 4 black black yes 4 5 white white no 414 6 white black no 37 7 black white no 16 8 black black no 139 > > pout <- glm(resp ~ deathpenalty + victim + defendant, family = poisson) > summary(pout) Call: glm(formula = resp ~ deathpenalty + victim + defendant, family = poisson) Deviance Residuals: 1 2 3 4 5 6 7 8 2.4276 -1.0165 -4.7949 -0.2614 4.3420 -9.7343 -10.6526 12.0733 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 3.70160 0.10103 36.64 <2e-16 *** deathpenaltyyes -2.18737 0.12789 -17.10 <2e-16 *** victimwhite 1.17526 0.09073 12.95 <2e-16 *** defendantwhite 0.92774 0.08548 10.85 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 1225.08 on 7 degrees of freedom Residual deviance: 402.84 on 4 degrees of freedom AIC: 448.88 Number of Fisher Scoring iterations: 6 > > > proc.time() user system elapsed 0.127 0.010 0.214