mosaicperm.panel.MosaicPanelInference¶
- class mosaicperm.panel.MosaicPanelInference(*args, **kwargs)[source]¶
Mosaic permutation-based inference for linear models in panel data.
- Parameters:
- *args
Positional arguments passed to the parent MosaicPanelTest class. See
MosaicPanelTestfor details on required arguments (outcomes, subjects, times, etc.). Note thattest_statis automatically set to None as it is not used in this inference class.- **kwargs
Additional keyword arguments passed to the parent MosaicPanelTest class. Common arguments include
cts_covariates,discrete_covariates,clusters,invariance,ntiles, etc.
Notes
For dense covariate matrices, the class uses efficient QR decomposition updates to avoid recomputing regressions for each feature. For sparse matrices, it falls back to recomputing regressions as needed.
Examples
>>> import numpy as np >>> import pandas as pd >>> import mosaicperm as mp >>> >>> # Generate synthetic panel data >>> n_subjects, n_times = 50, 20 >>> n_obs = n_subjects * n_times >>> subjects = np.repeat(np.arange(n_subjects), n_times) >>> times = np.tile(np.arange(n_times), n_subjects) >>> >>> # Generate covariates and outcomes >>> X = np.random.randn(n_obs, 3) >>> beta_true = np.array([1.0, -0.5, 0.2]) >>> outcomes = X @ beta_true + np.random.randn(n_obs) * 0.5 >>> >>> # Fit mosaic panel inference >>> mpi = mp.panel.MosaicPanelInference( ... outcomes=outcomes, ... subjects=subjects, ... times=times, ... cts_covariates=X, ... ntiles=8 ... ) >>> mpi.fit(nrand=1000, alpha=0.05) >>> print(mpi.summary)
The summary will show estimates, standard errors, confidence intervals, and p-values for each coefficient.
Methods
compute_cis([alpha])compute_mosaic_residuals([verbose])Computes full mosaic residuals and precomputes useful quantities.
fit([nrand, alpha, features, verbose, ...])Fits the linear model and computes confidence interva
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_plot([show_plot])Produces a plot summarizing the results of the test.
Properties
Produces a summary of key inferential results.