{"id":499,"date":"2018-09-25T19:05:10","date_gmt":"2018-09-26T02:05:10","guid":{"rendered":"https:\/\/blogs.ubc.ca\/datawithstata\/?page_id=499"},"modified":"2019-05-08T18:40:20","modified_gmt":"2019-05-09T01:40:20","slug":"poisson-regression-2","status":"publish","type":"page","link":"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/poisson-regression-2\/","title":{"rendered":"Regression with Count Variable"},"content":{"rendered":"<p>When the dependent variable is a non-negative count variable, the standard <abbr class='c2c-text-hover' title='Ordinary Least Square'>OLS<\/abbr> regression is no longer valid. Typically, the Poisson regression or some variation of it is used to analyze such count data. Here we will discuss the <strong>Poisson<\/strong>, <strong>Negative Binomial<\/strong>, and <strong>Zero-Inflated Negative Binomial<\/strong> regressions along with their <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> implementations.<\/p>\n<h3>Poisson Regression<\/h3>\n<p>Poisson regression fits models of the number of occurrences (counts) of an event where it is assumed that the number of occurrences follow a Poisson distribution. The Poisson distribution has been applied to diverse events with the following basic assumptions:<\/p>\n<ol>\n<li>There is a quantity called the <em>incidence rate<\/em> that is the rate at which events occur, e.g., 5 per second, 20 per square metre, etc.<\/li>\n<li>The incidence rate can be multiplied by <em>exposure<\/em> to obtain the expected number of observed events, e.g., a rate of 5 per second multiplied by 30 seconds means that 150 events are expected.<\/li>\n<li>Over very small exposures, the probability of finding more than one event is small compared with the exposure length.<\/li>\n<li>Non-overlapping exposures are mutually independent.<\/li>\n<\/ol>\n<p>With these assumptions, to find the probability of <em>k<\/em> events in an exposure of size <em>E<\/em>, one divides <em>E<\/em> into <em>n <\/em>sub-intervals, and approximate the answer as the binomial probability of observing <em>k<\/em> successes in <em>n<\/em> trials. By letting <em>n <\/em>to be arbitrarily large, one obtains the Poisson distribution.<\/p>\n<p>In the Poisson regression model, the incidence rate of the<em> j<\/em><sup>th<\/sup> observation is assumed to be given by<em> r<sub>j<\/sub> = exp(b<sub>0<\/sub>+b<sub>1<\/sub>x<sub>1j<\/sub>+b<sub>2<\/sub>x<sub>2j<\/sub>)\u00a0<\/em>if\u00a0x<sub>1<\/sub> and\u00a0x<sub>2<\/sub> were the two explanatory variables. If <em>E<sub>j<\/sub><\/em> is the exposure, the expected number of events will be C<em><sub>j<\/sub>\u00a0= exp[ln(E<sub>j<\/sub>)+ b<sub>0<\/sub>+b<sub>1<\/sub>x<sub>1j<\/sub>+b<sub>2<\/sub>x<sub>2j<\/sub>]<\/em>.<\/p>\n<p>The parameters are computed using a log-likelihood function which is:<\/p>\n<p>ln<em>L<\/em> = \u2211 [ y<sub>j<\/sub>*\u03b2*x &#8211; r<sub>j<\/sub> \u2013 lny<sub>j<\/sub>!]<\/p>\n<h4><span style=\"color: #dd3396;\">Example:<\/span><\/h4>\n<p>We have data on the number of deaths, average age in months and the total number of person-years of exposure to risk\u00a0 of the children between birth and age 10 for three cohorts of children born in 1941\u201349, 1960\u201367, and 1968\u201376.\u00a0 We want to understand how the deaths of the children changes with age of the children. This falls under running a regression with Count variable and\u00a0\u00a0a Poisson regression can be implemented (to install the data in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>Stata<\/abbr>, type: <strong>webuse\u00a0<\/strong>rod93, clear). Before we run a Poisson regression, generate <em>logexposure<\/em> as natural log of exposure.<\/p>\n<p><a id=\"poisson\"><\/a><strong>poisson<\/strong> deaths age_mos, <strong>exposure(<\/strong><em>logexposure<\/em><strong>)<br \/>\n<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1240\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson-300x150.png\" alt=\"\" width=\"502\" height=\"250\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson-300x150.png 300w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson-400x199.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson.png 626w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/p>\n<ul>\n<li>The option <strong>exposure()<\/strong> dictates <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to restrict the coefficient of ln(<em>logexposure<\/em>) to be 1.\u00a0 Note that without the <strong>exposure()<\/strong> option, the exposure <em>E<sub>j\u00a0<\/sub><\/em> is assumed to be 1.<\/li>\n<li>The coefficient of <em>age_mos<\/em> implies that the expected change in the log count of the number of deaths as age increases by one unit is -0.017.<\/li>\n<\/ul>\n<p>Often in Poisson regressions, one is interested in comparing the incidence rates. This is easily done by calculating incidence-rate ratios (IRR). The IRR for a one-unit change in <em>x<sub>i<\/sub><\/em> is <em>exp(b<sub>i<\/sub>)\u00a0<\/em>or in other words, the ratio of the expected number of events for a unit increase in the explanatory variable to the expected number of events. The option <strong>irr<\/strong> tells <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> to report the incidence-rate ratios <em>exp(b<sub>1<\/sub>) <\/em>and<em> exp(b<sub>2<\/sub>) <\/em>instead of the coefficients <em>b<sub>1<\/sub><\/em><em> and <\/em><em>b<sub>2<\/sub><\/em>.<\/p>\n<p><a id=\"poisson_irr\"><\/a><strong>poisson<\/strong> deaths age_mos, <strong>exposure(<\/strong>E<strong>) irr<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1241\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_irr-300x152.png\" alt=\"\" width=\"498\" height=\"252\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_irr-300x152.png 300w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_irr-400x203.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_irr.png 628w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/p>\n<ul>\n<li>The table shows that the percent change in the number of deaths for a unit increase in age is (0.983-1) = -1.7%.<\/li>\n<\/ul>\n<h3>Negative Binomial (NB) Regression<\/h3>\n<p>Similar to a Poisson regression, in a Negative Binomial regression the dependent count variable is believed to be generated by a Poisson-like process, except that the variation is greater than that of a true Poisson. This extra variation is referred to as <em>overdispersion<\/em>, which may arise due to an omitted explanatory variable.<\/p>\n<p>One derivation of the negative binomial mean-dispersion model is that individual units follow a Poisson regression model, but there is an omitted variable <em>Z<sub>j<\/sub><\/em>, such that <em>exp(Z<sub>j<\/sub>)<\/em> follows a Gamma distribution with mean 1 and variance <em>v<\/em>: <em>Y<sub>j<\/sub> <\/em><em>~ Poisson(M<sub>j<\/sub>)<\/em> where <em>M<sub>j<\/sub> = exp(b<sub>0<\/sub> + b<sub>1<\/sub>X<sub>1j<\/sub> + b<sub>2<\/sub>X<sub>2j<\/sub> + ln(E<sub>j<\/sub>) + Z<sub>j<\/sub>)<\/em> , <em>exp(Z<sub>j<\/sub>) <\/em><em>~ Gamma(1\/v, v) <\/em>and\u00a0<em>E<sub>j<\/sub> <\/em> is the exposure variable. We refer to <em>v <\/em>as the overdispersion parameter. The larger <em>v <\/em>is, the greater the overdispersion.<\/p>\n<h4><span style=\"color: #dd3396;\">Example:<\/span><\/h4>\n<p>Lets, return to the above example. In <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>, a Negative Binomial (mean-dispersion) regression can be executed by the following command:<\/p>\n<p><a id=\"nbreg\"><\/a><strong>nbreg <\/strong>deaths age_mos, <strong>offset(<\/strong><em>logexposure<\/em><strong>)<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1242\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/nbreg-244x300.png\" alt=\"\" width=\"406\" height=\"500\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/nbreg-244x300.png 244w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/nbreg-400x492.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/nbreg.png 632w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/p>\n<ul>\n<li>The option <strong>offset() <\/strong>is akin to the <strong>exposure()<\/strong> option in Poisson regression with the only difference being that\u00a0<strong>offset()<\/strong> does not automatically transform the exposure variable into its natural logarithm. Nevertheless, <strong>offset()<\/strong> restricts the coefficient of e(=ln(E)) to be equal to 1 in the regression.<\/li>\n<li>The coefficient of <em>age_mos<\/em> implies that the decrease in the expected log count of the number of deaths is 0.05.<\/li>\n<li><abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> also reports the estimate of the overdispersion parameter <em>v<\/em><span style=\"color: #444444;\">, which it calls<\/span><em> alpha. <\/em>It also reports the null hypothesis of <em>alpha<\/em> is equal to 0 in the last line of the output table. In a Poisson model, <em>alpha<\/em> is equal to 0 by assumption but in a Negative binomial model it is not. The test of the null hypothesis thus tells us if the Poisson model is appropriate or not. In this case, the null hypothesis that <em>alpha<\/em> is equal to 0 is rejected at lower than 1% level of significance, thus, the Poisson model is not the appropriate model to run.<\/li>\n<\/ul>\n<p><abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> allows the overdispersion parameter to be modelled as a linear combination of some observable variables <em>V<sub>1<\/sub><\/em> and <em>V<sub>2<\/sub><\/em> (say), that is, <em>ln(v<sub>j<\/sub>) = c<sub>0<\/sub> + c<sub>1<\/sub>V<sub>1j<\/sub> + c<sub>2<\/sub>V<sub>2j<\/sub><\/em>.<\/p>\n<p>Suppose, we think in our example that the overdispersion varies across cohorts. To implement such a specification in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr>, one needs to use the following command:<\/p>\n<p><strong>nbreg <\/strong>deaths age_mos, <strong>offset(<\/strong><em>logexposure<\/em><strong>)<\/strong> <strong>lnalpha(<\/strong>i.cohort<strong>)<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1243\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/gnbreg-272x300.png\" alt=\"\" width=\"453\" height=\"500\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/gnbreg-272x300.png 272w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/gnbreg-400x441.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/gnbreg.png 633w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/p>\n<ul>\n<li>The command <strong>gnbreg <\/strong><span style=\"color: #444444;\">stands for Generalized Negative Binomial Regression. <\/span><\/li>\n<li><strong>lnalpha()<\/strong><span style=\"color: #444444;\"> allows one to list the variables that affect the overdispersion parameter.<\/span><\/li>\n<li>The interpretation of the coefficient on age remains the same as before.<\/li>\n<li>Moreover, as we can see the coefficient on the <em>lnalpha<\/em> for the cohort 1960-1967 and 1968-1976 are slightly higher compared to the reference cohort 1940-1947, but these estimates are not significantly different so, overdispersion does not vary by cohorts.<\/li>\n<\/ul>\n<p>In a mean-dispersion Negative Binomial regression, the dispersion for the <em>j<\/em><sup>th<\/sup> observation is equal to 1 + <em>exp(b<sub>0<\/sub> + b<sub>1<\/sub>X<sub>1j<\/sub> + b<sub>2<\/sub>X<sub>2j<\/sub> + ln(E<sub>j<\/sub>) ), <\/em>that is, the dispersion for every observation is different. Another option is to have a constant dispersion, say <em>(1+delta)<\/em>, across all observations. The constant-dispersion Negative Binomial regression model assumes <em>M<sub>j <\/sub><\/em><em>~ Gamma(exp(b<sub>0<\/sub> + b<sub>1<\/sub>X<sub>1j<\/sub> + b<sub>2<\/sub>X<sub>2j<\/sub> + ln(E<sub>j<\/sub>))\/delta, delta)<\/em> instead of<em> M<sub>j <\/sub>~ Gamma(1\/v, v.exp(b<sub>0<\/sub> + b<sub>1<\/sub>X<sub>1j<\/sub> + b<sub>2<\/sub>X<sub>2j<\/sub> + ln(E<sub>j<\/sub>))) <\/em>in the mean-dispersion model. The Poisson model corresponds to either <em>d=0<\/em> or <em>v=0<\/em> depending on the type of Negative Binomial model considered.<\/p>\n<p>Continuing the example from Poisson regression, we can implement the Negative Binomial model in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> with the following command:<\/p>\n<p><strong>nbreg deaths <\/strong>age_mos<strong>, offset(<\/strong><em>logexposure<\/em><strong>) dispersion(constant)<\/strong><\/p>\n<ul>\n<li>The output table is not shown for brevity.<\/li>\n<li>The interpretation of the coefficient on <em>age_mos<\/em> remains the same as before.<\/li>\n<\/ul>\n<h3>How to choose between Poisson and Negative Binomial?<\/h3>\n<p><em>Step 1:<\/em> Run the Poisson regression.<\/p>\n<p><strong>poisson<\/strong> deaths age_mos, <strong>exposure(<\/strong><em>logexposure<\/em><strong>)<\/strong><\/p>\n<p><em>Step 2:<\/em> Run the goodness of fit test<\/p>\n<p><a id=\"gof\"><\/a><strong>estat gof<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1244\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_gof-300x113.png\" alt=\"\" width=\"300\" height=\"113\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_gof-300x113.png 300w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/poisson_gof.png 386w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><em>Step 3:<\/em> If the <strong>Prob&gt;chi2()<\/strong> is very close to zero (that is, lower than 0.05) then run the Negative Binomial regression. Else stick with the Poisson model. In this case, the p-value is very small so, the Poisson model is inappropriate for our example.<\/p>\n<h3>Zero-Inflated Negative Binomial (ZINB) Regression<\/h3>\n<p>Sometimes the count of zeros in a sample is much larger than the count of any other frequency. In other words, the number of zeros are inflated. In that case, instead of using the ordinary negative binomial or Poisson regression, one should run the Zero-Inflated Negative Binomial model. Obviously, how much zero-inflation is enough to call for the choice of this zer-inflated model is a matter of modelling preference, which is resolved by statistical tests discussed below. Specifically, one needs to test the ZINB model against both the ordinary NB model and the Zero-Inflated Poisson (ZIP) model.<\/p>\n<p>A zero-inflated model assumes that zero outcome is due to two different processes. For example, if different groups of campers are asked how many fishes they caught, the response can be zero due to two separate reasons: one, a camper has gone fishing but did not catch a fish, and two, the camper did not go fishing at all. Thus the two processes here are that a camper has gone fishing versus not gone fishing (which is essentially a binary choice Logit model) and if gone for fishing then the count of the number of fish caught (which is the Poisson or Negative Binomial part of the count model). In other words, the expectation of the event that k fishes were caught is given by the formula, E(k fishes caught) = Prob(Not gone fishing)*0 + Prob(Gone fishing)*E(k fishes caught | Gone fishing).<\/p>\n<h4><span style=\"color: #dd3396;\">Example:<\/span><\/h4>\n<p>Lets look at the following example, where we have data on 250 families that went to a park where they could do fishing if they wanted but we do not have data on whether a family fished or not. Each family was asked about how many fish they caught (<strong>count<\/strong>), whether or not they brought a camper to the park (<strong>camper<\/strong>), how many children were in the group (<strong>child<\/strong>), how many people (including children) were in the group (<strong>persons<\/strong>), and a dummy variable (<strong>livebait<\/strong>) which takes the value 1 if they brought a livebait while fishing\u00a0 and 0 otherwise.<\/p>\n<p>We are interested in predicting the factors that affect the number of fish caught but also in predicting the number of excess zeros since our data has many of them\u00a0 (142 of 250). We will run the ZINB model in <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> along with the tests of model selection can be done using the following command:<\/p>\n<p><a id=\"zinb\"><\/a><strong>zinb<\/strong> count child camper<strong>, inflate(<\/strong>persons<strong>) <\/strong><strong>vuong zip nolog<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1245\" src=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/zinb-300x229.png\" alt=\"\" width=\"523\" height=\"400\" srcset=\"https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/zinb-300x229.png 300w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/zinb-400x306.png 400w, https:\/\/blogs.ubc.ca\/datawithstata\/files\/2019\/05\/zinb.png 633w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/p>\n<ul>\n<li>The coefficient of <em>child\u00a0<\/em>implies that the expected change in log count for a one-unit increase in child is -1.51.<\/li>\n<li>The coefficient of <em>camper<\/em> implies that a camper has a higher log count of fish caught (by .88) than a non-camper.<\/li>\n<li>Both these results came from running a negative binomial model.<\/li>\n<li>The option <strong>inflate(<\/strong><strong>) <\/strong>tells <abbr class='c2c-text-hover' title='Statistical Software for Data Analysis'>STATA<\/abbr> that the variable person needs to be used to estimate the binary choice (or Logit) part of the process that generates the zero outcome.<\/li>\n<li>The log odds of being an excessive zero would decrease by 1.67 for every additional person in the group.<\/li>\n<li>The option <strong>vuong<\/strong><span style=\"color: #444444;\"> tests the zero-inflated negative binomial model with an ordinary negative binomial regression model. A significant z-test indicates that the zero-inflated model is preferred. The Vuong test suggests that the zero-inflated negative binomial model is a significant improvement over a standard negative binomial model.<\/span><\/li>\n<li>The option <strong>zip<\/strong> tests the ZINB model against the ZIP model. A significant likelihood ratio test for the overdispersion parameter, <em>alpha<\/em>=0 indicates that the ZINB model is preferred to the ZIP model. We can see at the bottom of our model that the likelihood ratio test that\u00a0<em>alpha<\/em> = 0\u00a0is significantly different from zero.\u00a0 This suggests that our data is overdispersed and that a zero-inflated negative binomial model is more appropriate than a zero-inflated Poisson model.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When the dependent variable is a non-negative count variable, the standard <abbr class='c2c-text-hover' title='Ordinary Least Square'>OLS<\/abbr> regression is no longer valid. Typically, the Poisson regression or some variation of it is used to analyze such count data. Here we will discuss the Poisson, Negative &hellip; <a href=\"https:\/\/blogs.ubc.ca\/datawithstata\/home-page\/regression\/poisson-regression-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":7089,"featured_media":0,"parent":170,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"full-width-page.php","meta":{"footnotes":""},"class_list":["post-499","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/users\/7089"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/comments?post=499"}],"version-history":[{"count":32,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/499\/revisions"}],"predecessor-version":[{"id":1254,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/499\/revisions\/1254"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/pages\/170"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/datawithstata\/wp-json\/wp\/v2\/media?parent=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}