Time-series index | AR | ARIMA | ARIMAX
MovingAverage implements a Gaussian MA(
The ordered parameter vector is IncludeIntercept=true, otherwise the Order is limited to 1–10.
An MA model represents a finite response to past innovations, not a regression on past observations. It is useful when shocks have short-lived effects and the empirical ACF cuts off, but hydrologic interpretation requires care because the innovations are inferred residuals rather than observed physical inputs.
BestFit sets all presample innovations to zero and recursively calculates
Every recursive residual, including the first
This is a conditional sum-of-squares likelihood with a fixed zero presample state, not the exact Gaussian likelihood obtained by integrating the initial innovations or using a state-space/Kalman representation. Exact-likelihood results from other packages can therefore differ at short records and near the invertibility boundary.
The transform and Jacobian conventions match the AR chapter. Box-Cox/Yeo-Johnson fitting uses only the training prefix, and manual transform assignment atomically rebuilds transformed state, residuals, and dependent likelihood quantities. Scalar and pointwise likelihoods both reject nonfinite or nonpositive
The full target is
where UseJeffreysRuleForScale is enabled. Default marginal priors are bounded uniforms. Pointwise-prior metadata identifies this contribution as JeffreysScalePrior.
Uniqueness of the innovation representation requires the roots of
to lie outside the unit circle under the sign convention in (MA.1). IsInvertible() checks
Inside the training window, Predict reconstructs innovations from observations. After the window, a deterministic forecast sets future innovations to zero; a seeded predictive realization injects new Gaussian innovations and feeds them through the finite MA recursion. Consequently, the conditional mean reaches
GenerateRandomValues(sampleSize, seed) draws the innovations and completes the finite MA
recursion entirely on transformed model scale, then inverse-transforms the completed vector once.
It returns exactly sampleSize values; Transform.None retains its established fixed-seed values.
MAAnalysis propagates joint posterior parameter uncertainty and innovations by calling Predict for posterior draws. Its bands are posterior predictive. Its AIC/BIC fields use the data log likelihood at the stored MAP and exclude prior-density terms. They are comparable with MLE criteria only when all active priors are constant; with the Jeffreys scale option or another nonconstant prior, use posterior criteria instead.
private static MAAnalysis ConfigureMovingAverageAnalysis()
{
double[] monthlyAnomaly =
{
0.3, -0.2, 0.1, 0.5, -0.4, 0.2,
0.0, 0.4, -0.1, -0.3, 0.2, 0.1,
-0.2, 0.3, 0.0, -0.1, 0.4, -0.2
};
var series = new NumericsTimeSeries(
TimeInterval.OneMonth,
new DateTime(2020, 1, 1),
monthlyAnomaly);
var model = new MovingAverage(
series,
order: 1,
includeIntercept: true)
{
UseDefaultTrainingSteps = false,
UseJeffreysRuleForScale = true
};
model.TrainingTimeSteps = 15;
model.SetDefaultParameters();
return new MAAnalysis(model)
{
ForecastingTimeSteps = 3
};
}The example treats the series as an already detrended anomaly. For raw streamflow, explicitly address trend, seasonality, transformation, missing intervals, and physical nonstationarity before choosing an MA order. Validate on the final three observations and inspect residual autocorrelation; an information criterion alone is insufficient.
The model assumes regular spacing, no missing times, Gaussian homoscedastic innovations on the fitted scale, fixed parameters, and an error-free response. It does not model seasonal MA factors, state-dependent variance, intervention effects, or exact initial-state uncertainty.
Implementation: Models/TimeSeries/MovingAverage.cs; orchestration:
Analyses/TimeSeries/MAAnalysis.cs. Fast tests cover API behavior, deterministic calculations,
generation transform algebra, and exact seed compatibility. The focused numerical oracle checks
independent inverse formulas and 1,000 model-scale Gaussian moment values; the verification report
records parameter-recovery results.
The time-series verification report records independent conditional likelihood and optimum comparisons, transformed forecast/generation identities, and retained 1,000-observation recovery designs. Acceptance is tied to the exact recurrence, conditioning window, identified parameters, and forecast quantities; it is not a claim for every order, transformation, or covariate design.
[1] G. E. P. Box, G. M. Jenkins, G. C. Reinsel, and G. M. Ljung, Time Series Analysis: Forecasting and Control, 5th ed., Wiley, 2015.
[2] P. J. Brockwell and R. A. Davis, Time Series: Theory and Methods, 2nd ed., Springer, 1991.