mosaicperm.panel.MosaicPanelTest

class mosaicperm.panel.MosaicPanelTest(outcomes: array | Series, test_stat: callable, subjects: array | Series, times: array | Series, clusters: array | Series | csr_matrix | None = None, cts_covariates: DataFrame | array | None = None, discrete_covariates: DataFrame | None = None, sparse: bool = True, tstat_kwargs: dict | None = None, invariance='local_exch', ntiles: int = 10, tile_ids: array | None = None)[source]

Initialize a MosaicPanelTest for panel data analysis.

Parameters:
outcomesnp.array or pd.Series

n-length array of outcome data for the panel analysis.

test_statcallable

A function mapping a n-length array of residuals to either:

  • A single statistic measuring evidence against the null.

  • Alternatively, a 1D array of many statistics, in which

    case the p-value will adaptively aggregate evidence across all test statistics.

subjectsnp.array or pd.Series

n-length array specifying the subject identifier for each observation.

timesnp.array or pd.Series

n-length array specifying the time identifier for each observation.

clustersnp.array, pd.Series, or scipy.sparse.csr_matrix, optional

n-length array where clusters[i] = k signals that observation i is in the kth cluster. If not provided, defalts to using subjects as clusters.

cts_covariatespd.DataFrame or np.array, optional

(n, p)-shaped array of continuous covariates to control for in the analysis. If not provided, defaults to an intercept-only model.

discrete_covariatespd.DataFrame, optional

DataFrame of discrete/categorical covariates to be converted to dummy variables and included in the model.

sparsebool, default True

If True, uses sparse representation of discrete_covariates. Ignored if discrete_covariates is not supplied.

tstat_kwargsdict, optional

Optional kwargs to be passed to test_stat.

invariancestr, default ‘local_exch’

A string specifying the type of transformation for permutations. Options:

  • ‘local_exch’: swaps time t and t+1 for all even t.

  • ‘local_exch_cts’: within each subject, swaps neighboring timepoints.

  • ‘time_reverse’: reverses order of each time series.

  • ‘wild_bs’: multiplies all residuals by -1.

ntilesint, default 10

Number of tiles to use for the mosaic permutation test.

tile_idsnp.array, optional

n-length array where tile_ids[i] = k implies that observation i is in tile k. If not provided, tiles are constructed automatically.

Methods

compute_mosaic_residuals()

Computes mosaic-style residual estimates.

fit([nrand, verbose])

Runs the mosaic permutation test.

fit_tseries([nrand, verbose, n_timepoints, ...])

Runs mosaic permutation tests for various windows of the data, producing a time series of p-values.

permute_residuals([_permute_all])

Permutes residuals within tiles.

plot_tseries([time_index, alpha, show_plot])

Plots the results of fit_tseries().

summary([coordinate_index])

Produces an output summarizing the test.

summary_plot([show_plot])

Produces a plot summarizing the results of the test.