I'm struggling to calculate an effect size between a continuous predictor's max-min value while using an R lme4 multilevel model.
Simulated data: predictor "x" ranges from 1 to 3
library(tidyverse)
n = 100
a = tibble(y = rep(c("pos", "neg", "neg", "neg"), length.out = n), x = rep(3, length.out = n), group = rep(letters[1:7], length.out = n))
b = tibble(y = rep(c("pos", "pos", "neg", "neg"), length.out = n), x = rep(2, length.out = n), group = rep(letters[1:7], length.out = n))
c = tibble(y = rep(c("pos", "pos", "pos", "neg"), length.out = n), x = rep(1, length.out = n), group = rep(letters[1:7], length.out = n))
d = rbind(a, b)
df = rbind(d, c)
df = df %>% mutate(y = as.factor(y))
df
Model
library("lme4")
m = glmer(
y ~ x + (x | group),
data = df,
family = binomial(link = "logit"))
Output
ggpredict(m, "x")
.
# Predicted probabilities of y
x | Predicted | 95% CI
----------------------------
1 | 0.75 | [0.67, 0.82]
2 | 0.50 | [0.44, 0.56]
3 | 0.25 | [0.18, 0.33]
Adjusted for:
* group = 0 (population-level)
I'm failing to calculate the effect size between the predictor's "x" max (3) and min (1) value
My best try
library("emmeans")
emmeans(m, "x", trans = "logit", type = "response", at = list(x = c(1, 3)))
x response SE df asymp.LCL asymp.UCL
1 0.75 0.0387 Inf 0.667 0.818
3 0.25 0.0387 Inf 0.182 0.333
Confidence level used: 0.95
Intervals are back-transformed from the logit scale
How can I calculate the effect size with CIs between the predictor's "x" max (3) and min (1) value? The effect size should be in probability scale.
