meg_reformulate
Reformulate a model to make a seasonal frequency stochastic after MEG detection: build the recommended model from the last .pre file, re-estimate, and write the output without manual editing.
Instructions
Reformulate the model for STOCHASTIC seasonality at frequency freq, after the
MEG (DCD_f / Shin-Fuller AR_f) has concluded stochastic there.
Builds the model the MEG recommends, FROM THE LAST .pre, without editing files by
hand. It loads the last fitted model (base_pre_path if given, else inp_path),
activates the seasonal AR_f unit root at freq (ifadf[freq]=1: the operator
1-2cos(w)B+B^2 for an interior frequency, or 1+B at the Nyquist f=s/2), removes the
now-annihilated deterministic harmonics at freq, re-estimates, writes the
reformulated .pre/.out to output_path and shows the model equation + diagnosis.
with_witness=True (DEFAULT) also adds the free invertible MA_f testigo
(1-2λcos(w)B+λ²B²), so the reformulated model is EXACTLY what the MEG/DCD_f
contrasts — the AR_f unit root AND the MA_f witness together. This is the correct
stochastic model S. After fitting, run formal_tests to read the witness DCD_f:
LR>crit ⇒ genuine stochastic; λ→boundary (−1) ⇒ quasi-cancellation (frontier).
with_witness=False gives the AR-only form (no witness): this OVER-DIFFERENCES the seasonal (inflated σ, exploded Q-test) and is only a diagnostic subproduct, NOT S. Use it only to inspect the bare over-differenced residuals.
Multiple stochastic frequencies: call iteratively (strongest first), passing the previous output's .pre as base_pre_path, re-running formal_tests after each — the per-frequency MEG on the all-deterministic model has cross-frequency contamination.
Parameters
inp_path : source .inp/.pre (series data; also the model if base_pre_path="") freq : seasonal frequency to make stochastic (1..s/2) output_path : path to write the reformulated model (.pre/.out alongside) base_pre_path : the last .pre (the deterministic model); if empty, uses inp_path with_witness : add the free MA_f testigo (default True → the correct S model)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| freq | Yes | ||
| inp_path | Yes | ||
| output_path | Yes | ||
| with_witness | No | ||
| base_pre_path | No |