{"id":705,"date":"2015-04-23T10:47:44","date_gmt":"2015-04-23T14:47:44","guid":{"rendered":"http:\/\/www.clayford.net\/statistics\/?p=705"},"modified":"2020-09-13T10:17:59","modified_gmt":"2020-09-13T14:17:59","slug":"poisson-regression-ch-6-of-gelman-and-hill","status":"publish","type":"post","link":"https:\/\/www.clayford.net\/statistics\/poisson-regression-ch-6-of-gelman-and-hill\/","title":{"rendered":"Poisson regression &#8211; Ch 6 of Gelman and Hill"},"content":{"rendered":"<p>Chapter 6 of Gelman and Hill&#39;s <a href=\"http:\/\/www.stat.columbia.edu\/%7Egelman\/arm\/\">Data Analysis Using Regression and Multilevel\/Hierarchical Models<\/a> presents an interesting example of Poisson regression using data on police stops in New York. Put simply, they seek to model the count of &ldquo;stop and frisks&rdquo; as a function of ethnicity and precinct with number of arrests in the previous year included as an offset. While the example is fun and informative, it&#39;s not terribly easy to replicate. The R code is provided to run the regressions but the data is a little hard to locate. I was eventually able to find it and get everything to mostly work, so I thought I would blog about it in case anyone else was trying to do the same.<\/p>\n<p>About the data: it turns out you can find it <a href=\"http:\/\/www.stat.columbia.edu\/%7Egelman\/arm\/examples\/\">here<\/a> in the &ldquo;police&rdquo; folder. In the folder is a dat file called &ldquo;frisk_with_noise&rdquo;. Here&#39;s one way to read it in:<\/p>\n<pre><code class=\"r\">url &lt;- &quot;http:\/\/www.stat.columbia.edu\/~gelman\/arm\/examples\/police\/frisk_with_noise.dat&quot;\r\ndat &lt;- read.table(url,header=TRUE, skip=6)\r\nhead(dat,n=4)\r\n<\/code><\/pre>\n<pre>##   stops  pop past.arrests precinct eth crime\r\n## 1    75 1720          191        1   1     1\r\n## 2    36 1720           57        1   1     2\r\n## 3    74 1720          599        1   1     3\r\n## 4    17 1720          133        1   1     4\r\n<\/pre>\n<pre><code class=\"r\">dim(dat)\r\n<\/code><\/pre>\n<pre>## [1] 900   6\r\n<\/pre>\n<p>But wait. You&#39;ll notice the data set has 900 rows but the regression output in the book references n = 225. To replicate the example in the book, I&#39;m pretty sure we need to aggregate over precinct and eth, like so:<\/p>\n<pre><code class=\"r\">stops &lt;- aggregate(cbind(stops, past.arrests) ~ eth + precinct, data=dat, sum)\r\n<\/code><\/pre>\n<p>Using <code>cbind()<\/code> on stops and past.arrests allows us to sum both stops <em>and<\/em> past.arrests over all combinations of eth and precinct. Now we&#39;re ready to run the code provided in the book, which can also be found <a href=\"http:\/\/www.stat.columbia.edu\/%7Egelman\/arm\/examples\/Book_Codes.zip\">here<\/a>. Here&#39;s one of the models they fit:<\/p>\n<pre><code class=\"r\">library(arm) # for the display() function\r\nfit.2 &lt;- glm (stops ~ factor(eth), data=stops, family=poisson, offset=log(past.arrests))\r\ndisplay(fit.2)\r\n<\/code><\/pre>\n<pre>## glm(formula = stops ~ factor(eth), family = poisson, data = stops, \r\n##     offset = log(past.arrests))\r\n##              coef.est coef.se\r\n## (Intercept)  -0.59     0.00  \r\n## factor(eth)2  0.07     0.01  \r\n## factor(eth)3 -0.16     0.01  \r\n## ---\r\n##   n = 225, k = 3\r\n##   residual deviance = 45437.4, null deviance = 46120.3 (difference = 682.9)\r\n<\/pre>\n<p>That works, but our output doesn&#39;t match the book&#39;s output! What&#39;s going on? Actually the explanation is in the title of the data file: &ldquo;frisk_with_noise&rdquo;. Also notice how I skipped the first 6 lines of the file when reading it in to R. Here&#39;s the first line of what I skipped:<\/p>\n<pre>stop and frisk data (with noise added to protect confidentiality)\r\n<\/pre>\n<p>So noise was apparently added after publication of the book to protect confidentiality. I guess we&#39;re not supposed to see which precincts are making the most stops of certain ethnicities? Oh well, at least we can run the code now.<\/p>\n<p>We can see fitted values using the <code>fitted()<\/code> function. Here are the first 10 fitted values compared to their observed values:<\/p>\n<pre><code class=\"r\">cbind(observed=stops$stops[1:10], fitted=fitted(fit.2)[1:10])\r\n<\/code><\/pre>\n<pre>##    observed    fitted\r\n## 1       202  544.2816\r\n## 2       102  175.7562\r\n## 3        81  180.0316\r\n## 4       132  418.2082\r\n## 5       144  331.8515\r\n## 6        71  203.6578\r\n## 7       752 1215.1920\r\n## 8       441  373.5563\r\n## 9       410  584.9845\r\n## 10      385  261.5884\r\n<\/pre>\n<p>Doesn&#39;t look too good to the eye, at least not the first 10. How are those fitted values calculated? Like this:<\/p>\n<p>\\[y = exp(\\alpha + \\beta x + log(t)) \\]<\/p>\n<p>where t is the offset, in this case, past arrrests. So to calculate the fitted value for precinct 1, ethnicity = 1 (black), and 980 arrests in the previous year, we do the following:<\/p>\n<pre><code class=\"r\">exp(coef(fit.2)[1] + log(980))\r\n<\/code><\/pre>\n<pre>## (Intercept) \r\n##    544.2816\r\n<\/pre>\n<pre><code class=\"r\"># or equivalently\r\n980*exp(coef(fit.2)[1])\r\n<\/code><\/pre>\n<pre>## (Intercept) \r\n##    544.2816\r\n<\/pre>\n<pre><code class=\"r\"># compare to R&#39;s fitted value\r\nfitted(fit.2)[1] == exp(coef(fit.2)[1] + log(980))\r\n<\/code><\/pre>\n<pre>##    1 \r\n## TRUE\r\n<\/pre>\n<p>Plotting standardized residuals versus fitted values can reveal overdispersion. That&#39;s what Gelman and Hill do in figure 6.1. Below I reproduce it. First I fit a new model that includes precinct as a predictor. The figure on the left plots raw residuals versus fitted values. This is of limited use since we expect variance to increase with larger fitted values in a Poisson distribution. In other words we wouldn&#39;t expect to see a constant scatter about 0 as we would in OLS regression. The figure on the right, however, uses standardized residuals which have a mean of 0 and standard deviation of 1. If the Poisson model is true, we would expect to see most residuals falling within 2 standard deviations from 0. Many residuals falling beyond this range reveal overdispersion. And indeed that&#39;s what we see here.<\/p>\n<pre><code class=\"r\">fit.3 &lt;- glm (stops ~ factor(eth) + factor(precinct), data=stops, family=poisson, offset=log(past.arrests))\r\npar(mfrow=c(1,2))\r\npv &lt;- fitted(fit.3)\r\nr &lt;- (stops$stops - fitted(fit.3))\r\nplot(pv, r, pch=20, ylab=&quot;raw residuals&quot;, xlab=&quot;predicted value&quot;)\r\nabline(h=0)\r\nsr &lt;- (stops$stops - fitted(fit.3))\/sqrt(fitted(fit.3))\r\nplot(pv, sr, pch=20, ylab=&quot;standardized residuals&quot;, xlab=&quot;predicted value&quot;)\r\nabline(h=c(-2,0,2),lty=c(2,1,2))\r\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfgAAAH4CAMAAACR9g9NAAAAhFBMVEUAAAAAADoAAGYAOjoAOmYAOpAAZrY6AAA6ADo6AGY6OmY6OpA6ZrY6kJA6kNtmAABmADpmAGZmOgBmZjpmtrZmtv+QOgCQOjqQOmaQkDqQtpCQ27aQ29uQ2\/+2ZgC225C2\/7a2\/\/\/bkDrb25Db\/7bb\/9vb\/\/\/\/tmb\/25D\/\/7b\/\/9v\/\/\/9MaFRuAAAACXBIWXMAAAsSAAALEgHS3X78AAAaZElEQVR4nO2di3bcuJGGqUnsrOOsNc6uNJNspF0riXXh+7\/fNtnNbl5AoFA3FIj6z5xRmyAKLH5E4UKQ7HpXk+pKH4CrjBx8o3LwjcrBNyoH36gcfKNy8I3KwTcqB9+oHHyjcvCNysE3KgffqBx8o3LwjcrBNyoH36gcfKNy8I3KwTcqB9+oHHyjcvCNysE3KgffqBx8o3LwjcrBNyoH36gcfKNy8I3KwTcqB9+oHHyjcvCNysE3KgffqBx8o3LwjcrBNyoH36gcfKNy8I3KwTcqB9+oHHyjcvCNysE3KgffqBx8o3LwjcrBNyoH36gcfKNy8I3KwTcqB9+oHHyjooDv7IvtPB3OdxJ4Ql4dCYIXs8wlB1+ZZS45+Mosc8nBV2aZSw6+MstccvCVWeaSg6\/MMpccfGWWueTgK7PMJQdfmWUukcG\/\/WmcAPzlByLvOoP26TIE3prvycP5eHwY\/75++pmdd71\/cgKZW3bAm\/M9eTTv338s\/ubkXe9vzXlFy+Z816zx5sKdpmVrvqcP5\/2erY1XlyHw6vJefWWWueTgK7PMJUvDOXU5eGwyb+dOXQ4emxwczgFXdRmQg8cme41Xt8wlH85VZplL3quvzDKXHHxllrnEMZz79txoqD\/wUBbUuXs+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\/pre>\n<p>To correct for overdisperson in R you can repeat the code for fit.3 above with <code>family = quasipoisson<\/code>. This corrects the standard errors of the regression coefficients by making them larger. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Chapter 6 of Gelman and Hill&#39;s Data Analysis Using Regression and Multilevel\/Hierarchical Models presents an interesting example of Poisson regression&#8230; <a class=\"read-more\" href=\"https:\/\/www.clayford.net\/statistics\/poisson-regression-ch-6-of-gelman-and-hill\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,13],"tags":[54,53],"class_list":["post-705","post","type-post","status-publish","format-standard","hentry","category-regression","category-using-r","tag-glm","tag-poisson-regression"],"_links":{"self":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/comments?post=705"}],"version-history":[{"count":2,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/705\/revisions\/708"}],"wp:attachment":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/media?parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/categories?post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/tags?post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}