################################################### ### chunk number 1: ################################################### #line 7 "case-paincov.Rnw" pp <- read.delim("http://rem.ph.ucla.edu/rob/mld/data/tabdelimiteddata/pain.txt") pp$trt <- as.character(pp$treatment) pp$trt[pp$trial<=3] <- "baseline" pp$trt <- factor(pp$trt, levels=c("baseline","attend","distract","no directions")) pp <- subset(pp, !is.na(pp$l2paintol)) ################################################### ### chunk number 2: ################################################### #line 15 "case-paincov.Rnw" source("printnotsoshort.R") library(nlme) library(multcomp) summ <- function(m) { K <- rbind(`attenders, attend-distract`= c(0,1,-1,0,0,0,0,0), `distracters, attend-distract`= c(0,1,-1,0,0,1,-1,0)) print(summary(m)) cat("\nA couple pairwise comparisons...\n") print(summary(glht(m, linfct=K))) } out <- list() ################################################### ### chunk number 3: ################################################### #line 33 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, data=pp) summary(m) K <- rbind(`attenders, attend-distract`= c(0,1,-1,0,0,0,0,0), `distracters, attend-distract`= c(0,1,-1,0,0,1,-1,0)) summary(glht(m, linfct=K)) out$IND <- m ################################################### ### chunk number 4: ################################################### #line 43 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~1|id, data=pp) out$RI <- m summ(m) ################################################### ### chunk number 5: ################################################### #line 50 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~trial|id, data=pp) summ(m) out$RIAS <- m ################################################### ### chunk number 6: ################################################### #line 57 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corAR1(form=~1|id), data=pp) summ(m) out$AR1 <- m ################################################### ### chunk number 7: ################################################### #line 64 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corARMA(form=~1|id, p=1, q=1), data=pp) summ(m) out$ARMA <- m ################################################### ### chunk number 8: ################################################### #line 71 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corARMA(form=~1|id, p=0, q=1), data=pp) summ(m) out$MA <- m ################################################### ### chunk number 9: ################################################### #line 78 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~1|id, correlation=corAR1(form=~1|id), data=pp) summ(m) out$AR1 <- m ################################################### ### chunk number 10: ################################################### #line 85 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corAR1(form=~1|id), weights=varIdent(form=~1|trial), data=pp) summ(m) out$AR1.byTrial <- m ################################################### ### chunk number 11: ################################################### #line 93 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~1|id, weights=varIdent(form=~1|trial), data=pp) summ(m) out$RI.byTrial <- m ################################################### ### chunk number 12: ################################################### #line 102 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corSymm(form=~1|id), data=pp) summ(m) out$UNCOR <- m ################################################### ### chunk number 13: ################################################### #line 109 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corSymm(form=~1|id), weights=varIdent(form=~1|trial), data=pp) summ(m) out$UN <- m ################################################### ### chunk number 14: ################################################### #line 116 "case-paincov.Rnw" mya <- function(x) { a1 <- anova(out$IND, x)[2,] a2 <- anova(out$UN, x)[2,] if(is.null(a1$L.Ratio)) {a1$L.Ratio <- a1$`p-value` <- NA} if(is.null(a2$L.Ratio)) {a2$L.Ratio <- a2$`p-value` <- NA} c(df=a1$df, AIC=a1$AIC, BIC=a1$BIC, logLik=a1$logLik, LRT.IND=a1$L.Ratio, p.IND=a1$`p-value`, LRT.UN=a2$L.Ratio, p.UN=a2$`p-value`) } res <- lapply(out, mya) res <- as.data.frame(do.call(rbind, res)) res$p.UN <- round(res$p.UN, 5) res[order(res$BIC),] ################################################### ### chunk number 15: ################################################### #line 131 "case-paincov.Rnw" out <- list() ################################################### ### chunk number 16: ################################################### #line 136 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, data=pp, weights=varIdent(form=~1|cs)) summ(m) out$IND <- m ################################################### ### chunk number 17: ################################################### #line 143 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~1|id, data=pp, weights=varIdent(form=~1|cs)) summ(m) out$RI.byCS <- m ################################################### ### chunk number 18: ################################################### #line 150 "case-paincov.Rnw" m <- lme(l2paintol ~ trt*cs, random=~1|id, data=pp, weights=varIdent(form=~1|cs)) summ(m) out$RI.byCS <- m ################################################### ### chunk number 19: ################################################### #line 158 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corAR1(form=~1|id), weights=varIdent(form=~1|cs), data=pp) summ(m) out$AR1.byCS <- m ################################################### ### chunk number 20: ################################################### #line 166 "case-paincov.Rnw" m <- gls(l2paintol ~ trt*cs, correlation=corSymm(form=~1|id), weights=varIdent(form=~1|cs*trial), data=pp) summ(m) out$UN <- m ################################################### ### chunk number 21: ################################################### #line 173 "case-paincov.Rnw" res <- lapply(out, mya) res <- as.data.frame(do.call(rbind, res)) res$p.UN <- round(res$p.UN, 5) res[order(res$BIC),]