In this excellent post on cross validated an answer mentioned that it is relatively easy to correct confidence intervals for multiple comparisons.
I am wondering whether this is possible using the multcomp package in R
Here's an example model using the mtcars dataset from base R, a multivariate regression predicting miles per gallon (mpg) from a list of predictors.
set.seed(1234)
df <- mtcars
# which variables predict miles per gallon?
sumMod <- summary(mod <- lm(formula = mpg ~ cyl + disp + hp + drat + wt + qsec + vs + gear,
data = df))
Now run the model through the multcomp package using the glht function.
# adjust using multcomp
library(multcomp)
K <- length(coefficients(mod))
modGLHT <- glht(model = mod,
linfct = diag(K))
In multcomp you choose the method of adjustment using the test = adjusted(type = 'foo') argument within the package's summary() function
sumNone <- summary(modGLHT, test = adjusted(type = "none")) # no adjustment
sumSingleStep <- summary(modGLHT, test = adjusted(type = "single-step")) # single-step method
Now if we compare the p-value for the wt coefficient under no correction and with single-step correction...
data.frame(correction = c("none", "single-step"),
coefs = c(round(sumNone$test$coefficients[6],2),
round(sumSingleStep$test$coefficients[6],2)),
p = c(round(sumNone$test$pvalues[6],3),
round(sumSingleStep$test$pvalues[6],3)))
# output
# correction coefs p
# none -4.36 0.003
# single-step -4.36 0.024
We can see that the p-value has increased after applying single-step correction. So far so good.
My issue is how to get corrected confidence intervals?
I tried applying adjusted(type = 'foo') within the confint() function (once again for illustration I have focused on the wt predictor) like so...
# get CIs using four different methods
ciNone <- round(as.data.frame(confint(modGLHT, adjusted(type = "none"))$confint)[6,],3)
ciSS <- round(as.data.frame(confint(modGLHT, adjusted(type = "single-step"))$confint)[6,],3)
ciShaffer <- round(as.data.frame(confint(modGLHT, adjusted(type = "Shaffer"))$confint)[6,],3)
ciWestfall <- round(as.data.frame(confint(modGLHT, adjusted(type = "Westfall"))$confint)[6,],3)
# put them all together for comparison
cbind(data.frame(correction = c("None", "Single_Step", "Shaffer", "Westfall")),
rbind(ciNone, ciSS, ciShaffer, ciWestfall))
# output
# correction Estimate lwr upr
# 6 None -4.356 -8.274 -0.439
# 61 Single_Step -4.356 -8.269 -0.444
# 62 Shaffer -4.356 -8.276 -0.437
# 63 Westfall -4.356 -8.279 -0.434
No it looks to me as if something is going on, there are some very small differences. But when I run the confint() function on its own and ...
confint(modGLHT, adjusted(type = "Shaffer"))
the output makes no mention anywhere of type of error correction. I also get no error message. So I can't tell if the adjusted(type = 'foo') argument is doing anything nor whether the above differences in the CIs using the different methods are actual differences due to the method itself or simply an artefact of some randomness in a Markov-type procedure used to generate the intervals.
So is it legitimate to add the adjusted(type = 'foo') argument to the confint() function in multcomp?. The help documentation for the function does not say so and although I got no error message when I did it I cannot tell if it worked.
Any help much appreciated.