Title: | Simulate Data from State Space Models |
---|---|
Description: | Provides a streamlined and user-friendly framework for simulating data in state space models, particularly when the number of subjects/units (n) exceeds one, a scenario commonly encountered in social and behavioral sciences. For an introduction to state space models in social and behavioral sciences, refer to Chow, Ho, Hamaker, and Dolan (2010) <doi:10.1080/10705511003661553>. |
Authors: | Ivan Jacob Agaloos Pesigan [aut, cre, cph] |
Maintainer: | Ivan Jacob Agaloos Pesigan <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.2.3 |
Built: | 2024-11-27 01:47:11 UTC |
Source: | CRAN |
simstatespace
to a Data FrameCoerce an Object of Class simstatespace
to a Data Frame
## S3 method for class 'simstatespace' as.data.frame( x, row.names = NULL, optional = FALSE, eta = FALSE, long = TRUE, ... )
## S3 method for class 'simstatespace' as.data.frame( x, row.names = NULL, optional = FALSE, eta = FALSE, long = TRUE, ... )
x |
Object of class |
row.names |
|
optional |
Logical.
If |
eta |
Logical.
If |
long |
Logical.
If |
... |
Additional arguments. |
Ivan Jacob Agaloos Pesigan
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE)) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE)) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE))
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE)) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE)) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) head(as.data.frame(ssm)) head(as.data.frame(ssm, long = FALSE))
simstatespace
to a MatrixCoerce an Object of Class simstatespace
to a Matrix
## S3 method for class 'simstatespace' as.matrix(x, eta = FALSE, long = TRUE, ...)
## S3 method for class 'simstatespace' as.matrix(x, eta = FALSE, long = TRUE, ...)
x |
Object of class |
eta |
Logical.
If |
long |
Logical.
If |
... |
Additional arguments. |
Ivan Jacob Agaloos Pesigan
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE)) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE)) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE))
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE)) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE)) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) head(as.matrix(ssm)) head(as.matrix(ssm, long = FALSE))
This function converts parameters from the linear stochastic differential equation model to state space model parameterization.
LinSDE2SSM(iota, phi, sigma_l, delta_t)
LinSDE2SSM(iota, phi, sigma_l, delta_t)
iota |
Numeric vector.
An unobserved term that is constant over time
( |
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 ( |
delta_t |
Numeric.
Time interval
( |
Let the linear stochastic equation model be given by
for individual and time
.
The discrete-time state space model
given below
represents the discrete-time solution
for the linear stochastic differential equation.
with
where denotes continuous-time processes
that can be defined by any arbitrary time point,
the
observed measurement occassion for individual
,
the number of latent variables and
the time interval.
Returns a list of state space parameters:
alpha
: Numeric vector.
Vector of constant values for the dynamic model
().
beta
: Numeric matrix.
Transition matrix relating the values of the latent variables
from the previous time point to the current time point.
().
psi_l
: Numeric matrix.
Cholesky factorization (t(chol(psi))
)
of the process noise covariance matrix
.
Ivan Jacob Agaloos Pesigan
Harvey, A. C. (1990). Forecasting, structural time series models and the Kalman filter. Cambridge University Press. doi:10.1017/cbo9781107049994
Other Simulation of State Space Models Data Functions:
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
p <- 2 iota <- c(0.317, 0.230) 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)) delta_t <- 0.10 LinSDE2SSM( iota = iota, phi = phi, sigma_l = sigma_l, delta_t = delta_t )
p <- 2 iota <- c(0.317, 0.230) 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)) delta_t <- 0.10 LinSDE2SSM( iota = iota, phi = phi, sigma_l = sigma_l, delta_t = delta_t )
simstatespace
Plot Method for an Object of Class simstatespace
## S3 method for class 'simstatespace' plot(x, id = NULL, time = NULL, eta = FALSE, type = "b", ...)
## S3 method for class 'simstatespace' plot(x, id = NULL, time = NULL, eta = FALSE, type = "b", ...)
x |
Object of class |
id |
Numeric vector.
Optional |
time |
Numeric vector.
Optional |
eta |
Logical.
If |
type |
Character indicating the type of plotting;
actually any of the types as in |
... |
Additional arguments. |
Ivan Jacob Agaloos Pesigan
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) plot(ssm, id = 1:3, time = 0:9) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) plot(ssm, id = 1:3, time = 0:9) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm) plot(ssm, id = 1:3, time = 0:9)
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) plot(ssm, id = 1:3, time = 0:9) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) plot(ssm, id = 1:3, time = 0:9) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm) plot(ssm, id = 1:3, time = 0:9)
simstatespace
Print Method for an Object of Class simstatespace
## S3 method for class 'simstatespace' print(x, ...)
## S3 method for class 'simstatespace' print(x, ...)
x |
Object of Class |
... |
Additional arguments. |
Prints simulated data in long format.
Ivan Jacob Agaloos Pesigan
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) print(ssm) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) print(ssm) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) print(ssm)
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 nu <- rep(x = 0, times = k) lambda <- diag(k) theta <- 0.50 * 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) print(ssm) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) print(ssm) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) print(ssm)
This function simulates random transition matrices
from the multivariate normal distribution.
The function ensures that the generated transition matrices are stationary
using TestStationarity()
.
SimBetaN(n, beta, vcov_beta_vec_l)
SimBetaN(n, beta, vcov_beta_vec_l)
n |
Positive integer. Number of replications. |
beta |
Numeric matrix.
The transition matrix ( |
vcov_beta_vec_l |
Numeric matrix.
Cholesky factorization ( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
n <- 10 beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0, 0, 0.5 ), nrow = 3 ) vcov_beta_vec_l <- t(chol(0.001 * diag(9))) SimBetaN(n = n, beta = beta, vcov_beta_vec_l = vcov_beta_vec_l)
n <- 10 beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0, 0, 0.5 ), nrow = 3 ) vcov_beta_vec_l <- t(chol(0.001 * diag(9))) SimBetaN(n = n, beta = beta, vcov_beta_vec_l = vcov_beta_vec_l)
This function simulates random drift matrices
from the multivariate normal distribution.
The function ensures that the generated drift matrices are stable
using TestPhi()
.
SimPhiN(n, phi, vcov_phi_vec_l)
SimPhiN(n, phi, vcov_phi_vec_l)
n |
Positive integer. Number of replications. |
phi |
Numeric matrix.
The drift matrix ( |
vcov_phi_vec_l |
Numeric matrix.
Cholesky factorization ( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
n <- 10 phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) vcov_phi_vec_l <- t(chol(0.001 * diag(9))) SimPhiN(n = n, phi = phi, vcov_phi_vec_l = vcov_phi_vec_l)
n <- 10 phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) vcov_phi_vec_l <- t(chol(0.001 * diag(9))) SimPhiN(n = n, phi = phi, vcov_phi_vec_l = vcov_phi_vec_l)
This function simulates data using a state space model. It assumes that the parameters remain constant across individuals and over time.
SimSSMFixed( n, time, delta_t = 1, mu0, sigma0_l, alpha, beta, psi_l, nu, lambda, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMFixed( n, time, delta_t = 1, mu0, sigma0_l, alpha, beta, psi_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.
The default value is |
mu0 |
Numeric vector.
Mean of initial latent variable values
( |
sigma0_l |
Numeric matrix.
Cholesky factorization ( |
alpha |
Numeric vector.
Vector of constant values for the dynamic model
( |
beta |
Numeric matrix.
Transition matrix relating the values of the latent variables
at the previous to the current time point
( |
psi_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
where
,
,
and
are random variables
and
,
,
and
are model parameters.
represents a vector of observed random variables,
a vector of latent random variables,
and
a vector of random measurement errors,
at time
and individual
.
denotes a vector of intercepts,
a matrix of factor loadings,
and
the covariance matrix of
.
An alternative representation of the measurement error is given by
where
is a vector of
independent standard normal random variables and
The dynamic structure is given by
where
,
,
and
are random variables,
and
,
,
and
are model parameters.
Here,
is a vector of latent variables
at time
and individual
,
represents a vector of latent variables
at time
and individual
,
and
represents a vector of dynamic noise
at time
and individual
.
denotes a vector of intercepts,
a matrix of autoregression
and cross regression coefficients,
and
the covariance matrix of
.
An alternative representation of the dynamic noise is given by
where
The measurement model is given by
The dynamic structure is given by
where
represents a vector of covariates
at time
and individual
,
and
the coefficient matrix
linking the covariates to the latent variables.
The measurement model is given by
where
represents the coefficient matrix
linking the covariates to the observed variables.
The dynamic structure is given by
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- 0.001 * diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- 0.001 * diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- 0.001 * diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- 0.001 * diag(p) psi_l <- t(chol(psi)) ## measurement model k <- 3 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 <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
This function simulates data using a state space model. It assumes that the parameters can vary across individuals.
SimSSMIVary( n, time, delta_t = 1, mu0, sigma0_l, alpha, beta, psi_l, nu, lambda, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMIVary( n, time, delta_t = 1, mu0, sigma0_l, alpha, beta, psi_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.
The default value is |
mu0 |
List of numeric vectors.
Each element of the list
is the mean of initial latent variable values
( |
sigma0_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
alpha |
List of numeric vectors.
Each element of the list
is the vector of constant values for the dynamic model
( |
beta |
List of numeric matrices.
Each element of the list
is the transition matrix relating the values of the latent variables
at the previous to the current time point
( |
psi_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
nu |
List of numeric vectors.
Each element of the list
is the vector of intercept values for the measurement model
( |
lambda |
List of numeric matrices.
Each element of the list
is the factor loading matrix linking the latent variables
to the observed variables
( |
theta_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
type |
Integer.
State space model type.
See Details in |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the latent variables
at current time point
( |
kappa |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the observed variables
at current time point
( |
Parameters can vary across individuals
by providing a list of parameter values.
If the length of any of the parameters
(mu0
,
sigma0_l
,
alpha
,
beta
,
psi_l
,
nu
,
lambda
,
theta_l
,
gamma
, or
kappa
)
is less the n
,
the function will cycle through the available values.
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters # In this example, beta varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- list( rep(x = 0, times = p) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) alpha <- list( rep(x = 0, times = p) ) beta <- list( 0.1 * diag(p), 0.2 * diag(p), 0.3 * diag(p), 0.4 * diag(p), 0.5 * diag(p) ) psi <- 0.001 * diag(p) psi_l <- list( t(chol(psi)) ) ## measurement model k <- 3 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# prepare parameters # In this example, beta varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- list( rep(x = 0, times = p) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) alpha <- list( rep(x = 0, times = p) ) beta <- list( 0.1 * diag(p), 0.2 * diag(p), 0.3 * diag(p), 0.4 * diag(p), 0.5 * diag(p) ) psi <- 0.001 * diag(p) psi_l <- list( t(chol(psi)) ) ## measurement model k <- 3 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
This function simulates data from the linear growth curve model.
SimSSMLinGrowth( n, time, mu0, sigma0_l, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMLinGrowth( n, time, mu0, sigma0_l, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
n |
Positive integer. Number of individuals. |
time |
Positive integer. Number of time points. |
mu0 |
Numeric vector. A vector of length two. The first element is the mean of the intercept, and the second element is the mean of the slope. |
sigma0_l |
Numeric matrix.
Cholesky factorization ( |
theta_l |
Numeric. Square root of the common measurement error variance. |
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
where ,
,
,
and
are random variables and
is a model parameter.
is the observed random variable
at time
and individual
,
(intercept)
and
(slope)
form a vector of latent random variables
at time
and individual
,
and
a vector of random measurement errors
at time
and individual
.
is the variance of
.
The dynamic structure is given by
The mean vector and covariance matrix of the intercept and slope are captured in the mean vector and covariance matrix of the initial condition given by
The measurement model is given by
The dynamic structure is given by
where
represents a vector of covariates
at time
and individual
,
and
the coefficient matrix
linking the covariates to the latent variables.
The measurement model is given by
where
represents the coefficient matrix
linking the covariates to the observed variables.
The dynamic structure is given by
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 5 ## dynamic structure p <- 2 mu0 <- c(0.615, 1.006) sigma0 <- matrix( data = c( 1.932, 0.618, 0.618, 0.587 ), nrow = p ) sigma0_l <- t(chol(sigma0)) ## measurement model k <- 1 theta <- 0.50 theta_l <- sqrt(theta) ## covariates j <- 2 x <- lapply( X = seq_len(n), FUN = function(i) { return( matrix( data = rnorm(n = j * time), nrow = j ) ) } ) gamma <- diag(x = 0.10, nrow = p, ncol = j) kappa <- diag(x = 0.10, nrow = k, ncol = j) # Type 0 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 5 ## dynamic structure p <- 2 mu0 <- c(0.615, 1.006) sigma0 <- matrix( data = c( 1.932, 0.618, 0.618, 0.587 ), nrow = p ) sigma0_l <- t(chol(sigma0)) ## measurement model k <- 1 theta <- 0.50 theta_l <- sqrt(theta) ## covariates j <- 2 x <- lapply( X = seq_len(n), FUN = function(i) { return( matrix( data = rnorm(n = j * time), nrow = j ) ) } ) gamma <- diag(x = 0.10, nrow = p, ncol = j) kappa <- diag(x = 0.10, nrow = k, ncol = j) # Type 0 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMLinGrowth( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
This function simulates data from the linear growth curve model. It assumes that the parameters can vary across individuals.
SimSSMLinGrowthIVary( n, time, mu0, sigma0_l, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMLinGrowthIVary( n, time, mu0, sigma0_l, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
n |
Positive integer. Number of individuals. |
time |
Positive integer. Number of time points. |
mu0 |
A list of numeric vectors. Each element of the list is a vector of length two. The first element is the mean of the intercept, and the second element is the mean of the slope. |
sigma0_l |
A list of numeric matrices.
Each element of the list is the
Cholesky factorization ( |
theta_l |
A list numeric values. Each element of the list is the square root of the common measurement error variance. |
type |
Integer.
State space model type.
See Details in |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the latent variables
at current time point
( |
kappa |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the observed variables
at current time point
( |
Parameters can vary across individuals
by providing a list of parameter values.
If the length of any of the parameters
(mu0
,
sigma0
,
mu
,
theta_l
,
gamma
, or
kappa
)
is less the n
,
the function will cycle through the available values.
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters # In this example, the mean vector of the intercept and slope vary. # Specifically, # there are two sets of values representing two latent classes. set.seed(42) ## number of individuals n <- 10 ## time points time <- 5 ## dynamic structure p <- 2 mu0_1 <- c(0.615, 1.006) # lower starting point, higher growth mu0_2 <- c(1.000, 0.500) # higher starting point, lower growth mu0 <- list(mu0_1, mu0_2) sigma0 <- matrix( data = c( 1.932, 0.618, 0.618, 0.587 ), nrow = p ) sigma0_l <- list(t(chol(sigma0))) ## measurement model k <- 1 theta <- 0.50 theta_l <- list(sqrt(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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# prepare parameters # In this example, the mean vector of the intercept and slope vary. # Specifically, # there are two sets of values representing two latent classes. set.seed(42) ## number of individuals n <- 10 ## time points time <- 5 ## dynamic structure p <- 2 mu0_1 <- c(0.615, 1.006) # lower starting point, higher growth mu0_2 <- c(1.000, 0.500) # higher starting point, lower growth mu0 <- list(mu0_1, mu0_2) sigma0 <- matrix( data = c( 1.932, 0.618, 0.618, 0.587 ), nrow = p ) sigma0_l <- list(t(chol(sigma0))) ## measurement model k <- 1 theta <- 0.50 theta_l <- list(sqrt(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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 1, x = x, gamma = gamma ) plot(ssm) # Type 2 ssm <- SimSSMLinGrowthIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
This function simulates data from the linear stochastic differential equation model using a state space model parameterization. It assumes that the parameters remain constant across individuals and over time.
SimSSMLinSDEFixed( n, time, delta_t = 1, mu0, sigma0_l, iota, phi, sigma_l, nu, lambda, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMLinSDEFixed( n, time, delta_t = 1, mu0, sigma0_l, iota, 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 ( |
iota |
Numeric vector.
An unobserved term that is constant over time
( |
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
where
,
,
and
are random variables
and
,
,
and
are model parameters.
represents a vector of observed random variables,
a vector of latent random variables,
and
a vector of random measurement errors,
at time
and individual
.
denotes a vector of intercepts,
a matrix of factor loadings,
and
the covariance matrix of
.
An alternative representation of the measurement error is given by
where
is a vector of
independent standard normal random variables and
The dynamic structure is given by
where
is a term which is unobserved and constant over time,
is the drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations,
is the matrix of volatility
or randomness in the process, and
is a Wiener process or Brownian motion,
which represents random fluctuations.
The measurement model is given by
The dynamic structure is given by
where
represents a vector of covariates
at time
and individual
,
and
the coefficient matrix
linking the covariates to the latent variables.
The measurement model is given by
where
represents the coefficient matrix
linking the covariates to the observed variables.
The dynamic structure is given by
The state space parameters as a function of the linear stochastic differential equation model parameters are given by
where is the number of latent variables and
is the time interval.
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. 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. doi:10.1017/cbo9781107049994
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
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)) iota <- c(0.317, 0.230) 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 <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, 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 <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# 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)) iota <- c(0.317, 0.230) 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 <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, 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 <- SimSSMLinSDEFixed( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
This function simulates data from the linear stochastic differential equation model using a state space model parameterization. It assumes that the parameters can vary across individuals.
SimSSMLinSDEIVary( n, time, delta_t = 1, mu0, sigma0_l, iota, phi, sigma_l, nu, lambda, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMLinSDEIVary( n, time, delta_t = 1, mu0, sigma0_l, iota, 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.
The default value is |
mu0 |
List of numeric vectors.
Each element of the list
is the mean of initial latent variable values
( |
sigma0_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
iota |
List of numeric vectors.
Each element of the list
is an unobserved term that is constant over time
( |
phi |
List of numeric matrix.
Each element of the list
is the drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
sigma_l |
List of numeric matrix.
Each element of the list
is the Cholesky factorization ( |
nu |
List of numeric vectors.
Each element of the list
is the vector of intercept values for the measurement model
( |
lambda |
List of numeric matrices.
Each element of the list
is the factor loading matrix linking the latent variables
to the observed variables
( |
theta_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
type |
Integer.
State space model type.
See Details in |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the latent variables
at current time point
( |
kappa |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the observed variables
at current time point
( |
Parameters can vary across individuals
by providing a list of parameter values.
If the length of any of the parameters
(mu0
,
sigma0_l
,
iota
,
phi
,
sigma_l
,
nu
,
lambda
,
theta_l
,
gamma
, or
kappa
)
is less the n
,
the function will cycle through the available values.
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. 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. doi:10.1017/cbo9781107049994
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters # In this example, phi varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 delta_t <- 0.10 ## dynamic structure p <- 2 mu0 <- list( c(-3.0, 1.5) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) iota <- list( c(0.317, 0.230) ) phi <- list( -0.1 * diag(p), -0.2 * diag(p), -0.3 * diag(p), -0.4 * diag(p), -0.5 * diag(p) ) sigma <- matrix( data = c( 2.79, 0.06, 0.06, 3.27 ), nrow = p ) sigma_l <- list( t(chol(sigma)) ) ## measurement model k <- 2 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, 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 <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
# prepare parameters # In this example, phi varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 delta_t <- 0.10 ## dynamic structure p <- 2 mu0 <- list( c(-3.0, 1.5) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) iota <- list( c(0.317, 0.230) ) phi <- list( -0.1 * diag(p), -0.2 * diag(p), -0.3 * diag(p), -0.4 * diag(p), -0.5 * diag(p) ) sigma <- matrix( data = c( 2.79, 0.06, 0.06, 3.27 ), nrow = p ) sigma_l <- list( t(chol(sigma)) ) ## measurement model k <- 2 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, 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 <- SimSSMLinSDEIVary( n = n, time = time, delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, iota = iota, phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l, type = 2, x = x, gamma = gamma, kappa = kappa ) plot(ssm)
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 )
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
where
,
,
and
are random variables
and
,
,
and
are model parameters.
represents a vector of observed random variables,
a vector of latent random variables,
and
a vector of random measurement errors,
at time
and individual
.
denotes a vector of intercepts,
a matrix of factor loadings,
and
the covariance matrix of
.
An alternative representation of the measurement error is given by
where
is a vector of
independent standard normal random variables and
The dynamic structure is given by
where
is the long-term mean or equilibrium level,
is the rate of mean reversion,
determining how quickly the variable returns to its mean,
is the matrix of volatility
or randomness in the process, and
is a Wiener process or Brownian motion,
which represents random fluctuations.
The measurement model is given by
The dynamic structure is given by
where
represents a vector of covariates
at time
and individual
,
and
the coefficient matrix
linking the covariates to the latent variables.
The measurement model is given by
where
represents the coefficient matrix
linking the covariates to the observed variables.
The dynamic structure is given by
The OU model is a first-order linear stochastic differential equation model in the form of
where
and, equivalently
.
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. 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. 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. doi:10.1037/a0024375
Uhlenbeck, G. E., & Ornstein, L. S. (1930). On the theory of the brownian motion. Physical Review, 36 (5), 823–841. 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)
# 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)
This function simulates data from the Ornstein–Uhlenbeck model using a state space model parameterization. It assumes that the parameters can vary across individuals.
SimSSMOUIVary( n, time, delta_t = 1, mu0, sigma0_l, mu, phi, sigma_l, nu, lambda, theta_l, type = 0, x = NULL, gamma = NULL, kappa = NULL )
SimSSMOUIVary( 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.
The default value is |
mu0 |
List of numeric vectors.
Each element of the list
is the mean of initial latent variable values
( |
sigma0_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
mu |
List of numeric vectors.
Each element of the list
is the long-term mean or equilibrium level
( |
phi |
List of numeric matrix.
Each element of the list
is the drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
sigma_l |
List of numeric matrix.
Each element of the list
is the Cholesky factorization ( |
nu |
List of numeric vectors.
Each element of the list
is the vector of intercept values for the measurement model
( |
lambda |
List of numeric matrices.
Each element of the list
is the factor loading matrix linking the latent variables
to the observed variables
( |
theta_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
type |
Integer.
State space model type.
See Details in |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the latent variables
at current time point
( |
kappa |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the observed variables
at current time point
( |
Parameters can vary across individuals
by providing a list of parameter values.
If the length of any of the parameters
(mu0
,
sigma0_l
,
mu
,
phi
,
sigma_l
,
nu
,
lambda
,
theta_l
,
gamma
, or
kappa
)
is less the n
,
the function will cycle through the available values.
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. 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. 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. doi:10.1037/a0024375
Uhlenbeck, G. E., & Ornstein, L. S. (1930). On the theory of the brownian motion. Physical Review, 36 (5), 823–841. doi:10.1103/physrev.36.823
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters # In this example, phi varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 delta_t <- 0.10 ## dynamic structure p <- 2 mu0 <- list( c(-3.0, 1.5) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) mu <- list( c(5.76, 5.18) ) phi <- list( -0.1 * diag(p), -0.2 * diag(p), -0.3 * diag(p), -0.4 * diag(p), -0.5 * diag(p) ) sigma <- matrix( data = c( 2.79, 0.06, 0.06, 3.27 ), nrow = p ) sigma_l <- list( t(chol(sigma)) ) ## measurement model k <- 2 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMOUIVary( 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 <- SimSSMOUIVary( 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 <- SimSSMOUIVary( 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)
# prepare parameters # In this example, phi varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 delta_t <- 0.10 ## dynamic structure p <- 2 mu0 <- list( c(-3.0, 1.5) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) mu <- list( c(5.76, 5.18) ) phi <- list( -0.1 * diag(p), -0.2 * diag(p), -0.3 * diag(p), -0.4 * diag(p), -0.5 * diag(p) ) sigma <- matrix( data = c( 2.79, 0.06, 0.06, 3.27 ), nrow = p ) sigma_l <- list( t(chol(sigma)) ) ## measurement model k <- 2 nu <- list( rep(x = 0, times = k) ) lambda <- list( diag(k) ) theta <- 0.001 * diag(k) theta_l <- list( 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 <- list( diag(x = 0.10, nrow = p, ncol = j) ) kappa <- list( diag(x = 0.10, nrow = k, ncol = j) ) # Type 0 ssm <- SimSSMOUIVary( 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 <- SimSSMOUIVary( 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 <- SimSSMOUIVary( 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)
This function simulates data from the vector autoregressive model using a state space model parameterization. It assumes that the parameters remain constant across individuals and over time.
SimSSMVARFixed( n, time, mu0, sigma0_l, alpha, beta, psi_l, type = 0, x = NULL, gamma = NULL )
SimSSMVARFixed( n, time, mu0, sigma0_l, alpha, beta, psi_l, type = 0, x = NULL, gamma = NULL )
n |
Positive integer. Number of individuals. |
time |
Positive integer. Number of time points. |
mu0 |
Numeric vector.
Mean of initial latent variable values
( |
sigma0_l |
Numeric matrix.
Cholesky factorization ( |
alpha |
Numeric vector.
Vector of constant values for the dynamic model
( |
beta |
Numeric matrix.
Transition matrix relating the values of the latent variables
at the previous to the current time point
( |
psi_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
( |
The measurement model is given by
where
represents a vector of observed variables
and
a vector of latent variables
for individual
and time
.
Since the observed and latent variables are equal,
we only generate data
from the dynamic structure.
The dynamic structure is given by
where
,
,
and
are random variables,
and
,
,
and
are model parameters.
Here,
is a vector of latent variables
at time
and individual
,
represents a vector of latent variables
at time
and individual
,
and
represents a vector of dynamic noise
at time
and individual
.
denotes a vector of intercepts,
a matrix of autoregression
and cross regression coefficients,
and
the covariance matrix of
.
An alternative representation of the dynamic noise is given by
where
The measurement model is given by
The dynamic structure is given by
where
represents a vector of covariates
at time
and individual
,
and
the coefficient matrix
linking the covariates to the latent variables.
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- 0.001 * diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- 0.001 * diag(p) psi_l <- t(chol(psi)) ## 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) # Type 0 ssm <- SimSSMVARFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMVARFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 1, x = x, gamma = gamma ) plot(ssm)
# prepare parameters set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- rep(x = 0, times = p) sigma0 <- 0.001 * diag(p) sigma0_l <- t(chol(sigma0)) alpha <- rep(x = 0, times = p) beta <- 0.50 * diag(p) psi <- 0.001 * diag(p) psi_l <- t(chol(psi)) ## 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) # Type 0 ssm <- SimSSMVARFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMVARFixed( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 1, x = x, gamma = gamma ) plot(ssm)
This function simulates data from the vector autoregressive model using a state space model parameterization. It assumes that the parameters can vary across individuals.
SimSSMVARIVary( n, time, mu0, sigma0_l, alpha, beta, psi_l, type = 0, x = NULL, gamma = NULL )
SimSSMVARIVary( n, time, mu0, sigma0_l, alpha, beta, psi_l, type = 0, x = NULL, gamma = NULL )
n |
Positive integer. Number of individuals. |
time |
Positive integer. Number of time points. |
mu0 |
List of numeric vectors.
Each element of the list
is the mean of initial latent variable values
( |
sigma0_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
alpha |
List of numeric vectors.
Each element of the list
is the vector of constant values for the dynamic model
( |
beta |
List of numeric matrices.
Each element of the list
is the transition matrix relating the values of the latent variables
at the previous to the current time point
( |
psi_l |
List of numeric matrices.
Each element of the list
is the Cholesky factorization ( |
type |
Integer.
State space model type.
See Details in |
x |
List.
Each element of the list is a matrix of covariates
for each individual |
gamma |
List of numeric matrices.
Each element of the list
is the matrix linking the covariates to the latent variables
at current time point
( |
Parameters can vary across individuals
by providing a list of parameter values.
If the length of any of the parameters
(mu0
,
sigma0_l
,
alpha
,
beta
,
psi_l
,
gamma
, or
kappa
)
is less the n
,
the function will cycle through the available values.
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. doi:10.1080/10705511003661553
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
TestPhi()
,
TestStability()
,
TestStationarity()
# prepare parameters # In this example, beta varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- list( rep(x = 0, times = p) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) alpha <- list( rep(x = 0, times = p) ) beta <- list( 0.1 * diag(p), 0.2 * diag(p), 0.3 * diag(p), 0.4 * diag(p), 0.5 * diag(p) ) psi <- 0.001 * diag(p) psi_l <- list( t(chol(psi)) ) ## covariates j <- 2 x <- lapply( X = seq_len(n), FUN = function(i) { matrix( data = stats::rnorm(n = time * j), nrow = j, ncol = time ) } ) gamma <- list( diag(x = 0.10, nrow = p, ncol = j) ) # Type 0 ssm <- SimSSMVARIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMVARIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 1, x = x, gamma = gamma ) plot(ssm)
# prepare parameters # In this example, beta varies across individuals. set.seed(42) ## number of individuals n <- 5 ## time points time <- 50 ## dynamic structure p <- 3 mu0 <- list( rep(x = 0, times = p) ) sigma0 <- 0.001 * diag(p) sigma0_l <- list( t(chol(sigma0)) ) alpha <- list( rep(x = 0, times = p) ) beta <- list( 0.1 * diag(p), 0.2 * diag(p), 0.3 * diag(p), 0.4 * diag(p), 0.5 * diag(p) ) psi <- 0.001 * diag(p) psi_l <- list( t(chol(psi)) ) ## covariates j <- 2 x <- lapply( X = seq_len(n), FUN = function(i) { matrix( data = stats::rnorm(n = time * j), nrow = j, ncol = time ) } ) gamma <- list( diag(x = 0.10, nrow = p, ncol = j) ) # Type 0 ssm <- SimSSMVARIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 0 ) plot(ssm) # Type 1 ssm <- SimSSMVARIVary( n = n, time = time, mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, psi_l = psi_l, type = 1, x = x, gamma = gamma ) plot(ssm)
Both have to be true for the function to return TRUE
.
Test that the real part of all eigenvalues of
are less than zero.
Test that the diagonal values of
are between 0 to negative inifinity.
TestPhi(phi)
TestPhi(phi)
phi |
Numeric matrix.
The drift matrix ( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestStability()
,
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) TestPhi(phi = phi)
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) TestPhi(phi = phi)
The function computes the eigenvalues of the input matrix x
.
It checks if the real part of all eigenvalues is negative.
If all eigenvalues have negative real parts,
the system is considered stable.
TestStability(x)
TestStability(x)
x |
Numeric matrix. |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStationarity()
x <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) TestStability(x)
x <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0, 0, -0.693 ), nrow = 3 ) TestStability(x)
The function computes the eigenvalues of the input matrix x
.
It checks if all eigenvalues have moduli less than 1.
If all eigenvalues have moduli less than 1,
the system is considered stationary.
TestStationarity(x)
TestStationarity(x)
x |
Numeric matrix. |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM()
,
SimBetaN()
,
SimPhiN()
,
SimSSMFixed()
,
SimSSMIVary()
,
SimSSMLinGrowth()
,
SimSSMLinGrowthIVary()
,
SimSSMLinSDEFixed()
,
SimSSMLinSDEIVary()
,
SimSSMOUFixed()
,
SimSSMOUIVary()
,
SimSSMVARFixed()
,
SimSSMVARIVary()
,
TestPhi()
,
TestStability()
x <- matrix( data = c(0.5, 0.3, 0.2, 0.4), nrow = 2 ) TestStationarity(x) x <- matrix( data = c(0.9, -0.5, 0.8, 0.7), nrow = 2 ) TestStationarity(x)
x <- matrix( data = c(0.5, 0.3, 0.2, 0.4), nrow = 2 ) TestStationarity(x) x <- matrix( data = c(0.9, -0.5, 0.8, 0.7), nrow = 2 ) TestStationarity(x)