## ----setup, message=FALSE, warning=FALSE,include=TRUE------- library(lme4) library(lmerTest) library(gee) # for generalized estimating equations library(MASS) # For confidence limits for parameters ## ----data--------------------------------------------------- resp <- read.table(file="D:/Dropbox/edps587/lectures/10 logreg/respitory.txt", header=TRUE) head(resp) ## ----logreg------------------------------------------------- # glm = Generalized Linear model model1 <- glm(resp ~ 1 + age, data=resp, family=binomial) summary(model1) ## ----------------------------------------------------------- round(confint(model1, level = 0.95),digits=2) ## ----------------------------------------------------------- odds <- exp(coefficients(model1)) round(odds,digits=2) odds2 <- 1/odds round(odds2,digits=2) ## ----quasibinom--------------------------------------------- model1b <- glm(resp ~ 1 + age, data=resp, family=quasibinomial) summary(model1b) ## ----gee---------------------------------------------------- model.gee <- gee(resp ~1 + age, id, data=resp,family=binomial,corstr="exchangeable") summary(model.gee) ## ----laplace------------------------------------------------ mod1.laplace <- glmer(resp ~ 1 + age + (1 | id), data=resp, family=binomial) summary(mod1.laplace) ## ----mle---------------------------------------------------- mod1.quad <- glmer(resp ~ 1 + age + (1 | id),data=resp, family=binomial, nAGQ=10 ) summary(mod1.quad) ## ----------------------------------------------------------- round(confint(mod1.quad),digits=4) ## ----mleodds------------------------------------------------ odds <- exp(fixef(mod1.quad)) round(odds,digits=2) ## ----extractR, eval=TRUE------------------------------------ setwd("D:/Dropbox/edps587/lectures/10 logreg") knitr::purl("Rmarkdown_respitory_example.Rmd","rscript_logreg_respitory.txt")