# modeling clustered data with GEE library(dplyr) library(tidyverse) library(geepack) library(gee) gss = read.csv(file.choose(), header=T) # "gss.confidence.csv" gss$c.age = gss$age - mean(gss$age) head(gss) table(gss$question, gss$conf) # all observations independent fit.glm = glm(greatly~question, data=gss, family=binomial(link='logit')) summary(fit.glm) # gee with independent corr structure fit.ind = geeglm(greatly~question, data=gss, id=id, family=binomial, corstr="independence", scale.fix=T) summary(fit.ind) anova(fit.ind) # gee with exchangeable corr structure fit.exch = geeglm(greatly~question, data=gss, id=id, family=binomial, corstr="exchangeable", scale.fix=T) summary(fit.exch) # gee with unstructured corr structure fit.un = geeglm(greatly~question, data=gss, id=id, family=binomial, corstr="unstructured", scale.fix=T) summary(fit.un) # gee with age covariate fit.age = geeglm(greatly~question+age, data=gss, id=id, family=binomial, corstr="exchangeable", scale.fix=T) summary(fit.age)