qpm_filter: Estimate latent states from data (Kalman filter/smoother)

View source: R/filter.R

qpm_filterR Documentation

Estimate latent states from data (Kalman filter/smoother)

Description

Runs the Kalman filter and RTS smoother over the solved model, jointly inferring every latent variable — output gap, neutral rate, equilibrium exchange rate, trend processes — and the historical structural shocks from whatever subset of variables you actually observe. Missing values (ragged edges, gappy series) are handled naturally.

Usage

qpm_filter(x, data, observables = NULL, measurement_error = 0, kappa = 1e+06)

Arguments

x

A qpm_model (solved internally) or qpm_solution.

data

A data frame in levels (model units). Columns whose names match declared variables are used as observables; an optional period column provides labels. NAs are allowed anywhere.

observables

Optional character vector restricting which columns are treated as observed.

measurement_error

Measurement-error standard deviation(s): scalar or named vector over observables. Defaults to 0.

kappa

Diffuse-prior variance scale used when the model has unit-root (random-walk) trends; see state_space().

Details

The filter is initialized at the model's stationary distribution (Lyapunov covariance), which is exact for the stationary models qpmR currently supports.

Value

An object of class qpm_filtration: smoothed states in levels (⁠$states⁠), their standard errors (⁠$se⁠), smoothed structural shocks (⁠$shocks⁠), the log-likelihood (⁠$loglik⁠), innovation diagnostics (⁠$diag⁠), and the full expanded-state matrix (⁠$states_dev⁠). Feed it to qpm_decompose() for historical shock decompositions or to qpm_forecast() to forecast from the smoothed current state.

Examples

sol <- qpm_solve(qpm_template("bkl"))
obs <- simulate(sol, nsim = 60, seed = 3, burn = 20)
fit <- qpm_filter(sol, obs[, c("period", "pi", "i", "q")])
fit
plot(fit, vars = c("y_gap", "r_bar"))

qpmR documentation built on Sept. 29, 2026, 5:10 p.m.