0
$\begingroup$

I am trying to make sure that I am specifying and interpreting this model correctly.

In my experiment, participants take two tests (test1, test2) and answer four questions on each test (it's the same test twice). They can either get each question right (1) or wrong (0). I am trying to see to what extent getting the question right on the first test predicts whether they'll get the question right on the second test.

Example data frame

df <- read.table(header = T, text = "
     subj question test1 test2
1     1        1     0     0
2     1        2     1     0
3     1        3     0     1
4     1        4     0     0
5     2        1     0     0
6     2        2     0     1
7     2        3     0     0
8     2        4     0     0
9     3        1     1     0
10    3        2     1     1
11    3        3     0     1
12    3        4     0     1
13    4        1     1     1
14    4        2     1     1
15    4        3     1     0
16    4        4     1     0
17    5        1     0     1
18    5        2     0     0
19    5        3     1     1
20    5        4     1     1
")

I am specifying the model as

fit <- glmer(test2 ~ test1 + (1 | subj),
             data = df,
             family = "binomial", na.action = na.exclude)

And here's the output

summary(fit)
Fixed effects:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)  -0.1823     0.6055  -0.301    0.763
test1         0.4055     0.9037   0.449    0.654

# exponentiate the log odds to get odds ratio
exp(fixef(fit))

(Intercept)       test1 
  0.8333333   1.5000000 

So according to this sample data & output, and ignoring the p-value, the odds of getting a question correct on test2 are about 50% higher if you got the question correct on test1.

Are my specification and interpretation correct?

$\endgroup$

1 Answer 1

3
$\begingroup$

In mixed-effects logistic regression, the fixed coefficients have an interpretation conditional on the random effects. For an explanation of the issue have a look here. Like in your case, I'd say that you want to see the effect of a correct response in test1 in the odds of test2 averaged over the subjects.

You can obtain coefficients with a marginal interpretation using the marginal_coefs() function from the GLMMadaptive package. For example, for your data you can try:

library("GLMMadaptive")

fm <- mixed_model(test2 ~ test1, random = ~ 1 | subj, data = df, 
                  family = binomial())

# conditional odds and odds ratio
exp(fixef(fm))

mcoefs <- marginal_coefs(fm)

# marginal odds and odds ratio
exp(coef(mcoefs))

Here you don't see any differences because the variance of the random effects is relatively small. The bigger the variance the greater the difference between the two sets of coefficients.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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