My model is here. I'm running a bootstrapping mixed-effects model with "case" type with lmersmapler. The thing is, now I'm using bootstrap_pvals()
to obtain p-values and the results are not matching. Based on the 95% CIs, I should get all p < 0.05 except for the interaction, but the CIs and p-values are not matching. I need some help.
- the model:
mod1 <- lmer(CONT_Y ~ YEAR * MY_GROUP + (1|PARTICIPANTS), data = data)
mod1_boot <- bootstrap(mod1, .f = fixef, type = "case", B = 1000,
resample = c(TRUE, FALSE))
> confint(mod1_boot, type = "norm")
# A tibble: 4 x 6
term estimate lower upper type level
<chr> <dbl> <dbl> <dbl> <chr> <dbl>
1 (Intercept) 17.6 16.7 18.5 norm 0.95 ##DOESN'T CONTAIN 0
2 YEAR2 1.14 0.186 2.13 norm 0.95 ## DOESN'T CONTAIN 0
3 GROUPB 0.915 0.155 1.68 norm 0.95 ## DOESN'T CONTAIN 0
4 YEAR2:GROUPB -0.602 -1.80 0.577 norm 0.95 ## CONTAINS 0!!!
>
- obtaining p-values:
bootstrap_pvals(mod1, type = "case", B = B, resample = c(TRUE, F),
aux.dist = norm)
$coefficients
# A tibble: 4 x 7
term Estimate `Std. Error` df `t value` `Pr(>|t|)` p.value
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 17.6 0.393 79.7 44.8 2.67e-58 0.389
2 YEAR2 1.14 0.517 63.0 2.21 3.06e- 2 0.565
3 GROUPB 0.915 0.517 63.0 1.77 8.17e- 2 0.589
4 YEAR2:GROUPB -0.602 0.731 63.0 -0.824 4.13e- 1 0.568
$B
[1] 1000
ps: conf.int doesn't work on this object
It doesn't make sense to me, the interaction should be ns and the other coefficient should be sig. Any ideas?
how can I get the 95 % CI for a
bootstrap_pvals
object ?Edit 1: Trying to convert the factor variables into binary numerical ones:
num_data <- data %>%
mutate(YEAR_num = case_when(
YEAR == "A" ~ 0, YEAR == "B" ~ 1),
GROUP_num = case_when(
GROUP == "G1" ~ 0, GROUP == "G2" ~ 1))
## check
> class(num_data$YEAR_num)
[1] "numeric"
> class(num_data$GROUP_num)
[1] "numeric"
## refit:
mod1 <- lmer(CONT_Y ~ YEAR_num * GROUP_num + (1|PARTICIPANTS), data = num_data, REML = FALSE)
## bootstrap it:
mod_p <- bootstrap_pvals(mod1, type = "case", B = 1000, resample = c(TRUE, F), aux.dist = norm)
## check:
mod_p
> mod_p
$coefficients
# A tibble: 4 x 7
term Estimate `Std. Error` df `t value` `Pr(>|t|)` p.value
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 17.6 0.393 79.7 44.8 2.67e-58 0.395
2 YEAR_num 1.14 0.517 63.0 2.21 3.06e- 2 0.559
3 GROUP_num 0.915 0.517 63.0 1.77 8.17e- 2 0.582
4 YEAR_num:GROUP_num -0.602 0.731 63.0 -0.824 4.13e- 1 0.574
- DATA:
data <- structure(list(PARTICIPANTS = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L,
7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L,
10L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L,
17L, 17L, 17L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 20L, 20L,
20L, 20L, 21L, 21L, 21L, 21L), CONT_Y = c(19.44, 20.07, 19.21,
16.35, 11.37, 12.82, 19.42, 18.94, 19.59, 20.01, 19.7, 17.92,
18.78, 19.21, 19.27, 18.46, 19.52, 20.02, 16.19, 19.97, 13.83,
15.93, 14.79, 21.55, 18.8, 19.42, 19.27, 19.37, 17.14, 14.45,
17.63, 20.01, 20.28, 17.93, 19.36, 20.15, 16.06, 17.04, 19.16,
20.1, 16.44, 18.39, 18.01, 19.05, 18.04, 19.69, 19.61, 16.88,
19.02, 20.42, 18.27, 18.43, 18.08, 17.1, 19.98, 19.43, 19.71,
19.93, 20.11, 18.41, 20.31, 20.1, 20.38, 20.29, 13.6, 18.92,
19.05, 19.13, 17.75, 19.15, 20.19, 18.3, 19.43, 19.8, 19.83,
19.53, 16.14, 21.14, 17.37, 18.73, 16.51, 17.51, 17.06, 19.42
), CATEGORIES = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("A",
"B"), class = "factor"), MY_GROUP = structure(c(1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L
), .Label = c("G1", "G2"), class = "factor")), row.names = c(NA,
-84L), class = c("tbl_df", "tbl", "data.frame"))
### rename collumn:
data <- data %>% rename(., YEAR = CATEGORIES)
Pr(>|t|)
is $0.413$ for the interaction so quite large and not significant at the 5% level. $\endgroup$bootstrap_pvals()
before, I've read the doc, but it didn't quite answer that. However, it was the only function that gave me pvalues for mylmeresampler
model $\endgroup$bootstrap_pvals
and especiallybootstrap_pvals.merMod
. I think it's a bug stemming from how the code updates the model. Try converting the group and year variables to binary numeric variables and refit the following model:lmer(CONT_Y ~ year_num + group_num + year_num:group_num + (1|PARTICIPANTS), data = data)
. Then run the bootstrap again. Now the p-values will be consistent (up to random error). I also strongly suggest submitting a bug report here: github.com/aloy/lmeresampler/issues $\endgroup$