View source: R/simStateSpace-sim-ssm-ou-fixed.R
SimSSMOUFixed | R Documentation |
This function simulates data from the Ornstein–Uhlenbeck (OU) model using a state space model parameterization. It assumes that the parameters remain constant across individuals and over time.
SimSSMOUFixed(
n,
time,
delta_t = 1,
mu0,
sigma0_l,
mu,
phi,
sigma_l,
nu,
lambda,
theta_l,
type = 0,
x = NULL,
gamma = NULL,
kappa = NULL
)
n |
Positive integer. Number of individuals. |
time |
Positive integer. Number of time points. |
delta_t |
Numeric.
Time interval
( |
mu0 |
Numeric vector.
Mean of initial latent variable values
( |
sigma0_l |
Numeric matrix.
Cholesky factorization ( |
mu |
Numeric vector.
The long-term mean or equilibrium level
( |
phi |
Numeric matrix.
The drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
sigma_l |
Numeric matrix.
Cholesky factorization ( |
nu |
Numeric vector.
Vector of intercept values for the measurement model
( |
lambda |
Numeric matrix.
Factor loading matrix linking the latent variables
to the observed variables
( |
theta_l |
Numeric matrix.
Cholesky factorization ( |
type |
Integer. State space model type. See Details for more information. |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
Numeric matrix.
Matrix linking the covariates to the latent variables
at current time point
( |
kappa |
Numeric matrix.
Matrix linking the covariates to the observed variables
at current time point
( |
The measurement model is given by
\mathbf{y}_{i, t}
=
\boldsymbol{\nu}
+
\boldsymbol{\Lambda}
\boldsymbol{\eta}_{i, t}
+
\boldsymbol{\varepsilon}_{i, t},
\quad
\mathrm{with}
\quad
\boldsymbol{\varepsilon}_{i, t}
\sim
\mathcal{N}
\left(
\mathbf{0},
\boldsymbol{\Theta}
\right)
where
\mathbf{y}_{i, t}
,
\boldsymbol{\eta}_{i, t}
,
and
\boldsymbol{\varepsilon}_{i, t}
are random variables
and
\boldsymbol{\nu}
,
\boldsymbol{\Lambda}
,
and
\boldsymbol{\Theta}
are model parameters.
\mathbf{y}_{i, t}
represents a vector of observed random variables,
\boldsymbol{\eta}_{i, t}
a vector of latent random variables,
and
\boldsymbol{\varepsilon}_{i, t}
a vector of random measurement errors,
at time t
and individual i
.
\boldsymbol{\nu}
denotes a vector of intercepts,
\boldsymbol{\Lambda}
a matrix of factor loadings,
and
\boldsymbol{\Theta}
the covariance matrix of
\boldsymbol{\varepsilon}
.
An alternative representation of the measurement error is given by
\boldsymbol{\varepsilon}_{i, t}
=
\boldsymbol{\Theta}^{\frac{1}{2}}
\mathbf{z}_{i, t},
\quad
\mathrm{with}
\quad
\mathbf{z}_{i, t}
\sim
\mathcal{N}
\left(
\mathbf{0},
\mathbf{I}
\right)
where
\mathbf{z}_{i, t}
is a vector of
independent standard normal random variables and
\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)
\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime}
=
\boldsymbol{\Theta} .
The dynamic structure is given by
\mathrm{d} \boldsymbol{\eta}_{i, t}
=
\boldsymbol{\Phi}
\left(
\boldsymbol{\eta}_{i, t}
-
\boldsymbol{\mu}
\right)
\mathrm{d}t
+
\boldsymbol{\Sigma}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t}
where
\boldsymbol{\mu}
is the long-term mean or equilibrium level,
\boldsymbol{\Phi}
is the rate of mean reversion,
determining how quickly the variable returns to its mean,
\boldsymbol{\Sigma}
is the matrix of volatility
or randomness in the process, and
\mathrm{d}\boldsymbol{W}
is a Wiener process or Brownian motion,
which represents random fluctuations.
The measurement model is given by
\mathbf{y}_{i, t}
=
\boldsymbol{\nu}
+
\boldsymbol{\Lambda}
\boldsymbol{\eta}_{i, t}
+
\boldsymbol{\varepsilon}_{i, t},
\quad
\mathrm{with}
\quad
\boldsymbol{\varepsilon}_{i, t}
\sim
\mathcal{N}
\left(
\mathbf{0},
\boldsymbol{\Theta}
\right) .
The dynamic structure is given by
\mathrm{d} \boldsymbol{\eta}_{i, t}
=
\boldsymbol{\Phi}
\left(
\boldsymbol{\eta}_{i, t}
-
\boldsymbol{\mu}
\right)
\mathrm{d}t
+
\boldsymbol{\Gamma}
\mathbf{x}_{i, t}
+
\boldsymbol{\Sigma}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t}
where
\mathbf{x}_{i, t}
represents a vector of covariates
at time t
and individual i
,
and \boldsymbol{\Gamma}
the coefficient matrix
linking the covariates to the latent variables.
The measurement model is given by
\mathbf{y}_{i, t}
=
\boldsymbol{\nu}
+
\boldsymbol{\Lambda}
\boldsymbol{\eta}_{i, t}
+
\boldsymbol{\kappa}
\mathbf{x}_{i, t}
+
\boldsymbol{\varepsilon}_{i, t},
\quad
\mathrm{with}
\quad
\boldsymbol{\varepsilon}_{i, t}
\sim
\mathcal{N}
\left(
\mathbf{0},
\boldsymbol{\Theta}
\right)
where
\boldsymbol{\kappa}
represents the coefficient matrix
linking the covariates to the observed variables.
The dynamic structure is given by
\mathrm{d} \boldsymbol{\eta}_{i, t}
=
\boldsymbol{\Phi}
\left(
\boldsymbol{\eta}_{i, t}
-
\boldsymbol{\mu}
\right)
\mathrm{d}t
+
\boldsymbol{\Gamma}
\mathbf{x}_{i, t}
+
\boldsymbol{\Sigma}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t} .
The OU model is a first-order linear stochastic differential equation model in the form of
\mathrm{d} \boldsymbol{\eta}_{i, t}
=
\left(
\boldsymbol{\iota}
+
\boldsymbol{\Phi}
\boldsymbol{\eta}_{i, t}
\right)
\mathrm{d}t
+
\boldsymbol{\Sigma}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t}
where
\boldsymbol{\mu} = - \boldsymbol{\Phi}^{-1} \boldsymbol{\iota}
and, equivalently
\boldsymbol{\iota} = - \boldsymbol{\Phi} \boldsymbol{\mu}
.
Returns an object of class simstatespace
which is a list with the following elements:
call
: Function call.
args
: Function arguments.
data
: Generated data which is a list of length n
.
Each element of data
is a list with the following elements:
id
: A vector of ID numbers with length l
,
where l
is the value of the function argument time
.
time
: A vector time points of length l
.
y
: A l
by k
matrix of values for the manifest variables.
eta
: A l
by p
matrix of values for the latent variables.
x
: A l
by j
matrix of values for the covariates
(when covariates are included).
fun
: Function used.
Ivan Jacob Agaloos Pesigan
Chow, S.-M., Ho, M. R., Hamaker, E. L., & Dolan, C. V. (2010). Equivalence and differences between structural equation modeling and state-space modeling techniques. Structural Equation Modeling: A Multidisciplinary Journal, 17(2), 303–332. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10705511003661553")}
Chow, S.-M., Losardo, D., Park, J., & Molenaar, P. C. M. (2023). Continuous-time dynamic models: Connections to structural equation models and other discrete-time models. In R. H. Hoyle (Ed.), Handbook of structural equation modeling (2nd ed.). The Guilford Press.
Harvey, A. C. (1990). Forecasting, structural time series models and the Kalman filter. Cambridge University Press. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1017/cbo9781107049994")}
Oravecz, Z., Tuerlinckx, F., & Vandekerckhove, J. (2011). A hierarchical latent stochastic differential equation model for affective dynamics. Psychological Methods, 16 (4), 468–490. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1037/a0024375")}
Uhlenbeck, G. E., & Ornstein, L. S. (1930). On the theory of the brownian motion. Physical Review, 36 (5), 823–841. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1103/physrev.36.823")}
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters
set.seed(42)
## number of individuals
n <- 5
## time points
time <- 50
delta_t <- 0.10
## dynamic structure
p <- 2
mu0 <- c(-3.0, 1.5)
sigma0 <- 0.001 * diag(p)
sigma0_l <- t(chol(sigma0))
mu <- c(5.76, 5.18)
phi <- matrix(
data = c(
-0.10,
0.05,
0.05,
-0.10
),
nrow = p
)
sigma <- matrix(
data = c(
2.79,
0.06,
0.06,
3.27
),
nrow = p
)
sigma_l <- t(chol(sigma))
## measurement model
k <- 2
nu <- rep(x = 0, times = k)
lambda <- diag(k)
theta <- 0.001 * diag(k)
theta_l <- t(chol(theta))
## covariates
j <- 2
x <- lapply(
X = seq_len(n),
FUN = function(i) {
matrix(
data = stats::rnorm(n = time * j),
nrow = j,
ncol = time
)
}
)
gamma <- diag(x = 0.10, nrow = p, ncol = j)
kappa <- diag(x = 0.10, nrow = k, ncol = j)
# Type 0
ssm <- SimSSMOUFixed(
n = n,
time = time,
delta_t = delta_t,
mu0 = mu0,
sigma0_l = sigma0_l,
mu = mu,
phi = phi,
sigma_l = sigma_l,
nu = nu,
lambda = lambda,
theta_l = theta_l,
type = 0
)
plot(ssm)
# Type 1
ssm <- SimSSMOUFixed(
n = n,
time = time,
delta_t = delta_t,
mu0 = mu0,
sigma0_l = sigma0_l,
mu = mu,
phi = phi,
sigma_l = sigma_l,
nu = nu,
lambda = lambda,
theta_l = theta_l,
type = 1,
x = x,
gamma = gamma
)
plot(ssm)
# Type 2
ssm <- SimSSMOUFixed(
n = n,
time = time,
delta_t = delta_t,
mu0 = mu0,
sigma0_l = sigma0_l,
mu = mu,
phi = phi,
sigma_l = sigma_l,
nu = nu,
lambda = lambda,
theta_l = theta_l,
type = 2,
x = x,
gamma = gamma,
kappa = kappa
)
plot(ssm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.