dlm-js
    Preparing search index...

    Function dlmForecast

    • Forecast h steps ahead from the end of a fitted DLM.

      Starting from the last smoothed state (fit.x[:][n-1], fit.C[:][:][-1]), iterates the state-space model forward h times with no observations:

      x_pred(k+1) = G · x_pred(k) (state mean) C_pred(k+1) = G · C_pred(k) · G' + W (state covariance) yhat(k) = FF_k · x_pred(k) (observation mean) ystd(k) = sqrt(FF_k · C_pred(k) · FF_k' + s²) (observation std)

      This is the standard Kalman prediction step with no measurement update — equivalent to appending NaN observations and running dlmFit on the extended series, but cheaper (O(h) vs O(n+h)) because it skips the full filter+smoother pass over the already-fitted data.

      Equivalence with NaN-extended dlmFit: Appending NaN values to y and calling dlmFit on the extended series produces numerically identical yhat/ystd for the appended steps, because the RTS smoother propagates no new information backwards through NaN steps. Use that pattern instead when:

      • You have some known future observations (partial future data, revised estimates, scenario constraints) — mix real values and NaN freely.
      • You want the smoothed state trajectory to continue into the forecast window as part of the same DlmFitResult (e.g. for plotting continuity).

      All model types are supported: local level/trend, full/trigonometric seasonal, AR(p), and covariate (β) models. Covariate states (static β blocks in G/W) are propagated correctly; pass X_forecast for their observation contributions.

      The jittable core uses lax.scan over h steps, capturing G and W as constants. The scan input is a time-varying FF_scan [h,1,m] so that covariate F rows are included inside the same compiled body.

      Parameters

      • fit: DlmFitResult

        DlmFitResult from dlmFit (provides G, F, W, last smoothed state)

      • h: number

        Forecast horizon (number of steps ahead)

      • Optionalopts: DlmForecastOptions

        Optional forecast options (obsStd, dtype, covariates)

      Returns Promise<DlmForecastResult>

      Predicted state means, covariances, and observation predictions for steps 1…h