fit_ou: Inference about the parameters of an Ornstein-Uhlenbeck...

View source: R/fit_ou.R

fit_ouR Documentation

Inference about the parameters of an Ornstein–Uhlenbeck process

Description

Implements the EM algorithm to perform inference on the parameters of an Ornstein–Uhlenbeck process with mixed drift effects.

Usage

fit_ou(df,
  mu = "at^1",
  tol = 1e-4,
  max_iter = 100,
  theta = NULL,
  M = 100,
  verbose = TRUE,
  mu_cond = NULL,
  n_mcmc = 1000,
  burnin = 500)

Arguments

df

Data frame with the observed data. It must include the columns t (time), unit (unit identifier) and Y (the observed trajectory).

mu

Functional form of the drift. Supported drifts include "at^p", "exp(at)", "cos(at)" and "sin(at)". The default is "at^1".

tol

Convergence tolerance for the EM algorithm. The algorithm stops when the maximum absolute difference between the parameter estimates at two consecutive EM iterations is smaller than tol.

max_iter

Maximum number of EM iterations.

theta

Optional named vector of initial parameter values. If NULL, default initial values are used.

M

Number of Monte Carlo samples used to approximate the conditional expectations in the E-step.

verbose

Logical indicating whether to print EM iteration progress.

mu_cond

Optional user-supplied function defining the conditional mean of the process. If NULL, it is constructed automatically from mu.

n_mcmc

Number of MCMC iterations used in the E-step to sample the random effects.

burnin

Number of initial MCMC iterations discarded.

Details

The model is a one-dimensional Ornstein–Uhlenbeck diffusion defined by

dY_{kt} = \lambda\{\mu(t, a_k) - Y_{kt}\}\,dt + \sigma\,dW_{kt},

where \mu(t, a_k) is a user-specified drift function depending on a unit-specific random effect a_k \sim \mathcal{N}(\mu_a, \sigma_a^2).

The parameter \lambda controls the strength of mean reversion toward the time-dependent mean.

For discretely observed trajectories, the conditional mean is given by

E\{Y_{kt_i} \mid Y_{kt_{i-1}}, a_k\} = Y_{kt_{i-1}} e^{-\lambda \Delta t_i} + \lambda \int_{t_{i-1}}^{t_i} e^{-\lambda (t_i - s)} \mu(s,a_k)\,ds.

The function mu_cond represents this conditional mean. If not provided, it is constructed automatically from the drift specification supplied through mu using closed-form expressions.

Value

A named numeric vector containing the estimated model parameters:

mu_a

Estimated mean of the random effects distribution.

sigma2_a

Estimated variance of the random effects distribution.

sigma2

Estimated diffusion variance of the process.

lambda

Estimated mean reversion parameter.

Examples

library(mixediffusion)
data(datasim03)
plot_paths(df = datasim03)
fit <- fit_ou(df = datasim03, mu = "at^1",
              verbose = FALSE, max_iter = 2)
fit

mixediffusion documentation built on March 20, 2026, 5:10 p.m.