Title: | Permutation Tests for Time Series Data |
---|---|
Description: | Helps you determine the analysis window to use when analyzing densely-sampled time-series data, such as EEG data, using permutation testing (Maris & Oostenveld, 2007) <doi:10.1016/j.jneumeth.2007.03.024>. These permutation tests can help identify the timepoints where significance of an effect begins and ends, and the results can be plotted in various types of heatmap for reporting. Mixed-effects models are supported using an implementation of the approach by Lee & Braun (2012) <doi:10.1111/j.1541-0420.2011.01675.x>. |
Authors: | Cesko C. Voeten [aut, cre] |
Maintainer: | Cesko C. Voeten <[email protected]> |
License: | FreeBSD |
Version: | 2.7 |
Built: | 2025-02-08 03:22:35 UTC |
Source: | https://gitlab.com/cvoeten/permutes |
buildmer
models. This is an alias for clusterperm.lm
provided for discoverability.Cluster-based permutation tests for time series data, based on generalized linear models or other buildmer
models. This is an alias for clusterperm.lm
provided for discoverability.
clusterperm.glm(...)
clusterperm.glm(...)
... |
Arguments to be passed to |
clusterperm.lm, clusterperm.lmer
perms <- clusterperm.glm(Fz ~ Deviant * Session,data=MMN,series.var=~Time)
perms <- clusterperm.glm(Fz ~ Deviant * Session,data=MMN,series.var=~Time)
buildmer
models. This is an alias for clusterperm.lmer
provided for discoverability.Cluster-based permutation tests for time series data, based on generalized linear mixed-effects models or other buildmer
models. This is an alias for clusterperm.lmer
provided for discoverability.
clusterperm.glmer(...)
clusterperm.glmer(...)
... |
Arguments to be passed to |
clusterperm.lmer
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject),data=MMN) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject),data=MMN,type='anova')
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject),data=MMN) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject),data=MMN,type='anova')
buildglmmTMB
.Cluster-based permutation tests for time series data, based on buildglmmTMB
.
clusterperm.glmmTMB( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var = ~0, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
clusterperm.glmmTMB( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var = ~0, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
formula |
A normal formula, possibly using |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
series.var |
A one-sided formula giving the variable grouping the time series. |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
parallel |
Whether to parallelize the permutation testing using plyr's |
progress |
A plyr |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
clusterperm.glmmTMB
is much slower than clusterperm.lmer
, but it is also more flexible, allowing for things like beta regression and zero-inflation.
A data frame.
# buildglmmTMB is much slower than clusterperm.lmer perms <- clusterperm.glmmTMB(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],series.var=~Time)
# buildglmmTMB is much slower than clusterperm.lmer perms <- clusterperm.glmmTMB(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],series.var=~Time)
buildmer
models. This is an alias for clusterperm.lmer
, except that random effects are explicily disallowed.Cluster-based permutation tests for time series data, based on mixed-effects models or other buildmer
models. This is an alias for clusterperm.lmer
, except that random effects are explicily disallowed.
clusterperm.lm( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
clusterperm.lm( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
formula |
A normal formula without random effects. This can also be a buildmer terms object, provided |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
series.var |
A one-sided formula giving the variable grouping the time series. |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
parallel |
Whether to parallelize the permutation testing using plyr's |
progress |
A plyr |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
A data frame.
clusterperm.lmer
perms <- clusterperm.lm(Fz ~ Deviant * Session,data=MMN,series.var=~Time)
perms <- clusterperm.lm(Fz ~ Deviant * Session,data=MMN,series.var=~Time)
buildmer
models.Cluster-based permutation tests for time series data, based on mixed-effects models or other buildmer
models.
clusterperm.lmer( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var = ~0, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
clusterperm.lmer( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, series.var = ~0, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", parallel = FALSE, progress = "none" )
formula |
A normal formula, possibly using |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
series.var |
A one-sided formula giving the variable grouping the time series. |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
parallel |
Whether to parallelize the permutation testing using plyr's |
progress |
A plyr |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
A data frame.
# Testing a single EEG electrode, with random effects by participants perms <- clusterperm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN,series.var=~Time) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- clusterperm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN,series.var=~Time,type='anova')
# Testing a single EEG electrode, with random effects by participants perms <- clusterperm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN,series.var=~Time) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- clusterperm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN,series.var=~Time,type='anova')
ERP data from Jager (in prep.). See the vignettes for details.
data(MMN)
data(MMN)
A standard data frame.
buildmer
models. This is an alias for perm.lm
provided for discoverability.A general permutation test for mixed-effects models or other buildmer
models. This is an alias for perm.lm
provided for discoverability.
perm.glm(...)
perm.glm(...)
... |
Arguments to be passed to |
perm.lm, perm.lmer
perms <- perm.glm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,])
perms <- perm.glm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,])
buildmer
models. This is an alias for perm.lmer
provided for discoverability.A general permutation test for mixed-effects models or other buildmer
models. This is an alias for perm.lmer
provided for discoverability.
perm.glmer(...)
perm.glmer(...)
... |
Arguments to be passed to |
perm.lmer
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.glmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
glmmTMB
models.A general permutation test for glmmTMB
models.
perm.glmmTMB( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
perm.glmmTMB( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
formula |
A normal formula, possibly using |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
progress |
Logical indicating whether to print progress messages during the permutation testing. |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
A data frame.
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmmTMB(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,])
# Testing a single EEG electrode, with random effects by participants perms <- perm.glmmTMB(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,])
buildmer
models. This is an alias for perm.lmer
, except that random effects are explicily disallowed.A general permutation test for mixed-effects models or other buildmer
models. This is an alias for perm.lmer
, except that random effects are explicily disallowed.
perm.lm( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
perm.lm( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
formula |
A normal formula, possibly using |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
progress |
Logical indicating whether to print progress messages during the permutation testing. |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
A data frame.
# Testing a single EEG electrode, with random effects by participants perms <- perm.lm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.lm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
# Testing a single EEG electrode, with random effects by participants perms <- perm.lm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.lm(Fz ~ Deviant * Session,data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
buildmer
models.A general permutation test for mixed-effects models or other buildmer
models.
perm.lmer( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
perm.lmer( formula, data = NULL, family = gaussian(), weights = NULL, offset = NULL, buildmerControl = list(direction = "order", crit = "LRT", quiet = TRUE, ddf = "lme4"), nperm = 1000, type = "regression", progress = TRUE )
formula |
A normal formula, possibly using |
data |
The data. |
family |
The family. |
weights |
An optional vector of prior case weights. This vector is evaluated in the calling environment, not in the formula or data frame! |
offset |
An optional vector containing a prior offset term. This vector is evaluated in the calling environment, not in the formula or data frame! |
buildmerControl |
Options overriding the defaults in |
nperm |
The number of permutations. |
type |
A character string of either |
progress |
Logical indicating whether to print progress messages during the permutation testing. |
If not explicitly overridden in the buildmerControl
argument, the function changes a few buildmer defaults to make more sense for permutation testing. This includes setting direction='order'
and quiet=TRUE
. Set these options explicitly to override this behavior.
Because model comparisons are used for efficient permutation testing, REML is not supported.
Omega squared is not available for mixed-effects ANOVA; the w2
column will not be included in the resulting permutes
object.
The returned object provides the raw bootstrap samples in the pb
attribute. These are used to compute a corrected p-value using Maris & Oostenveld's (2007) cluster mass statistic, but can also be used by the user to compute other such statistics. These obviously significantly increase the size of the R object; if this becomes a problem, there is no harm in deleting them using e.g. attr(x,'perms') <- NULL
.
A data frame.
# Testing a single EEG electrode, with random effects by participants perms <- perm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
# Testing a single EEG electrode, with random effects by participants perms <- perm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,]) # Testing a single EEG electrode, with random effects by participants, ANOVA inference perms <- perm.lmer(Fz ~ Deviant * Session + (Deviant * Session | Subject), data=MMN[MMN$Time > 150 & MMN$Time < 250,],type='anova')
perm.lm
or perm.lmer
instead.
permu.test
is the only function to support multivariate responses, although multivariate data can trivially be recoded into a univariate model.
permu.test
does not support random effects or corrected p-values (e.g. the cluster mass test), which are supported by permutelm
.Permutation tests for time series data, based on classic linear regression or ANOVA
This is a legacy function that is primarily provided for backward compatibility. You should probably use perm.lm
or perm.lmer
instead.
permu.test
is the only function to support multivariate responses, although multivariate data can trivially be recoded into a univariate model.
permu.test
does not support random effects or corrected p-values (e.g. the cluster mass test), which are supported by permutelm
.
permu.test( formula, data, subset = NULL, type = "anova", parallel = FALSE, progress = "text", ... )
permu.test( formula, data, subset = NULL, type = "anova", parallel = FALSE, progress = "text", ... )
formula |
A formula of the following form: |
data |
The dataset referencing these predictors. |
subset |
If specified, will only analyze the specified subset of the data. |
type |
A character string of either |
parallel |
Whether to parallelize the permutation testing using plyr's |
progress |
A plyr |
... |
Other arguments to be passed to |
A data frame.
clusterperm.lm
, clusterperm.lmer
# EEG data example using the MMN dataset # Run permutation tests on all electrodes and timepoints, reporting p-values for the three # manipulated factors perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN) # Run the tests in parallel on two CPU threads # first, set up the parallel backend library(doParallel) cl <- makeCluster(2) registerDoParallel(cl) perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN, parallel=TRUE) stopCluster(cl) # Plot the results by F-value, removing points that were not significant in the # permutation tests plot(perms,sig='p') # t-values instead of F-values perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN, type='regression')
# EEG data example using the MMN dataset # Run permutation tests on all electrodes and timepoints, reporting p-values for the three # manipulated factors perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN) # Run the tests in parallel on two CPU threads # first, set up the parallel backend library(doParallel) cl <- makeCluster(2) registerDoParallel(cl) perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN, parallel=TRUE) stopCluster(cl) # Plot the results by F-value, removing points that were not significant in the # permutation tests plot(perms,sig='p') # t-values instead of F-values perms <- permu.test(cbind(Fp1,AF3,F7,F3,FC1,FC5,C3,CP1,CP5,P7,P3,Pz,PO3,O1,Oz,O2,PO4,P4, P8,CP6,CP2,C4,FC6,FC2,F4,F8,AF4,Fp2,Fz,Cz) ~ Deviant * Session | Time,data=MMN, type='regression')
Create a heatmap of the results of cluster-based permutation testing.
## S3 method for class 'permutes' plot( x, type = c("LRT", "F", "t", "beta", "w2", "cluster_mass"), breaks = NULL, sig = NULL, ... )
## S3 method for class 'permutes' plot( x, type = c("LRT", "F", "t", "beta", "w2", "cluster_mass"), breaks = NULL, sig = NULL, ... )
x |
Output of |
type |
The quantity to plot. For ANOVA, the options are |
breaks |
The granularity of the labels of the x axis. Pass ‘unique(x[,2])’ to get a tick for every timepoint. Combine this trick with subsetting of your dataset, and perhaps averaging over all your dependent variables, to ‘zoom in’ on your data to help you determine precisely where significance begins and stops to occur. |
sig |
An optional column name. If specified, only cases with a value of <.05 in this column will be plotted. NULL by default, but suggested to be set to |
... |
Other arguments, which will be ignored (the ellipsis is provided for consistency with the generic plot() method). |
A ggplot2 object.