Multiple Comparisons for MixMod Objects

Dimitris Rizopoulos

2018-09-27

Multiple Comparisons with MixMod Objects

In this vignette we illustrate how to correct p-values for multiple comparisons using the multcomp package.

We start by simulating some data for a binary longitudinal outcome:

set.seed(1234)
n <- 300 # number of subjects
K <- 4 # number of measurements per subject
t_max <- 15 # maximum follow-up time

# we constuct a data frame with the design: 
# everyone has a baseline measurment, and then measurements at K time points
DF <- data.frame(id = rep(seq_len(n), each = K),
                 time = gl(K, 1, n*K, labels = paste0("Time", 1:K)),
                 sex = rep(gl(2, n/2, labels = c("male", "female")), each = K))

# design matrices for the fixed and random effects
X <- model.matrix(~ sex * time, data = DF)
Z <- model.matrix(~ 1, data = DF)

betas <- c(-2.13, 1, rep(c(1.2, -1.2), K-1)) # fixed effects coefficients
D11 <- 1 # variance of random intercepts

# we simulate random effects
b <- cbind(rnorm(n, sd = sqrt(D11)))
# linear predictor
eta_y <- as.vector(X %*% betas + rowSums(Z * b[DF$id, ]))
# we simulate binary longitudinal data
DF$y <- rbinom(n * K, 1, plogis(eta_y))

We fit a mixed effects logistic regression for y assuming random intercepts for the random-effects part, and the main effects of sex and time for the fixed-effects part.

fm <- mixed_model(fixed = y ~ sex + time, random = ~ 1 | id, data = DF,
                  family = binomial())

The uncorrected p-values for the 4 time points are give by the summary() method:

summary(fm)
#> 
#> Call:
#> mixed_model(fixed = y ~ sex + time, random = ~1 | id, data = DF, 
#>     family = binomial())
#> 
#> Data Descriptives:
#> Number of Observations: 1200
#> Number of Groups: 300 
#> 
#> Model:
#>  family: binomial
#>  link: logit 
#> 
#> Fit statistics:
#>    log.Lik      AIC      BIC
#>  -583.4797 1178.959 1201.182
#> 
#> Random effects covariance matrix:
#>               StdDev
#> (Intercept) 1.448146
#> 
#> Fixed effects:
#>               Value Std.Err z-value    p-value
#> (Intercept) -2.2865  0.2496 -9.1597    < 1e-04
#> sexfemale    0.8853  0.2448  3.6171 0.00029798
#> timeTime2    0.3066  0.2266  1.3533 0.17594625
#> timeTime3   -0.5049  0.2463 -2.0501 0.04035455
#> timeTime4    0.5633  0.2237  2.5184 0.01178997
#> 
#> Integration:
#> method: adaptive Gauss-Hermite quadrature rule
#> quadrature points: 11
#> 
#> Optimization:
#> method: hybrid EM and quasi-Newton
#> converged: TRUE

To perform the pairwise comparisons and obtain corrected p-values, we load the multcomp package and use the glht() function. Because no specific methods exist for MixMod object returned by mixed_model(), we need to specify the vcov. and coef. arguments of glht(), i.e.,

library("multcomp")
#> Loading required package: mvtnorm
#> Loading required package: survival
#> Loading required package: TH.data
#> Loading required package: MASS
#> 
#> Attaching package: 'MASS'
#> The following object is masked from 'package:GLMMadaptive':
#> 
#>     negative.binomial
#> 
#> Attaching package: 'TH.data'
#> The following object is masked from 'package:MASS':
#> 
#>     geyser
fm_mc <- glht(fm, linfct = mcp(time = "Tukey"),
           vcov. = vcov(fm, "fixed"), coef. = fixef)

summary(fm_mc)
#> 
#>   Simultaneous Tests for General Linear Hypotheses
#> 
#> Multiple Comparisons of Means: Tukey Contrasts
#> 
#> 
#> Fit: mixed_model(fixed = y ~ sex + time, random = ~1 | id, data = DF, 
#>     family = binomial())
#> 
#> Linear Hypotheses:
#>                    Estimate Std. Error z value Pr(>|z|)    
#> Time2 - Time1 == 0   0.3066     0.2266   1.353  0.52811    
#> Time3 - Time1 == 0  -0.5049     0.2463  -2.050  0.16945    
#> Time4 - Time1 == 0   0.5633     0.2237   2.518  0.05691 .  
#> Time3 - Time2 == 0  -0.8115     0.2423  -3.350  0.00465 ** 
#> Time4 - Time2 == 0   0.2567     0.2165   1.186  0.63520    
#> Time4 - Time3 == 0   1.0682     0.2406   4.440  < 0.001 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> (Adjusted p values reported -- single-step method)