Resampling inference for mixed models of densely sampled physiological time series.
lmmresample provides permutation and bootstrap inference
for models fitted to repeated measurements organised in blocks (trials,
epochs or participants). Resampling always operates on whole blocks and
refits a single model on the full data, so dependence within each block,
such as the strong autocorrelation of samples within a trial, is carried
into the reference distribution without having to be modelled. Where
hundreds of autocorrelated samples per trial make standard Wald or
Satterthwaite inference unreliable, this gives valid tests and
intervals.
It applies to any block-structured signal, including pupillometry,
eye movements, EEG, fNIRS, heart rate and HRV, electrodermal activity,
EMG and kinematics, and at any level of aggregation: the full time
series, features extracted per trial, or one value per participant.
Supported models are lm() and
lme4::lmer().
Status: under active development. The interface is not yet stable.
future framework, with reproducible seeds.Development version from GitHub:
# install.packages("pak")
pak::pak("ricardo-martinez-flores/lmmresample")A permutation test of a condition × time interaction in a mixed model of full time series, and bootstrap intervals for its coefficients:
library(lmmresample)
library(lme4)
library(splines)
d <- sim_blocks("within", level = "timeseries", n_participants = 20,
n_trials = 20, n_time = 50, sampling_rate = 25,
effect_condition = 0.6, effect_onset = 0.5, seed = 2)
m <- lmer(y ~ condition * ns(time, 4) + (1 | participant), data = d)
# Whole trials are permuted; samples within a trial are matched by time
perm_test(m, "condition:ns(time, 4)", unit = "trial",
exchange = exch_signflip("participant"), time = "time")
# Whole participants are resampled
boot_ci(m, cluster = "participant",
terms = grep("^conditionB:", names(fixef(m)), value = TRUE))
# Does the test hold its error rate for this design?
ac <- diag_acf(m, series = "trial", time = "time")
perm_calibrate(m, "condition:ns(time, 4)", unit = "trial",
exchange = exch_signflip("participant"), ar1 = ac,
series = "trial", time = "time")Computation runs in parallel with
future::plan("multisession").
vignette("lmmresample"): getting started with a
trial-level analysis.vignette("time-courses"): full time series, diagnostics
and calibration.vignette("multiple-comparisons"): families of tests and
pairwise comparisons.MIT © lmmresample authors