1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
R version 2.4.0 (2006-10-03)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
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.
>
> library("multcomp")
Loading required package: mvtnorm
> set.seed(290875)
>
> testdata <- data.frame(y = rnorm(21),
+ f1 <- factor(c(rep(c("A", "B", "C"), 7))),
+ f2 <- factor(c(rep("D", 10), rep("E", 11))),
+ x <- rnorm(21))
>
> # one-way ANOVA
> coef(amod <- aov(y ~ f1, data = testdata))
(Intercept) f1B f1C
-0.4394751 0.5151680 0.6886101
> glht(amod, linfct = mcp(f1 = "Dunnett"))
General Linear Hypotheses
Multiple Comparisons of Means: Dunnett Contrasts
Linear Hypotheses:
Estimate
B - A == 0 0.5152
C - A == 0 0.6886
>
> # and a continuous covariable: ANCOVA
> coef(lmod <- lm(y ~ f1 + x, data = testdata))
(Intercept) f1B f1C x
-0.434528566 0.509444592 0.686181780 -0.009491201
> glht(lmod, linfct = mcp(f1 = "Dunnett"))
General Linear Hypotheses
Multiple Comparisons of Means: Dunnett Contrasts
Linear Hypotheses:
Estimate
B - A == 0 0.5094
C - A == 0 0.6862
>
> # ANCOVA with an additional factor as covariable
> coef(lmod <- lm(y ~ f1 + f2 + x, data = testdata))
(Intercept) f1B f1C f2E x
-0.40849498 0.51296437 0.69200699 -0.05266965 -0.01613183
> glht(lmod, linfct = mcp(f1 = "Dunnett"))
General Linear Hypotheses
Multiple Comparisons of Means: Dunnett Contrasts
Linear Hypotheses:
Estimate
B - A == 0 0.513
C - A == 0 0.692
>
> # and with interaction terms
> coef(lmod <- lm(y ~ f1 + f2 + f2:f1 + x, data = testdata))
(Intercept) f1B f1C f2E x f1B:f2E
-0.44532319 0.70282663 0.65613337 0.05552324 -0.03443721 -0.37862471
f1C:f2E
0.02753451
> glht(lmod, linfct = mcp(f1 = "Dunnett"))
General Linear Hypotheses
Multiple Comparisons of Means: Dunnett Contrasts
Linear Hypotheses:
Estimate
B - A == 0 0.5135
C - A == 0 0.6699
>
> # with contrasts as expressions
> glht(lmod, linfct = mcp(f1 = c("B - A = 0", "C - A = 0")))
General Linear Hypotheses
Multiple Comparisons of Means: User-defined Contrasts
Linear Hypotheses:
Estimate
B - A == 0 0.5135
C - A == 0 0.6699
>
> tmp <- multcomp:::chrlinfct2matrix(c(l1 = "x1 - x2 = 2",
+ l2 = "x2 + 3 * x3 = 1"),
+ paste("x", 1:3, sep = ""))
>
> stopifnot(max(abs(tmp$K - rbind(c(1, -1, 0), c(0, 1, 3)))) < sqrt(.Machine$double.eps))
> stopifnot(max(abs(tmp$m - c(2, 1))) < sqrt(.Machine$double.eps))
>
> ### coef.survreg and vcov.survreg need special tuning
> ### thx to Z for pointing this out
> if (require("survival")) {
+ smod <- survreg(Surv(futime, fustat) ~ ecog.ps + rx,
+ data = ovarian, dist = 'weibull')
+ K <- diag(length(coef(smod)))
+ rownames(K) <- names(coef(smod))
+ glht(smod, linfct = K)
+ }
Loading required package: survival
Loading required package: splines
General Linear Hypotheses
Linear Hypotheses:
Estimate
(Intercept) == 0 6.8967
ecog.ps == 0 -0.3850
rx == 0 0.5286
>
|