| Title: | Mixed-Effects Diffusion Models with General Drift |
|---|---|
| Description: | Provides tools for likelihood-based inference in one-dimensional stochastic differential equations with mixed effects using expectation–maximization (EM) algorithms. The package supports Wiener and Ornstein–Uhlenbeck diffusion processes with user-specified drift functions, allowing flexible parametric forms including polynomial, exponential, and trigonometric structures. Estimation is performed via Markov chain Monte Carlo EM. |
| Authors: | Pedro Abraham Montoya Calzada [aut, cre, cph] (ORCID: <https://orcid.org/0009-0002-3497-210X>), Rogelio Salinas Gutiérrez [aut, cph] (ORCID: <https://orcid.org/0000-0002-1669-4460>), Silvia Rodríguez-Narciso [aut, cph] (ORCID: <https://orcid.org/0000-0001-5429-5914>), Netzahualcóyotl Castañeda-Leyva [aut, cph] (ORCID: <https://orcid.org/0000-0001-9414-3923>) |
| Maintainer: | Pedro Abraham Montoya Calzada <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.1 |
| Built: | 2026-06-09 07:25:50 UTC |
| Source: | https://github.com/cran/mixediffusion |
A simulated dataset consisting of discretely observed trajectories generated from a one-dimensional Wiener diffusion model with random effects in the drift term.
data(datasim01)data(datasim01)
A data frame with observations from multiple experimental units and the following variables:
tObservation time.
unitUnit identifier.
YObserved process value.
The data were generated from the stochastic differential equation
where the unit-specific random effects follow a normal distribution
and the diffusion variance is given by .
The process was simulated for units, each observed at
equally spaced time points, with initial condition
.
A data frame with simulated data.
Simulated data generated for illustrative purposes.
None.
data(datasim01) plot_paths(df = datasim01)data(datasim01) plot_paths(df = datasim01)
A simulated dataset consisting of discretely observed trajectories generated from a one-dimensional Wiener diffusion model with random effects in the drift term.
data(datasim02)data(datasim02)
A data frame with observations from multiple experimental units and the following variables:
tObservation time.
unitUnit identifier.
YObserved process value.
The data were generated from the stochastic differential equation
where the unit-specific random effects follow a normal distribution
and the diffusion variance is given by .
The integrated drift used for simulation is given by
The process was simulated for units, each observed at
equally spaced time points, with initial condition
.
A data frame with simulated data.
Simulated data generated for illustrative purposes.
None.
data(datasim02) plot_paths(df = datasim02)data(datasim02) plot_paths(df = datasim02)
A simulated dataset consisting of discretely observed trajectories generated from a one-dimensional Ornstein–Uhlenbeck diffusion model with a time-dependent mean function and random effects.
data(datasim03)data(datasim03)
A data frame with observations from multiple experimental units and the following variables:
tObservation time.
unitUnit identifier.
YObserved process value.
The data were generated from the stochastic differential equation
where the unit-specific random effects follow a normal distribution
the mean-reversion parameter is given by , and the diffusion
variance satisfies .
The process was simulated for units, each observed at
equally spaced time points over the interval ,
with initial condition .
A data frame with simulated data.
Simulated data generated for illustrative purposes.
None.
data(datasim03) plot_paths(df = datasim03)data(datasim03) plot_paths(df = datasim03)
Implements the EM algorithm to perform inference on the parameters of an Ornstein–Uhlenbeck process with mixed drift effects.
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)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)
df |
Data frame with the observed data. It must include the columns
|
mu |
Functional form of the drift. Supported drifts include
|
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 |
max_iter |
Maximum number of EM iterations. |
theta |
Optional named vector of initial parameter values. If |
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 |
n_mcmc |
Number of MCMC iterations used in the E-step to sample the random effects. |
burnin |
Number of initial MCMC iterations discarded. |
The model is a one-dimensional Ornstein–Uhlenbeck diffusion defined by
where is a user-specified drift function depending on a
unit-specific random effect .
The parameter controls the strength of mean reversion toward the
time-dependent mean.
For discretely observed trajectories, the conditional mean is given by
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.
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. |
library(mixediffusion) data(datasim03) plot_paths(df = datasim03) fit <- fit_ou(df = datasim03, mu = "at^1", verbose = FALSE, max_iter = 1) fitlibrary(mixediffusion) data(datasim03) plot_paths(df = datasim03) fit <- fit_ou(df = datasim03, mu = "at^1", verbose = FALSE, max_iter = 1) fit
Implement the EM algorithm to perform inference on the parameters of a Wiener process with mixed drift effects.
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)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)
df |
Data frame with the observed data. It must include the columns |
mu |
Functional form of the drift. Supported drifts include
|
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 |
max_iter |
Maximum number of EM iterations. |
theta |
Optional named vector of initial parameter values. If |
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 |
n_mcmc |
Number of MCMC iterations used in the E-step to sample the random effects. |
burnin |
Number of initial MCMC iterations discarded. |
The model is a one-dimensional Wiener diffusion defined by
,
where is a user-specified drift function depending on a
unit-specific random effect .
For discretely observed trajectories, the mean of the increments is given by the integrated drift
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.
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. |
library(mixediffusion) data(datasim01) plot_paths(df = datasim01) fit <- fit_wiener(df = datasim01, mu = "at^1", verbose = FALSE, max_iter = 1) fit # 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 = 1) fitlibrary(mixediffusion) data(datasim01) plot_paths(df = datasim01) fit <- fit_wiener(df = datasim01, mu = "at^1", verbose = FALSE, max_iter = 1) fit # 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 = 1) fit
Plots multiple trajectories from panel or longitudinal data grouped by unit.
plot_paths(df, col = NULL, lwd = 1, xlab = "t", ylab = "Y", main = NULL, ...)plot_paths(df, col = NULL, lwd = 1, xlab = "t", ylab = "Y", main = NULL, ...)
df |
Data frame containing the observed data. It must include the columns
|
col |
Optional vector of colors, one per unit. If |
lwd |
Line width used for the trajectories. |
xlab |
Label for the x-axis. |
ylab |
Label for the y-axis. |
main |
Optional main title for the plot. |
... |
Additional graphical parameters passed to |
A ggplot graph.
data(datasim02) plot_paths(datasim02)data(datasim02) plot_paths(datasim02)