multcomp/0000755000176200001440000000000014165102037012111 5ustar liggesusersmultcomp/NAMESPACE0000644000176200001440000000266014073246327013345 0ustar liggesusers importFrom(sandwich, estfun, meat, bread, sandwich) import(mvtnorm) import(survival) import(TH.data) importFrom(codetools, walkCode, makeCodeWalker) importFrom("graphics", "abline", "axis", "box", "boxplot", "legend", "mosaicplot", "plot", "points", "segments", "title") importFrom("stats", "aggregate", "as.formula", "coef", "confint", "cov2cor", "delete.response", "df.residual", "fitted", "get_all_vars", "model.frame", "model.matrix", "model.weights", "p.adjust", "p.adjust.methods", "pchisq", "pf", "pnorm", "predict", "printCoefmat", "pt", "terms", "vcov", "xtabs", "na.exclude") export(glht, contrMat, univariate, adjusted, Ftest, Chisqtest, mcp, modelparm, adjusted_calpha, univariate_calpha, parm, cftest, cld, mmm, mlf) S3method(summary, glht) S3method(confint, glht) S3method(print, glht) S3method(coef, glht) S3method(vcov, glht) S3method(print, confint.glht) S3method(plot, confint.glht) S3method(plot, glht) S3method(print, contrMat) S3method(print, summary.glht) S3method(print, summary.gtest) S3method(print, cld) S3method(glht, matrix) S3method(glht, character) S3method(glht, expression) S3method(glht, mcp) S3method(glht, mlf) S3method(glht, means) S3method(coef, parm) S3method(vcov, parm) S3method(cld, summary.glht) S3method(cld, confint.glht) S3method(cld, glht) S3method(plot, cld) S3method(coef, mmm) S3method(vcov, mmm) S3method(bread, mmm) S3method(estfun, mmm) multcomp/demo/0000755000176200001440000000000013732620022013033 5ustar liggesusersmultcomp/demo/Ch_Misc.R0000644000176200001440000002126613732617736014514 0ustar liggesusers ################################################### ### chunk number 2: setup ################################################### set.seed(290875) ################################################### ### chunk number 3: packages-5 ################################################### library("multcomp") library("coin") ################################################### ### chunk number 4: hypergeom ################################################### layout(matrix(1:2, ncol = 2)) x1 <- 0:8 x2 <- 0:11 plot(x1,dhyper(x1,50,52,8), type="h", ylim=c(-0.001,0.3), yaxp=c(0,0.3,3), ylab="Probability", xlab=expression(paste("Number of events, ", E[1]))) abline(h = 0.1, lty=3) abline(h = 0.2, lty=3) plot(x2,dhyper(x2,51,55,11), type="h", ylim=c(0,0.3), yaxp=c(0,0.3,3), ylab="Probability", xlab=expression(paste("Number of events, ", E[2]))) abline(h = 0.1, lty=3) abline(h = 0.2, lty=3) ################################################### ### chunk number 5: hypergeom2 ################################################### layout(matrix(1:1, ncol = 1)) ################################################### ### chunk number 6: adevent-fm ################################################### data("adevent", package = "multcomp") library("coin") fm <- as.formula(paste( paste("E", 1:28, sep = "", collapse = "+"), "~ group")) fm ################################################### ### chunk number 7: adevent-coin ################################################### it <- independence_test(fm, data = adevent, distribution = approximate(B = 10000)) statistic(it, "standardized") pvalue(it, method = "single-step") ################################################### ### chunk number 8: mtept-coin ################################################### data("mtept", package = "multcomp") it <- independence_test(E1 + E2 + E3 + E4 ~ treatment, data = mtept, distribution = approximate(B = 50000)) statistic(it, "standardized") pvalue(it, method = "single-step") ################################################### ### chunk number 9: gsd-1 ################################################### library("gsDesign") x0.0 <- gsDesign(k=4, test.type=1, sfu="WT", sfupar=0) x0.25 <- gsDesign(k=4, test.type=1, sfu="WT", sfupar=0.25) x0.5 <- gsDesign(k=4, test.type=1, sfu="WT", sfupar=0.5) ################################################### ### chunk number 10: GSD-a ################################################### plot(x0.0$timing,x0.0$upper$bound, type="b", pch=20, xlab="Information fraction", ylab="Rejection boundaries") lines(x0.25$timing,x0.25$upper$bound, lty=2) points(x0.25$timing,x0.25$upper$bound, pch=21) lines(x0.5$timing,x0.5$upper$bound, lty=3) points(x0.5$timing,x0.5$upper$bound, pch=22) legend(x=c(0.6,1), y = c(3.6,4.0), lty=c(1,2,3), pch=c(20,21,22), legend=c(expression(paste(Delta,"=0 (O'Brien-Fleming)")), expression(paste(Delta,"=0.25")), expression(paste(Delta,"=0.5 (Pocock)"))), bty = "n") ################################################### ### chunk number 11: GSD-b ################################################### plot(0:100/100, sfHSD(.025, 0:100/100, -4)$spend, type="l", lwd=2,xlab="Information fraction", ylab="Cumulative error-spending") lines(0:100/100, sfHSD(.025, 0:100/100, -2)$spend, lty=2, lwd=2) lines(0:100/100, sfHSD(.025, 0:100/100, 1)$spend, lty=3, lwd=2) legend(x=c(.0, .27), y=.025 * c(.8, 1), lty=1:3, lwd=2, legend=c(expression(paste(gamma," = -4")), expression(paste(gamma," = -2")), expression(paste(gamma," = 1"))), bty = "n") ################################################### ### chunk number 12: gsd-2 ################################################### library("gsDesign") gsd.OF <- gsDesign(k = 4, test.type = 1, sfu = "OF", alpha = 0.025, beta = 0.1, timing = 1, delta = 0.15) ################################################### ### chunk number 13: gsd-3 ################################################### gsd.OF ################################################### ### chunk number 14: gsd-4 ################################################### gsd.OF2 <- gsDesign(k = 4, test.type = 1, sfu = "OF", alpha = 0.025, beta = 0.1, timing = 1, delta = 0) gsd.OF2$n.I[4] ################################################### ### chunk number 15: gsd-5 ################################################### gsd.OF$upper$bound ################################################### ### chunk number 16: gsd-6 ################################################### gsd.OF$n.I ################################################### ### chunk number 17: GSD-c ################################################### print(plot(gsd.OF, plottype = 1, xlab = "Cumulative sample size", main = "")) ################################################### ### chunk number 18: gsd-7 ################################################### gsd.OF3 <- gsProbability(theta = gsd.OF$delta*seq(0,2,0.25), d = gsd.OF) gsd.OF3 ################################################### ### chunk number 19: gsd-8 ################################################### gsd.OF3$theta ################################################### ### chunk number 20: GSD-d ################################################### plot(gsd.OF3, plottype=2, main="", ylab="Boundary crossing probabilities", base = TRUE) ################################################### ### chunk number 21: GSD-e ################################################### plot(gsd.OF3, plottype=6, main="", ylab="Average sample size", base = TRUE) abline(h = 467, lty=3) ################################################### ### chunk number 22: ad-1 ################################################### if (FALSE) { ### asd.sim doesn't exist in asd anymore library("asd") res <- asd.sim(nsamp = c(110, 110), early = c(0.3, 0.3), final = c(0.3, 0.3), nsim = 10000, corr = 1, select = 1, ptest = c(1, 2)) res ################################################### ### chunk number 23: ad-2 ################################################### d <- seq(0,0.3,0.025) len <- length(d) nsim <- 10000 if (!file.exists("ad-2.Rda")) { res <- matrix(nrow = 4, ncol = len) for (i in 1:len){ res[1,i] <- asd.sim(nsamp=c(110,110), early=c(d[i],d[len]), final=c(d[i],d[len]), nsim=nsim, corr=1, select=1, ptest=c(1,2))$sim.reject/nsim res[2,i] <- asd.sim(nsamp=c(110,110), early=c(d[i],d[len]), final=c(d[i],d[len]), nsim=nsim, corr=1, select=2, ptest=c(1,2))$sim.reject/nsim res[3,i] <- asd.sim(nsamp=c(110,110), early=c(d[i],d[len]), final=c(d[i],d[len]), nsim=nsim, corr=1, select=5, ptest=c(1,2))$sim.reject/nsim res[4,i] <- asd.sim(nsamp=c(110,165), early=c(d[i],d[len]), final=c(d[i],d[len]), nsim=nsim, corr=1, select=1, ptest=c(1,2))$sim.reject/nsim } save(res, file = "ad-2.Rda") } else { load("ad-2.Rda") } ################################################### ### chunk number 24: ad-3 ################################################### plot(d, res[1,], type="n", ylim=c(0.4,1), ylab="Disjunctive power", xlab=expression(theta[1])) lines(lowess(d,res[1,]), lty="11") lines(lowess(d,res[2,]), lty="44") lines(lowess(d,res[3,]), lty="13") lines(lowess(d,res[4,]), lty="F5") legend(0.22,0.55,c("A","B","C","D"), lty=c("11", "44", "13", "F5"), bty = "n") } ################################################### ### chunk number 25: mcpmod-1 ################################################### library("DoseFinding") candMods <- Mods(linear = NULL, emax = 0.2, logistic = c(0.25, 0.09), doses = c(0, 0.05, 0.2, 0.6, 1)) ################################################### ### chunk number 26: mcpmod-2 ################################################### plot(candMods, base = 0, maxEff = 1) ################################################### ### chunk number 28: mcpmod-4 ################################################### data("biom", package = "DoseFinding") res <- MCPMod(dose, resp, biom, candMods, alpha = 0.05, pVal = TRUE, Delta=0.5) ################################################### ### chunk number 29: mcpmod-5 ################################################### res ################################################### ### chunk number 30: mcpmod-6 ################################################### summary(res) ################################################### ### chunk number 31: mcpmod-7 ################################################### plot(res, complData = TRUE, clinRel = TRUE, CI = TRUE, doseEst = TRUE) ################################################### ### chunk number 32: mcpmod-7 ################################################### detach(package:DoseFinding) library(DoseFinding) print(plot(res, complData = TRUE, clinRel = TRUE, CI = TRUE, doseEst = TRUE, lty = 1, colors = c("black", "gray", "black", "gray", "black"))) multcomp/demo/Ch_Intro.R0000644000176200001440000000467311471214240014674 0ustar liggesusers ################################################### ### chunk number 2: setup ################################################### set.seed(290875) ################################################### ### chunk number 3: packages-1 ################################################### library("ISwR") library("multcomp") ################################################### ### chunk number 4: TypeIerror ################################################### typeI <- function(alpha) 1 - (1-alpha)^(1:100) results <- cbind(typeI(alpha = 0.10), typeI(alpha = 0.05), typeI(alpha = 0.01)) plot(results[,1], type = "l", xlab = "m", ylab = "P(at least one Type I error)", lty = 1, ylim = c(0, 1)) lines(results[,2], lty = 2) lines(results[,3], lty = 3) legend(70, 0.2, c(expression(alpha == 0.10), expression(alpha == 0.05), expression(alpha == 0.01)), lty = 1:3, bty = "n") ################################################### ### chunk number 5: thuesen ################################################### data("thuesen", package = "ISwR") plot(short.velocity ~ blood.glucose, data = thuesen, xlab = "Blood glucose", ylab = "Velocity") abline(lm(short.velocity ~ blood.glucose, data = thuesen)) ################################################### ### chunk number 6: thuesen:lm ################################################### thuesen.lm <- lm(short.velocity ~ blood.glucose, data = thuesen) summary(thuesen.lm) ################################################### ### chunk number 7: thuesen:mc ################################################### library("multcomp") thuesen.mc <- glht(thuesen.lm, linfct = diag(2)) summary(thuesen.mc, test = adjusted(type = "bonferroni")) ################################################### ### chunk number 8: thuesen:mc2 ################################################### summary(thuesen.mc) ################################################### ### chunk number 9: Bias ################################################### n <- 1 curve(n*dnorm(x)*(pnorm(x))^(n-1), -5, 5, ylim = c(0,1), ylab = "y") n <- 2 curve(n*dnorm(x)*(pnorm(x))^(n-1), -5, 5, add = T, lty = 2) n <- 5 curve(n*dnorm(x)*(pnorm(x))^(n-1), -5, 5, add = T, lty = 3) n <- 10 curve(n*dnorm(x)*(pnorm(x))^(n-1), -5, 5, add = T, lty = 4) n <- 100 curve(n*dnorm(x)*(pnorm(x))^(n-1), -5, 5, add = T, lty = 5) legend(-4, 1, c("m = 1", "m = 2", "m = 5", "m = 10", "m = 100"), lty = 1:5, bty = "n") abline(v = 0, col = "lightgray") multcomp/demo/Ch_GLM.R0000644000176200001440000002053213732617011014215 0ustar liggesusers ################################################### ### chunk number 2: setup ################################################### set.seed(290875) ################################################### ### chunk number 3: thuesen:ex ################################################### data("thuesen", package = "ISwR") thuesen <- thuesen[!is.na(thuesen[,"short.velocity"]),] thuesen.lm <- lm(short.velocity ~ blood.glucose, data = thuesen) ################################################### ### chunk number 4: lm-coef-vcov ################################################### betahat <- coef(thuesen.lm) Vbetahat <- vcov(thuesen.lm) ################################################### ### chunk number 5: lm-C ################################################### C <- diag(2) Sigma <- diag(1 / sqrt(diag(C %*% Vbetahat %*% t(C)))) t <- Sigma %*% C %*% betahat Cor <- Sigma %*% (C %*% Vbetahat %*% t(C)) %*% t(Sigma) ################################################### ### chunk number 6: corr ################################################### Cor ################################################### ### chunk number 7: lm-partial ################################################### library("mvtnorm") thuesen.df <- nrow(thuesen) - length(betahat) q <- sapply(abs(t), function(x) 1 - pmvt(-rep(x, 2), rep(x, 2), corr = Cor, df = thuesen.df)) ################################################### ### chunk number 8: lm-partial ################################################### delta <- rep(0, 2) myfct <- function(x, conf) { lower <- rep(-x, 2) upper <- rep(x, 2) pmvt(lower, upper, df = thuesen.df, corr = Cor, delta, abseps = 0.0001)[1] - conf } ################################################### ### chunk number 9: lm-partial ################################################### u <- uniroot(myfct, lower = 1, upper = 5, conf = 0.95)$root round(u, 3) ################################################### ### chunk number 10: lm-C2 ################################################### rownames(C) <- names(betahat) ################################################### ### chunk number 11: lm-mcp ################################################### library("multcomp") thuesen.mc <- glht(thuesen.lm, linfct = C) summary(thuesen.mc) ################################################### ### chunk number 12: lm-confint ################################################### confint(thuesen.mc) ################################################### ### chunk number 13: lm-confint ################################################### summary(thuesen.mc, test = adjusted(type = "Westfall")) ################################################### ### chunk number 14: warpbreaksBoxplot ################################################### plot(breaks ~ tension, data = warpbreaks, varwidth = TRUE, main = "", xlab = "Tension", ylab = "Breaks") ################################################### ### chunk number 15: aov-fit ################################################### warpbreaks.aov <- aov(breaks ~ tension, data = warpbreaks) summary(warpbreaks.aov) ################################################### ### chunk number 16: contr-1 ################################################### glht(warpbreaks.aov, linfct = mcp(tension = "Tukey")) ################################################### ### chunk number 17: contr-2 ################################################### glht(warpbreaks.aov, linfct = mcp(tension = c("M - L = 0", "H - L = 0", "H - M = 0"))) ################################################### ### chunk number 18: contr-3a ################################################### contr <- rbind("M - L" = c(-1, 1, 0), "H - L" = c(-1, 0, 1), "H - M" = c( 0, -1, 1)) contr ################################################### ### chunk number 19: contr-3c ################################################### glht(warpbreaks.aov, linfct = mcp(tension = contr)) ################################################### ### chunk number 20: contr-3 ################################################### glht(warpbreaks.aov, linfct = cbind(0, contr %*% contr.treatment(3))) ################################################### ### chunk number 21: trt-contr ################################################### contr.treatment(3) ################################################### ### chunk number 22: out-1 ################################################### warpbreaks.mc <- glht(warpbreaks.aov, linfct = mcp(tension = "Tukey")) names(warpbreaks.mc) ################################################### ### chunk number 23: out-2 ################################################### warpbreaks.mc$model ################################################### ### chunk number 24: out-3 ################################################### warpbreaks.mc$linfct ################################################### ### chunk number 25: out-4 ################################################### warpbreaks.mc$rhs ################################################### ### chunk number 26: out-5 ################################################### warpbreaks.mc$coef warpbreaks.mc$vcov ################################################### ### chunk number 27: out-6 ################################################### warpbreaks.mc$df ################################################### ### chunk number 28: out-7 ################################################### warpbreaks.mc$alternative ################################################### ### chunk number 29: out-7 ################################################### warpbreaks.mc$type ################################################### ### chunk number 30: summary-1 ################################################### summary(warpbreaks.mc) ################################################### ### chunk number 31: summary-1a ################################################### warpbreaks.res <- summary(warpbreaks.mc) ################################################### ### chunk number 32: summary-1b ################################################### warpbreaks.res$test$pvalues ################################################### ### chunk number 33: summary-2 ################################################### summary(warpbreaks.mc, test = Ftest()) ################################################### ### chunk number 34: summary-3 ################################################### summary(warpbreaks.mc, test = univariate()) ################################################### ### chunk number 35: summary-4 ################################################### summary(warpbreaks.mc, test = adjusted(type = "bonferroni")) ################################################### ### chunk number 36: summary-4 ################################################### summary(warpbreaks.mc, test = adjusted(type = "single-step")) ################################################### ### chunk number 37: sci-1 ################################################### warpbreaks.ci <- confint(warpbreaks.mc, level = 0.95) warpbreaks.ci ################################################### ### chunk number 38: sci-2 ################################################### plot(warpbreaks.ci, main = "", ylim = c(0.5, 3.5), xlab = "Breaks") ################################################### ### chunk number 39: warpbreaksCI ################################################### plot(warpbreaks.ci, main = "", ylim = c(0.5, 3.5), xlab = "Breaks") ################################################### ### chunk number 40: sci-3 ################################################### cbon <- qt(1-0.05/6, 51) cbon ################################################### ### chunk number 41: sci-4 ################################################### confint(warpbreaks.mc, calpha = cbon) ################################################### ### chunk number 42: warpbreaksCLD ################################################### warpbreaks.cld <- cld(warpbreaks.mc) plot(warpbreaks.cld) ################################################### ### chunk number 43: cld-1 ################################################### warpbreaks.cld <- cld(warpbreaks.mc) ################################################### ### chunk number 44: cld-2 ################################################### plot(warpbreaks.cld) multcomp/demo/00Index0000644000176200001440000000022111471214240014157 0ustar liggesusersCh_Intro Introduction Ch_Theory General Concepts Ch_GLM Multiple Comparisons in Parametric Models Ch_Appl Applications Ch_Misc Further Topics multcomp/demo/Ch_Theory.R0000644000176200001440000000241211471214240015040 0ustar liggesusers ################################################### ### chunk number 2: setup ################################################### set.seed(290875) ################################################### ### chunk number 3: padj-1 ################################################### p <- c(0.01, 0.015, 0.005) p.adjust(p, "bonferroni") ################################################### ### chunk number 4: padj-2 ################################################### p.adjust(p, "holm") ################################################### ### chunk number 5: simesplot ################################################### library("mvtnorm") set.seed(12345) x <- rmvnorm(n = 100, mean = c(2,2), sigma = diag(2)) p <- 1 - pnorm(x) plot(p, xlim = c(0, 1), ylim = c(0, 1), ylab = expression(p[2]), xlab = expression(p[1]), col = rgb(0,0,0,1)) abline(h = 0.05, lty=3) abline(h = 0.1, lty=3) abline(v = 0.05, lty=3) abline(v = 0.1, lty=3) ################################################### ### chunk number 6: padj-3 ################################################### p <- c(0.01, 0.02, 0.022, 0.09) p.adjust(p, "hochberg") ################################################### ### chunk number 7: padj-4 ################################################### p.adjust(p, "hommel") multcomp/demo/Ch_Appl.R0000644000176200001440000006646113732617652014520 0ustar liggesusers ################################################### ### chunk number 2: setup ################################################### set.seed(290875) ################################################### ### chunk number 3: packages-4 ################################################### library("sandwich") library("robustbase") library("lme4") library("multcomp") ################################################### ### chunk number 4: BoxplotRecovery ################################################### data("recovery", package = "multcomp") plot(minutes ~ blanket, data = recovery, xlab = "Blanket", ylab = "Minutes", varwidth = TRUE, main = "") ################################################### ### chunk number 5: recovery-1 ################################################### data("recovery", package = "multcomp") summary(recovery) ################################################### ### chunk number 6: recovery-2 ################################################### recovery.aov <- aov(minutes ~ blanket, data = recovery) ################################################### ### chunk number 7: recovery-3 ################################################### library("multcomp") recovery.mc <- glht(recovery.aov, linfct = mcp(blanket = "Dunnett"), alternative = "less") ################################################### ### chunk number 8: recovery-4 ################################################### summary(recovery.mc) ################################################### ### chunk number 9: recovery-5 ################################################### summary(recovery.mc, test = adjusted(type = "bonferroni")) ################################################### ### chunk number 10: recovery-6 ################################################### recovery.ci <- confint(recovery.mc, level = 0.95) recovery.ci ################################################### ### chunk number 11: recovery-6 ################################################### plot(recovery.ci, main = "", ylim = c(0.5, 3.5), xlab = "Minutes") ################################################### ### chunk number 12: CIrecovery ################################################### plot(recovery.ci, main = "", ylim = c(0.5, 3.5), xlab = "Minutes") ################################################### ### chunk number 13: recovery-7a ################################################### contr <- rbind("b1 -b0" = c(-1, 1, 0, 0), "b2 -b0" = c(-1, 0, 1, 0), "b3 -b0" = c(-1, 0, 0, 1)) summary(glht(recovery.aov, linfct = mcp(blanket = contr), alternative = "less")) ################################################### ### chunk number 14: recovery-8a ################################################### contr2 <- rbind("b2 -b0" = c(-1, 0, 1, 0), "b2 -b1" = c( 0, -1, 1, 0), "b3 -b0" = c(-1, 0, 0, 1), "b3 -b1" = c( 0, -1, 0, 1)) ################################################### ### chunk number 15: recovery-8c ################################################### summary(glht(recovery.aov, linfct = mcp(blanket = contr2), alternative = "less")) ################################################### ### chunk number 16: recovery-9 ################################################### summary(recovery.mc, test = adjusted(type = "free")) ################################################### ### chunk number 17: recovery-9 ################################################### summary(recovery.mc, test = adjusted(type = "holm")) ################################################### ### chunk number 18: immer-1 ################################################### data("immer", package = "MASS") immer.aov <- aov((Y1 + Y2)/2 ~ Var + Loc, data = immer) summary(immer.aov) ################################################### ### chunk number 19: immer-2 ################################################### model.tables(immer.aov, type = "means")$tables$Var ################################################### ### chunk number 20: immer-3 ################################################### immer.mc <- glht(immer.aov, linfct = mcp(Var = "Tukey")) ################################################### ### chunk number 21: immer-4 ################################################### summary(immer.mc) ################################################### ### chunk number 22: immer-4a ################################################### immer.mc2 <-TukeyHSD(immer.aov, which = "Var") immer.mc2$Var ################################################### ### chunk number 23: immer-4b ################################################### glht(immer.aov, linfct = mcp(Var = "Tukey"), alternative = "greater") ################################################### ### chunk number 24: immer-5 ################################################### immer.ci <- confint(immer.mc, level = 0.95) immer.ci ################################################### ### chunk number 25: immer-6 ################################################### plot(immer.ci, main = "", xlab = "Yield") ################################################### ### chunk number 26: CIimmer ################################################### plot(immer.ci, main = "", xlab = "Yield") ################################################### ### chunk number 27: immer-7 ################################################### immer.cld <- cld(immer.mc) ################################################### ### chunk number 28: immerCLD ################################################### plot(immer.cld) ################################################### ### chunk number 29: immerCLD ################################################### plot(immer.cld) ################################################### ### chunk number 30: immerCLD-2 ################################################### data("immer", package = "MASS") library("HH") immer2 <- immer immer2$Var <- ordered(immer2$Var, levels = c("S", "M", "V", "P", "T")) immer2.aov <- aov((Y1 + Y2)/2 ~ Var + Loc, data = immer2) position(immer2$Var) <- model.tables(immer2.aov, type = "means")$tables$Var immer2.mc <- glht(immer2.aov, linfct = mcp(Var = "Tukey")) immer2.cld <- cld(immer2.mc) immer2.cld$pos.x <- immer2.cld$x position(immer2.cld$pos.x) <- position(immer2$Var) lab <- immer2.cld$mcletters$monospacedLetters[levels(immer2$Var)] bwplot(lp ~ pos.x, data = immer2.cld, panel=function(...){ panel.bwplot.intermediate.hh(...) cpl <- current.panel.limits() pushViewport(viewport(xscale = cpl$xlim, yscale = cpl$ylim, clip = "off")) panel.axis("top", at = position(immer2$Var), labels = lab, outside = TRUE) upViewport() }, scales = list(x = list(limits = c(90, 120), at = position(immer2$Var), labels = levels(immer2$Var))), main = "", xlab = "Var", ylab = "linear predictor") ################################################### ### chunk number 31: immerCLD-2 ################################################### print(bwplot(lp ~ pos.x, data=immer2.cld, panel=function(...){ panel.bwplot.intermediate.hh(...) cpl <- current.panel.limits() pushViewport(viewport(xscale = cpl$xlim, yscale = cpl$ylim, clip = "off")) panel.axis("top", at=position(immer2$Var), labels=immer2.cld$mcletters$monospacedLetters[levels(immer2$Var)], outside=TRUE) upViewport() }, scales=list(x=list(limits=c(90,120), at=position(immer2$Var), labels=levels(immer2$Var))), main="", col="black", xlab="Var", ylab="linear predictor")) ################################################### ### chunk number 32: immer-9 ################################################### library("HH") immer.mmc <- glht(immer.aov, linfct = mcp(Var = "Tukey"), focus = "Var", lmat.rows = 2:5) ################################################### ### chunk number 33: immer-linfct ################################################### rownames(immer.mc$linfct) <- gsub(" ", "", rownames(immer.mc$linfct)) ################################################### ### chunk number 34: immer-10 ################################################### t(immer.mc$linfct) ################################################### ### chunk number 35: immer-11 ################################################### plot(immer.mmc, ry = c(85, 122), x.offset = 8, main = "", main2 = "") ################################################### ### chunk number 36: immerMMC ################################################### # par(mai = par("mai") * c(1, 1, 1, 1.1)) layout(matrix(1:2, ncol = 1)) plot(immer.mmc, ry=c(85, 122), x.offset = 8, main = "Mean-mean multiple comparison plot", main2 = "", col.mca.signif = "grey") ### plot.matchMMC doesn't exist in HH if (FALSE) { plot.matchMMC(immer.mmc$mca, main = "Tiebreaker plot", col.signif = "grey") ################################################### ### chunk number 37: immer-11a ################################################### plot.matchMMC(immer.mmc$mca, main = "") } ################################################### ### chunk number 38: immer-12 ################################################### immer.lmat <- cbind("M-S" = c(1, 0,-1, 0, 0), "MS-V" = c(1, 0, 1, 0,-2), "VMS-P" = c(1,-3, 1, 0, 1), "PVMS-T" = c(1, 1, 1,-4, 1)) row.names(immer.lmat) <- c("M","P","S","T","V") ################################################### ### chunk number 39: immer-12 ################################################### immer.mmc2 <- glht(immer.aov, linfct = mcp(Var = "Tukey"), focus.lmat = immer.lmat) ################################################### ### chunk number 40: immerMMC2 ################################################### plot(immer.mmc2, ry = c(85, 122), x.offset = 8, main = "", main2 = "", col.lmat.signif = "grey") ################################################### ### chunk number 41: immer-7 ################################################### summary(immer.mc, test = adjusted(type = "Westfall")) ################################################### ### chunk number 42: immer-8 ################################################### summary(immer.mc, test = adjusted(type = "none")) ################################################### ### chunk number 43: immer-9 ################################################### summary(immer.mc, test = adjusted(type = "Shaffer")) ################################################### ### chunk number 44: Thalidomide-plot ################################################### lsmDat <- data.frame(dose = c(0, 5, 50, 500), doseC = 1:4, mean = c(32.3651425, 29.0127426, 30.0742635, 29.6898998), se = c(0.8939097, 0.9294513, 0.9978421, 0.9902196)) library("lattice") print(xyplot(mean ~ dose, lsmDat, xlab = "Dose", ylab = "Litter weight LSMEANS (g)", panel = function(x, y, se, ...) { lsegments(x, y - se, x, y + se, col = "gray80", lwd = 3) panel.xyplot(x, y, type = "b", col = "black", lwd = 2, cex = 1.25) }, se = lsmDat$se, ylim = c(27, 34))) ################################################### ### chunk number 45: litter-1 ################################################### data("litter", package = "multcomp") litter.aov <- aov(weight ~ dose + gesttime + number, data = litter) ################################################### ### chunk number 46: litter-1 ################################################### litter.mc <- glht(litter.aov, linfct = mcp(dose = "Dunnett"), alternative = "less") summary(litter.mc, test = adjusted(type = "single-step")) ################################################### ### chunk number 47: litter-fig1 ################################################### library("lattice") contMat <- matrix(c( 1, 0, 0, -1, 1, 0, -0.5, -0.5, 1, -0.3333, -0.3333, -0.3333, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0, -1, 0.3333, 0.3333, 0.3333, -1, 1, 0, 0, -1, 1, 0, -0.5, -0.5, 1, -0.3333, -0.3333, -0.3333 ), ncol=4, byrow=TRUE) contMat <- t(contMat) contNames <- c("Williams 1", "Williams 2", "Williams 3", "mod Williams 1","mod Williams 2","mod Williams 3","mod Williams 4","mod Williams 5","mod Williams 6") contMatTrl <- data.frame(cont = as.vector(contMat), type = factor(rep(contNames, each = 4), levels = contNames), type2 = factor(rep(c("Williams", "modified Williams"), c(12, 24))), dose = rep(0:3, 9)) trellis.par.set("superpose.line", list(col = c("lightgrey", "lightgrey", "lightgrey", "darkgrey", "darkgrey", "darkgrey"), lty = c(4, 4, 4, 1, 1, 1), lwd = rep(3, 6))) trellis.par.set("superpose.symbol", list(col = c(1, 1, 1, 1, 1, 1), pch = c(1, 1, 1, 2, 2, 2), cex = rep(1, 6), font = rep(1, 6))) print(xyplot(cont ~ dose | type2, contMatTrl, panel = function(x, y, subscripts, groups, ...) { panel.superpose(x, y, subscripts, groups, type = "l", ...) panel.superpose(x, y, subscripts, groups, type = "p", ...) }, groups = type, xlab = "Dose", ylab = "Contrast")) ################################################### ### chunk number 48: litter-3 ################################################### n <- c(20, 19, 18, 17) -contrMat(n, type = "Williams") ################################################### ### chunk number 49: litter-4 ################################################### -contrMat(n, type = "Marcus") ################################################### ### chunk number 50: litter-5a ################################################### set.seed(1234) ################################################### ### chunk number 51: litter-5 ################################################### litter.mc2 <- glht(litter.aov, alternative = "less", linfct = mcp(dose = "Williams")) summary(litter.mc2) ################################################### ### chunk number 52: litter-6 ################################################### glht(litter.aov, linfct = mcp(dose = "Marcus"), alternative = "less") ################################################### ### chunk number 53: litter-7 ################################################### summary(litter.mc2, test = adjusted(type = "free")) ################################################### ### chunk number 54: body-1 ################################################### data("bodyfat", package = "TH.data") bodyfat.lm <- lm(DEXfat ~ ., data = bodyfat) summary(bodyfat.lm) ################################################### ### chunk number 55: body-opt ################################################### op <- options(width = 70) ################################################### ### chunk number 56: body-2 ################################################### K <- cbind(0, diag(length(coef(bodyfat.lm)) - 1)) rownames(K) <- names(coef(bodyfat.lm))[-1] K ################################################### ### chunk number 57: body-opt ################################################### options(op) ################################################### ### chunk number 58: body-3 ################################################### bodyfat.mc <- glht(bodyfat.lm, linfct = K) ################################################### ### chunk number 59: body-4 ################################################### summary(bodyfat.mc, test = Ftest()) ################################################### ### chunk number 60: body-4 ################################################### summary(bodyfat.mc) ################################################### ### chunk number 61: body-5 ################################################### vcov.lmrob <-function(object) object$cov summary(glht(lmrob(DEXfat ~ ., data = bodyfat), linfct = K)) ################################################### ### chunk number 62: scb-2 ################################################### data("sbp", package = "multcomp") sbp.lm <- lm(sbp ~ gender * age, data = sbp) coef(sbp.lm) ################################################### ### chunk number 63: scb-3 ################################################### age <- seq(from = 17, to = 47, by = 1) K <- cbind(0, 1, 0, age) rownames(K) <- paste("age", age, sep = "") ################################################### ### chunk number 64: scb-4 ################################################### sbp.mc <- glht(sbp.lm, linfct = K) sbp.ci <- confint(sbp.mc, level = 0.99) ################################################### ### chunk number 65: scb-4a ################################################### attr(sbp.ci$confint, "calpha") ################################################### ### chunk number 66: scb5 ################################################### plot(age, coef(sbp.mc), type = "l", ylim = c(-30, 2)) lines(age, sbp.ci$confint[,"upr"]) lines(age, sbp.ci$confint[,"lwr"]) abline(h = 0, lty = 2) ################################################### ### chunk number 67: scb ################################################### plot(age, coef(sbp.mc), type = "l", ylim = c(-30, 2), ylab = expression(x^T * (beta[F] - beta[M])), main = "", xlab = "Age") points(age, coef(sbp.mc), pch = 19, cex = 0.6) lines(age, sbp.ci$confint[,"upr"]) lines(age, sbp.ci$confint[,"lwr"]) abline(h = 0, lty = 2) ################################################### ### chunk number 68: alpha-data ################################################### data("alpha", package = "coin") ################################################### ### chunk number 69: alpha-data-figure ################################################### levels(alpha$alength)[2] <- "med" n <- table(alpha$alength) boxplot(elevel ~ alength, data = alpha, ylab = "Expression level", xlab = "NACP-REP1 Allele Length", varwidth = TRUE) axis(3, at = 1:3, labels = paste("n = ", n)) rankif <- function(data) trafo(data, numeric_trafo = rank) ################################################### ### chunk number 70: alpha-3 ################################################### alpha.aov <- aov(elevel ~ alength, data = alpha) ################################################### ### chunk number 71: alpha-4 ################################################### alpha.mc <- glht(alpha.aov, linfct = mcp(alength = "Tukey")) ################################################### ### chunk number 72: alpha-3 ################################################### alpha.mc$linfct ################################################### ### chunk number 73: alpha-aov-coefvcov ################################################### coef(alpha.mc) vcov(alpha.mc) ################################################### ### chunk number 74: alpha-aov-results ################################################### confint(alpha.mc) summary(alpha.mc) ################################################### ### chunk number 75: alpha-aov-tukey-sandwich ################################################### alpha.mc2 <- glht(alpha.aov, linfct = mcp(alength = "Tukey"), vcov = sandwich) summary(alpha.mc2) ################################################### ### chunk number 76: alpha-confint-plot ################################################### layout(matrix(1:2, ncol = 1)) ci1 <- confint(glht(alpha.aov, linfct = mcp(alength = "Tukey"))) ci2 <- confint(glht(alpha.aov, linfct = mcp(alength = "Tukey"), vcov = sandwich)) plot(ci1, main = "Ordinary covariance matrix estimate", ylim = c(0.5, 3.5), xlab = "Difference") plot(ci2, main = "Sandwich estimate", ylim = c(0.5, 3.5), xlab = "Difference") layout(matrix(1:1, ncol = 1)) ################################################### ### chunk number 77: alzheimer-demographics ################################################### data("alzheimer", package = "coin") total <- nrow(alzheimer) stopifnot(total == 538) male <- sum(alzheimer$gender == "Male") stopifnot(male == 200) female <- sum(alzheimer$gender == "Female") stopifnot(female == 338) disease <- table(alzheimer$disease) smoked <- sum(alzheimer$smoking != "None") atab <- xtabs(~ smoking + disease + gender, data = alzheimer) ### there is a discrepancy between Table 1 (32% smokers of 117 women ### suffering from other diagnoses) and Table 4 (63% non-smokers). ### We used the data as given in Table 4. ################################################### ### chunk number 78: alzheimer-tab ################################################### x <- t(atab[,,"Female"]) lines <- paste(paste(dimnames(x)$disease, " & "), paste(apply(x, 1, function(l) paste(l, collapse = " & ")), "\\\\")) for (i in 1:length(lines)) cat(lines[i], "\n") ################################################### ### chunk number 79: alzheimer-tab ################################################### x <- t(atab[,,"Male"]) lines <- paste(paste(dimnames(x)$disease, " & "), paste(apply(x, 1, function(l) paste(l, collapse = " & ")), "\\\\")) for (i in 1:length(lines)) cat(lines[i], "\n") ################################################### ### chunk number 80: alzheimer-plot ################################################### layout(matrix(1:2, ncol = 2)) spineplot(disease ~ smoking, data = alzheimer, subset = gender == "Male", main = "Male", xlab = "Smoking", ylab = "Disease", tol = 1) spineplot(disease ~ smoking, data = alzheimer, subset = gender == "Female", main = "Female", xlab = "Smoking", ylab = "Disease", tol = 1) ################################################### ### chunk number 81: alzheimer-plot ################################################### layout(matrix(1:1, ncol = 1)) ################################################### ### chunk number 82: alz-1 ################################################### data("alzheimer", package = "coin") y <- factor(alzheimer$disease == "Alzheimer", labels = c("other", "Alzheimer")) alzheimer.glm <- glm(y ~ smoking * gender, data = alzheimer, family = binomial()) ################################################### ### chunk number 83: alz-options ################################################### op <- options(show.signif.stars = FALSE) ################################################### ### chunk number 84: alz-2 ################################################### summary(alzheimer.glm) ################################################### ### chunk number 85: alz-options ################################################### options(op) ################################################### ### chunk number 86: alzheimer-K ################################################### a <- cbind(levels(alzheimer$smoking), "Female") b <- cbind(levels(alzheimer$smoking), "Male") d <- rbind(a, b) smk <- factor(d[,1], levels = levels(alzheimer$smoking)) gen <- factor(d[,2], levels = levels(alzheimer$gender)) d <- data.frame(smk, gen) ### colnames(d) <- c("smoking", "gender") colnames(d) <- c("s", "g") rownames(d) <- paste(d[,1], d[,2], sep = ":") K <- model.matrix(~ s * g, data = d) colnames(K)[1] <- "(Icpt)" attr(K, "assign") <- NULL attr(K, "contrasts") <- NULL ################################################### ### chunk number 87: alz-3 ################################################### K ################################################### ### chunk number 88: alz-3 ################################################### alzheimer.ci <- confint(glht(alzheimer.glm, linfct = K)) ################################################### ### chunk number 89: alz-3a ################################################### attr(alzheimer.ci$confint, "calpha") ################################################### ### chunk number 90: alz-3b ################################################### qnorm((1-(1-0.05)^(1/8))/2, lower.tail = FALSE) ################################################### ### chunk number 91: alz-4 ################################################### alzheimer.ci$confint <- apply(alzheimer.ci$confint, 2, binomial()$linkinv) plot(alzheimer.ci, main = "", xlim = c(0, 1)) ################################################### ### chunk number 92: alzheimer-plot2 ################################################### plot(alzheimer.ci, xlab = "Probability of suffering from Alzheimer's disease", xlim = c(0, 1), ylim = c(0.5, 8.5), main = "") ################################################### ### chunk number 93: alm-0 ################################################### library("TH.data") load(file.path(path.package(package = "TH.data"), "rda", "AML_Bullinger.rda")) risk <- rep(0, nrow(clinical)) rlev <- levels(clinical[, "Cytogenetic.group"]) risk[clinical[, "Cytogenetic.group"] %in% rlev[c(7,8,4)]] <- "low" risk[clinical[, "Cytogenetic.group"] %in% rlev[c(5, 9)]] <- "intermediate" risk[clinical[, "Cytogenetic.group"] %in% rlev[-c(4,5, 7,8,9)]] <- "high" risk <- as.factor(risk) names(clinical)[6] <- "FLT3" ################################################### ### chunk number 94: alm-options ################################################### op <- options(show.signif.stars = FALSE) ################################################### ### chunk number 95: alm-1 ################################################### library("survival") aml.surv <- survreg(Surv(time, event) ~ Sex + Age + WBC + LDH + FLT3 + risk, data = clinical) summary(glht(aml.surv, linfct = mcp(risk = "Tukey"))) ################################################### ### chunk number 96: alm-options ################################################### options(op) ################################################### ### chunk number 97: tree-1 ################################################### data("trees513", package = "multcomp") ################################################### ### chunk number 98: trees-setup ################################################### trees513 <- subset(trees513, !species %in% c("fir", "softwood (other)")) trees513$species <- trees513$species[,drop = TRUE] levels(trees513$species)[5:6] <- c("ash/maple/elm", "hardwood") ################################################### ### chunk number 99: tree-2 ################################################### trees513.lme <- glmer(damage ~ species -1 + (1 | lattice/plot), data = trees513, family = binomial()) K <- diag(length(fixef(trees513.lme))) ################################################### ### chunk number 100: trees-K-cosmetics ################################################### colnames(K) <- rownames(K) <- paste(gsub("species", "", names(fixef(trees513.lme))), " (", table(trees513$species), ")", sep = "") ################################################### ### chunk number 101: tree-3 ################################################### trees513.ci <- confint(glht(trees513.lme, linfct = K)) prob <- binomial()$linkinv(trees513.ci$confint) trees513.ci$confint <- 1 - prob trees513.ci$confint[, 2:3] <- trees513.ci$confint[, 3:2] ################################################### ### chunk number 102: CItrees ################################################### plot(trees513.ci, main = "", xlab = "Probability of browsing damage" ) multcomp/data/0000755000176200001440000000000012504274134013025 5ustar liggesusersmultcomp/data/detergent.rda0000644000176200001440000000070712223037755015506 0ustar liggesusers͔R0ƓtF߃$U 'nN NQŧ􄦒j =flv#mn3|ƘÜ]-+8cEF}JsOu@gڋ]R)sJ[*%Z 97Z5LFcW$$8NdypM ?մJew>͉}w'\\\\se7\h g'م\ia1}>A~o>:{WV>GVT*RAE"g͙C!ٙof3ًӳ<[N7Xޥ˸n#>)ߌ3i~I=zq.> s6ϐvO-s|xZ♩v ksO{^m>:߉&{X՗&yR|)'4M)1ۑ'mi*N=}x?_zY0P).?aG>6[4aOQ~Hr9W~pusܼ8 9\s@ak3gK$L9ʄfB33331<L,22L2*Lff9O?` LE`X66%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % % % % % % % % % % % % % % % % % % %J"D(P$BI%J"ij/hmultcomp/data/litter.rda0000644000176200001440000000154714165061536015034 0ustar liggesusersMhSA_^Rk4XVP#+Ń-z(bڦ/h(xA zћAD`/^K=JUxSmgo$ ۙٝlc#Vl$fiDBa}5bBFĈrtVY4~e/w4wqwiFYTZǶV6d2e|\1y<^gBxC8`#F}GG}_[ڊ1rܣkݫDD' ߈RQ{.䠂`?kyO_ z@k  *<γ=szyI8Y/Mc|œWf'eޱ}:'ykO|Ϝ,){-Ϋ#vJ0]Q]5 Qx 7UqUvWy>} ׯ CW9N|ȃSy ^gٯH9/VΕIa\u/Hct /#{u@|kvFSڪgWQ]uU9}߼}qGug?ѿ=yi7=:Wjs:|k8Vz}su;V׽_u}):v J[sn_UWq{=wg{^yuc7777?=ke_׽7_ s|RP^wk̵S[}zlk{}zعIW5z={x2l{y>Ss_I]C:tos[_;ީб<) 7[ݏcsR#p칽И7[[gOckl7͞32US:>K{?G?h_yG/xݷjyw񓏖{¿_>w寇:wu&Xu^su|rem/Wym{?߽}`_C~+zn9'WAz|U߽q幹ײ\y&qC[ⱼ~1^yoerΡskG5OGl'Z|8[lޫ`؞gc?:wڶPŶ8tlϴkk[z3ރka{ֺ[]+{yo\;iڹ^ubˇcS;TzkaO=W'/{+w`GkZg_d|[^t{O^,/]=٧yǏ7?~'[^Z?ç~Ⴧ <һHwj^GC?ԛkw~piS ~kzwϜkwyε~v7kwszsv]tϵ~Ĺv׏<?7P7aMg o5P?{~@܁@=i4Pib@Ձj /_4Px~@ҁe[W ԯ_5Pz~@ځu7o/ p@=l{gw'Iz4,,',19:qzy2Føz'Kc&\= WOՓp$\= S0 S0 SmضaۆmipZ$ Ei|30iX \@k,pf=0YLo`s(0GQml[-70 o`~s(0Gnƥqf\fofofofofofofoU|||c|C|#||{{=k=}~|7~{o]={?[ 'y e?qKW/kuUAGߤy)K1/NwG{hoI=|_jqSs#ߡ{6|#=#=#=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ=ܣ_nYvɎ9BØdmultcomp/data/adevent.rda0000644000176200001440000000123512223037755015150 0ustar liggesusersKN0@򩄄 jK\K"(lJJ-GO vgԈAkB?EDiZqpa§A;};A~WPсUtcTEgQԹC؇P@x!GCx)M@6dM@6dMٺs^?l6M}8 &9b_ߒ^GETmultcomp/data/waste.rda0000644000176200001440000000074512223037755014652 0ustar liggesusers=L@ǯ-DCHф88ď &:"KEI@ItvqqUgg\pvqaqU{%w^Q=BTب1lP c5[6!{Np]+ɍTCd*|շWUj#UXnW+TTP֒UheDx/kNzx)WKZVKy<l{s#mћ$o0uy=1nc g7~VćtIQo q0c;!B Oec 9st|cBg, #4x)Zj]}rCN/ՋVZ*5hY"DSU*< $ PqEJ"-#VV֐ЃE=(zPAуEd\\7wxmultcomp/data/cml.rda0000644000176200001440000001130012223037755014267 0ustar liggesusers\wUX"IL,AdU&H}-Y &DSlp5& `b["[X,e*E{OH;;}L`~ùe̙y^7LcJLKŔt %GM6˓_7cnE N:J8(%tB/-^Fx+W%_=8xQB<8+=.zAqsp^ &#!#σ0E `H % B"EBPu p4zfVTE]dE]Tb.UytU.FFWU#D<2L#D<2L#D<l#F<l#F<l#Eijw/1v Ƿ+_f>iƍI/,cIv{J Ṗ열ZԷ[A1=. ɽfȎIoI6Me|RRއ 8:!![#c| {q<ͷGR攴md\jcE(]ѮښLu~}I^ U؀d88Y33D'PhEgqr.4}쑤clI%#.N $$J{,1d4'4ۤKZ'si6HgٹغgI~-Ծq- 4\olgBCIt>-|[HBrNBu2 ݶJֈ^0wct#D+ݿ=w s^ }R͔[gCT9&^wW>q{dpcOxIPʫE;x6)߻KBN.S/}ߏIi~Dӕs) @tI%i1]06AT덭.&q 286I=NoC/mzSsh ڰ16q=h|u'0ڦt$_qXڸK)kdA{ZNm~g\ߜabz }֗t';ǧ7FڽȳϚzXN= k_޽ڼ'mTB޻xI?^F9FӆùpʛGһco_>9U\L']ޕ.vJyyŎO:7דx>NkWJx yk<璶zG$7wdBQR5$wz\I]b4]{hG5MKnPo)Ϗ8ۅi 6.䷤8q qMZ+d̤|cb>i6Mϐ/r8{bύBsМ ˞oۤgXÐ,qqP'LP՟8B;%.BzЗ#.B5'yh_+i݄ʚ룁4Zo y^>$q&pzW|/&$C3Xq6MS^I+gi69Hz_Lڮآ>m:t'MFc2}D'Mb?+O}1|.i]hQ, |ot-[, w}uX-^Pg3OYbq[w [jiqBaqTWJC<w`q3<1|>V0k8~)jx[kq7Z|X\7v^+K->qퟢ6k_nS-7-~I7>{,wP-~ų)|^F xoH~\v=wS6%Gi{yϡnY|plx/ h?`Ρ^өgn"zzZXoZrQgSCi[,~/!qw}保|gqnw{[?(֏3.8z!G^=7Sٓ-^N~w5>_Zi\ڵxz!?|oޭE{.gX@y[g&3ԧf#suե'717U~O|m꿒yv2PnE XM;\e_J3[hͷ=~)͑vXúfㅇ,^@y%~Yqk)O ֓˳Fbռ_:,&GHg>r ^Ǽn~m/7TRNk=bwnǭ<~V8xmTb]6wzN)̋ȗs[}'[2?g;s dz_ ob|5sZwųg)o:ȸ^Wx[FzK[nbqyVZ<}T#=Df.w2^Ү<: K#%|?tSϙ@yf/bKo>fChwƫ{f(ǭ/~>~]|C{o|x7S' [q~|xboKI~D?`+kaec5V]ߦ}.x;+7Or[ﬢ>{(Ͻ:{Sg:[E:k'ߥIqPnƧ[_=v2v\A=H/g>|`rofug6ypp{q<<>f v7GZ\˺5b#׷ |껀L5PG_%ϒ>cplʾd1V֏vփg^[xGմj?OÓTQ[]ûSjkjtQ} }ƻo~ʌڪڻgnV1?fNwTA]6m݀ـmoti]?t!X|\$‚[' ș%j$l9%FP!.P[Z~DKɀg3S]A:a(z:-}7: J,|'?4 4ܵ4Yrr㑖2 K-_ǻ3%b^BI,Ӝhhۥ)Irf@a--?   L@FQ@Σ-reBP"( @A)CȥVt;aZUhN,@[6xQeiwxWz0[}/Q{1T5h;|d\k6n t&@6A\C,k ʯ NW \ulM*!!-_rA)&gOؗtG[?|70oL ,`9",e5+X N4@Oo#mO-u#{ArXT.y;@^`ĭ@vVEUt1]HPd0킠nʦbϠ:]:EM~?EO˩Na^+=6h)В5J׮: ]ľ6=  etA ~:a $hS2J@H-VҀ q!h<KAĜ|Z"mitGZNru%@QOz-`kyy+[N[Cmn;bјC ]]vNqzbt9[GF[{AA0NPLX4F-`Kϐmy#m?t rhLq+ØWqA`9"A ZA<rZ4: GM jh\ӼEoN?Qc:b5hq& A MTSNmZ5Z(Ђn nom}ygft x~ 9z({rAvm-Ngڲ_l6I hpE"ٚ ʡ.i>OrJi>`| .knG@`휡u 6?? )! 9usI? B&P}x\zv%] ^~a `y:.=IGq SR]0 Q3[uDV;JU3?(|APk |3H-ͫzHLj9:h{ ;qlG>.{۳j< HVڇ.);?4x]}S_>F(1Vt4Lrn<'aoʹalj-T"ĉ/BX.C"H<ER#"!#G<:xtGu]]E&( `Xќmultcomp/data/recovery.rda0000644000176200001440000000051412223037755015357 0ustar liggesusersR0C2E>E/?}O8RXǗ&5#U6BH!-&>"!];S'} .y":אAA$_gd꣥g]{ AGn^W}Y: <.^uXiPs 77A73{gã5`hwnLϯwY4\D{wѠk?`K"/="aɰbX3lyf&Z`&Z-A+Pp(8 CPpApApG G=Umultcomp/man/0000755000176200001440000000000014165061465012675 5ustar liggesusersmultcomp/man/plot.cld.Rd0000644000176200001440000001237212223513211014670 0ustar liggesusers\name{plot.cld} \alias{plot.cld} \title{Plot a cld object} \description{ Plot information of \code{glht}, \code{summary.glht} or \code{confint.glht} objects stored as \code{cld} objects together with a compact letter display of all pair-wise comparisons. } \usage{ \method{plot}{cld}(x, type = c("response", "lp"), ...) } \arguments{ \item{x}{ An object of class \code{cld}. } \item{type}{ Should the response or the linear predictor (lp) be plotted. If there are any covariates, the lp is automatically used. To use the response variable, set \code{type="response"} and \code{covar=FALSE} of the \code{cld} object. } \item{...}{ Other optional print parameters which are passed to the plotting functions. } } \details{ This function plots the information stored in \code{glht}, \code{summary.glht} or \code{confint.glht} objects. Prior to plotting, these objects have to be converted to \code{cld} objects (see \code{\link{cld}} for details). All types of plots include a compact letter display (cld) of all pair-wise comparisons. Equal letters indicate no significant differences. Two levels are significantly different, in case they do not have any letters in common. If the fitted model contains any covariates, a boxplot of the linear predictor is generated with the cld within the upper margin. Otherwise, three different types of plots are used depending on the class of variable \code{y} of the \code{cld} object. In case of \code{class(y) == "numeric"}, a boxplot is generated using the response variable, classified according to the levels of the variable used for the Tukey contrast matrix. Is \code{class(y) == "factor"}, a mosaic plot is generated, and the cld is printed above. In case of \code{class(y) == "Surv"}, a plot of fitted survival functions is generated where the cld is plotted within the legend. The compact letter display is computed using the algorithm of Piepho (2004). Note: The user has to provide a sufficiently large upper margin which can be used to depict the compact letter display (see examples). } \references{ Hans-Peter Piepho (2004), An Algorithm for a Letter-Based Representation of All-Pairwise Comparisons, \emph{Journal of Computational and Graphical Statistics}, \bold{13}(2), 456--466. } \seealso{ \code{\link{glht}} \code{\link{cld}} \code{\link{cld.summary.glht}} \code{\link{cld.confint.glht}} \code{\link{cld.glht}} \code{\link{boxplot}} \code{\link{mosaicplot}} \code{\link{plot.survfit}} } \examples{ ### multiple comparison procedures ### set up a one-way ANOVA data(warpbreaks) amod <- aov(breaks ~ tension, data = warpbreaks) ### specify all pair-wise comparisons among levels of variable "tension" tuk <- glht(amod, linfct = mcp(tension = "Tukey")) ### extract information tuk.cld <- cld(tuk) ### use sufficiently large upper margin old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) ### plot plot(tuk.cld) par(old.par) ### now using covariates amod2 <- aov(breaks ~ tension + wool, data = warpbreaks) tuk2 <- glht(amod2, linfct = mcp(tension = "Tukey")) tuk.cld2 <- cld(tuk2) old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) ### use different colors for boxes plot(tuk.cld2, col=c("green", "red", "blue")) par(old.par) ### get confidence intervals ci.glht <- confint(tuk) ### plot them plot(ci.glht) old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) ### use 'confint.glht' object to plot all pair-wise comparisons plot(cld(ci.glht), col=c("white", "blue", "green")) par(old.par) ### set up all pair-wise comparisons for count data data(Titanic) mod <- glm(Survived ~ Class, data = as.data.frame(Titanic), weights = Freq, family = binomial()) ### specify all pair-wise comparisons among levels of variable "Class" glht.mod <- glht(mod, mcp(Class = "Tukey")) ### extract information mod.cld <- cld(glht.mod) ### use sufficiently large upper margin old.par <- par(mai=c(1,1,1.5,1), no.readonly=TRUE) ### plot plot(mod.cld) par(old.par) ### set up all pair-wise comparisons of a Cox-model if (require("survival") && require("MASS")) { ### construct 4 classes of age Melanoma$Cage <- factor(sapply(Melanoma$age, function(x){ if( x <= 25 ) return(1) if( x > 25 & x <= 50 ) return(2) if( x > 50 & x <= 75 ) return(3) if( x > 75 & x <= 100) return(4) } )) ### fit Cox-model cm <- coxph(Surv(time, status == 1) ~ Cage, data = Melanoma) ### specify all pair-wise comparisons among levels of "Cage" cm.glht <- glht(cm, mcp(Cage = "Tukey")) # extract information & plot old.par <- par(no.readonly=TRUE) ### use mono font family if (dev.interactive()) old.par <- par(family = "mono") plot(cld(cm.glht), col=c("black", "red", "blue", "green")) par(old.par) } if (require("nlme") && require("lme4")) { data("ergoStool", package = "nlme") stool.lmer <- lmer(effort ~ Type + (1 | Subject), data = ergoStool) glme41 <- glht(stool.lmer, mcp(Type = "Tukey")) old.par <- par(mai=c(1,1,1.5,1), no.readonly=TRUE) plot(cld(glme41)) par(old.par) } } \keyword{hplot} multcomp/man/trees513.Rd0000644000176200001440000000456113732651406014544 0ustar liggesusers\name{trees513} \alias{trees513} \docType{data} \title{ Frankonian Tree Damage Data } \description{ Damages on young trees caused by deer browsing. } \usage{data("trees513")} \format{ A data frame with 2700 observations on the following 4 variables. \describe{ \item{\code{damage}}{a factor with levels \code{yes} and \code{no} indicating whether or not the trees has been damaged by game animals, mostly roe deer.} \item{\code{species}}{a factor with levels \code{spruce}, \code{fir}, \code{pine}, \code{softwood (other)}, \code{beech}, \code{oak}, \code{ash/maple/elm/lime}, and \code{hardwood (other)}.} \item{\code{lattice}}{a factor with levels \code{1}, ..., \code{53}, essentially a number indicating the position of the sampled area.} \item{\code{plot}}{a factor with levels \code{x_1}, ..., \code{x_5} where \code{x} is the lattice. \code{plot} is nested within \code{lattice} and is a replication for each lattice point.} } } \details{ In most parts of Germany, the natural or artificial regeneration of forests is difficult due to a high browsing intensity. Young trees suffer from browsing damage, mostly by roe and red deer. In order to estimate the browsing intensity for several tree species, the Bavarian State Ministry of Agriculture and Foresty conducts a survey every three years. Based on the estimated percentage of damaged trees, suggestions for the implementation or modification of deer management plans are made. The survey takes place in all 756 game management districts (`Hegegemeinschaften') in Bavaria. The data given here are from the game management district number 513 `Unterer Aischgrund' (located in Frankonia between Erlangen and H\"ochstadt) in 2006. The data of 2700 trees include the species and a binary variable indicating whether or not the tree suffers from damage caused by deer browsing. } \source{ Bayerisches Staatsministerium fuer Landwirtschaft und Forsten (2006), Forstliche Gutachten zur Situation der Waldverjuengung 2006. \url{https://www.stmelf.bayern.de/wald/} Torsten Hothorn, Frank Bretz and Peter Westfall (2008), Simultaneous Inference in General Parametric Models. \emph{Biometrical Journal}, \bold{50}(3), 346--363; See \code{vignette("generalsiminf", package = "multcomp")}. } \examples{ summary(trees513) } \keyword{datasets} multcomp/man/cld.Rd0000644000176200001440000000740512223513211013714 0ustar liggesusers\name{cld} \alias{cld} \alias{cld.glht} \alias{cld.summary.glht} \alias{cld.confint.glht} \title{Set up a compact letter display of all pair-wise comparisons} \description{ Extract information from \code{glht}, \code{summary.glht} or \code{confint.glht} objects which is required to create and plot compact letter displays of all pair-wise comparisons. } \usage{ \method{cld}{summary.glht}(object, level = 0.05, decreasing = FALSE, ...) \method{cld}{glht}(object, level = 0.05, decreasing = FALSE, ...) \method{cld}{confint.glht}(object, decreasing = FALSE, ...) } \arguments{ \item{object}{ An object of class \code{glht}, \code{summary.glht} or \code{confint.glht}. } \item{level}{ Significance-level to be used to term a specific pair-wise comparison significant. } \item{decreasing}{ logical. Should the order of the letters be increasing or decreasing? } \item{...}{additional arguments.} } \details{ This function extracts all the information from \code{glht}, \code{summary.glht} or \code{confint.glht} objects that is required to create a compact letter display of all pair-wise comparisons. In case the contrast matrix is not of type \code{"Tukey"}, an error is issued. In case of \code{confint.glht} objects, a pair-wise comparison is termed significant whenever a particular confidence interval contains 0. Otherwise, p-values are compared to the value of \code{"level"}. Once, this information is extracted, plotting of all pair-wise comparisons can be carried out. } \value{ An object of class \code{cld}, a list with items: \item{y}{ Values of the response variable of the original model. } \item{yname}{ Name of the response variable. } \item{x}{ Values of the variable used to compute Tukey contrasts. } \item{weights}{ Weights used in the fitting process. } \item{lp}{ Predictions from the fitted model. } \item{covar}{ A logical indicating whether the fitted model contained covariates. } \item{signif}{ Vector of logicals indicating significant differences with hyphenated names that identify pair-wise comparisons. } } \references{ Hans-Peter Piepho (2004), An Algorithm for a Letter-Based Representation of All-Pairwise Comparisons, \emph{Journal of Computational and Graphical Statistics}, \bold{13}(2), 456--466. } \seealso{ \code{\link{glht}} \code{\link{plot.cld}} } \examples{ ### multiple comparison procedures ### set up a one-way ANOVA data(warpbreaks) amod <- aov(breaks ~ tension, data = warpbreaks) ### specify all pair-wise comparisons among levels of variable "tension" tuk <- glht(amod, linfct = mcp(tension = "Tukey")) ### extract information tuk.cld <- cld(tuk) ### use sufficiently large upper margin old.par <- par(mai=c(1,1,1.25,1), no.readonly = TRUE) ### plot plot(tuk.cld) par(old.par) ### now using covariates data(warpbreaks) amod2 <- aov(breaks ~ tension + wool, data = warpbreaks) ### specify all pair-wise comparisons among levels of variable "tension" tuk2 <- glht(amod2, linfct = mcp(tension = "Tukey")) ### extract information tuk.cld2 <- cld(tuk2) ### use sufficiently large upper margin old.par <- par(mai=c(1,1,1.25,1), no.readonly = TRUE) ### plot using different colors plot(tuk.cld2, col=c("black", "red", "blue")) par(old.par) ### set up all pair-wise comparisons for count data data(Titanic) mod <- glm(Survived ~ Class, data = as.data.frame(Titanic), weights = Freq, family = binomial()) ### specify all pair-wise comparisons among levels of variable "Class" glht.mod <- glht(mod, mcp(Class = "Tukey")) ### extract information mod.cld <- cld(glht.mod) ### use sufficiently large upper margin old.par <- par(mai=c(1,1,1.5,1), no.readonly = TRUE) ### plot plot(mod.cld) par(old.par) } multcomp/man/glht.Rd0000644000176200001440000002564413435530003014121 0ustar liggesusers\name{glht} \alias{glht} \alias{glht.matrix} \alias{glht.character} \alias{glht.expression} \alias{glht.mcp} \alias{glht.mlf} \alias{mcp} \title{ General Linear Hypotheses } \description{ General linear hypotheses and multiple comparisons for parametric models, including generalized linear models, linear mixed effects models, and survival models. } \usage{ \method{glht}{matrix}(model, linfct, alternative = c("two.sided", "less", "greater"), rhs = 0, ...) \method{glht}{character}(model, linfct, ...) \method{glht}{expression}(model, linfct, ...) \method{glht}{mcp}(model, linfct, ...) \method{glht}{mlf}(model, linfct, ...) mcp(..., interaction_average = FALSE, covariate_average = FALSE) } \arguments{ \item{model}{ a fitted model, for example an object returned by \code{\link{lm}}, \code{\link{glm}}, or \code{\link{aov}} etc. It is assumed that \code{\link{coef}} and \code{\link{vcov}} methods are available for \code{model}. For multiple comparisons of means, methods \code{\link{model.matrix}}, \code{\link{model.frame}} and \code{\link{terms}} are expected to be available for \code{model} as well.} \item{linfct}{ a specification of the linear hypotheses to be tested. Linear functions can be specified by either the matrix of coefficients or by symbolic descriptions of one or more linear hypotheses. Multiple comparisons in AN(C)OVA models are specified by objects returned from function \code{mcp}.}. \item{alternative}{ a character string specifying the alternative hypothesis, must be one of '"two.sided"' (default), '"greater"' or '"less"'. You can specify just the initial letter.} \item{rhs}{ an optional numeric vector specifying the right hand side of the hypothesis.} \item{interaction_average}{logical indicating if comparisons are averaging over interaction terms. Experimental!} \item{covariate_average}{logical indicating if comparisons are averaging over additional covariates. Experimental!} \item{\dots}{ additional arguments to function \code{\link{modelparm}} in all \code{glht} methods. For function \code{mcp}, multiple comparisons are defined by matrices or symbolic descriptions specifying contrasts of factor levels where the arguments correspond to factor names.} } \details{ A general linear hypothesis refers to null hypotheses of the form \eqn{H_0: K \theta = m} for some parametric model \code{model} with parameter estimates \code{coef(model)}. The null hypothesis is specified by a linear function \eqn{K \theta}, the direction of the alternative and the right hand side \eqn{m}. Here, \code{alternative} equal to \code{"two.sided"} refers to a null hypothesis \eqn{H_0: K \theta = m}, whereas \code{"less"} corresponds to \eqn{H_0: K \theta \ge m} and \code{"greater"} refers to \eqn{H_0: K \theta \le m}. The right hand side vector \eqn{m} can be defined via the \code{rhs} argument. The generic method \code{glht} dispatches on its second argument (\code{linfct}). There are three ways, and thus methods, to specify linear functions to be tested: 1) The \code{matrix} of coefficients \eqn{K} can be specified directly via the \code{linfct} argument. In this case, the number of columns of this matrix needs to correspond to the number of parameters estimated by \code{model}. It is assumed that appropriate \code{coef} and \code{vcov} methods are available for \code{model} (\code{\link{modelparm}} deals with some exceptions). 2) A symbolic description, either a \code{character} or \code{expression} vector passed to \code{glht} via its \code{linfct} argument, can be used to define the null hypothesis. A symbolic description must be interpretable as a valid R expression consisting of both the left and right hand side of a linear hypothesis. Only the names of \code{coef(model)} must be used as variable names. The alternative is given by the direction under the null hypothesis (\code{=} or \code{==} refer to \code{"two.sided"}, \code{<=} means \code{"greater"} and \code{>=} indicates \code{"less"}). Numeric vectors of length one are valid values for the right hand side. 3) Multiple comparisons of means are defined by objects of class \code{mcp} as returned by the \code{mcp} function. For each factor, which is included in \code{model} as independent variable, a contrast matrix or a symbolic description of the contrasts can be specified as arguments to \code{mcp}. A symbolic description may be a \code{character} or \code{expression} where the factor levels are only used as variables names. In addition, the \code{type} argument to the contrast generating function \code{\link{contrMat}} may serve as a symbolic description of contrasts as well. 4) The \code{lsm} function in package \code{lsmeans} offers a symbolic interface for the definition of least-squares means for factor combinations which is very helpful when more complex contrasts are of special interest. The \code{mcp} function must be used with care when defining parameters of interest in two-way ANOVA or ANCOVA models. Here, the definition of treatment differences (such as Tukey's all-pair comparisons or Dunnett's comparison with a control) might be problem specific. Because it is impossible to determine the parameters of interest automatically in this case, \code{mcp} in multcomp version 1.0-0 and higher generates comparisons for the main effects only, ignoring covariates and interactions (older versions automatically averaged over interaction terms). A warning is given. We refer to Hsu (1996), Chapter 7, and Searle (1971), Chapter 7.3, for further discussions and examples on this issue. \code{glht} extracts the number of degrees of freedom for models of class \code{lm} (via \code{\link{modelparm}}) and the exact multivariate t distribution is evaluated. For all other models, results rely on the normal approximation. Alternatively, the degrees of freedom to be used for the evaluation of multivariate t distributions can be given by the additional \code{df} argument to \code{\link{modelparm}} specified via \code{\dots}. \code{glht} methods return a specification of the null hypothesis \eqn{H_0: K \theta = m}. The value of the linear function \eqn{K \theta} can be extracted using the \code{\link{coef}} method and the corresponding covariance matrix is available from the \code{\link{vcov}} method. Various simultaneous and univariate tests and confidence intervals are available from \code{\link{summary.glht}} and \code{\link{confint.glht}} methods, respectively. A more detailed description of the underlying methodology is available from Hothorn et al. (2008) and Bretz et al. (2010). } \value{ An object of class \code{glht}, more specifically a list with elements \item{model}{a fitted model, used in the call to \code{glht}} \item{linfct}{ the matrix of linear functions} \item{rhs}{ the vector of right hand side values \eqn{m}} \item{coef}{ the values of the linear functions} \item{vcov}{ the covariance matrix of the values of the linear functions} \item{df}{ optionally, the degrees of freedom when the exact t distribution is used for inference} \item{alternative}{ a character string specifying the alternative hypothesis} \item{type}{ optionally, a character string giving the name of the specific procedure} with \code{print}, \code{\link{summary}}, \code{\link{confint}}, \code{\link{coef}} and \code{\link{vcov}} methods being available. When called with \code{linfct} being an \code{mcp} object, an additional element \code{focus} is available storing the names of the factors under test. } \references{ Frank Bretz, Torsten Hothorn and Peter Westfall (2010), \emph{Multiple Comparisons Using R}, CRC Press, Boca Raton. Shayle R. Searle (1971), \emph{Linear Models}. John Wiley \& Sons, New York. Jason C. Hsu (1996), \emph{Multiple Comparisons}. Chapman & Hall, London. Torsten Hothorn, Frank Bretz and Peter Westfall (2008), Simultaneous Inference in General Parametric Models. \emph{Biometrical Journal}, \bold{50}(3), 346--363; See \code{vignette("generalsiminf", package = "multcomp")}. } \examples{ ### multiple linear model, swiss data lmod <- lm(Fertility ~ ., data = swiss) ### test of H_0: all regression coefficients are zero ### (ignore intercept) ### define coefficients of linear function directly K <- diag(length(coef(lmod)))[-1,] rownames(K) <- names(coef(lmod))[-1] K ### set up general linear hypothesis glht(lmod, linfct = K) ### alternatively, use a symbolic description ### instead of a matrix glht(lmod, linfct = c("Agriculture = 0", "Examination = 0", "Education = 0", "Catholic = 0", "Infant.Mortality = 0")) ### multiple comparison procedures ### set up a one-way ANOVA amod <- aov(breaks ~ tension, data = warpbreaks) ### set up all-pair comparisons for factor `tension' ### using a symbolic description (`type' argument ### to `contrMat()') glht(amod, linfct = mcp(tension = "Tukey")) ### alternatively, describe differences symbolically glht(amod, linfct = mcp(tension = c("M - L = 0", "H - L = 0", "H - M = 0"))) ### alternatively, define contrast matrix directly contr <- rbind("M - L" = c(-1, 1, 0), "H - L" = c(-1, 0, 1), "H - M" = c(0, -1, 1)) glht(amod, linfct = mcp(tension = contr)) ### alternatively, define linear function for coef(amod) ### instead of contrasts for `tension' ### (take model contrasts and intercept into account) glht(amod, linfct = cbind(0, contr \%*\% contr.treatment(3))) ### mix of one- and two-sided alternatives warpbreaks.aov <- aov(breaks ~ wool + tension, data = warpbreaks) ### contrasts for `tension' K <- rbind("L - M" = c( 1, -1, 0), "M - L" = c(-1, 1, 0), "L - H" = c( 1, 0, -1), "M - H" = c( 0, 1, -1)) warpbreaks.mc <- glht(warpbreaks.aov, linfct = mcp(tension = K), alternative = "less") ### correlation of first two tests is -1 cov2cor(vcov(warpbreaks.mc)) ### use smallest of the two one-sided ### p-value as two-sided p-value -> 0.0232 summary(warpbreaks.mc) ### more complex models: Continuous outcome logistic ### regression; parameters are log-odds ratios if (require("tram")) { confint(glht(Colr(breaks ~ wool + tension, data = warpbreaks), linfct = mcp("tension" = "Tukey"))) } } \keyword{htest} multcomp/man/recovery.Rd0000644000176200001440000000304212223513211015001 0ustar liggesusers\name{recovery} \alias{recovery} \docType{data} \title{ Recovery Time Data Set } \usage{data("recovery")} \description{ Recovery time after surgery. } \format{ This data frame contains the following variables \describe{ \item{blanket}{blanket type, a factor at four levels: \code{b0}, \code{b1}, \code{b2}, and \code{b3}.} \item{minutes}{response variable: recovery time after a surgical procedure.} } } \details{ A company developed specialized heating blankets designed to help the body heat following a surgical procedure. Four types of blankets were tried on surgical patients with the aim of comparing the recovery time of patients. One of the blanket was a standard blanket that had been in use already in various hospitals. } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc., page 66. } \examples{ ### set up one-way ANOVA amod <- aov(minutes ~ blanket, data = recovery) ### set up multiple comparisons: one-sided Dunnett contrasts rht <- glht(amod, linfct = mcp(blanket = "Dunnett"), alternative = "less") ### cf. Westfall et al. (1999, p. 80) confint(rht, level = 0.9) ### the same rht <- glht(amod, linfct = mcp(blanket = c("b1 - b0 >= 0", "b2 - b0 >= 0", "b3 - b0 >= 0"))) confint(rht, level = 0.9) } \keyword{datasets} multcomp/man/adevent.Rd0000644000176200001440000000525512223513211014601 0ustar liggesusers\name{adevent} \alias{adevent} \docType{data} \title{ Adverse Events Data } \description{ Indicators of 28 adverse events in a two-arm clinical trial. } \usage{data(adevent)} \format{ A data frame with 160 observations on the following 29 variables. \describe{ \item{\code{E1}}{a factor with levels \code{no event} \code{event}} \item{\code{E2}}{a factor with levels \code{no event} \code{event}} \item{\code{E3}}{a factor with levels \code{no event} \code{event}} \item{\code{E4}}{a factor with levels \code{no event} \code{event}} \item{\code{E5}}{a factor with levels \code{no event} \code{event}} \item{\code{E6}}{a factor with levels \code{no event} \code{event}} \item{\code{E7}}{a factor with levels \code{no event} \code{event}} \item{\code{E8}}{a factor with levels \code{no event} \code{event}} \item{\code{E9}}{a factor with levels \code{no event} \code{event}} \item{\code{E10}}{a factor with levels \code{no event} \code{event}} \item{\code{E11}}{a factor with levels \code{no event} \code{event}} \item{\code{E12}}{a factor with levels \code{no event} \code{event}} \item{\code{E13}}{a factor with levels \code{no event} \code{event}} \item{\code{E14}}{a factor with levels \code{no event} \code{event}} \item{\code{E15}}{a factor with levels \code{no event} \code{event}} \item{\code{E16}}{a factor with levels \code{no event} \code{event}} \item{\code{E17}}{a factor with levels \code{no event} \code{event}} \item{\code{E18}}{a factor with levels \code{no event} \code{event}} \item{\code{E19}}{a factor with levels \code{no event} \code{event}} \item{\code{E20}}{a factor with levels \code{no event} \code{event}} \item{\code{E21}}{a factor with levels \code{no event} \code{event}} \item{\code{E22}}{a factor with levels \code{no event} \code{event}} \item{\code{E23}}{a factor with levels \code{no event} \code{event}} \item{\code{E24}}{a factor with levels \code{no event} \code{event}} \item{\code{E25}}{a factor with levels \code{no event} \code{event}} \item{\code{E26}}{a factor with levels \code{no event} \code{event}} \item{\code{E27}}{a factor with levels \code{no event} \code{event}} \item{\code{E28}}{a factor with levels \code{no event} \code{event}} \item{\code{group}}{group indicator.} } } \details{ The data is provided by Westfall et al. (1999, p. 242) and contains binary indicators of 28 adverse events (\code{E1},..., \code{E28}) for two arms (\code{group}). } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc. } \keyword{datasets} multcomp/man/methods.Rd0000644000176200001440000001670313077412772014640 0ustar liggesusers\name{glht-methods} \alias{summary.glht} \alias{confint.glht} \alias{coef.glht} \alias{vcov.glht} \alias{plot.glht} \alias{plot.confint.glht} \alias{univariate} \alias{adjusted} \alias{Ftest} \alias{Chisqtest} \alias{adjusted_calpha} \alias{univariate_calpha} \title{ Methods for General Linear Hypotheses } \description{ Simultaneous tests and confidence intervals for general linear hypotheses. } \usage{ \method{summary}{glht}(object, test = adjusted(), ...) \method{confint}{glht}(object, parm, level = 0.95, calpha = adjusted_calpha(), ...) \method{coef}{glht}(object, rhs = FALSE, ...) \method{vcov}{glht}(object, ...) \method{plot}{confint.glht}(x, xlim, xlab, ylim, ...) \method{plot}{glht}(x, ...) univariate() adjusted(type = c("single-step", "Shaffer", "Westfall", "free", p.adjust.methods), ...) Ftest() Chisqtest() adjusted_calpha(...) univariate_calpha(...) } \arguments{ \item{object}{ an object of class \code{\link{glht}}.} \item{test}{ a function for computing p values.} \item{parm}{ additional parameters, currently ignored.} \item{level}{ the confidence level required.} \item{calpha}{ either a function computing the critical value or the critical value itself.} \item{rhs}{logical, indicating whether the linear function \eqn{K \hat{\theta}} or the right hand side \eqn{m} (\code{rhs = TRUE}) of the linear hypothesis should be returned.} \item{type}{ the multiplicity adjustment (\code{adjusted}) to be applied. See below and \code{\link{p.adjust}}.} \item{x}{an object of class \code{\link{glht}} or \code{confint.glht}.} \item{xlim}{the \code{x} limits \code{(x1, x2)} of the plot.} \item{ylim}{the y limits of the plot.} \item{xlab}{a label for the \code{x} axis.} \item{...}{ additional arguments, such as \code{maxpts}, \code{abseps} or \code{releps} to \code{\link[mvtnorm]{pmvnorm}} in \code{adjusted} or \code{\link[mvtnorm]{qmvnorm}} in \code{confint}. Note that additional arguments specified to \code{summary}, \code{confint}, \code{coef} and \code{vcov} methods are currently ignored.} } \details{ The methods for general linear hypotheses as described by objects returned by \code{\link{glht}} can be used to actually test the global null hypothesis, each of the partial hypotheses and for simultaneous confidence intervals for the linear function \eqn{K \theta}. The \code{\link{coef}} and \code{\link{vcov}} methods compute the linear function \eqn{K \hat{\theta}} and its covariance, respectively. The \code{test} argument to \code{summary} takes a function specifying the type of test to be applied. Classical Chisq (Wald test) or F statistics for testing the global hypothesis \eqn{H_0} are implemented in functions \code{Chisqtest} and \code{Ftest}. Several approaches to multiplicity adjusted p values for each of the linear hypotheses are implemented in function \code{adjusted}. The \code{type} argument to \code{adjusted} specifies the method to be applied: \code{"single-step"} implements adjusted p values based on the joint normal or t distribution of the linear function, and \code{"Shaffer"} and \code{"Westfall"} implement logically constraint multiplicity adjustments (Shaffer, 1986; Westfall, 1997). \code{"free"} implements multiple testing procedures under free combinations (Westfall et al, 1999). In addition, all adjustment methods implemented in \code{\link{p.adjust}} are available as well. Simultaneous confidence intervals for linear functions can be computed using method \code{\link{confint}}. Univariate confidence intervals can be computed by specifying \code{calpha = univariate_calpha()} to \code{confint}. The critical value can directly be specified as a scalar to \code{calpha} as well. Note that \code{plot(a)} for some object \code{a} of class \code{glht} is equivalent to \code{plot(confint(a))}. All simultaneous inference procedures implemented here control the family-wise error rate (FWER). Multivariate normal and t distributions, the latter one only for models of class \code{\link{lm}}, are evaluated using the procedures implemented in package \code{mvtnorm}. Note that the default procedure is stochastic. Reproducible p-values and confidence intervals require appropriate settings of seeds. A more detailed description of the underlying methodology is available from Hothorn et al. (2008) and Bretz et al. (2010). } \value{ \code{summary} computes (adjusted) p values for general linear hypotheses, \code{\link{confint}} computes (adjusted) confidence intervals. \code{\link{coef}} returns estimates of the linear function \eqn{K \theta} and \code{\link{vcov}} its covariance. } \references{ Frank Bretz, Torsten Hothorn and Peter Westfall (2010), \emph{Multiple Comparisons Using R}, CRC Press, Boca Raton. Juliet P. Shaffer (1986), Modified sequentially rejective multiple test procedures. \emph{Journal of the American Statistical Association}, \bold{81}, 826--831. Peter H. Westfall (1997), Multiple testing of general contrasts using logical constraints and correlations. \emph{Journal of the American Statistical Association}, \bold{92}, 299--306. P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc. Torsten Hothorn, Frank Bretz and Peter Westfall (2008), Simultaneous Inference in General Parametric Models. \emph{Biometrical Journal}, \bold{50}(3), 346--363; See \code{vignette("generalsiminf", package = "multcomp")}. } \examples{ ### set up a two-way ANOVA amod <- aov(breaks ~ wool + tension, data = warpbreaks) ### set up all-pair comparisons for factor `tension' wht <- glht(amod, linfct = mcp(tension = "Tukey")) ### 95\% simultaneous confidence intervals plot(print(confint(wht))) ### the same (for balanced designs only) TukeyHSD(amod, "tension") ### corresponding adjusted p values summary(wht) ### all means for levels of `tension' amod <- aov(breaks ~ tension, data = warpbreaks) glht(amod, linfct = matrix(c(1, 0, 0, 1, 1, 0, 1, 0, 1), byrow = TRUE, ncol = 3)) ### confidence bands for a simple linear model, `cars' data plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)", las = 1) ### fit linear model and add regression line to plot lmod <- lm(dist ~ speed, data = cars) abline(lmod) ### a grid of speeds speeds <- seq(from = min(cars$speed), to = max(cars$speed), length = 10) ### linear hypotheses: 10 selected points on the regression line != 0 K <- cbind(1, speeds) ### set up linear hypotheses cht <- glht(lmod, linfct = K) ### confidence intervals, i.e., confidence bands, and add them plot cci <- confint(cht) lines(speeds, cci$confint[,"lwr"], col = "blue") lines(speeds, cci$confint[,"upr"], col = "blue") ### simultaneous p values for parameters in a Cox model if (require("survival") && require("MASS")) { data("leuk", package = "MASS") leuk.cox <- coxph(Surv(time) ~ ag + log(wbc), data = leuk) ### set up linear hypotheses lht <- glht(leuk.cox, linfct = diag(length(coef(leuk.cox)))) ### adjusted p values print(summary(lht)) } } \keyword{htest} multcomp/man/sbp.Rd0000644000176200001440000000117212223513211013731 0ustar liggesusers\name{sbp} \alias{sbp} \docType{data} \title{ Systolic Blood Pressure Data } \description{ Systolic blood pressure, age and gender of 69 people. } \usage{data("sbp")} \format{ A data frame with 69 observations on the following 3 variables. \describe{ \item{\code{gender}}{a factor with levels \code{male} \code{female}} \item{\code{sbp}}{systolic blood pressure in mmHg} \item{\code{age}}{age in years} } } \source{ D. G. Kleinbaum, L. L. Kupper, K. E. Muller, A. Nizam, A. (1998), \emph{Applied Regression Analysis and Other Multivariable Methods}, Duxbury Press, North Scituate, MA. } \keyword{datasets} multcomp/man/cholesterol.Rd0000644000176200001440000000413012223513211015465 0ustar liggesusers\name{cholesterol} \alias{cholesterol} \docType{data} \title{ Cholesterol Reduction Data Set } \usage{data("cholesterol")} \description{ Cholesterol reduction for five treatments. } \format{ This data frame contains the following variables \describe{ \item{trt}{treatment groups, a factor at levels \code{1time}, \code{2times}, \code{4times}, \code{drugD} and \code{drugE}.} \item{response}{cholesterol reduction.} } } \details{ A clinical study was conducted to assess the effect of three formulations of the same drug on reducing cholesterol. The formulations were 20mg at once (\code{1time}), 10mg twice a day (\code{2times}), and 5mg four times a day (\code{4times}). In addition, two competing drugs were used as control group (\code{drugD} and \code{drugE}). The purpose of the study was to find which of the formulations, if any, is efficacious and how these formulations compare with the existing drugs. } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc., page 153. } \examples{ ### adjusted p-values for all-pairwise comparisons in a one-way layout ### set up ANOVA model amod <- aov(response ~ trt, data = cholesterol) ### set up multiple comparisons object for all-pair comparisons cht <- glht(amod, linfct = mcp(trt = "Tukey")) ### cf. Westfall et al. (1999, page 171) summary(cht, test = univariate()) summary(cht, test = adjusted("Shaffer")) summary(cht, test = adjusted("Westfall")) ### use only a subset of all pairwise hypotheses K <- contrMat(table(cholesterol$trt), type="Tukey") Ksub <- rbind(K[c(1,2,5),], "D - test" = c(-1, -1, -1, 3, 0), "E - test" = c(-1, -1, -1, 0, 3)) ### reproduce results in Westfall et al. (1999, page 172) ### note: the ordering of our estimates here is different amod <- aov(response ~ trt - 1, data = cholesterol) summary(glht(amod, linfct = mcp(trt = Ksub[,5:1])), test = adjusted("Westfall")) } \keyword{datasets} multcomp/man/parm.Rd0000644000176200001440000000311312223513211014101 0ustar liggesusers\name{parm} \alias{parm} \title{ Model Parameters } \description{ Directly specify estimated model parameters and their covariance matrix. } \usage{ parm(coef, vcov, df = 0) } \arguments{ \item{coef}{ estimated coefficients.} \item{vcov}{ estimated covariance matrix of the coefficients.} \item{df}{ an optional specification of the degrees of freedom to be used in subsequent computations. } } \details{ When only estimated model parameters and the corresponding covariance matrix is available for simultaneous inference using \code{\link{glht}} (for example, when only the results but not the original data are available or, even worse, when the model has been fitted outside R), function \code{parm} sets up an object \code{\link{glht}} is able to compute on (mainly by offering \code{coef} and \code{vcov} methods). Note that the linear function in \code{\link{glht}} can't be specified via \code{\link{mcp}} since the model terms are missing. } \value{ An object of class \code{parm} with elements \item{coef}{model parameters} \item{vcov}{covariance matrix of model parameters} \item{df}{degrees of freedom} } \examples{ ## example from ## Bretz, Hothorn, and Westfall (2002). ## On multiple comparisons in R. R News, 2(3):14-17. beta <- c(V1 = 14.8, V2 = 12.6667, V3 = 7.3333, V4 = 13.1333) Sigma <- 6.7099 * (diag(1 / c(20, 3, 3, 15))) confint(glht(model = parm(beta, Sigma, 37), linfct = c("V2 - V1 >= 0", "V3 - V1 >= 0", "V4 - V1 >= 0")), level = 0.9) } \keyword{misc} multcomp/man/fattyacid.Rd0000644000176200001440000000303112223513211015111 0ustar liggesusers\name{fattyacid} \alias{fattyacid} \docType{data} \title{Fatty Acid Content of Bacillus simplex.} \description{ Fatty acid content of different putative ecotypes of Bacillus simplex. } \usage{data("fattyacid")} \format{ A data frame with 93 observations on the following 2 variables. \describe{ \item{\code{PE}}{a factor with levels \code{PE3}, \code{PE4}, \code{PE5}, \code{PE6}, \code{PE7}, \code{PE9} indicating the putative ecotype (PE).} \item{\code{FA}}{a numeric vector indicating the content of fatty acid (FA).} } } \details{ The data give the fatty acid content for different putative ecotypes of Bacillus simplex. Variances of the values of fatty acid are heterogeneous among the putative ecotypes.} \source{ J. Sikorski, E. Brambilla, R. M. Kroppenstedt, B. J. Tindal (2008), The temperature adaptive fatty acid content in Bacillus simplex strains from ''Evolution Canyon``, Israel. \emph{Microbiology} \bold{154}, 2416-2426. } \examples{ if (require("sandwich")) { data("fattyacid") ### all-pairwise comparisons of the means of fatty acid content ### FA between different putative ecotypes PE accounting for ### heteroscedasticity by using a heteroscedastic consistent ### covariance estimation amod <- aov(FA ~ PE, data = fattyacid) amod_glht <- glht(amod, mcp(PE = "Tukey"), vcov = vcovHC) summary(amod_glht) ### simultaneous confidence intervals for the differences of ### means of fatty acid content between the putative ecotypes confint(amod_glht) } } \keyword{datasets} multcomp/man/modelparm.Rd0000644000176200001440000000404214160373354015142 0ustar liggesusers\name{modelparm} \alias{modelparm} \title{ Generic Accessor Function for Model Parameters } \description{ Extract model parameters and their covariance matrix as well as degrees of freedom (if available) from a fitted model. } \usage{ modelparm(model, coef., vcov., df, ...) } \arguments{ \item{model}{a fitted model, for example an object returned by \code{\link{lm}}, \code{\link{glm}}, \code{\link{aov}}, \code{\link[survival]{survreg}}, \code{\link[fixest]{fixest}}, or \code{\link[lme4]{lmer}} etc. } \item{coef.}{ an accessor function for the model parameters. Alternatively, the vector of coefficients.} \item{vcov.}{ an accessor function for the covariance matrix of the model parameters. Alternatively, the covariance matrix directly.} \item{df}{ an optional specification of the degrees of freedom to be used in subsequent computations. } \item{\dots}{ additional arguments, currently ignored. } } \details{ One can't expect \code{\link{coef}} and \code{\link{vcov}} methods for arbitrary models to return a vector of \eqn{p} fixed effects model parameters (\code{coef}) and corresponding \eqn{p \times p} covariance matrix (\code{vcov}). The \code{coef.} and \code{vcov.} arguments can be used to define modified \code{coef} or \code{vcov} methods for a specific model. Methods for \code{\link[lme4]{lmer}}, \code{\link[fixest]{fixest}}, and \code{\link[survival]{survreg}} objects are available (internally). For objects inheriting from class \code{\link{lm}} the degrees of freedom are determined from \code{model} and the corresponding multivariate t distribution is used by all methods to \code{\link{glht}} objects. By default, the asymptotic multivariate normal distribution is used in all other cases unless \code{df} is specified by the user. } \value{ An object of class \code{modelparm} with elements \item{coef}{model parameters} \item{vcov}{covariance matrix of model parameters} \item{df}{degrees of freedom} } \keyword{misc} multcomp/man/mtept.Rd0000644000176200001440000000153512223513211014301 0ustar liggesusers\name{mtept} \alias{mtept} \docType{data} \title{ Multiple Endpoints Data } \description{ Measurements on four endpoints in a two-arm clinical trial. } \usage{data(mtept)} \format{ A data frame with 111 observations on the following 5 variables. \describe{ \item{\code{treatment}}{a factor with levels \code{Drug} \code{Placebo}} \item{\code{E1}}{endpoint 1} \item{\code{E2}}{endpoint 2} \item{\code{E3}}{endpoint 3} \item{\code{E4}}{endpoint 4} } } \details{ The data (from Westfall et al., 1999) contain measurements of patients in treatment (\code{Drug}) and control (\code{Placebo}) groups, with four outcome variables. } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc. } \keyword{datasets} multcomp/man/mmm.Rd0000644000176200001440000002052114042470671013747 0ustar liggesusers\name{mmm} \alias{mmm} \alias{mlf} \title{Simultaneous Inference for Multiple Marginal Models} \description{Calculation of correlation between test statistics from multiple marginal models using the score decomposition} \usage{ mmm(...) mlf(...) } \arguments{ \item{\dots}{A names argument list containing fitted models (\code{mmm}) or definitions of linear functions (\code{mlf}). If only one linear function is defined for \code{mlf}, it will be applied to all models in \code{mmm} by \code{\link{glht.mlf}}.} } \details{ Estimated correlations of the estimated parameters of interest from the multiple marginal models are obtained using a stacked version of the i.i.d. decomposition of parameter estimates by means of score components (first derivatives of the log likelihood). The method is less conservative than the Bonferroni correction. The details are provided by Pipper, Ritz and Bisgaard (2012). The implementation assumes that the model were fitted to the same data, i.e., the rows of the matrices returned by \code{estfun} belong to the same observations for each model. The reference distribution is always multivariate normal, if you want to use the multivariate t, please specify the corresponding degrees of freedom as an additional \code{df} argument to \code{\link{glht}}. Observations with missing values contribute zero to the score function. Models have to be fitted using \code{\link{na.exclude}} as \code{na.action} argument. } \value{ An object of class \code{mmm} or \code{mlf}, basically a named list of the arguments with a special method for \code{\link{glht}} being available for the latter. \code{vcov}, \code{\link[sandwich]{estfun}}, and \code{\link[sandwich]{bread}} methods are available for objects of class \code{mmm}. } \references{ Christian Bressen Pipper, Christian Ritz and Hans Bisgaard (2012), A Versatile Method for Confirmatory Evaluation of the Effects of a Covariate in Multiple Models, \emph{Journal of the Royal Statistical Society, Series C (Applied Statistics)}, \bold{61}, 315--326. } \author{ Code for the computation of the joint covariance and sandwich matrices was contributed by Christian Ritz and Christian B. Pipper. } \examples{ ### replicate analysis of Hasler & Hothorn (2011), ### A Dunnett-Type Procedure for Multiple Endpoints, ### The International Journal of Biostatistics: Vol. 7: Iss. 1, Article 3. ### DOI: 10.2202/1557-4679.1258 library("sandwich") ### see ?coagulation if (require("SimComp")) { data("coagulation", package = "SimComp") ### level "S" is the standard, "H" and "B" are novel procedures coagulation$Group <- relevel(coagulation$Group, ref = "S") ### fit marginal models (m1 <- lm(Thromb.count ~ Group, data = coagulation)) (m2 <- lm(ADP ~ Group, data = coagulation)) (m3 <- lm(TRAP ~ Group, data = coagulation)) ### set-up Dunnett comparisons for H - S and B - S ### for all three models g <- glht(mmm(Thromb = m1, ADP = m2, TRAP = m3), mlf(mcp(Group = "Dunnett")), alternative = "greater") ### joint correlation cov2cor(vcov(g)) ### simultaneous p-values adjusted by taking the correlation ### between the score contributions into account summary(g) ### simultaneous confidence intervals confint(g) ### compare with \dontrun{ library("SimComp") SimCiDiff(data = coagulation, grp = "Group", resp = c("Thromb.count","ADP","TRAP"), type = "Dunnett", alternative = "greater", covar.equal = TRUE) } ### use sandwich variance matrix g <- glht(mmm(Thromb = m1, ADP = m2, TRAP = m3), mlf(mcp(Group = "Dunnett")), alternative = "greater", vcov = sandwich) summary(g) confint(g) } ### attitude towards science data data("mn6.9", package = "TH.data") ### one model for each item mn6.9.y1 <- glm(y1 ~ group, family = binomial(), na.action = na.omit, data = mn6.9) mn6.9.y2 <- glm(y2 ~ group, family = binomial(), na.action = na.omit, data = mn6.9) mn6.9.y3 <- glm(y3 ~ group, family = binomial(), na.action = na.omit, data = mn6.9) mn6.9.y4 <- glm(y4 ~ group, family = binomial(), na.action = na.omit, data = mn6.9) ### test all parameters simulaneously summary(glht(mmm(mn6.9.y1, mn6.9.y2, mn6.9.y3, mn6.9.y4), mlf(diag(2)))) ### group differences summary(glht(mmm(mn6.9.y1, mn6.9.y2, mn6.9.y3, mn6.9.y4), mlf("group2 = 0"))) ### alternative analysis of Klingenberg & Satopaa (2013), ### Simultaneous Confidence Intervals for Comparing Margins of ### Multivariate Binary Data, CSDA, 64, 87-98 ### http://dx.doi.org/10.1016/j.csda.2013.02.016 ### see supplementary material for data description ### NOTE: this is not the real data but only a subsample influenza <- structure(list( HEADACHE = c(1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L), MALAISE = c(0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L), PYREXIA = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L ), ARTHRALGIA = c(0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L ), group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("pla", "trt"), class = "factor"), Freq = c(32L, 165L, 10L, 23L, 3L, 1L, 4L, 2L, 4L, 2L, 1L, 1L, 1L, 1L, 167L, 1L, 11L, 37L, 7L, 7L, 5L, 3L, 3L, 1L, 2L, 4L, 2L)), .Names = c("HEADACHE", "MALAISE", "PYREXIA", "ARTHRALGIA", "group", "Freq"), row.names = c(1L, 2L, 3L, 5L, 9L, 36L, 43L, 50L, 74L, 83L, 139L, 175L, 183L, 205L, 251L, 254L, 255L, 259L, 279L, 281L, 282L, 286L, 302L, 322L, 323L, 366L, 382L), class = "data.frame") influenza <- influenza[rep(1:nrow(influenza), influenza$Freq), 1:5] ### Fitting marginal logistic regression models (head_logreg <- glm(HEADACHE ~ group, data = influenza, family = binomial())) (mala_logreg <- glm(MALAISE ~ group, data = influenza, family = binomial())) (pyre_logreg <- glm(PYREXIA ~ group, data = influenza, family = binomial())) (arth_logreg <- glm(ARTHRALGIA ~ group, data = influenza, family = binomial())) ### Simultaneous inference for log-odds xy.sim <- glht(mmm(head = head_logreg, mala = mala_logreg, pyre = pyre_logreg, arth = arth_logreg), mlf("grouptrt = 0")) summary(xy.sim) confint(xy.sim) ### Artificial examples ### Combining linear regression and logistic regression set.seed(29) y1 <- rnorm(100) y2 <- factor(y1 + rnorm(100, sd = .1) > 0) x1 <- gl(4, 25) x2 <- runif(100, 0, 10) m1 <- lm(y1 ~ x1 + x2) m2 <- glm(y2 ~ x1 + x2, family = binomial()) ### Note that the same explanatory variables are considered in both models ### but the resulting parameter estimates are on 2 different scales ### (original and log-odds scales) ### Simultaneous inference for the same parameter in the 2 model fits summary(glht(mmm(m1 = m1, m2 = m2), mlf("x12 = 0"))) ### Simultaneous inference for different parameters in the 2 model fits summary(glht(mmm(m1 = m1, m2 = m2), mlf(m1 = "x12 = 0", m2 = "x13 = 0"))) ### Simultaneous inference for different and identical parameters in the 2 ### model fits summary(glht(mmm(m1 = m1, m2 = m2), mlf(m1 = c("x12 = 0", "x13 = 0"), m2 = "x13 = 0"))) ### Examples for binomial data ### Two independent outcomes y1.1 <- rbinom(100, 1, 0.45) y1.2 <- rbinom(100, 1, 0.55) group <- factor(rep(c("A", "B"), 50)) m1 <- glm(y1.1 ~ group, family = binomial) m2 <- glm(y1.2 ~ group, family = binomial) summary(glht(mmm(m1 = m1, m2 = m2), mlf("groupB = 0"))) ### Two perfectly correlated outcomes y2.1 <- rbinom(100, 1, 0.45) y2.2 <- y2.1 group <- factor(rep(c("A", "B"), 50)) m1 <- glm(y2.1 ~ group, family = binomial) m2 <- glm(y2.2 ~ group, family = binomial) summary(glht(mmm(m1 = m1, m2 = m2), mlf("groupB = 0"))) ### use sandwich covariance matrix summary(glht(mmm(m1 = m1, m2 = m2), mlf("groupB = 0"), vcov = sandwich)) } \keyword{models} multcomp/man/cml.Rd0000644000176200001440000000363012223513211013721 0ustar liggesusers\name{cml} \alias{cml} \docType{data} \title{Chronic Myelogenous Leukemia survival data.} \description{ Survival in a randomised trial comparing three treatments for Chronic Myelogeneous Leukemia (simulated data). } \usage{data("cml")} \format{ A data frame with 507 observations on the following 7 variables. \describe{ \item{\code{center}}{a factor with 54 levels indicating the study center.} \item{\code{treatment}}{a factor with levels \code{trt1}, \code{trt2}, \code{trt3} indicating the treatment group.} \item{\code{sex}}{sex (0 = female, 1 = male)} \item{\code{age}}{age in years} \item{\code{riskgroup}}{risk group (0 = low, 1 = medium, 2 = high)} \item{\code{status}}{censoring status (FALSE = censored, TRUE = dead)} \item{\code{time}}{survival or censoring time in days.} } } \details{ The data are simulated according to structure of the data by the German CML Study Group used in Hehlmann (1994).} \source{ R. Hehlmann, H. Heimpel, J. Hasford, H.J. Kolb, H. Pralle, D.K. Hossfeld, W. Queisser, H. Loeffler, A. Hochhaus, B. Heinze (1994), Randomized comparison of interferon-alpha with busulfan and hydroxyurea in chronic myelogenous leukemia. The German CML study group. \emph{Blood} \bold{84}(12):4064-4077. } \examples{ if (require("coxme")) { data("cml") ### one-sided simultaneous confidence intervals for many-to-one ### comparisons of treatment effects concerning time of survival ### modeled by a frailty Cox model with adjustment for further ### covariates and center-specific random effect. cml_coxme <- coxme(Surv(time, status) ~ treatment + sex + age + riskgroup + (1|center), data = cml) glht_coxme <- glht(model = cml_coxme, linfct = mcp(treatment = "Dunnett"), alternative = "greater") ci_coxme <- confint(glht_coxme) exp(ci_coxme$confint)[1:2,] } } \keyword{datasets} multcomp/man/litter.Rd0000644000176200001440000000360312223513211014451 0ustar liggesusers\name{litter} \alias{litter} \docType{data} \title{ Litter Weights Data Set } \usage{data("litter")} \description{ Dose response of litter weights in rats. } \format{ This data frame contains the following variables \describe{ \item{dose}{dosages at four levels: \code{0}, \code{5}, \code{50}, \code{500}.} \item{gesttime}{gestation time as covariate.} \item{number}{number of animals in litter as covariate.} \item{weight}{response variable: average post-birth weights in the entire litter.} } } \details{ Pregnant mice were divided into four groups and the compound in four different doses was administered during pregnancy. Their litters were evaluated for birth weights. } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc., page 109. P. H. Westfall (1997). Multiple Testing of General Contrasts Using Logical Constraints and Correlations. \emph{Journal of the American Statistical Association}, \bold{92}(437), 299--306. } \examples{ ### fit ANCOVA model to data amod <- aov(weight ~ dose + gesttime + number, data = litter) ### define matrix of linear hypotheses for `dose' doselev <- as.integer(levels(litter$dose)) K <- rbind(contrMat(table(litter$dose), "Tukey"), otrend = c(-1.5, -0.5, 0.5, 1.5), atrend = doselev - mean(doselev), ltrend = log(1:4) - mean(log(1:4))) ### set up multiple comparison object Kht <- glht(amod, linfct = mcp(dose = K), alternative = "less") ### cf. Westfall (1997, Table 2) summary(Kht, test = univariate()) summary(Kht, test = adjusted("bonferroni")) summary(Kht, test = adjusted("Shaffer")) summary(Kht, test = adjusted("Westfall")) summary(Kht, test = adjusted("single-step")) } \keyword{datasets} multcomp/man/detergent.Rd0000644000176200001440000000316213605630625015145 0ustar liggesusers\name{detergent} \alias{detergent} \docType{data} \title{ Detergent Durability Data Set } \usage{data("detergent")} \description{ Detergent durability in an incomplete two-way design. } \format{ This data frame contains the following variables \describe{ \item{detergent}{detergent, a factor at levels \code{A}, \code{B}, \code{C}, \code{D}, and \code{E}.} \item{block}{block, a factor at levels \code{B_1}, ..., \code{B_10}.} \item{plates}{response variable: number of plates washed before the foam disappears.} } } \details{ Plates were washed with five detergent varieties, in ten blocks. A complete design would have 50 combinations, here only three detergent varieties in each block were applied in a balanced incomplete block design. Note that there are six observations taken at each detergent level. } \source{ H. Scheffe (1959). \emph{The Analysis of Variance}. New York: John Wiley & Sons, page 189. P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc., page 189. } \examples{ ### set up two-way ANOVA without interactions amod <- aov(plates ~ block + detergent, data = detergent) ### set up all-pair comparisons dht <- glht(amod, linfct = mcp(detergent = "Tukey")) ### see Westfall et al. (1999, p. 190) confint(dht) ### see Westfall et al. (1999, p. 192) summary(dht, test = univariate()) \dontrun{ summary(dht, test = adjusted("Shaffer")) summary(dht, test = adjusted("Westfall")) } } \keyword{datasets} multcomp/man/cftest.Rd0000644000176200001440000000152712654355067014466 0ustar liggesusers\name{cftest} \alias{cftest} \title{ Testing Estimated Coefficients } \description{ A convenience function for univariate testing via z- and t-tests of estimated model coefficients } \usage{ cftest(model, parm, test = univariate(), ...) } \arguments{ \item{model}{a fitted model.} \item{parm}{a vector of parameters to be tested, either a character vector of names or an integer.} \item{test}{ a function for computing p values, see \code{\link{summary.glht}}.} \item{\dots}{additional arguments passed to \code{\link{summary.glht}}.} } \details{ The usual z- or t-tests are tested without adjusting for multiplicity. } \value{ An object of class \code{summary.glht}. } \seealso{ \code{\link[lmtest]{coeftest}} } \examples{ lmod <- lm(dist ~ speed, data = cars) summary(lmod) cftest(lmod) } \keyword{htest} multcomp/man/contrMat.Rd0000644000176200001440000000337512342032017014745 0ustar liggesusers\name{contrMat} \alias{contrMat} \title{ Contrast Matrices } \description{ Computes contrast matrices for several multiple comparison procedures. } \usage{ contrMat(n, type = c("Dunnett", "Tukey", "Sequen", "AVE", "Changepoint", "Williams", "Marcus", "McDermott", "UmbrellaWilliams", "GrandMean"), base = 1) } \arguments{ \item{n}{ a (possibly named) vector of sample sizes for each group.} \item{type}{ type of contrast. } \item{base}{ an integer specifying which group is considered the baseline group for Dunnett contrasts.} } \details{ Computes the requested matrix of contrasts for comparisons of mean levels. } \value{ The matrix of contrasts with appropriate row names is returned. } \references{ Frank Bretz, Torsten Hothorn and Peter Westfall (2010), \emph{Multiple Comparisons Using R}, CRC Press, Boca Raton. Frank Bretz, Alan Genz and Ludwig A. Hothorn (2001), On the numerical availability of multiple comparison procedures. \emph{Biometrical Journal}, \bold{43}(5), 645--656. } \examples{ n <- c(10,20,30,40) names(n) <- paste("group", 1:4, sep="") contrMat(n) # Dunnett is default contrMat(n, base = 2) # use second level as baseline contrMat(n, type = "Tukey") contrMat(n, type = "Sequen") contrMat(n, type = "AVE") contrMat(n, type = "Changepoint") contrMat(n, type = "Williams") contrMat(n, type = "Marcus") contrMat(n, type = "McDermott") ### Umbrella-protected Williams contrasts, i.e. a sequence of ### Williams-type contrasts with groups of higher order ### stepwise omitted contrMat(n, type = "UmbrellaWilliams") ### comparison of each group with grand mean of all groups contrMat(n, type = "GrandMean") } \keyword{misc} \keyword{Dunnett} \keyword{Tukey} multcomp/man/waste.Rd0000644000176200001440000000341712223513211014274 0ustar liggesusers\name{waste} \alias{waste} \docType{data} \title{ Industrial Waste Data Set } \usage{data("waste")} \description{ Industrial waste output in a manufactoring plant. } \format{ This data frame contains the following variables \describe{ \item{temp}{temperature, a factor at three levels: \code{low}, \code{medium}, \code{high}.} \item{envir}{environment, a factor at five levels: \code{env1} \dots \code{env5}.} \item{waste}{response variable: waste output in a manufacturing plant.} } } \details{ The data are from an experiment designed to study the effect of temperature (\code{temp}) and environment (\code{envir}) on waste output in a manufactoring plant. Two replicate measurements were taken at each temperature / environment combination. } \source{ P. H. Westfall, R. D. Tobias, D. Rom, R. D. Wolfinger, Y. Hochberg (1999). \emph{Multiple Comparisons and Multiple Tests Using the SAS System}. Cary, NC: SAS Institute Inc., page 177. } \examples{ ### set up two-way ANOVA with interactions amod <- aov(waste ~ temp * envir, data=waste) ### comparisons of main effects only K <- glht(amod, linfct = mcp(temp = "Tukey"))$linfct K glht(amod, K) ### comparisons of means (by averaging interaction effects) low <- grep("low:envi", colnames(K)) med <- grep("medium:envi", colnames(K)) K[1, low] <- 1 / (length(low) + 1) K[2, med] <- 1 / (length(low) + 1) K[3, med] <- 1 / (length(low) + 1) K[3, low] <- - 1 / (length(low) + 1) K confint(glht(amod, K)) ### same as TukeyHSD TukeyHSD(amod, "temp") ### set up linear hypotheses for all-pairs of both factors wht <- glht(amod, linfct = mcp(temp = "Tukey", envir = "Tukey")) ### cf. Westfall et al. (1999, page 181) summary(wht, test = adjusted("Shaffer")) } \keyword{datasets} multcomp/DESCRIPTION0000644000176200001440000000333114165102037013617 0ustar liggesusersPackage: multcomp Title: Simultaneous Inference in General Parametric Models Version: 1.4-18 Date: 2022-01-04 Authors@R: c(person("Torsten", "Hothorn", role = c("aut", "cre"), email = "Torsten.Hothorn@R-project.org", comment = c(ORCID = "0000-0001-8301-0471")), person("Frank", "Bretz", role = "aut"), person("Peter", "Westfall", role = "aut"), person("Richard M.", "Heiberger", role = "ctb"), person("Andre", "Schuetzenmeister", role = "ctb"), person("Susan", "Scheibe", role = "ctb")) Description: Simultaneous tests and confidence intervals for general linear hypotheses in parametric models, including linear, generalized linear, linear mixed effects, and survival models. The package includes demos reproducing analyzes presented in the book "Multiple Comparisons Using R" (Bretz, Hothorn, Westfall, 2010, CRC Press). Depends: stats, graphics, mvtnorm (>= 1.0-10), survival (>= 2.39-4), TH.data (>= 1.0-2) Imports: sandwich (>= 2.3-0), codetools Suggests: lme4 (>= 0.999375-16), nlme, robustbase, coin, MASS, foreign, xtable, lmtest, coxme (>= 2.2-1), SimComp, ISwR, tram (>= 0.2-5), fixest (>= 0.10) URL: http://multcomp.R-forge.R-project.org The publishers web page is http://www.crcpress.com/product/isbn/9781584885740 LazyData: yes License: GPL-2 NeedsCompilation: no Packaged: 2022-01-04 15:10:22 UTC; hothorn Author: Torsten Hothorn [aut, cre] (), Frank Bretz [aut], Peter Westfall [aut], Richard M. Heiberger [ctb], Andre Schuetzenmeister [ctb], Susan Scheibe [ctb] Maintainer: Torsten Hothorn Repository: CRAN Date/Publication: 2022-01-04 17:30:07 UTC multcomp/build/0000755000176200001440000000000014165061526013217 5ustar liggesusersmultcomp/build/vignette.rds0000644000176200001440000000061714165061526015562 0ustar liggesusersuRMO1-|&F p0z`zH1"VzubPSV0Xz΀$,1N,Θ DtaIA,ѡ"rGDHHc ] ,# Ep,B`8AN $`X0 gPn/;fBM[R#<~3IbPxdR!5Νu0:o:&Xpj[|Gk;XWkKEXrE,':N(b!kK{E^oN^k5֐n[Nڂx0ǒ>x^R,|Gvd~ߎFRבs~d>F? $}+multcomp/tests/0000755000176200001440000000000014165061465013264 5ustar liggesusersmultcomp/tests/regtest-lme.Rout.save0000644000176200001440000000465212654130706017327 0ustar liggesusers R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > ### mixed effects models > ### feature request by John Wilkinson > ### and Dieter Menne > > library("multcomp") Loading required package: mvtnorm Loading required package: survival Loading required package: TH.data Loading required package: MASS Attaching package: 'TH.data' The following object is masked from 'package:MASS': geyser > > lme4OK <- require("lme4") Loading required package: lme4 Loading required package: Matrix > if (lme4OK) { + + data("ergoStool", package = "nlme") + K <- glht(aov(effort ~ Type, data = ergoStool), mcp(Type = "Tukey"))$linfct + + stool.lmer <- lmer(effort ~ Type + (1 | Subject), + data = ergoStool) + glme4 <- glht(stool.lmer, K) + glme41 <- glht(stool.lmer, mcp(Type = "Tukey")) + stopifnot(all.equal(coef(glme4), coef(glme41))) + print(summary(glme41, test = Chisqtest())) + + nlmeOK <- require("nlme") + if (nlmeOK) { + + stool.lme <- lme(effort ~ Type, data = ergoStool, + random = ~ 1 | Subject) + gnlme <- glht(stool.lme,K) + stopifnot(all.equal(coef(glme4), coef(gnlme))) + + gnlme2 <- glht(stool.lme, linfct = mcp(Type = "Tukey")) + stopifnot(all.equal(coef(glme4), coef(gnlme2))) + } + } General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Linear Hypotheses: Estimate T2 - T1 == 0 3.8889 T3 - T1 == 0 2.2222 T4 - T1 == 0 0.6667 T3 - T2 == 0 -1.6667 T4 - T2 == 0 -3.2222 T4 - T3 == 0 -1.5556 Global Test: Chisq DF Pr(>Chisq) 1 67.07 3 1.812e-14 Loading required package: nlme Attaching package: 'nlme' The following object is masked from 'package:lme4': lmList > > proc.time() user system elapsed 1.304 0.032 1.331 multcomp/tests/angina.rda0000644000176200001440000000260211471214240015175 0ustar liggesusersRDX2 X  angina 2 levels 0 1 2 3 4 class factor2@(\(@3\(@,zG{@&W =p@00 =q@%@*\(\@$33333@/G{@2\(@1=p @.\(@5B\(@#B\(@-\(@/Q@0333333@)Q@7ǮzH@.\(\@2Q@2\(@2Q@+Q@0EQ@1}p =@/W =p@,R@1zG@6(\@4@30 =q@7aGz@2Q@1s33333@-(\@5(\)@*\(@5\(@5333333@9J=p @@(\)@8zG@2@@:G{@ pkgname <- "multcomp" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('multcomp') Loading required package: mvtnorm Loading required package: survival Loading required package: TH.data Loading required package: MASS Attaching package: ‘TH.data’ The following object is masked from ‘package:MASS’: geyser > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("cftest") > ### * cftest > > flush(stderr()); flush(stdout()) > > ### Name: cftest > ### Title: Testing Estimated Coefficients > ### Aliases: cftest > ### Keywords: htest > > ### ** Examples > > > lmod <- lm(dist ~ speed, data = cars) > summary(lmod) Call: lm(formula = dist ~ speed, data = cars) Residuals: Min 1Q Median 3Q Max -29.069 -9.525 -2.272 9.215 43.201 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -17.5791 6.7584 -2.601 0.0123 * speed 3.9324 0.4155 9.464 1.49e-12 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 15.38 on 48 degrees of freedom Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438 F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12 > cftest(lmod) Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = dist ~ speed, data = cars) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) (Intercept) == 0 -17.5791 6.7584 -2.601 0.0123 * speed == 0 3.9324 0.4155 9.464 1.49e-12 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Univariate p values reported) > > > > > cleanEx() > nameEx("cholesterol") > ### * cholesterol > > flush(stderr()); flush(stdout()) > > ### Name: cholesterol > ### Title: Cholesterol Reduction Data Set > ### Aliases: cholesterol > ### Keywords: datasets > > ### ** Examples > > > ### adjusted p-values for all-pairwise comparisons in a one-way layout > ### set up ANOVA model > amod <- aov(response ~ trt, data = cholesterol) > > ### set up multiple comparisons object for all-pair comparisons > cht <- glht(amod, linfct = mcp(trt = "Tukey")) > > ### cf. Westfall et al. (1999, page 171) > summary(cht, test = univariate()) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = response ~ trt, data = cholesterol) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) 2times - 1time == 0 3.443 1.443 2.385 0.021333 * 4times - 1time == 0 6.593 1.443 4.568 3.82e-05 *** drugD - 1time == 0 9.579 1.443 6.637 3.53e-08 *** drugE - 1time == 0 15.166 1.443 10.507 1.08e-13 *** 4times - 2times == 0 3.150 1.443 2.182 0.034352 * drugD - 2times == 0 6.136 1.443 4.251 0.000106 *** drugE - 2times == 0 11.723 1.443 8.122 2.29e-10 *** drugD - 4times == 0 2.986 1.443 2.069 0.044316 * drugE - 4times == 0 8.573 1.443 5.939 3.84e-07 *** drugE - drugD == 0 5.586 1.443 3.870 0.000348 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Univariate p values reported) > summary(cht, test = adjusted("Shaffer")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = response ~ trt, data = cholesterol) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) 2times - 1time == 0 3.443 1.443 2.385 0.042666 * 4times - 1time == 0 6.593 1.443 4.568 0.000153 *** drugD - 1time == 0 9.579 1.443 6.637 2.12e-07 *** drugE - 1time == 0 15.166 1.443 10.507 1.08e-12 *** 4times - 2times == 0 3.150 1.443 2.182 0.042666 * drugD - 2times == 0 6.136 1.443 4.251 0.000317 *** drugE - 2times == 0 11.723 1.443 8.122 1.38e-09 *** drugD - 4times == 0 2.986 1.443 2.069 0.044316 * drugE - 4times == 0 8.573 1.443 5.939 1.54e-06 *** drugE - drugD == 0 5.586 1.443 3.870 0.000697 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Shaffer method) > summary(cht, test = adjusted("Westfall")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = response ~ trt, data = cholesterol) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) 2times - 1time == 0 3.443 1.443 2.385 0.0420 * 4times - 1time == 0 6.593 1.443 4.568 <0.001 *** drugD - 1time == 0 9.579 1.443 6.637 <0.001 *** drugE - 1time == 0 15.166 1.443 10.507 <0.001 *** 4times - 2times == 0 3.150 1.443 2.182 0.0420 * drugD - 2times == 0 6.136 1.443 4.251 <0.001 *** drugE - 2times == 0 11.723 1.443 8.122 <0.001 *** drugD - 4times == 0 2.986 1.443 2.069 0.0443 * drugE - 4times == 0 8.573 1.443 5.939 <0.001 *** drugE - drugD == 0 5.586 1.443 3.870 <0.001 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Westfall method) > > ### use only a subset of all pairwise hypotheses > K <- contrMat(table(cholesterol$trt), type="Tukey") > Ksub <- rbind(K[c(1,2,5),], + "D - test" = c(-1, -1, -1, 3, 0), + "E - test" = c(-1, -1, -1, 0, 3)) > > ### reproduce results in Westfall et al. (1999, page 172) > ### note: the ordering of our estimates here is different > amod <- aov(response ~ trt - 1, data = cholesterol) > summary(glht(amod, linfct = mcp(trt = Ksub[,5:1])), + test = adjusted("Westfall")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = response ~ trt - 1, data = cholesterol) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) 2times - 1time == 0 -5.586 1.443 -3.870 <0.001 *** 4times - 1time == 0 -8.573 1.443 -5.939 <0.001 *** 4times - 2times == 0 -2.986 1.443 -2.069 0.0443 * D - test == 0 -21.009 3.536 -5.942 <0.001 *** E - test == 0 -31.338 3.536 -8.864 <0.001 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Westfall method) > > > > cleanEx() > nameEx("cld") > ### * cld > > flush(stderr()); flush(stdout()) > > ### Name: cld > ### Title: Set up a compact letter display of all pair-wise comparisons > ### Aliases: cld cld.glht cld.summary.glht cld.confint.glht > > ### ** Examples > > ### multiple comparison procedures > ### set up a one-way ANOVA > data(warpbreaks) > amod <- aov(breaks ~ tension, data = warpbreaks) > ### specify all pair-wise comparisons among levels of variable "tension" > tuk <- glht(amod, linfct = mcp(tension = "Tukey")) > ### extract information > tuk.cld <- cld(tuk) > ### use sufficiently large upper margin > old.par <- par(mai=c(1,1,1.25,1), no.readonly = TRUE) > ### plot > plot(tuk.cld) > par(old.par) > > ### now using covariates > data(warpbreaks) > amod2 <- aov(breaks ~ tension + wool, data = warpbreaks) > ### specify all pair-wise comparisons among levels of variable "tension" > tuk2 <- glht(amod2, linfct = mcp(tension = "Tukey")) > ### extract information > tuk.cld2 <- cld(tuk2) > ### use sufficiently large upper margin > old.par <- par(mai=c(1,1,1.25,1), no.readonly = TRUE) > ### plot using different colors > plot(tuk.cld2, col=c("black", "red", "blue")) > par(old.par) > > ### set up all pair-wise comparisons for count data > data(Titanic) > mod <- glm(Survived ~ Class, data = as.data.frame(Titanic), weights = Freq, family = binomial()) > ### specify all pair-wise comparisons among levels of variable "Class" > glht.mod <- glht(mod, mcp(Class = "Tukey")) > ### extract information > mod.cld <- cld(glht.mod) > ### use sufficiently large upper margin > old.par <- par(mai=c(1,1,1.5,1), no.readonly = TRUE) > ### plot > plot(mod.cld) > par(old.par) > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() > nameEx("cml") > ### * cml > > flush(stderr()); flush(stdout()) > > ### Name: cml > ### Title: Chronic Myelogenous Leukemia survival data. > ### Aliases: cml > ### Keywords: datasets > > ### ** Examples > > > if (require("coxme")) { + data("cml") + ### one-sided simultaneous confidence intervals for many-to-one + ### comparisons of treatment effects concerning time of survival + ### modeled by a frailty Cox model with adjustment for further + ### covariates and center-specific random effect. + cml_coxme <- coxme(Surv(time, status) ~ treatment + sex + age + riskgroup + (1|center), + data = cml) + glht_coxme <- glht(model = cml_coxme, linfct = mcp(treatment = "Dunnett"), + alternative = "greater") + ci_coxme <- confint(glht_coxme) + exp(ci_coxme$confint)[1:2,] + } Loading required package: coxme Loading required package: bdsmatrix Attaching package: ‘bdsmatrix’ The following object is masked from ‘package:base’: backsolve Estimate lwr upr trt2 - trt1 1.551055 1.184052 Inf trt3 - trt1 1.396362 1.068766 Inf > > > > cleanEx() detaching ‘package:coxme’, ‘package:bdsmatrix’ > nameEx("contrMat") > ### * contrMat > > flush(stderr()); flush(stdout()) > > ### Name: contrMat > ### Title: Contrast Matrices > ### Aliases: contrMat > ### Keywords: misc Dunnett Tukey > > ### ** Examples > > n <- c(10,20,30,40) > names(n) <- paste("group", 1:4, sep="") > contrMat(n) # Dunnett is default Multiple Comparisons of Means: Dunnett Contrasts group1 group2 group3 group4 group2 - group1 -1 1 0 0 group3 - group1 -1 0 1 0 group4 - group1 -1 0 0 1 > contrMat(n, base = 2) # use second level as baseline Multiple Comparisons of Means: Dunnett Contrasts group1 group2 group3 group4 group1 - group2 1 -1 0 0 group3 - group2 0 -1 1 0 group4 - group2 0 -1 0 1 > contrMat(n, type = "Tukey") Multiple Comparisons of Means: Tukey Contrasts group1 group2 group3 group4 group2 - group1 -1 1 0 0 group3 - group1 -1 0 1 0 group4 - group1 -1 0 0 1 group3 - group2 0 -1 1 0 group4 - group2 0 -1 0 1 group4 - group3 0 0 -1 1 > contrMat(n, type = "Sequen") Multiple Comparisons of Means: Sequen Contrasts group1 group2 group3 group4 group2 - group1 -1 1 0 0 group3 - group2 0 -1 1 0 group4 - group3 0 0 -1 1 > contrMat(n, type = "AVE") Multiple Comparisons of Means: AVE Contrasts group1 group2 group3 group4 C 1 1.0000 -0.2222 -0.3333 -0.4444 C 2 -0.1250 1.0000 -0.3750 -0.5000 C 3 -0.1429 -0.2857 1.0000 -0.5714 C 4 -0.1667 -0.3333 -0.5000 1.0000 > contrMat(n, type = "Changepoint") Multiple Comparisons of Means: Changepoint Contrasts group1 group2 group3 group4 C 1 -1.0000 0.2222 0.3333 0.4444 C 2 -0.3333 -0.6667 0.4286 0.5714 C 3 -0.1667 -0.3333 -0.5000 1.0000 > contrMat(n, type = "Williams") Multiple Comparisons of Means: Williams Contrasts group1 group2 group3 group4 C 1 -1 0.0000 0.0000 1.0000 C 2 -1 0.0000 0.4286 0.5714 C 3 -1 0.2222 0.3333 0.4444 > contrMat(n, type = "Marcus") Multiple Comparisons of Means: Marcus Contrasts group1 group2 group3 group4 C 1 -1.0000 0.2222 0.3333 0.4444 C 2 -1.0000 0.0000 0.4286 0.5714 C 3 -0.3333 -0.6667 0.4286 0.5714 C 4 -1.0000 0.0000 0.0000 1.0000 C 5 -0.3333 -0.6667 0.0000 1.0000 C 6 -0.1667 -0.3333 -0.5000 1.0000 > contrMat(n, type = "McDermott") Multiple Comparisons of Means: McDermott Contrasts group1 group2 group3 group4 C 1 -1.0000 1.0000 0.0 0 C 2 -0.3333 -0.6667 1.0 0 C 3 -0.1667 -0.3333 -0.5 1 > ### Umbrella-protected Williams contrasts, i.e. a sequence of > ### Williams-type contrasts with groups of higher order > ### stepwise omitted > contrMat(n, type = "UmbrellaWilliams") Multiple Comparisons of Means: UmbrellaWilliams Contrasts group1 group2 group3 group4 C 1 -1 0.0000 0.0000 1.0000 C 2 -1 0.0000 0.4286 0.5714 C 3 -1 0.2222 0.3333 0.4444 C 4 -1 0.0000 1.0000 0.0000 C 5 -1 0.4000 0.6000 0.0000 C 6 -1 1.0000 0.0000 0.0000 > ### comparison of each group with grand mean of all groups > contrMat(n, type = "GrandMean") Multiple Comparisons of Means: GrandMean Contrasts group1 group2 group3 group4 group1 0.9 -0.2 -0.3 -0.4 group2 -0.1 0.8 -0.3 -0.4 group3 -0.1 -0.2 0.7 -0.4 group4 -0.1 -0.2 -0.3 0.6 > > > > > cleanEx() > nameEx("detergent") > ### * detergent > > flush(stderr()); flush(stdout()) > > ### Name: detergent > ### Title: Detergent Durability Data Set > ### Aliases: detergent > ### Keywords: datasets > > ### ** Examples > > > ### set up two-way ANOVA without interactions > amod <- aov(plates ~ block + detergent, data = detergent) > > ### set up all-pair comparisons > dht <- glht(amod, linfct = mcp(detergent = "Tukey")) > > ### see Westfall et al. (1999, p. 190) > confint(dht) Simultaneous Confidence Intervals Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = plates ~ block + detergent, data = detergent) Quantile = 3.0637 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr B - A == 0 -2.1333 -4.7925 0.5258 C - A == 0 3.6000 0.9409 6.2591 D - A == 0 2.2000 -0.4591 4.8591 E - A == 0 -4.3333 -6.9925 -1.6742 C - B == 0 5.7333 3.0742 8.3925 D - B == 0 4.3333 1.6742 6.9925 E - B == 0 -2.2000 -4.8591 0.4591 D - C == 0 -1.4000 -4.0591 1.2591 E - C == 0 -7.9333 -10.5925 -5.2742 E - D == 0 -6.5333 -9.1925 -3.8742 > > ### see Westfall et al. (1999, p. 192) > summary(dht, test = univariate()) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = plates ~ block + detergent, data = detergent) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) B - A == 0 -2.1333 0.8679 -2.458 0.025762 * C - A == 0 3.6000 0.8679 4.148 0.000757 *** D - A == 0 2.2000 0.8679 2.535 0.022075 * E - A == 0 -4.3333 0.8679 -4.993 0.000133 *** C - B == 0 5.7333 0.8679 6.606 6.05e-06 *** D - B == 0 4.3333 0.8679 4.993 0.000133 *** E - B == 0 -2.2000 0.8679 -2.535 0.022075 * D - C == 0 -1.4000 0.8679 -1.613 0.126291 E - C == 0 -7.9333 0.8679 -9.140 9.45e-08 *** E - D == 0 -6.5333 0.8679 -7.527 1.21e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Univariate p values reported) > ## Not run: > ##D summary(dht, test = adjusted("Shaffer")) > ##D summary(dht, test = adjusted("Westfall")) > ##D > ## End(Not run) > > > > > cleanEx() > nameEx("fattyacid") > ### * fattyacid > > flush(stderr()); flush(stdout()) > > ### Name: fattyacid > ### Title: Fatty Acid Content of Bacillus simplex. > ### Aliases: fattyacid > ### Keywords: datasets > > ### ** Examples > > > if (require("sandwich")) { + data("fattyacid") + ### all-pairwise comparisons of the means of fatty acid content + ### FA between different putative ecotypes PE accounting for + ### heteroscedasticity by using a heteroscedastic consistent + ### covariance estimation + amod <- aov(FA ~ PE, data = fattyacid) + amod_glht <- glht(amod, mcp(PE = "Tukey"), vcov = vcovHC) + summary(amod_glht) + + ### simultaneous confidence intervals for the differences of + ### means of fatty acid content between the putative ecotypes + confint(amod_glht) + } Loading required package: sandwich Simultaneous Confidence Intervals Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = FA ~ PE, data = fattyacid) Quantile = 2.8944 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr PE4 - PE3 == 0 -0.012820 -0.114116 0.088477 PE5 - PE3 == 0 -0.084398 -0.182363 0.013566 PE6 - PE3 == 0 0.019286 -0.084218 0.122789 PE7 - PE3 == 0 -0.010048 -0.120052 0.099957 PE9 - PE3 == 0 0.075536 -0.028035 0.179107 PE5 - PE4 == 0 -0.071579 -0.128783 -0.014375 PE6 - PE4 == 0 0.032105 -0.034139 0.098349 PE7 - PE4 == 0 0.002772 -0.073229 0.078773 PE9 - PE4 == 0 0.088355 0.022006 0.154704 PE6 - PE5 == 0 0.103684 0.042656 0.164712 PE7 - PE5 == 0 0.074351 0.002850 0.145851 PE9 - PE5 == 0 0.159934 0.098792 0.221076 PE7 - PE6 == 0 -0.029333 -0.108252 0.049586 PE9 - PE6 == 0 0.056250 -0.013423 0.125923 PE9 - PE7 == 0 0.085583 0.006576 0.164591 > > > > cleanEx() detaching ‘package:sandwich’ > nameEx("glht") > ### * glht > > flush(stderr()); flush(stdout()) > > ### Name: glht > ### Title: General Linear Hypotheses > ### Aliases: glht glht.matrix glht.character glht.expression glht.mcp > ### glht.mlf mcp > ### Keywords: htest > > ### ** Examples > > > ### multiple linear model, swiss data > lmod <- lm(Fertility ~ ., data = swiss) > > ### test of H_0: all regression coefficients are zero > ### (ignore intercept) > > ### define coefficients of linear function directly > K <- diag(length(coef(lmod)))[-1,] > rownames(K) <- names(coef(lmod))[-1] > K [,1] [,2] [,3] [,4] [,5] [,6] Agriculture 0 1 0 0 0 0 Examination 0 0 1 0 0 0 Education 0 0 0 1 0 0 Catholic 0 0 0 0 1 0 Infant.Mortality 0 0 0 0 0 1 > > ### set up general linear hypothesis > glht(lmod, linfct = K) General Linear Hypotheses Linear Hypotheses: Estimate Agriculture == 0 -0.1721 Examination == 0 -0.2580 Education == 0 -0.8709 Catholic == 0 0.1041 Infant.Mortality == 0 1.0770 > > ### alternatively, use a symbolic description > ### instead of a matrix > glht(lmod, linfct = c("Agriculture = 0", + "Examination = 0", + "Education = 0", + "Catholic = 0", + "Infant.Mortality = 0")) General Linear Hypotheses Linear Hypotheses: Estimate Agriculture == 0 -0.1721 Examination == 0 -0.2580 Education == 0 -0.8709 Catholic == 0 0.1041 Infant.Mortality == 0 1.0770 > > > ### multiple comparison procedures > ### set up a one-way ANOVA > amod <- aov(breaks ~ tension, data = warpbreaks) > > ### set up all-pair comparisons for factor `tension' > ### using a symbolic description (`type' argument > ### to `contrMat()') > glht(amod, linfct = mcp(tension = "Tukey")) General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Linear Hypotheses: Estimate M - L == 0 -10.000 H - L == 0 -14.722 H - M == 0 -4.722 > > ### alternatively, describe differences symbolically > glht(amod, linfct = mcp(tension = c("M - L = 0", + "H - L = 0", + "H - M = 0"))) General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Linear Hypotheses: Estimate M - L == 0 -10.000 H - L == 0 -14.722 H - M == 0 -4.722 > > ### alternatively, define contrast matrix directly > contr <- rbind("M - L" = c(-1, 1, 0), + "H - L" = c(-1, 0, 1), + "H - M" = c(0, -1, 1)) > glht(amod, linfct = mcp(tension = contr)) General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Linear Hypotheses: Estimate M - L == 0 -10.000 H - L == 0 -14.722 H - M == 0 -4.722 > > ### alternatively, define linear function for coef(amod) > ### instead of contrasts for `tension' > ### (take model contrasts and intercept into account) > glht(amod, linfct = cbind(0, contr %*% contr.treatment(3))) General Linear Hypotheses Linear Hypotheses: Estimate M - L == 0 -10.000 H - L == 0 -14.722 H - M == 0 -4.722 > > > ### mix of one- and two-sided alternatives > warpbreaks.aov <- aov(breaks ~ wool + tension, + data = warpbreaks) > > ### contrasts for `tension' > K <- rbind("L - M" = c( 1, -1, 0), + "M - L" = c(-1, 1, 0), + "L - H" = c( 1, 0, -1), + "M - H" = c( 0, 1, -1)) > > warpbreaks.mc <- glht(warpbreaks.aov, + linfct = mcp(tension = K), + alternative = "less") > > ### correlation of first two tests is -1 > cov2cor(vcov(warpbreaks.mc)) L - M M - L L - H M - H L - M 1.0 -1.0 0.5 -0.5 M - L -1.0 1.0 -0.5 0.5 L - H 0.5 -0.5 1.0 0.5 M - H -0.5 0.5 0.5 1.0 > > ### use smallest of the two one-sided > ### p-value as two-sided p-value -> 0.0232 > summary(warpbreaks.mc) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 10.000 3.872 2.582 1.0000 M - L >= 0 -10.000 3.872 -2.582 0.0232 * L - H >= 0 14.722 3.872 3.802 1.0000 M - H >= 0 4.722 3.872 1.219 1.0000 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > > ### more complex models: Continuous outcome logistic > ### regression; parameters are log-odds ratios > if (require("tram")) { + confint(glht(Colr(breaks ~ wool + tension, + data = warpbreaks), + linfct = mcp("tension" = "Tukey"))) + } Loading required package: tram Loading required package: mlt Loading required package: basefun Loading required package: variables Simultaneous Confidence Intervals Multiple Comparisons of Means: Tukey Contrasts Fit: Colr(formula = breaks ~ wool + tension, data = warpbreaks) Quantile = 2.3437 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr M - L == 0 1.1969 -0.2336 2.6275 H - L == 0 2.1613 0.6761 3.6464 H - M == 0 0.9643 -0.4297 2.3584 > > > > cleanEx() detaching ‘package:tram’, ‘package:mlt’, ‘package:basefun’, ‘package:variables’ > nameEx("litter") > ### * litter > > flush(stderr()); flush(stdout()) > > ### Name: litter > ### Title: Litter Weights Data Set > ### Aliases: litter > ### Keywords: datasets > > ### ** Examples > > > ### fit ANCOVA model to data > amod <- aov(weight ~ dose + gesttime + number, data = litter) > > ### define matrix of linear hypotheses for `dose' > doselev <- as.integer(levels(litter$dose)) > K <- rbind(contrMat(table(litter$dose), "Tukey"), + otrend = c(-1.5, -0.5, 0.5, 1.5), + atrend = doselev - mean(doselev), + ltrend = log(1:4) - mean(log(1:4))) > > ### set up multiple comparison object > Kht <- glht(amod, linfct = mcp(dose = K), alternative = "less") > > ### cf. Westfall (1997, Table 2) > summary(Kht, test = univariate()) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = weight ~ dose + gesttime + number, data = litter) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 -3.3524 1.2908 -2.597 0.00575 ** 50 - 0 >= 0 -2.2909 1.3384 -1.712 0.04576 * 500 - 0 >= 0 -2.6752 1.3343 -2.005 0.02448 * 50 - 5 >= 0 1.0615 1.3973 0.760 0.77498 500 - 5 >= 0 0.6772 1.3394 0.506 0.69260 500 - 50 >= 0 -0.3844 1.4510 -0.265 0.39595 otrend >= 0 -3.4821 2.0867 -1.669 0.04988 * atrend >= 0 -314.7324 408.9901 -0.770 0.22212 ltrend >= 0 -1.9400 0.9616 -2.018 0.02379 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Univariate p values reported) > summary(Kht, test = adjusted("bonferroni")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = weight ~ dose + gesttime + number, data = litter) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 -3.3524 1.2908 -2.597 0.0518 . 50 - 0 >= 0 -2.2909 1.3384 -1.712 0.4118 500 - 0 >= 0 -2.6752 1.3343 -2.005 0.2203 50 - 5 >= 0 1.0615 1.3973 0.760 1.0000 500 - 5 >= 0 0.6772 1.3394 0.506 1.0000 500 - 50 >= 0 -0.3844 1.4510 -0.265 1.0000 otrend >= 0 -3.4821 2.0867 -1.669 0.4490 atrend >= 0 -314.7324 408.9901 -0.770 1.0000 ltrend >= 0 -1.9400 0.9616 -2.018 0.2141 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- bonferroni method) > summary(Kht, test = adjusted("Shaffer")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = weight ~ dose + gesttime + number, data = litter) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 -3.3524 1.2908 -2.597 0.0518 . 50 - 0 >= 0 -2.2909 1.3384 -1.712 0.0915 . 500 - 0 >= 0 -2.6752 1.3343 -2.005 0.0734 . 50 - 5 >= 0 1.0615 1.3973 0.760 1.0000 500 - 5 >= 0 0.6772 1.3394 0.506 1.0000 500 - 50 >= 0 -0.3844 1.4510 -0.265 1.0000 otrend >= 0 -3.4821 2.0867 -1.669 0.0998 . atrend >= 0 -314.7324 408.9901 -0.770 0.4442 ltrend >= 0 -1.9400 0.9616 -2.018 0.0518 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Shaffer method) > summary(Kht, test = adjusted("Westfall")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = weight ~ dose + gesttime + number, data = litter) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 -3.3524 1.2908 -2.597 0.0320 * 50 - 0 >= 0 -2.2909 1.3384 -1.712 0.0893 . 500 - 0 >= 0 -2.6752 1.3343 -2.005 0.0647 . 50 - 5 >= 0 1.0615 1.3973 0.760 0.7750 500 - 5 >= 0 0.6772 1.3394 0.506 0.7271 500 - 50 >= 0 -0.3844 1.4510 -0.265 0.7271 otrend >= 0 -3.4821 2.0867 -1.669 0.0917 . atrend >= 0 -314.7324 408.9901 -0.770 0.3951 ltrend >= 0 -1.9400 0.9616 -2.018 0.0459 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Westfall method) > summary(Kht, test = adjusted("single-step")) Warning in RET$pfunction("adjusted", ...) : Completion with error > abseps Warning in RET$pfunction("adjusted", ...) : Completion with error > abseps Warning in RET$pfunction("adjusted", ...) : Completion with error > abseps Warning in RET$pfunction("adjusted", ...) : Completion with error > abseps Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = weight ~ dose + gesttime + number, data = litter) Linear Hypotheses: Estimate Std. Error t value Pr(= 0 -3.3524 1.2908 -2.597 0.0316 * 50 - 0 >= 0 -2.2909 1.3384 -1.712 0.2031 500 - 0 >= 0 -2.6752 1.3343 -2.005 0.1186 50 - 5 >= 0 1.0615 1.3973 0.760 0.9999 500 - 5 >= 0 0.6772 1.3394 0.506 0.9987 500 - 50 >= 0 -0.3844 1.4510 -0.265 0.8908 otrend >= 0 -3.4821 2.0867 -1.669 0.2185 atrend >= 0 -314.7324 408.9901 -0.770 0.6625 ltrend >= 0 -1.9400 0.9616 -2.018 0.1157 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > > > > > cleanEx() > nameEx("methods") > ### * methods > > flush(stderr()); flush(stdout()) > > ### Name: glht-methods > ### Title: Methods for General Linear Hypotheses > ### Aliases: summary.glht confint.glht coef.glht vcov.glht plot.glht > ### plot.confint.glht univariate adjusted Ftest Chisqtest adjusted_calpha > ### univariate_calpha > ### Keywords: htest > > ### ** Examples > > > ### set up a two-way ANOVA > amod <- aov(breaks ~ wool + tension, data = warpbreaks) > > ### set up all-pair comparisons for factor `tension' > wht <- glht(amod, linfct = mcp(tension = "Tukey")) > > ### 95% simultaneous confidence intervals > plot(print(confint(wht))) Simultaneous Confidence Intervals Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks) Quantile = 2.4151 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr M - L == 0 -10.0000 -19.3520 -0.6480 H - L == 0 -14.7222 -24.0743 -5.3702 H - M == 0 -4.7222 -14.0743 4.6298 > > ### the same (for balanced designs only) > TukeyHSD(amod, "tension") Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks) $tension diff lwr upr p adj M-L -10.000000 -19.35342 -0.6465793 0.0336262 H-L -14.722222 -24.07564 -5.3688015 0.0011218 H-M -4.722222 -14.07564 4.6311985 0.4474210 > > ### corresponding adjusted p values > summary(wht) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = breaks ~ wool + tension, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) M - L == 0 -10.000 3.872 -2.582 0.03362 * H - L == 0 -14.722 3.872 -3.802 0.00109 ** H - M == 0 -4.722 3.872 -1.219 0.44738 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > > ### all means for levels of `tension' > amod <- aov(breaks ~ tension, data = warpbreaks) > glht(amod, linfct = matrix(c(1, 0, 0, + 1, 1, 0, + 1, 0, 1), byrow = TRUE, ncol = 3)) General Linear Hypotheses Linear Hypotheses: Estimate 1 == 0 36.39 2 == 0 26.39 3 == 0 21.67 > > ### confidence bands for a simple linear model, `cars' data > plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)", + las = 1) > > ### fit linear model and add regression line to plot > lmod <- lm(dist ~ speed, data = cars) > abline(lmod) > > ### a grid of speeds > speeds <- seq(from = min(cars$speed), to = max(cars$speed), + length = 10) > > ### linear hypotheses: 10 selected points on the regression line != 0 > K <- cbind(1, speeds) > > ### set up linear hypotheses > cht <- glht(lmod, linfct = K) > > ### confidence intervals, i.e., confidence bands, and add them plot > cci <- confint(cht) > lines(speeds, cci$confint[,"lwr"], col = "blue") > lines(speeds, cci$confint[,"upr"], col = "blue") > > > ### simultaneous p values for parameters in a Cox model > if (require("survival") && require("MASS")) { + data("leuk", package = "MASS") + leuk.cox <- coxph(Surv(time) ~ ag + log(wbc), data = leuk) + + ### set up linear hypotheses + lht <- glht(leuk.cox, linfct = diag(length(coef(leuk.cox)))) + + ### adjusted p values + print(summary(lht)) + } Simultaneous Tests for General Linear Hypotheses Fit: coxph(formula = Surv(time) ~ ag + log(wbc), data = leuk) Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) 1 == 0 -1.0691 0.4293 -2.490 0.0253 * 2 == 0 0.3677 0.1360 2.703 0.0137 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > > > > > cleanEx() > nameEx("mmm") > ### * mmm > > flush(stderr()); flush(stdout()) > > ### Name: mmm > ### Title: Simultaneous Inference for Multiple Marginal Models > ### Aliases: mmm mlf > ### Keywords: models > > ### ** Examples > > > ### replicate analysis of Hasler & Hothorn (2011), > ### A Dunnett-Type Procedure for Multiple Endpoints, > ### The International Journal of Biostatistics: Vol. 7: Iss. 1, Article 3. > ### DOI: 10.2202/1557-4679.1258 > > library("sandwich") > > ### see ?coagulation > if (require("SimComp")) { + data("coagulation", package = "SimComp") + + ### level "S" is the standard, "H" and "B" are novel procedures + coagulation$Group <- relevel(coagulation$Group, ref = "S") + + ### fit marginal models + (m1 <- lm(Thromb.count ~ Group, data = coagulation)) + (m2 <- lm(ADP ~ Group, data = coagulation)) + (m3 <- lm(TRAP ~ Group, data = coagulation)) + + ### set-up Dunnett comparisons for H - S and B - S + ### for all three models + g <- glht(mmm(Thromb = m1, ADP = m2, TRAP = m3), + mlf(mcp(Group = "Dunnett")), alternative = "greater") + + ### joint correlation + cov2cor(vcov(g)) + + ### simultaneous p-values adjusted by taking the correlation + ### between the score contributions into account + summary(g) + ### simultaneous confidence intervals + confint(g) + + ### compare with + ## Not run: + ##D library("SimComp") + ##D SimCiDiff(data = coagulation, grp = "Group", + ##D resp = c("Thromb.count","ADP","TRAP"), + ##D type = "Dunnett", alternative = "greater", + ##D covar.equal = TRUE) + ##D + ## End(Not run) + + ### use sandwich variance matrix + g <- glht(mmm(Thromb = m1, ADP = m2, TRAP = m3), + mlf(mcp(Group = "Dunnett")), + alternative = "greater", vcov = sandwich) + summary(g) + confint(g) + } Loading required package: SimComp Simultaneous Confidence Intervals Fit: NULL Quantile = -2.2714 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr Thromb: B - S <= 0 0.12170 -0.07633 Inf Thromb: H - S <= 0 0.04351 -0.17941 Inf ADP: B - S <= 0 0.21211 0.03802 Inf ADP: H - S <= 0 0.08422 -0.06907 Inf TRAP: B - S <= 0 0.10525 -0.20344 Inf TRAP: H - S <= 0 0.07109 -0.24483 Inf > > ### attitude towards science data > data("mn6.9", package = "TH.data") > > ### one model for each item > mn6.9.y1 <- glm(y1 ~ group, family = binomial(), + na.action = na.omit, data = mn6.9) > mn6.9.y2 <- glm(y2 ~ group, family = binomial(), + na.action = na.omit, data = mn6.9) > mn6.9.y3 <- glm(y3 ~ group, family = binomial(), + na.action = na.omit, data = mn6.9) > mn6.9.y4 <- glm(y4 ~ group, family = binomial(), + na.action = na.omit, data = mn6.9) > > ### test all parameters simulaneously > summary(glht(mmm(mn6.9.y1, mn6.9.y2, mn6.9.y3, mn6.9.y4), + mlf(diag(2)))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) mn6.9.y1: 1 == 0 1.47323 0.06649 22.156 <1e-04 *** mn6.9.y1: 2 == 0 0.14833 0.09638 1.539 0.5806 mn6.9.y2: 1 == 0 -1.38713 0.06476 -21.419 <1e-04 *** mn6.9.y2: 2 == 0 -0.19598 0.09455 -2.073 0.2331 mn6.9.y3: 1 == 0 0.44024 0.05306 8.298 <1e-04 *** mn6.9.y3: 2 == 0 -0.37449 0.07417 -5.049 <1e-04 *** mn6.9.y4: 1 == 0 0.16537 0.05197 3.182 0.0107 * mn6.9.y4: 2 == 0 -0.37132 0.07357 -5.047 <1e-04 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > ### group differences > summary(glht(mmm(mn6.9.y1, mn6.9.y2, mn6.9.y3, mn6.9.y4), + mlf("group2 = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) mn6.9.y1: group2 == 0 0.14833 0.09638 1.539 0.409 mn6.9.y2: group2 == 0 -0.19598 0.09455 -2.073 0.144 mn6.9.y3: group2 == 0 -0.37449 0.07417 -5.049 <1e-04 *** mn6.9.y4: group2 == 0 -0.37132 0.07357 -5.047 <1e-04 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > > ### alternative analysis of Klingenberg & Satopaa (2013), > ### Simultaneous Confidence Intervals for Comparing Margins of > ### Multivariate Binary Data, CSDA, 64, 87-98 > ### http://dx.doi.org/10.1016/j.csda.2013.02.016 > > ### see supplementary material for data description > ### NOTE: this is not the real data but only a subsample > influenza <- structure(list( + HEADACHE = c(1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, + 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, + 1L, 1L), MALAISE = c(0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, + 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, + 0L), PYREXIA = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, + 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L + ), ARTHRALGIA = c(0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, + 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L + ), group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L), .Label = c("pla", "trt"), class = "factor"), Freq = c(32L, + 165L, 10L, 23L, 3L, 1L, 4L, 2L, 4L, 2L, 1L, 1L, 1L, 1L, 167L, + 1L, 11L, 37L, 7L, 7L, 5L, 3L, 3L, 1L, 2L, 4L, 2L)), .Names = c("HEADACHE", + "MALAISE", "PYREXIA", "ARTHRALGIA", "group", "Freq"), row.names = c(1L, + 2L, 3L, 5L, 9L, 36L, 43L, 50L, 74L, 83L, 139L, 175L, 183L, 205L, + 251L, 254L, 255L, 259L, 279L, 281L, 282L, 286L, 302L, 322L, 323L, + 366L, 382L), class = "data.frame") > influenza <- influenza[rep(1:nrow(influenza), influenza$Freq), 1:5] > > ### Fitting marginal logistic regression models > (head_logreg <- glm(HEADACHE ~ group, data = influenza, + family = binomial())) Call: glm(formula = HEADACHE ~ group, family = binomial(), data = influenza) Coefficients: (Intercept) grouptrt -0.8664 -0.1384 Degrees of Freedom: 499 Total (i.e. Null); 498 Residual Null Deviance: 594.8 Residual Deviance: 594.3 AIC: 598.3 > (mala_logreg <- glm(MALAISE ~ group, data = influenza, + family = binomial())) Call: glm(formula = MALAISE ~ group, family = binomial(), data = influenza) Coefficients: (Intercept) grouptrt -1.9551 0.4114 Degrees of Freedom: 499 Total (i.e. Null); 498 Residual Null Deviance: 422.7 Residual Deviance: 420 AIC: 424 > (pyre_logreg <- glm(PYREXIA ~ group, data = influenza, + family = binomial())) Call: glm(formula = PYREXIA ~ group, family = binomial(), data = influenza) Coefficients: (Intercept) grouptrt -2.389 -1.158 Degrees of Freedom: 499 Total (i.e. Null); 498 Residual Null Deviance: 215.8 Residual Deviance: 208.1 AIC: 212.1 > (arth_logreg <- glm(ARTHRALGIA ~ group, data = influenza, + family = binomial())) Call: glm(formula = ARTHRALGIA ~ group, family = binomial(), data = influenza) Coefficients: (Intercept) grouptrt -2.6178 -0.1337 Degrees of Freedom: 499 Total (i.e. Null); 498 Residual Null Deviance: 237.8 Residual Deviance: 237.7 AIC: 241.7 > > ### Simultaneous inference for log-odds > xy.sim <- glht(mmm(head = head_logreg, + mala = mala_logreg, + pyre = pyre_logreg, + arth = arth_logreg), + mlf("grouptrt = 0")) > summary(xy.sim) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) head: grouptrt == 0 -0.1384 0.1990 -0.695 0.9181 mala: grouptrt == 0 0.4114 0.2538 1.621 0.3354 pyre: grouptrt == 0 -1.1580 0.4460 -2.596 0.0356 * arth: grouptrt == 0 -0.1337 0.3661 -0.365 0.9918 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- single-step method) > confint(xy.sim) Simultaneous Confidence Intervals Fit: NULL Quantile = 2.4744 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr head: grouptrt == 0 -0.13837 -0.63067 0.35392 mala: grouptrt == 0 0.41140 -0.21655 1.03935 pyre: grouptrt == 0 -1.15795 -2.26163 -0.05428 arth: grouptrt == 0 -0.13371 -1.03959 0.77217 > > ### Artificial examples > ### Combining linear regression and logistic regression > set.seed(29) > y1 <- rnorm(100) > y2 <- factor(y1 + rnorm(100, sd = .1) > 0) > x1 <- gl(4, 25) > x2 <- runif(100, 0, 10) > > m1 <- lm(y1 ~ x1 + x2) > m2 <- glm(y2 ~ x1 + x2, family = binomial()) > ### Note that the same explanatory variables are considered in both models > ### but the resulting parameter estimates are on 2 different scales > ### (original and log-odds scales) > > ### Simultaneous inference for the same parameter in the 2 model fits > summary(glht(mmm(m1 = m1, m2 = m2), mlf("x12 = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: x12 == 0 -0.3537 0.2850 -1.241 0.321 m2: x12 == 0 -0.6409 0.5765 -1.112 0.392 (Adjusted p values reported -- single-step method) > > ### Simultaneous inference for different parameters in the 2 model fits > summary(glht(mmm(m1 = m1, m2 = m2), + mlf(m1 = "x12 = 0", m2 = "x13 = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: x12 == 0 -0.3537 0.2850 -1.241 0.362 m2: x13 == 0 -0.8264 0.5824 -1.419 0.270 (Adjusted p values reported -- single-step method) > > ### Simultaneous inference for different and identical parameters in the 2 > ### model fits > summary(glht(mmm(m1 = m1, m2 = m2), + mlf(m1 = c("x12 = 0", "x13 = 0"), m2 = "x13 = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: x12 == 0 -0.3537 0.2850 -1.241 0.418 m1: x13 == 0 -0.4220 0.2849 -1.481 0.286 m2: x13 == 0 -0.8264 0.5824 -1.419 0.317 (Adjusted p values reported -- single-step method) > > ### Examples for binomial data > ### Two independent outcomes > y1.1 <- rbinom(100, 1, 0.45) > y1.2 <- rbinom(100, 1, 0.55) > group <- factor(rep(c("A", "B"), 50)) > > m1 <- glm(y1.1 ~ group, family = binomial) > m2 <- glm(y1.2 ~ group, family = binomial) > > summary(glht(mmm(m1 = m1, m2 = m2), + mlf("groupB = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: groupB == 0 0.41502 0.40905 1.015 0.523 m2: groupB == 0 0.08161 0.40407 0.202 0.974 (Adjusted p values reported -- single-step method) > > ### Two perfectly correlated outcomes > y2.1 <- rbinom(100, 1, 0.45) > y2.2 <- y2.1 > group <- factor(rep(c("A", "B"), 50)) > > m1 <- glm(y2.1 ~ group, family = binomial) > m2 <- glm(y2.2 ~ group, family = binomial) > > summary(glht(mmm(m1 = m1, m2 = m2), + mlf("groupB = 0"))) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: groupB == 0 0.2427 0.4028 0.603 0.547 m2: groupB == 0 0.2427 0.4028 0.603 0.547 (Adjusted p values reported -- single-step method) > > ### use sandwich covariance matrix > summary(glht(mmm(m1 = m1, m2 = m2), + mlf("groupB = 0"), vcov = sandwich)) Simultaneous Tests for General Linear Hypotheses Linear Hypotheses: Estimate Std. Error z value Pr(>|z|) m1: groupB == 0 0.2427 0.4028 0.603 0.547 m2: groupB == 0 0.2427 0.4028 0.603 0.547 (Adjusted p values reported -- single-step method) > > > > > cleanEx() detaching ‘package:SimComp’, ‘package:sandwich’ > nameEx("parm") > ### * parm > > flush(stderr()); flush(stdout()) > > ### Name: parm > ### Title: Model Parameters > ### Aliases: parm > ### Keywords: misc > > ### ** Examples > > > ## example from > ## Bretz, Hothorn, and Westfall (2002). > ## On multiple comparisons in R. R News, 2(3):14-17. > > beta <- c(V1 = 14.8, V2 = 12.6667, V3 = 7.3333, V4 = 13.1333) > Sigma <- 6.7099 * (diag(1 / c(20, 3, 3, 15))) > confint(glht(model = parm(beta, Sigma, 37), + linfct = c("V2 - V1 >= 0", + "V3 - V1 >= 0", + "V4 - V1 >= 0")), + level = 0.9) Simultaneous Confidence Intervals Fit: NULL Quantile = 1.8428 90% family-wise confidence level Linear Hypotheses: Estimate lwr upr V2 - V1 >= 0 -2.13330 -Inf 0.82209 V3 - V1 >= 0 -7.46670 -Inf -4.51131 V4 - V1 >= 0 -1.66670 -Inf -0.03628 > > > > > cleanEx() > nameEx("plot.cld") > ### * plot.cld > > flush(stderr()); flush(stdout()) > > ### Name: plot.cld > ### Title: Plot a cld object > ### Aliases: plot.cld > ### Keywords: hplot > > ### ** Examples > > > ### multiple comparison procedures > ### set up a one-way ANOVA > data(warpbreaks) > amod <- aov(breaks ~ tension, data = warpbreaks) > ### specify all pair-wise comparisons among levels of variable "tension" > tuk <- glht(amod, linfct = mcp(tension = "Tukey")) > ### extract information > tuk.cld <- cld(tuk) > ### use sufficiently large upper margin > old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) > ### plot > plot(tuk.cld) > par(old.par) > > ### now using covariates > amod2 <- aov(breaks ~ tension + wool, data = warpbreaks) > tuk2 <- glht(amod2, linfct = mcp(tension = "Tukey")) > tuk.cld2 <- cld(tuk2) > old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) > ### use different colors for boxes > plot(tuk.cld2, col=c("green", "red", "blue")) > par(old.par) > > ### get confidence intervals > ci.glht <- confint(tuk) > ### plot them > plot(ci.glht) > old.par <- par(mai=c(1,1,1.25,1), no.readonly=TRUE) > ### use 'confint.glht' object to plot all pair-wise comparisons > plot(cld(ci.glht), col=c("white", "blue", "green")) > par(old.par) > > ### set up all pair-wise comparisons for count data > data(Titanic) > mod <- glm(Survived ~ Class, data = as.data.frame(Titanic), + weights = Freq, family = binomial()) > ### specify all pair-wise comparisons among levels of variable "Class" > glht.mod <- glht(mod, mcp(Class = "Tukey")) > ### extract information > mod.cld <- cld(glht.mod) > ### use sufficiently large upper margin > old.par <- par(mai=c(1,1,1.5,1), no.readonly=TRUE) > ### plot > plot(mod.cld) > par(old.par) > > ### set up all pair-wise comparisons of a Cox-model > if (require("survival") && require("MASS")) { + ### construct 4 classes of age + Melanoma$Cage <- factor(sapply(Melanoma$age, function(x){ + if( x <= 25 ) return(1) + if( x > 25 & x <= 50 ) return(2) + if( x > 50 & x <= 75 ) return(3) + if( x > 75 & x <= 100) return(4) } + )) + ### fit Cox-model + cm <- coxph(Surv(time, status == 1) ~ Cage, data = Melanoma) + ### specify all pair-wise comparisons among levels of "Cage" + cm.glht <- glht(cm, mcp(Cage = "Tukey")) + # extract information & plot + old.par <- par(no.readonly=TRUE) + ### use mono font family + if (dev.interactive()) + old.par <- par(family = "mono") + plot(cld(cm.glht), col=c("black", "red", "blue", "green")) + par(old.par) + } > > if (require("nlme") && require("lme4")) { + data("ergoStool", package = "nlme") + + stool.lmer <- lmer(effort ~ Type + (1 | Subject), + data = ergoStool) + glme41 <- glht(stool.lmer, mcp(Type = "Tukey")) + + old.par <- par(mai=c(1,1,1.5,1), no.readonly=TRUE) + plot(cld(glme41)) + par(old.par) + } Loading required package: nlme Loading required package: lme4 Loading required package: Matrix Attaching package: ‘lme4’ The following object is masked from ‘package:nlme’: lmList > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() detaching ‘package:lme4’, ‘package:Matrix’, ‘package:nlme’ > nameEx("recovery") > ### * recovery > > flush(stderr()); flush(stdout()) > > ### Name: recovery > ### Title: Recovery Time Data Set > ### Aliases: recovery > ### Keywords: datasets > > ### ** Examples > > > ### set up one-way ANOVA > amod <- aov(minutes ~ blanket, data = recovery) > > ### set up multiple comparisons: one-sided Dunnett contrasts > rht <- glht(amod, linfct = mcp(blanket = "Dunnett"), + alternative = "less") > > ### cf. Westfall et al. (1999, p. 80) > confint(rht, level = 0.9) Simultaneous Confidence Intervals Multiple Comparisons of Means: Dunnett Contrasts Fit: aov(formula = minutes ~ blanket, data = recovery) Quantile = 1.8428 90% family-wise confidence level Linear Hypotheses: Estimate lwr upr b1 - b0 >= 0 -2.13333 -Inf 0.82206 b2 - b0 >= 0 -7.46667 -Inf -4.51127 b3 - b0 >= 0 -1.66667 -Inf -0.03624 > > ### the same > rht <- glht(amod, linfct = mcp(blanket = c("b1 - b0 >= 0", + "b2 - b0 >= 0", + "b3 - b0 >= 0"))) > confint(rht, level = 0.9) Simultaneous Confidence Intervals Multiple Comparisons of Means: User-defined Contrasts Fit: aov(formula = minutes ~ blanket, data = recovery) Quantile = 1.8431 90% family-wise confidence level Linear Hypotheses: Estimate lwr upr b1 - b0 >= 0 -2.13333 -Inf 0.82261 b2 - b0 >= 0 -7.46667 -Inf -4.51073 b3 - b0 >= 0 -1.66667 -Inf -0.03594 > > > > > cleanEx() > nameEx("trees513") > ### * trees513 > > flush(stderr()); flush(stdout()) > > ### Name: trees513 > ### Title: Frankonian Tree Damage Data > ### Aliases: trees513 > ### Keywords: datasets > > ### ** Examples > > > summary(trees513) damage species lattice plot yes: 448 oak :1258 1 : 75 10_1 : 15 no :2252 pine : 823 2 : 75 10_2 : 15 beech : 266 3 : 75 10_3 : 15 hardwood (other) : 191 7 : 75 10_4 : 15 spruce : 119 9 : 75 10_5 : 15 ash/maple/elm/lime: 30 10 : 75 1_1 : 15 (Other) : 13 (Other):2250 (Other):2610 > > > > > cleanEx() > nameEx("waste") > ### * waste > > flush(stderr()); flush(stdout()) > > ### Name: waste > ### Title: Industrial Waste Data Set > ### Aliases: waste > ### Keywords: datasets > > ### ** Examples > > > ### set up two-way ANOVA with interactions > amod <- aov(waste ~ temp * envir, data=waste) > > ### comparisons of main effects only > K <- glht(amod, linfct = mcp(temp = "Tukey"))$linfct Warning in mcp2matrix(model, linfct = linfct) : covariate interactions found -- default contrast might be inappropriate > K (Intercept) templow tempmedium envirenv2 envirenv3 envirenv4 low - high 0 1 0 0 0 0 medium - high 0 0 1 0 0 0 medium - low 0 -1 1 0 0 0 envirenv5 templow:envirenv2 tempmedium:envirenv2 low - high 0 0 0 medium - high 0 0 0 medium - low 0 0 0 templow:envirenv3 tempmedium:envirenv3 templow:envirenv4 low - high 0 0 0 medium - high 0 0 0 medium - low 0 0 0 tempmedium:envirenv4 templow:envirenv5 tempmedium:envirenv5 low - high 0 0 0 medium - high 0 0 0 medium - low 0 0 0 attr(,"type") [1] "Tukey" > glht(amod, K) General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Linear Hypotheses: Estimate low - high == 0 -1.26 medium - high == 0 -1.34 medium - low == 0 -0.08 > > ### comparisons of means (by averaging interaction effects) > low <- grep("low:envi", colnames(K)) > med <- grep("medium:envi", colnames(K)) > K[1, low] <- 1 / (length(low) + 1) > K[2, med] <- 1 / (length(low) + 1) > K[3, med] <- 1 / (length(low) + 1) > K[3, low] <- - 1 / (length(low) + 1) > K (Intercept) templow tempmedium envirenv2 envirenv3 envirenv4 low - high 0 1 0 0 0 0 medium - high 0 0 1 0 0 0 medium - low 0 -1 1 0 0 0 envirenv5 templow:envirenv2 tempmedium:envirenv2 low - high 0 0.2 0.0 medium - high 0 0.0 0.2 medium - low 0 -0.2 0.2 templow:envirenv3 tempmedium:envirenv3 templow:envirenv4 low - high 0.2 0.0 0.2 medium - high 0.0 0.2 0.0 medium - low -0.2 0.2 -0.2 tempmedium:envirenv4 templow:envirenv5 tempmedium:envirenv5 low - high 0.0 0.2 0.0 medium - high 0.2 0.0 0.2 medium - low 0.2 -0.2 0.2 attr(,"type") [1] "Tukey" > confint(glht(amod, K)) Simultaneous Confidence Intervals Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = waste ~ temp * envir, data = waste) Quantile = 2.5961 95% family-wise confidence level Linear Hypotheses: Estimate lwr upr low - high == 0 -2.0150 -3.2734 -0.7566 medium - high == 0 -2.2560 -3.5144 -0.9976 medium - low == 0 -0.2410 -1.4994 1.0174 > > ### same as TukeyHSD > TukeyHSD(amod, "temp") Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = waste ~ temp * envir, data = waste) $temp diff lwr upr p adj low-high -2.015 -3.274054 -0.7559457 0.0022853 medium-high -2.256 -3.515054 -0.9969457 0.0008562 medium-low -0.241 -1.500054 1.0180543 0.8737275 > > ### set up linear hypotheses for all-pairs of both factors > wht <- glht(amod, linfct = mcp(temp = "Tukey", envir = "Tukey")) Warning in mcp2matrix(model, linfct = linfct) : covariate interactions found -- default contrast might be inappropriate Warning in mcp2matrix(model, linfct = linfct) : covariate interactions found -- default contrast might be inappropriate > > ### cf. Westfall et al. (1999, page 181) > summary(wht, test = adjusted("Shaffer")) Simultaneous Tests for General Linear Hypotheses Multiple Comparisons of Means: Tukey Contrasts Fit: aov(formula = waste ~ temp * envir, data = waste) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) temp: low - high == 0 -1.260 1.084 -1.162 1.000 temp: medium - high == 0 -1.340 1.084 -1.236 1.000 temp: medium - low == 0 -0.080 1.084 -0.074 1.000 envir: env2 - env1 == 0 1.830 1.084 1.688 0.784 envir: env3 - env1 == 0 1.330 1.084 1.227 1.000 envir: env4 - env1 == 0 3.805 1.084 3.511 0.041 * envir: env5 - env1 == 0 3.660 1.084 3.377 0.041 * envir: env3 - env2 == 0 -0.500 1.084 -0.461 1.000 envir: env4 - env2 == 0 1.975 1.084 1.822 0.619 envir: env5 - env2 == 0 1.830 1.084 1.688 0.619 envir: env4 - env3 == 0 2.475 1.084 2.283 0.337 envir: env5 - env3 == 0 2.330 1.084 2.150 0.337 envir: env5 - env4 == 0 -0.145 1.084 -0.134 1.000 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- Shaffer method) > > > > > ### *