I have simulated some longitudinal data with 100 subjects and 7 measurements per subject. My data has random intercept which will induce "exchangeable" correlation matrix. My goal is to fit two separate models below and compare the results:

  1. Model 1: GLM (not accounting for within-subj correlation)
  2. Model 2: GEE with exchangeable correlation structure

We know that GLM is basically GEE with "Independent" correlation structure. What happens is my GEE only takes ONE iteration and therefore returns the estimates from it's first iteration (initial estimates) which are GLM estimates (Code is in R).

I've tried different simulation scenarios where the estimated exchangeable correlation matrix has: Low, medium, and high off-diagonal correlation values but in all of them my GLM estimates and GEE estimates are all the same (that is over 2000 different simulated data and 100% of estimates are the same between GEE and GLM). Why do you think this happens?

Here is my code:

# Data Simulation:
dataSim <- function(seedNum, n, mi, beta0FE, beta1, beta0RE){

      # Setting the seed number:

      # Generating covariates:
      x <- rnorm(n, mean = 0, sd = 1)

      # Generating Y:
      data <- data.frame(id = rep(1:n, each = mi), x = rep(x, each = mi), 
                 beta0_RE = rep(beta0RE, each = mi))
      etaTmp <- data$beta0_RE + beta0FE + beta1*data$x
      piTmp <- exp(etaTmp)/(1 + exp(etaTmp))
      data$Y <- sapply(piTmp, rbinom, n = 1, size = 1)  

# Data Simulation Parameters:
n <- 300
mi <- 7
beta0FE <- 0.3
beta1 <- 1
beta0RE <- rnorm(n, mean = 0, sd = 1)

data <- dataSim(1, n, mi, beta0FE, beta1, beta0RE)
fit.glm <- glm(Y ~ x, data = data, family='binomial')
fit.gee <- gee(Y ~ x, id = id, data = data, family = binomial, 
               corstr = "exchangeable", silent = TRUE)

The parameter estimates of the intercept and slope are the same for GLM and GEE, which is expected. The standard errors, however, are different, which is also expected. GEE used the exchangeable covariance to adjust the standard errors in order to account for the correlation within ID that was induced in the $Y$ values by adding a random intercept for each ID.


Might know the answer. GEE won't work if your id variable is not 'sorted' in the data frame. Check to make sure it's 'clustered' in order.

From the GEE documentation: "id: a vector which identifies the clusters. The length of id should be the same as the number of observations. Data are assumed to be sorted so that observations on a cluster are contiguous rows for all entities in the formula."


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.