Most texts I have read about Poisson-regression assumes that the data is available in an already grouped form, i.e. counts are given for each unique covariate combination. For instance, we have (in R)

    Gender Counts
  1      M      6
  2      F      2

thus we can use


to run the Poisson-regression.

However, often we have individual-level data, such as

    PatientID  Gender
  1         1      M
  2         2      M
  3         3      M
  4         4      M
  5         5      M
  6         6      M
  7         7      F
  8         8      F

which is clearly identical to the above database.

The question is: how can I run the Poisson-regression on such individual-level database?

Of course, I am aware that I could simply do the counting myself, for example with


but I am interested in whether it is possible without an explicit, manual counting. Especially, whether it is possible to somehow interface DataIndividual directly to glm.

  • $\begingroup$ Yes, you can. There is an example here $\endgroup$
    – Peter Flom
    Aug 6, 2014 at 10:36
  • $\begingroup$ @PeterFlom : Well, maybe I am overlooking something, but I couldn't find the example there... The only use of glm I found was glm(num_awards ~ prog + math, family = "poisson", data = p), but here, p is just the grouped data I was speaking of (i.e. already the counts are given), see p$num_awards. My question addresses a situation where we don't have - for instance - num_awards==6, but rather 6 rows with the same StudentID. $\endgroup$ Aug 6, 2014 at 10:49
  • $\begingroup$ No, p is not grouped. It is one id per line. Try p <- read.csv("http://www.ats.ucla.edu/stat/data/poisson_sim.csv") head(p) $\endgroup$
    – Peter Flom
    Aug 6, 2014 at 11:53
  • 1
    $\begingroup$ In that case you will have to modify your data frame prior to using glm. This question should be reworded and posted to StackOverflow where programming questions are asked $\endgroup$
    – Peter Flom
    Aug 6, 2014 at 12:52
  • 1
    $\begingroup$ Yes - in other circumstances you may in fact have a truncated Poisson distribution, where you don't know how many zero counts there are. Another potential complication might be where you have the same patient ID coded as male in one row & female in another. I just wanted to point out why, IMO, glm shouldn't be trying to sort out these sort of issues for you. $\endgroup$ Aug 6, 2014 at 14:04

2 Answers 2


There are two answers to this, particularly in light of your example:

  1. The example is clearly an example, where it does not make sense to use Poisson regression. This is data with two categories (which you could regard as 0 or 1), into which each single observation can fall. Using the binomial (or multinomial, if there are more than 2 categories) distribution makes much more sense. Yes, sure for really small proportions assuming a Poisson distribution may give similar answers, but this example is not one where that would be the case.
  2. In general, if these were data, for which Poisson regression did make sense, you can just dump such observations into Poisson regression software, you just need to decide on what offset to use. The very nature of Poisson regression means that it does not care whether the total count comes from multiple individuals or a single individual. I.e. 10 individuals with counts of 0, 5, 10, 100, 85, 0, 0, 0, 50, 50 in 1 time unit each (log(1) offset in each observation), or a single individual with a count of 300 in 10 time units (log(10) offset in Poisson regression) are exactly the same to Poisson regression. This may be very implausible, because you might assume that there should be between individual variability, but in that case Poisson regression is the wrong tool (negative binomial or a random effects Poisson model would then be preferable).

Partially answered in comments. The main takeaway is this: Yes, this is a problem. Poisson regression needs the data tabled in a way such that covariates is constant in each cell, so using extra covariates in the model ay require retallying the data.

And, secondary, one should not expect glm (or equivalents in other software than R) to do the tallying. Data can come in many different formats, and (re)arranging the data is a proper format tidying the data should be done prior to analysis. The complications caused by data formats (some discussed in the comments) are orthogonal to the complications of analysis, and should be tackled as a different problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.