ARResult.simulate#
- ARResult.simulate(n=200, *, seed=None, burn=_SIMULATION_BURN)[source]#
A fresh sample path at the fitted parameters.
burn + nperiods of the zero-mean autoregression are generated from a zero start with Gaussian innovations of variancesigma2and the firstburndiscarded. The constant and trend are regressors inside the recursion, \(y_t = c + b t + \sum_i \phi_i y_{t-i} + \varepsilon_t\), so the mean path they imply is what is added,\[A + B t,\qquad B = \frac{b}{1 - \sum_i \phi_i},\qquad A = \frac{c - B \sum_i i\,\phi_i}{1 - \sum_i \phi_i},\]with the time index running
1 .. n.- Parameters:
- Return type:
- Returns:
An array of shape
(n,).- Raises:
SpecificationError – If the counts are not usable, or the autoregressive coefficients sum to one so that no mean path exists.
Example
The simulated mean and variance are the fitted model’s unconditional moments:
>>> rng = np.random.default_rng(0) >>> y = np.zeros(500) >>> for t in range(1, 500): ... y[t] = 1.0 + 0.5 * y[t - 1] + rng.standard_normal() >>> res = AR(y, order=1, trend="c").fit() >>> path = res.simulate(20000, seed=0) >>> mean = res.const / (1 - res.ar_params[0]) >>> variance = res.sigma2 / (1 - res.ar_params[0] ** 2) >>> bool(abs(path.mean() - mean) < 0.05), bool(abs(path.var() - variance) < 0.05) (True, True) >>> res.simulate(0) Traceback (most recent call last): ... cultivars.exceptions.SpecificationError: n must be at least 1; got 0.