% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/npf_seir.R
\name{npf_seir}
\alias{npf_seir}
\title{Run the Nested Particle Filter for a stochastic SEIR model}
\usage{
npf_seir(
  observations,
  fixed,
  K = 100L,
  M = 200L,
  tau_outer = 0.3,
  x0 = NULL,
  seed = NULL,
  h_min = 0.01,
  h_max = 0.1,
  rho = 0.995,
  verbose = FALSE
)
}
\arguments{
\item{observations}{Numeric vector of length \eqn{T}. Daily confirmed case
counts \eqn{P_1, \ldots, P_T}.}

\item{fixed}{Named list of fixed model parameters (see \code{\link{seir_simulate}}).}

\item{K}{Integer. Number of outer (parameter) particles. Default 100.}

\item{M}{Integer. Number of inner (state) particles per outer particle.
Default 200.}

\item{tau_outer}{Numeric in (0,1). ESS threshold for outer resampling.
Outer resampling is triggered when
\eqn{\mathrm{ESS}_\mathrm{outer} < \tau_\mathrm{outer} \cdot K}.
Default 0.3.}

\item{x0}{Numeric vector of length 5, or \code{NULL}. Initial state
\eqn{(S_0, E_0, I_0, R_0, \Psi_0)}.  If \code{NULL}, derived from
\code{observations[1]} via quasi-steady-state initialization; in that
case the first observation is used only for initialization and excluded
from the filtering updates.}

\item{seed}{Integer or \code{NULL}. Random seed for reproducibility.}

\item{h_min, h_max, rho}{Jittering bandwidth schedule parameters. The
bandwidth at step \eqn{n} is
\eqn{h_n = h_{min} + (h_{max} - h_{min}) \rho^n}.
Defaults: \code{h_min = 0.01}, \code{h_max = 0.10}, \code{rho = 0.995}.}

\item{verbose}{Logical. Print progress every 50 steps. Default \code{FALSE}.}
}
\value{
An object of class \code{"npf_seir"}, a list with components:
\describe{
\item{\code{Rt_mean}, \code{Rt_lo}, \code{Rt_hi}}{Numeric vectors of
length \eqn{T}. Posterior mean and 95\\% credible interval for
\eqn{R_t = \beta_t S_t / ((\gamma+\delta)N)}.}
\item{\code{beta_mean}, \code{beta_lo}, \code{beta_hi}}{Posterior
summaries for \eqn{\beta_t}.}
\item{\code{theta_mean}}{Matrix of size \eqn{T \times 3}. Weighted
posterior mean of \eqn{\theta = (\kappa, \sigma_\Psi, \mu_\Psi)} at
each step.}
\item{\code{final_theta}}{Matrix \eqn{K \times 3}. Outer particles at
time \eqn{T}.}
\item{\code{final_w}}{Numeric vector of length \eqn{K}. Outer weights
at time \eqn{T}.}
\item{\code{final_inner}}{List of length \eqn{K}. Final inner state
particles used for posterior predictive simulation.}
\item{\code{outer_ess}}{Numeric vector of length \eqn{T}. Outer ESS
trace.}
\item{\code{observations}, \code{fixed}, \code{call}}{Input metadata.}
}
}
\description{
Performs online Bayesian joint state and parameter estimation for the
stochastic SEIR model with latent Ornstein-Uhlenbeck transmission dynamics,
using the nested particle filter (NPF) of Crisan and Miguez (2018).
}
\examples{
\donttest{
# Simulate and recover
fixed <- list(eps = 1/5, gamma = 1/10, delta = 1/(70*365),
              b = 1/(70*365), q = 0.3, N = 1e6, sigma_comp = 0.01)
x0    <- c(1e6 - 100, 50, 50, 0, log(0.25))
set.seed(1)
traj  <- seir_simulate(200, kappa=0.05, sigma_psi=0.10,
                       mu_psi=log(0.25), x0=x0, fixed=fixed)
fit   <- npf_seir(traj$obs[-1], fixed=fixed, K=50, M=100, seed=42)
plot(fit)
summary(fit)
}
}
\references{
Crisan, D. and Miguez, J. (2018). Nested particle filters for online
parameter estimation in discrete-time state-space Markov models.
\emph{Bernoulli}, 24(4A):3039--3086.

Feng, W. and Wang, W. (2025). Bayesian sequential inference for a stochastic SEIR model
with latent transmission dynamics. \emph{Preprint}.
}
