Learn R Programming

EmpiricalDynamics (version 0.1.2)

simulate_trajectory: Simulate Trajectory from SDE

Description

Simulates trajectories using the discovered SDE to assess whether the model can reproduce observed dynamics.

Usage

simulate_trajectory(
  sde,
  initial_conditions,
  times,
  n_sims = 100,
  method = c("euler", "milstein", "rk4"),
  exogenous_data = NULL,
  seed = NULL
)

Value

Object of class "trajectory_simulation" containing:

trajectories

Array of simulated trajectories (time x variable x simulation)

times

Time points

summary

Summary statistics (mean, quantiles) at each time

Arguments

sde

SDE object from construct_sde or estimate_sde_iterative.

initial_conditions

Named vector of initial values for all variables.

times

Numeric vector of time points.

n_sims

Number of Monte Carlo simulations (for stochastic models).

method

Integration method: "euler", "milstein", "rk4" (deterministic only).

exogenous_data

Data frame with exogenous variable trajectories (if any).

seed

Random seed for reproducibility.

Examples

Run this code
# \donttest{
# Toy example: dX = 0.5 * X
# Mock SDE object structure
sde <- list(
  drift = list(expression = "0.5 * X"),
  diffusion = list(expression = "0.1"), # Add noise
  variable = "X"
)
class(sde) <- "sde_model"

# Simulation
sim <- simulate_trajectory(
  sde = sde,
  initial_conditions = c(X = 1),
  times = seq(0, 1, by = 0.1),
  n_sims = 10,
  seed = 123
)
print(sim$summary$mean)
# }

Run the code above in your browser using DataLab