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)
DataGrouped<-data.frame(Gender=as.factor(c("M","F")),Counts=c(6,2))
DataGrouped
Gender Counts
1 M 6
2 F 2
thus we can use
glm(Counts~Gender,data=DataGrouped,family=poisson)
to run the Poisson-regression.
However, often we have individual-level data, such as
DataIndividual<-data.frame(PatientID=1:8,Gender=as.factor(c(rep("M",6),rep("F",2))))
DataIndividual
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
glm(Freq~Var1,data=data.frame(table(DataIndividual$Gender)),family=poisson)
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
.
glm
I found wasglm(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), seep$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$p <- read.csv("http://www.ats.ucla.edu/stat/data/poisson_sim.csv") head(p)
$\endgroup$glm
shouldn't be trying to sort out these sort of issues for you. $\endgroup$