mosaicperm.factor.MosaicBCV¶
- class mosaicperm.factor.MosaicBCV(new_exposures: array, *args, **kwargs)[source]¶
Mosaic factor test based on
mosaicperm.statistics.adaptive_mosaic_bcv_stat()- Parameters:
- outcomesnp.array
(
n_obs,n_subjects) array of outcomes, e.g., asset returns.outcomesmay contain nans to indicate missing values.- exposuresnp.array
(
n_obs,n_subjects,n_factors) array of factor exposures OR (n_subjects,n_factors) array of factor exposures if the exposures do not change with time.- new_exposuresnp.array or list
(
n_models,n_subject)-shaped array such thatnew_exposures[i]is an array of new exposures.- tilesmosaicperm.tilings.Tiling
An optional
Tilingto use as the tiling.- **kwargsdict
Optional kwargs to
default_factor_tiles(). Ignored iftilesis provided.
Examples
>>> import numpy as np >>> import mosaicperm as mp >>> >>> # synthetic outcomes and exposures >>> n_obs, n_subjects, n_factors = 100, 200, 20 >>> outcomes = np.random.randn(n_obs, n_subjects) >>> exposures = np.random.randn(n_obs, n_subjects, n_factors) >>> >>> # estimate candidate exposures on the first half of the data >>> n0 = int(0.5 * n_obs) >>> resid0 = mp.factor.ols_residuals(outcomes[0:n0], exposures[0:n0]) >>> new_exposures = mp.statistics.approximate_sparse_pcas(np.corrcoef(resid0.T)) >>> >>> # fit mosaic permutation test >>> mpt_bcv = mp.factor.MosaicFactorTest( ... outcomes=outcomes[n0:], ... exposures=exposures[n0:], ... new_exposures=new_exposures, >>> ) >>> mpt_bcv.fit().summary()
Methods
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([method])Permutes residuals within tiles.
plot_tseries([time_index, alpha, show_plot])Plots the results of
fit_tseries().summary(*args, **kwargs)Produces an output summarizing the test.
summary_plot([show_plot])Produces a plot summarizing the results of the test.