osl_dynamics.analysis.statistics#

Functions to perform statistical significance testing.

Note

This module is used in the following tutorials:

Module Contents#

Functions#

_check_glm_data(data, covariates[, assignments])

Check shapes and remove subjects from GLM data which contain nans.

evoked_response_max_stat_perm(data, n_perm[, ...])

Statistical significant testing for evoked responses.

group_diff_max_stat_perm(data, assignments, n_perm[, ...])

Statistical significant testing for the difference between two groups.

paired_diff_max_stat_perm(data, n_perm[, metric, n_jobs])

Statistical significant testing for paired differences.

Attributes#

_logger

osl_dynamics.analysis.statistics._logger[source]#
osl_dynamics.analysis.statistics._check_glm_data(data, covariates, assignments=None)[source]#

Check shapes and remove subjects from GLM data which contain nans.

osl_dynamics.analysis.statistics.evoked_response_max_stat_perm(data, n_perm, covariates=None, metric='copes', n_jobs=1)[source]#

Statistical significant testing for evoked responses.

This function fits a General Linear Model (GLM) with ordinary least squares and performs a sign flip permutations test with the maximum statistic to determine a p-value for evoked responses.

Parameters:
  • data (np.ndarray) – Baseline corrected evoked responses. This will be the target data for the GLM. Must be shape (n_subjects, n_samples, …).

  • n_perm (int) – Number of permutations.

  • covariates (dict, optional) – Covariates (extra regressors) to add to the GLM fit. These will be z-transformed. Must be of shape (n_subjects,).

  • metric (str, optional) – Metric to use to build the null distribution. Can be 'tstats' or 'copes'.

  • n_jobs (int, optional) – Number of processes to run in parallel.

Returns:

pvalues – P-values for the evoked response. Shape is (n_subjects, n_samples, …).

Return type:

np.ndarray

osl_dynamics.analysis.statistics.group_diff_max_stat_perm(data, assignments, n_perm, covariates=None, metric='tstats', n_jobs=1)[source]#

Statistical significant testing for the difference between two groups.

This function fits a General Linear Model (GLM) with ordinary least squares and performs a row shuffle permutations test with the maximum statistic to determine a p-value for differences between two groups.

Parameters:
  • data (np.ndarray) – Subject-specific quantities to compare. This will be the target data for the GLM. Must be shape (n_subjects, features1, features2, …).

  • assignments (np.ndarray) – 1D numpy array containing group assignments. A value of 1 indicates Group1 and a value of 2 indicates Group2. Note, we test the contrast abs(Group1 - Group2) > 0.

  • n_perm (int) – Number of permutations.

  • covariates (dict, optional) – Covariates (extra regressors) to add to the GLM fit. These will be z-transformed. Must be of shape (n_subjects,).

  • metric (str, optional) – Metric to use to build the null distribution. Can be 'tstats' or 'copes'.

  • n_jobs (int, optional) – Number of processes to run in parallel.

Returns:

  • group_diff (np.ndarray) – Group difference: Group1 - Group2. Shape is (features1, features2, …).

  • pvalues (np.ndarray) – P-values for the features. Shape is (features1, features2, …).

osl_dynamics.analysis.statistics.paired_diff_max_stat_perm(data, n_perm, metric='tstats', n_jobs=1)[source]#

Statistical significant testing for paired differences.

This function fits a General Linear Model (GLM) with ordinary least squares and performs a sign flip permutations test with the maximum statistic to determine a p-value for paired differences.

Parameters:
  • data (np.ndarray) – Paired differences to compare. This will be the target data for the GLM. Must be shape (n_subjects, features1, features2, …).

  • n_perm (int) – Number of permutations.

  • metric (str, optional) – Metric to use to build the null distribution. Can be 'tstats' or 'copes'.

  • n_jobs (int, optional) – Number of processes to run in parallel.

Returns:

  • paired_diff (np.ndarray) – Paired differences. Shape is (features1, features2, …).

  • pvalues (np.ndarray) – P-values for the features. Shape is (features1, features2, …).