4
$\begingroup$

I want to fit a regression model to see whether these is changes in the proportion of First-year students over years. I have count data for the total count of First-year students (FirstTimeStudents) and total count of all students (TotalStudents). I want to fit a GEE model with this data and wrote the following code. My output for coefficients are all NA

combFirstYear = geeglm(cbind(data$FirstTimeStudents, data$TotalStudents -
data$FirstTimeStudents) ~ Year, family=binomial(logit), data=data, id=DeptID,
corstr="independence")

summary(combFirstYear)

The reason I fit the model this way is because I read on this website about doing similar thing using glm and it works. But for some reasons, it does not work with geeglm. If anyone can think of different way of answering this question in terms of proportion, I'd really appreciate it too.

It says: "R can handle this using glm with the binomial(link="logit") family, with a dependent variable that is actually a two-vector object, the first being the number of 'successes' and the second the number of 'failures'."

Here's an example by modeling hemlock cover with respect to total cover. The example is a bit forced (as these are not actual samples of individuals) but you get the idea. We start by generating the summed cover of all species for each plot:

sumcover = tapply(dat$cover,dat$plotID,sum)`

coverdat = data.frame(names(sumcover),sumcover)

Now we merge these data with our dat5 hemlock object, based on plotID:

dat6 = merge(dat5,coverdat,all.x=T,by.x=1,by.y=1)

And create our response variables of hemlock cover (successes) and total cover minus hemlock cover (failures):

cover.y = cbind(dat6$cover,dat6$sumcover-dat6$cover)

We can now model these data as a binomial process of varying number of trials per observation: glm6 = glm(cover.y~disturb*elev,data=dat6,family=binomial)

summary(glm6)

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use the weights parameter of geeglm to incorporate the total counts. This formulation of the model requires the response to be the proportion (rather than raw counts), with the weights parameter set equal to the total counts.

In this case, the call would look like:

data$FirstTimeProp <- data$FirstTimeStudents / data$TotalStudents

combFirstYear <- geeglm(data$FirstTimeProp ~ Year, family=binomial(logit), 
                        data=data, id=DeptID, corstr="independence",
                        weights = data$TotalStudents)

This approach also works with the glm function.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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