Load up relevant libraries
devtools::install_github("jofrhwld/lsa2017")
library(lsa2017)
library(tidyverse)
library(lme4)
library(boot)
Prepare data to investigate the effect of duration and location within the word (initial vs internal).
iy <- iy_ah %>%
filter(plt_vclass == "iy",
context %in% c("initial", "internal"))%>%
mutate(log2dur = log2(dur),
cdur = log2dur - median(log2dur))
Fit the model (this isn’t maximal, jus for show).
iy_mod <- lmer(F1_n ~ cdur * context + (1|idstring) + (1|word), data = iy)
Get your bootstrap replicates of the fixed effects.
iy_boot <- bootMer(iy_mod, FUN = fixef, nsim = 500, type = "parametric")
First, get the parameter names into a data frame. It is CRUCIAL that they be characters, not factors. If using data.frame() you must set stringsAsFactors=F.
param_df <- data_frame(params = colnames(iy_boot$t))
Three step process.
boot.ci() onto the parameter names, using them as the argument to index.boot.ci() output into a nice data frame.ci_df <- param_df%>%
mutate(ci = map(params, ~boot.ci(iy_boot,
type = "perc",
index = .x)),
ci_df = map(ci, ~data_frame(lo = .x$percent[4],
est = .x$t0,
hi = .x$percent[5])))%>%
unnest(ci_df)
Now plot! (filtering out (Intercept) because its scale is so different).
ci_df %>%
filter(params != "(Intercept)") %>%
ggplot(aes(params, est))+
geom_hline(yintercept = 0, color = "grey40", linetype = 2)+
geom_pointrange(aes(ymin = lo,
ymax = hi)) +
xlim("cdur:contextinternal", "contextinternal", "cdur")+
coord_flip()+
theme_minimal()