6.10.3.2.2. statsmodels.sandbox.tools.mctools.StatTestMC

class statsmodels.sandbox.tools.mctools.StatTestMC(dgp, statistic)[source]

class to run Monte Carlo study on a statistical test’‘’

TODO print(summary, for quantiles and for histogram draft in trying out script log

Parameters:

dgp : callable

Function that generates the data to be used in Monte Carlo that should return a new sample with each call

statistic : callable

Function that calculates the test statistic, which can return either a single statistic or a 1d array_like (tuple, list, ndarray). see also statindices in description of run

Notes

Warning

This is (currently) designed for a single call to run. If run is called a second time with different arguments, then some attributes might not be updated, and, therefore, not correspond to the same run.

Warning

Under Construction, don’t expect stability in Api or implementation

Examples

Define a function that defines our test statistic:

def lb(x):
s,p = acorr_ljungbox(x, lags=4) return np.r_[s, p]

Note lb returns eight values.

Define a random sample generator, for example 500 independently, normal distributed observations in a sample:

def normalnoisesim(nobs=500, loc=0.0):
return (loc+np.random.randn(nobs))

Create instance and run Monte Carlo. Using statindices=list(range(4)) means that only the first for values of the return of the statistic (lb) are stored in the Monte Carlo results.

mc1 = StatTestMC(normalnoisesim, lb) mc1.run(5000, statindices=list(range(4)))

Most of the other methods take an idx which indicates for which columns the results should be presented, e.g.

print(mc1.cdf(crit, [1,2,3])[1]

Attributes

many methods store intermediate results  
self.mcres (ndarray (nrepl, nreturns) or (nrepl, len(statindices))) Monte Carlo results stored by run
__init__(dgp, statistic)[source]

6.10.3.2.2.1. Methods

__init__(dgp, statistic)
cdf(x[, idx]) calculate cumulative probabilities of Monte Carlo results
get_mc_sorted()
histogram([idx, critval]) calculate histogram values
plot_hist(idx[, distpdf, bins, ax, kwds]) plot the histogram against a reference distribution
quantiles([idx, frac]) calculate quantiles of Monte Carlo results
run(nrepl[, statindices, dgpargs, statsargs]) run the actual Monte Carlo and save results
summary_cdf(idx, frac, crit[, varnames, title]) summary table for cumulative density function
summary_quantiles(idx, distppf[, frac, ...]) summary table for quantiles (critical values)