2
$\begingroup$

Similar to question here.

3 variables (1 continuous (X) and 2 categorical (A & B)) predict 1 dichotomous variable in generalized linear mixed models.

Both variables A and B are dichotomous and are coded with 0 (reference category) and 1. Criterion is coded with 0 & 1.

After

library(lmerTest)
glmer(Y ~ X*A*B + (0+X|G) + (1|G), data=dat, family = "binomial", verbose = T, control = glmerControl(optimizer = "bobyqa"))

we have the following results:

Random effects:
 Groups    Name                        Variance  Std.Dev.
 G         (Intercept)                 0.1458298 0.38188 
 G          X                          0.21727   0.46612
Number of obs: 26260, groups:  G, 230
Fixed effects:
                                   Estimate Std. Error z value Pr(>|z|)    
(Intercept)                         1.47384    0.04094  35.997  < 2e-16 ***
X                                  -0.03252    0.01612  -2.017  0.04370 *  
A2                                 -0.46066    0.04853  -9.492  < 2e-16 ***
B2                                 -0.61576    0.04811 -12.799  < 2e-16 ***
X:A2                                0.07502    0.01810   4.144 3.41e-05 ***
X:B2                                0.08031    0.01945   4.129 3.64e-05 ***
A2:B2                               0.62260    0.06653   9.358  < 2e-16 ***
X:A2:B2                            -0.06789    0.02367  -2.868  0.00413 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Now, the slopes for different conditions are:

    A1      A2 
B1  X       X+X:A2
B2  X+X:B2  X+X:A2+X:B2+X:A2:B2

How can I test the following hypothesis

X+X:B2 = X+X:A2 + X:B2 + X:A2:B2 which equals to 0 = X:A2 + X:A2:B2 and finally

X:A2 = -X:A2:B2

For logistic one-level models we use Wald's test as described in here.

library(aod)
R <- cbind(0,0,0,0,0,0,1,1)
wald.test(b = coef(model), Sigma = vcov(model), L = R)

Can we use the identical approach for mixed models?

$\endgroup$
  • $\begingroup$ I suppose you fit the model in R judging by the output. What is the fit command? $\endgroup$ – Jesper for President Feb 25 '19 at 21:42
  • $\begingroup$ Added the code in the OP $\endgroup$ – User33268 Feb 25 '19 at 21:56
  • 1
    $\begingroup$ $R$ vector should be $(0, 0, 0,0,0,0, 1, 1)$ if you want to test whether fixed effect 7th and 8th covariate - counting the intercept - together are 0, as implied when you say 0 = X:A2 + X:A2:B2. $\endgroup$ – Jesper for President Feb 25 '19 at 22:52
  • $\begingroup$ Yes, you are right! $\endgroup$ – User33268 Feb 26 '19 at 12:35
1
$\begingroup$

I am not overly familiar with mixed models (read I cannot tell you whether this is a correct statistical approach) but based on reading here mixed models on SSC I think you may be looking for something like this:

set.seed(1)
#### SIMULATE ####
n <- 1000
K <- 4
A <- as.numeric( runif(n)<0.5 )
B <- as.numeric( runif(n)<0.3 )
X <- rnorm(n) + runif(n)
random_effect_index <- sample(1:K,10,replace=TRUE)
random_effect <- rnorm(K,sd=0.3)[random_effect_index]

# Fixed effect parameters
beta_0 <- 0
beta_X <- 0.5
beta_B <- 1
beta_A <- 1.3

beta_XA <- 0.5
beta_XB <- 1.3
beta_AB <- -0.5

beta_XAB <- -1

# probabilities

interaction_effects <- (beta_XA*X*A) + (beta_XB*X*B) + (beta_AB*A*B) + (beta_XAB*X*A*B)

exp_z <- exp(beta_0 + beta_X * X + beta_A * A + beta_B * B + interaction_effects + random_effect)
p <- exp_z / (1 + exp_z)
hist(p)

# dependent
Y <- as.numeric( runif(n) < p ) 
mydata <- data.frame(Y=Y,X=X,A=A,B=B,G=random_effect_index)
head(mydata)


#### FIT MODEL ####
library(lme4)
gmm <- glmer(Y ~ X*A*B + (0+X|G) + (1|G), data=mydata, family = "binomial", verbose = T, control = glmerControl(optimizer = "bobyqa"))
summary(gmm)

# Likelihood Ratio Test using Linear Hypothesis Command
library(car)
LH <- linearHypothesis(gmm,c("X:A + X:A:B=0") ) 
LH
| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

You can use the GLMMadaptive package in which the anova() method has an argument called L that is a user-defined contrast matrix. For more info check here.

The relevant code would be something like:

library(GLMMadaptive)
fm <- mixed_model(Y ~ X * A * B, random = ~ X || G, data = dat,
                  family = binomial())
R <- cbind(0,0,0,0,0,0,1,1)
anova(fm, L = R)
| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you but using GLMMadaptive is not an option for me now. Is there something similar to Wald's test for logit models? $\endgroup$ – User33268 Feb 25 '19 at 20:35
  • $\begingroup$ You can check the aod package that has the wald.test() function. $\endgroup$ – Dimitris Rizopoulos Feb 25 '19 at 22:02
  • $\begingroup$ BTW, the model you posted above can be fitted with GLMMadaptive. $\endgroup$ – Dimitris Rizopoulos Feb 25 '19 at 22:07
0
$\begingroup$

If you have two predictors in a regression model and want to test whether or not they have equivalent effects, i.e. that $\beta_1 = \beta_2$ in

$$ Y = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \varepsilon$$

Then form a new predictor, $Z = X_1 + X_2$, and compare the model with $X_1, X_2$ as predictors to the one using only $Z$. If the larger model is not significantly better you don't have evidence that the coefficients are different.

I described this in terms of continuous predictors, and for linear regression, but you can imagine an analogous approach for categorical variables and for GLMs like logistic regression.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.