library(gee) library(lme4) setwd("C:/Users/knapp/Documents/Guido/GemischteModelle/Datensätze") epilepsy <- read.table("Epilepsy.txt", header=TRUE) str(epilepsy) head(epilepsy) itp <- interaction(epilepsy$treatment, epilepsy$period) tapply(epilepsy$seizure.rate, itp, mean) tapply(epilepsy$seizure.rate, itp, var) # # Offset log(2) per <- rep(log(2), nrow(epilepsy)) epilepsy$period <- as.numeric(epilepsy$period) names(epilepsy)[names(epilepsy) == "treatment"] <- "trt" fm <- seizure.rate ~ base + age + trt + offset(per) # Log-lineares Poisson-Modell epilepsy_glm <- glm(fm, data=epilepsy, family = "poisson") summary(epilepsy_glm) # Overdispersion im log-linearen Poisson-Modell epilepsy_glm1 <- glm(fm, data=epilepsy, family = "quasipoisson") summary(epilepsy_glm1) anova(epilepsy_glm1, epilepsy_glm) library(MASS) # Log-lineare Negativ-Binomial-Modell epilepsy_glm_nb <- glm.nb(fm, data=epilepsy) summary(epilepsy_glm_nb) # GEE epilepsy_gee1 <- gee(fm, data=epilepsy, family = "poisson", id=subject, corstr = "independence", scale.fix = TRUE, scale.value = 1) summary(epilepsy_gee1) epilepsy_gee2 <- gee(fm, data=epilepsy, family = "poisson", id=subject, corstr = "exchangeable", scale.fix = TRUE, scale.value = 1) summary(epilepsy_gee2) # Bringt die unstrukturierte Kovarianzstruktur noch eine Verbesserung? # Berücksichtignung von Overdispersion epilepsy_gee3 <- gee(fm, data=epilepsy, family = "poisson", id=subject, corstr = "exchangeable", scale.fix = FALSE, scale.value = 1) summary(epilepsy_gee3) # Bringt die unstrukturierte Kovarianzstruktur noch eine Verbesserung? # Berücksichtigung von Zero-Inflation epilepsy$subject <- as.factor(epilepsy$subject) library(glmmADMB) epilepsy_admb <- glmmadmb(fm, random = ~1|subject, data = epilepsy, family = "poisson", corStruct = "diag", zeroInflation=TRUE) summary(epilepsy_admb)