osl_dynamics.glm.permutation#

GLM Permutations base class.

Classes#

Permutation

Base class for permutation tests.

MaxStatPermutation

Max statistic permutation test.

Module Contents#

class osl_dynamics.glm.permutation.Permutation(design, contrast_indx, n_perm, perm_type=None, n_jobs=1)[source]#

Base class for permutation tests.

Parameters:
  • design (osl_dynamics.glm.base.Design) – Design object.

  • contrast_indx (int) – Index of the contrast of interest.

  • n_perm (int) – Number of permutations.

  • perm_type (str, optional) – Type of permutation. Options are ‘sign_flip’ and ‘row_shuffle’. If None, it will be determined based on the feature types and contrast type.

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

glm[source]#
contrast_indx[source]#
c[source]#
n_perm[source]#
n_jobs = 1[source]#
perm_type[source]#
permute_X()[source]#

Permute the design matrix based on the perm_type.

Returns:

X_copy – Permuted design matrix. Shape is (n_samples, n_features).

Return type:

np.ndarray

fit(y)[source]#

Fit the GLM with unpermuted data and run permutations.

Parameters:

y (np.ndarray) – Target variable. Shape is (n_samples, *target_dims).

Return type:

None

property copes: numpy.ndarray[source]#

Contrast Of Parameter Estimates.

Return type:

numpy.ndarray

property tstats: numpy.ndarray[source]#

T-stats of the contrast of interest.

Return type:

numpy.ndarray

summary()[source]#

Print summary of the permutation test.

Return type:

Dict

class osl_dynamics.glm.permutation.MaxStatPermutation(design, contrast_indx, n_perm, perm_type=None, n_jobs=1)[source]#

Bases: Permutation

Max statistic permutation test.

Parameters:
  • design (osl_dynamics.glm.base.Design) – Design object.

  • contrast_indx (int) – Index of the contrast of interest.

  • n_perm (int) – Number of permutations.

  • perm_type (str, optional) – Type of permutation. Options are ‘sign_flip’ and ‘row_shuffle’. If None, it will be determined based on the feature types and contrast type.

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

fit(y)[source]#

Fit the GLM with unpermuted data and run permutations.

Parameters:

y (np.ndarray) – Target variable. Shape is (n_samples, *target_dims).

Return type:

None

get_pvalues(metric='copes')[source]#

Get p-values.

Parameters:

metric (str, optional) – Metric to compute p-values. Options are ‘copes’ and ‘tstats’.

Returns:

pvalues – P-values. Shape is (*target_dims).

Return type:

np.ndarray