% \VignetteIndexEntry{Knee Injuries - Marginal Models} % \VignetteDepends{gee, geepack} %\VignetteEngine{knitr::knitr} %\VignetteEncoding{UTF-8} \documentclass[a4paper]{article} \title{Knee Injuries - Marginal Models} \begin{document} \maketitle <>= options(width=80) @ First the dataset knee is loaded: <>= library(catdata) data(knee) attach(knee) @ To obtain a simple binary model the response variables are dichotomized. The groups are constructed by pain level up to level 2 und pain level higher than level 2. <>= R2D <- rep(0, length(R2)) R3D <- rep(0, length(R3)) R4D <- rep(0, length(R3)) R2D[R2>2] <- 1 R3D[R3>2] <- 1 R4D[R4>2] <- 1 @ Now the covariates have to be transformed so that they can be used for the functions "gee" from the "gee"--library and "geeglm" from the "geepack"--library, which will be employed for fitting the models. <>= N <- rep(knee$N, each=3) Th <- rep(knee$Th, each=3) Age <- rep(knee$Age, each=3) Sex <- rep(knee$Sex, each=3) @ Now the response vector is built and the quadratic age--effect "Age2" is computed. <>= Response <- c(rbind(R2D,R3D,R4D)) Age2 <- Age^2 @ The covariates therapy and sex are treated as factors: <>= Th <- as.factor(Th) Sex <- as.factor(Sex) @ First the GEEs are fitted with the funtion "gee" from library "gee". <>= library(gee) @ The first model is a GEE with independent correlation structure: <>= gee1a <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit)) @ <>= summary(gee1a) @ The second model is a GEE with exchangeable correlation structure: <>= gee2a <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="exchangeable") @ <>= summary(gee2a) @ Finally a GEE with exponential correlation structure is fitted: <>= gee3a <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="AR-M", Mv=1) @ <>= summary(gee3a) @ In the following the corresponding marginal models are fitted with the function "geeglm" from the library "geepack". <>= library(geepack) @ Model with independent correlation structure: <>= gee1b <- geeglm(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit)) @ <>= summary(gee1b) @ Model with exchangeable correlation structure: <>= gee2b <- geeglm(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="exchangeable") @ <>= summary(gee2b) @ Model with exponential correlation structure: <>= gee3b <- geeglm(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="ar1") @ <>= summary(gee3b) @ \bigskip For comparison a simple GLM with logit--link is fitted with the same covariates as in the marginal models above: <>= glm1 <- glm(Response ~ Th + Sex + Age + Age2, family=binomial(link=logit)) summary(glm1) @ It is often advatageous to center the variables like age around a value in the middle of its range. So now the marginal models from above are replicated with age centered around 30 years. <>= Age <- Age-30 Age2 <- Age^2 @ Again we use the function "gee" from the "gee"--library for fitting those models. \bigskip Model with independent correlation structure and centered age: <>= gee1c <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit)) @ <>= summary(gee1c) @ Model with exchangeable correlation structure and centered age: <>= gee2c <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="exchangeable") @ <>= summary(gee2c) @ Model with exponential correlation structure and centered age: <>= gee3c <- gee(Response ~ Th + Sex + Age + Age2, id=N, family=binomial(link=logit), corstr="AR-M", Mv=1) @ <>= summary(gee3c) @ \end{document}