fit_wiener: Inference about the parameters of a Wiener process

View source: R/EM_wiener.R

fit_wienerR Documentation

Inference about the parameters of a Wiener process

Description

Implement the EM algorithm to perform inference on the parameters of a Wiener process with mixed drift effects.

Usage

fit_wiener(df,
  mu = "at^1",
  tol = 1e-4,
  max_iter = 100,
  theta = NULL,
  M = 100,
  verbose = TRUE,
  mu_dlt = 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_dlt

Optional user-supplied function defining the integrated drift term. 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 Wiener diffusion defined by

dY_{kt} = \mu(t, a_k)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).

For discretely observed trajectories, the mean of the increments is given by the integrated drift

\mu_{\Delta}(a_k, t_i, t_{i-1}) = \int_{t_{i-1}}^{t_i} \mu(s, a_k)\, ds.

The function mu_dlt represents this integrated drift. If not provided, it is constructed automatically from mu using closed-form expressions for common drift specifications.

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 Wiener process.

Examples

library(mixediffusion)
data(datasim01)
plot_paths(df = datasim01)
## Not run: 
fit <- fit_wiener(df = datasim01, mu = "at^1",
                  verbose = FALSE, max_iter = 20)
fit

## End(Not run)

# mu(ak,t) = ak*sin(pi*t)
data(datasim02)
plot_paths(df = datasim02)
mu_dlt_new <- function(ak,ti,ti_1){
  value <- -ak*(cos(pi*ti) - cos(pi*ti_1))
  return(value)
}

fit <- fit_wiener(df = datasim02, mu_dlt = mu_dlt_new,
                  verbose = FALSE, max_iter = 2)
fit

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