Skip to contents

Estimate marginal effects with generalized estimating equations. Data must be in long format.

Usage

fit_gee(data, formula, id, family, corstr)

Examples

# Load repeated measures of adolescent tooth growth (must be of long format)
data <- read.csv("https://raw.githubusercontent.com/alejandroh3005/modelLong/main/data/ortho.csv")[-1]

# Define subject/cluster ID
id <- as.factor(data$Subject)

# Fit a GEE model of adolescent tooth growth from age and sex
mod_gee <- modelLong::fit_gee(
  data = data,
  formula = formula(distance ~ age + Sex),
  id = id,
  family = gaussian(),
  corstr = "independence")

# Fitted coefficients
coef(mod_gee$fit)
#> (Intercept)         age     SexMale 
#>  17.5513997   0.4263492   2.7373106 

# Full model
mod_gee$fit
#> 
#> Call:
#> geepack::geeglm(formula = formula, family = family, data = data, 
#>     id = id, corstr = corstr)
#> 
#> Coefficients:
#> (Intercept)         age     SexMale 
#>  17.5513997   0.4263492   2.7373106 
#> 
#> Degrees of Freedom: 162 Total (i.e. Null);  159 Residual
#> 
#> Scale Link:                   identity
#> Estimated Scale Parameters:  [1] 5.67822
#> 
#> Correlation:  Structure = independence  
#> Number of clusters:   162   Maximum cluster size: 1 
#>