5

I'm fitting a gee model on a dataset including 13,500 observations (here students). Students are grouped into 52 different schools. I know that there is evidence that students are nested within schools (low ICC) and therefore I should adjust this nesting effect in the variance covariance matrix. What I'm planning to do is to first fit a gee model with exchangeable var-cov structure. Then, on top of that, I'll run Huber-White Sandwich estimator also known as robust variance estimator. I wrote my own code for robust variance estimator and it works perfectly. My gee statement doesn't work and give the error below:

NA/NaN/Inf in foreign function call (arg 3)

Here is my code:

STMath.OneYr.C1 = gee(postCSTMath1Yr ~ TRT1Yr + preCSTMath + preCSTENG + 
post1YrGradeRef + ELLBaseLine + GENDER + ECODIS + ETHNICITY.F + 
as.factor(FailedInd1Yr), data = UCI.clone[UCI.clone$COHORT0809 == "C1",], 
id =  post1YrSchIID, corstr = "exchangeable") 

Unfortunately, the code above is not reproducible for you guys and perhaps difficult to figure out what the issue is.

I appreciate if you could help me figure out to solve the issue.

Sam
  • 4,357
  • 6
  • 36
  • 60

1 Answers1

8

OK, this question is quite old but I ended up here, so this might help someone eventually.

Basically, this error was caused because unlike in other libraries, the id parameter is treated as a numeric vector.

Indeed, the gee function is casting id as a double, which I don't really understand. Here are the implicated lines (l. 119-120 of the function):

if (!(is.double(id))) 
  id <- as.double(id)

If your id column is a character, just cast it to a factor, or use some function (like dplyr::min_rank) to turn it to a numeric variable.

This should do the trick.

Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92