| 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. This package was designed to generate data for the simulations performed in Pesigan, Russell, and Chow (2025) <doi:10.1037/met0000779>. |
| Authors: | Ivan Jacob Agaloos Pesigan [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-4818-8420>), Michael A. Russell [ctb] (ORCID: <https://orcid.org/0000-0002-3956-604X>), Sy-Miin Chow [ctb] (ORCID: <https://orcid.org/0000-0003-1938-027X>) |
| Maintainer: | Ivan Jacob Agaloos Pesigan <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.2.16 |
| Built: | 2026-05-31 20:20:51 UTC |
| Source: | https://github.com/jeksterslab/simStateSpace |
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, burnin = 0, reset_time = TRUE, ... )## S3 method for class 'simstatespace' as.data.frame( x, row.names = NULL, optional = FALSE, eta = FALSE, long = TRUE, burnin = 0, reset_time = TRUE, ... )
x |
Object of class |
row.names |
|
optional |
Logical.
If |
eta |
Logical.
If |
long |
Logical.
If |
burnin |
Positive integer. Initial data points to discard. Default is zero. |
reset_time |
Logical. Reset the time index after burnin. |
... |
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, burnin = 0, reset_time = TRUE, ...)## S3 method for class 'simstatespace' as.matrix(x, eta = FALSE, long = TRUE, burnin = 0, reset_time = TRUE, ...)
x |
Object of class |
eta |
Logical.
If |
long |
Logical.
If |
burnin |
Positive integer. Initial data points to discard. Default is zero. |
reset_time |
Logical. Reset the time index after burnin. |
... |
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:
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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 )
The steady-state covariance matrix
for the latent variables
in the linear stochastic differential equation model
is the solution
to the Sylvester equation,
i.e.
where is unknown,
,
, and
where
is the drift matrix
and
is the covariance matrix
of volatility or randomness in the process.
LinSDECovEta(phi, sigma)LinSDECovEta(phi, sigma)
phi |
Numeric matrix.
The drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
sigma |
Numeric matrix.
The covariance matrix of volatility
or randomness in the process
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) sigma <- matrix( data = c( 0.24455556, 0.02201587, -0.05004762, 0.02201587, 0.07067800, 0.01539456, -0.05004762, 0.01539456, 0.07553061 ), nrow = 3 ) LinSDECovEta( phi = phi, sigma = sigma )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) sigma <- matrix( data = c( 0.24455556, 0.02201587, -0.05004762, 0.02201587, 0.07067800, 0.01539456, -0.05004762, 0.01539456, 0.07553061 ), nrow = 3 ) LinSDECovEta( phi = phi, sigma = sigma )
The steady-state covariance matrix
for the observed variables
in the linear stochastic differential equation model
is given by
where
is the matrix of factor loadings,
is the covariance matrix of
the measurement error,
and
is the steady-state covariance matrix
for the latent variables.
LinSDECovY(lambda, theta, cov_eta)LinSDECovY(lambda, theta, cov_eta)
lambda |
Numeric matrix.
Factor loading matrix linking the latent variables
to the observed variables
( |
theta |
Numeric matrix.
The covariance matrix of
the measurement error
( |
cov_eta |
Numeric matrix. The steady-state covariance matrix for the latent variables in the linear stochastic differential equation model |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) sigma <- matrix( data = c( 0.24455556, 0.02201587, -0.05004762, 0.02201587, 0.07067800, 0.01539456, -0.05004762, 0.01539456, 0.07553061 ), nrow = 3 ) lambda <- diag(3) theta <- diag(3) cov_eta <- LinSDECovEta( phi = phi, sigma = sigma ) LinSDECovY( lambda = lambda, theta = theta, cov_eta = cov_eta )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) sigma <- matrix( data = c( 0.24455556, 0.02201587, -0.05004762, 0.02201587, 0.07067800, 0.01539456, -0.05004762, 0.01539456, 0.07553061 ), nrow = 3 ) lambda <- diag(3) theta <- diag(3) cov_eta <- LinSDECovEta( phi = phi, sigma = sigma ) LinSDECovY( lambda = lambda, theta = theta, cov_eta = cov_eta )
The intercept vector
for the latent variables
in the linear stochastic differential equation model
is given by
where
is the drift matrix and
is the steady-state mean vector
for the latent variables.
LinSDEInterceptEta(phi, mean_eta)LinSDEInterceptEta(phi, mean_eta)
phi |
Numeric matrix.
The drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) LinSDEMeanEta( phi = phi, iota = iota )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) LinSDEMeanEta( phi = phi, iota = iota )
The intercept vector
for the observed variables
in the linear stochastic differential equation model
is given by
where
is the matrix of factor loadings,
is the steady-state mean vector
for the observed variables,
and
is the steady-state mean vector
for the latent variables.
LinSDEInterceptY(mean_y, mean_eta, lambda)LinSDEInterceptY(mean_y, mean_eta, lambda)
mean_y |
Numeric vector.
Steady-state mean vector
of the observed variables
|
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
lambda |
Numeric matrix.
Factor loading matrix linking the latent variables
to the observed variables
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- LinSDEMeanEta( phi = phi, iota = iota ) mean_y <- LinSDEMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta ) LinSDEInterceptY( mean_y = mean_y, mean_eta = mean_eta, lambda = lambda )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- LinSDEMeanEta( phi = phi, iota = iota ) mean_y <- LinSDEMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta ) LinSDEInterceptY( mean_y = mean_y, mean_eta = mean_eta, lambda = lambda )
The steady-state mean vector
for the latent variables
in the linear stochastic differential equation model
is given by
where
is the drift matrix,
and
is an unobserved term that is constant over time.
LinSDEMeanEta(phi, iota)LinSDEMeanEta(phi, iota)
phi |
Numeric matrix.
The drift matrix
which represents the rate of change of the solution
in the absence of any random fluctuations
( |
iota |
Numeric vector.
An unobserved term that is constant over time
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) LinSDEMeanEta( phi = phi, iota = iota )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) LinSDEMeanEta( phi = phi, iota = iota )
The steady-state mean vector
for the observed variables
in the linear stochastic differential equation model
is given by
where
is the vector of intercept values
for the measurement model,
is the matrix of factor loadings,
and
is the steady-state mean vector
for the latent variables.
LinSDEMeanY(nu, lambda, mean_eta)LinSDEMeanY(nu, lambda, mean_eta)
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
( |
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- LinSDEMeanEta( phi = phi, iota = iota ) LinSDEMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta )phi <- matrix( data = c( -0.357, 0.771, -0.450, 0.0, -0.511, 0.729, 0.0, 0.0, -0.693 ), nrow = 3 ) iota <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- LinSDEMeanEta( phi = phi, iota = iota ) LinSDEMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta )
simstatespace
Plot Method for an Object of Class simstatespace
## S3 method for class 'simstatespace' plot( x, id = NULL, time = NULL, eta = FALSE, type = "b", burnin = 0, reset_time = TRUE, ... )## S3 method for class 'simstatespace' plot( x, id = NULL, time = NULL, eta = FALSE, type = "b", burnin = 0, reset_time = TRUE, ... )
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 |
burnin |
Positive integer. Initial data points to discard. Default is zero. |
reset_time |
Logical. Reset the time index after burnin. |
... |
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)
Shifts a square matrix left on the real axis
so that its spectral abscissa (maximum real part of the eigenvalues)
is strictly less than -margin.
This is useful for ensuring that continuous-time drift matrices
(e.g. in linear SDEs/state-space models) are Hurwitz-stable.
If the matrix already satisfies the margin,
it is returned unchanged.
ProjectToHurwitz(x, margin = 0.001)ProjectToHurwitz(x, margin = 0.001)
x |
Numeric square matrix. |
margin |
Positive numeric.
Target buffer inside the Hurwitz region;
the result satisfies
|
The projection is performed by subtracting a multiple of the identity:
where is the spectral abscissa.
A numeric matrix of the same dimensions as x,
shifted if necessary to satisfy the Hurwitz stability constraint.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
# Unstable (spectral abscissa >= 0): x <- matrix( data = c( 0.10, -0.40, 0.50, 0.20 ), nrow = 2 ) SpectralAbscissa(x = x) # >= 0 SpectralAbscissa(x = ProjectToHurwitz(x = x)) # <= -1e-3 (default margin) # Already Hurwitz-stable is returned unchanged up to numerics: x <- matrix( data = c( -0.50, -0.20, 1.00, -0.30 ), nrow = 2 ) SpectralAbscissa(x = x) # < 0 identical(ProjectToHurwitz(x = x), x)# Unstable (spectral abscissa >= 0): x <- matrix( data = c( 0.10, -0.40, 0.50, 0.20 ), nrow = 2 ) SpectralAbscissa(x = x) # >= 0 SpectralAbscissa(x = ProjectToHurwitz(x = x)) # <= -1e-3 (default margin) # Already Hurwitz-stable is returned unchanged up to numerics: x <- matrix( data = c( -0.50, -0.20, 1.00, -0.30 ), nrow = 2 ) SpectralAbscissa(x = x) # < 0 identical(ProjectToHurwitz(x = x), x)
Scales a square matrix so that its spectral radius is strictly less than 1 by a specified stability margin. This is useful for ensuring that transition matrices in state space or vector autoregressive (VAR) models are stationary. If the matrix is already within the margin, it is returned unchanged.
ProjectToStability(x, margin = 0.98, tol = 1e-12)ProjectToStability(x, margin = 0.98, tol = 1e-12)
x |
Numeric square matrix. |
margin |
Double in |
tol |
Small positive double
added to the denominator in the scaling
factor to avoid division by zero
(default |
The projection is performed
by multiplying the matrix by a constant factor
,
where is the spectral radius and tol
is a small positive number to prevent division by zero.
A numeric matrix of the same dimensions as x,
scaled if necessary to satisfy the stability constraint.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
# Matrix with eigenvalues greater than 1 x <- matrix( data = c( 1.2, 0.3, 0.4, 0.9 ), nrow = 2 ) SpectralRadius(x = x) # > 1 SpectralRadius(x = ProjectToStability(x = x)) # < 1 # Matrix already stable is returned unchanged x <- matrix( data = c( 0.5, 0.3, 0.2, 0.4 ), nrow = 2 ) identical(ProjectToStability(x = x), x)# Matrix with eigenvalues greater than 1 x <- matrix( data = c( 1.2, 0.3, 0.4, 0.9 ), nrow = 2 ) SpectralRadius(x = x) # > 1 SpectralRadius(x = ProjectToStability(x = x)) # < 1 # Matrix already stable is returned unchanged x <- matrix( data = c( 0.5, 0.3, 0.2, 0.4 ), nrow = 2 ) identical(ProjectToStability(x = x), x)
This function simulates random intercept vectors in a discrete-time vector autoregressive model from the multivariate normal distribution.
SimAlphaN(n, alpha, vcov_alpha_l)SimAlphaN(n, alpha, vcov_alpha_l)
n |
Positive integer. Number of replications. |
alpha |
Numeric vector.
Intercept ( |
vcov_alpha_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random intercept vectors.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 alpha <- c(0, 0, 0) vcov_alpha_l <- t(chol(0.001 * diag(3))) SimAlphaN(n = n, alpha = alpha, vcov_alpha_l = vcov_alpha_l)n <- 10 alpha <- c(0, 0, 0) vcov_alpha_l <- t(chol(0.001 * diag(3))) SimAlphaN(n = n, alpha = alpha, vcov_alpha_l = vcov_alpha_l)
This function simulates random transition matrices
from the multivariate normal distribution.
The function ensures that the generated transition matrices are stationary
using TestStationarity() with a rejection sampling approach.
SimBetaN( n, beta, vcov_beta_vec_l, margin = 1, beta_lbound = NULL, beta_ubound = NULL, bound = FALSE, max_iter = 100000L )SimBetaN( n, beta, vcov_beta_vec_l, margin = 1, beta_lbound = NULL, beta_ubound = NULL, bound = FALSE, max_iter = 100000L )
n |
Positive integer. Number of replications. |
beta |
Numeric matrix.
The transition matrix ( |
vcov_beta_vec_l |
Numeric matrix.
Cholesky factorization ( |
margin |
Numeric scalar specifying the stationarity threshold. Values less than 1 indicate stricter stationarity criteria. |
beta_lbound |
Optional numeric matrix of same dim as |
beta_ubound |
Optional numeric matrix of same dim as |
bound |
Logical; if TRUE, resample until all elements respect bounds (NA bounds ignored). |
max_iter |
Safety cap on resampling attempts per draw. |
Returns a list of random transition matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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 transition matrices
from the multivariate normal distribution
then projects each draw to the stability region
using ProjectToStability().
SimBetaN2(n, beta, vcov_beta_vec_l, margin = 0.98, tol = 1e-12)SimBetaN2(n, beta, vcov_beta_vec_l, margin = 0.98, tol = 1e-12)
n |
Positive integer. Number of replications. |
beta |
Numeric matrix.
The transition matrix ( |
vcov_beta_vec_l |
Numeric matrix.
Cholesky factorization ( |
margin |
Double in |
tol |
Small positive double added to the denominator in the scaling factor to avoid division by zero (default = 1e-12). |
Returns a list of random transition matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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))) SimBetaN2(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))) SimBetaN2(n = n, beta = beta, vcov_beta_vec_l = vcov_beta_vec_l)
This function simulates random transition matrices from a multivariate
normal distribution, allowing the mean transition matrix to vary as a
linear function of a covariate.
The function ensures that the generated transition matrices are stationary
using TestStationarity() with a rejection sampling approach.
SimBetaNCovariate( n, beta0, vcov_beta_vec_l, beta1, x, margin = 1, beta_lbound = NULL, beta_ubound = NULL, bound = FALSE, max_iter = 100000L )SimBetaNCovariate( n, beta0, vcov_beta_vec_l, beta1, x, margin = 1, beta_lbound = NULL, beta_ubound = NULL, bound = FALSE, max_iter = 100000L )
n |
Positive integer. Number of replications. |
beta0 |
Numeric matrix.
Baseline transition matrix |
vcov_beta_vec_l |
Numeric matrix.
Cholesky factorization ( |
beta1 |
Numeric matrix.
Matrix of covariate effects mapping |
x |
List of numeric vectors. Covariate values. |
margin |
Numeric scalar specifying the stationarity threshold. Values less than 1 indicate stricter stationarity criteria. |
beta_lbound |
Optional numeric matrix of same dim as |
beta_ubound |
Optional numeric matrix of same dim as |
bound |
Logical; if TRUE, resample until all elements respect bounds (NA bounds ignored). |
max_iter |
Safety cap on resampling attempts per draw. |
Returns a list of random transition matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 5 beta0 <- 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))) # One scalar covariate per replication beta1 <- matrix(data = 0, nrow = 9, ncol = 1) beta1[1, 1] <- 0.10 # x shifts beta[1,1] x <- list(c(0), c(1), c(-1), c(0.5), c(2)) SimBetaNCovariate( n = n, beta0 = beta0, vcov_beta_vec_l = vcov_beta_vec_l, beta1 = beta1, x = x )n <- 5 beta0 <- 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))) # One scalar covariate per replication beta1 <- matrix(data = 0, nrow = 9, ncol = 1) beta1[1, 1] <- 0.10 # x shifts beta[1,1] x <- list(c(0), c(1), c(-1), c(0.5), c(2)) SimBetaNCovariate( n = n, beta0 = beta0, vcov_beta_vec_l = vcov_beta_vec_l, beta1 = beta1, x = x )
This function simulates random diagonal covariance matrices from the multivariate normal distribution. The function ensures that the generated covariance matrices are positive semi-definite.
SimCovDiagN(n, sigma_diag, vcov_sigma_diag_l)SimCovDiagN(n, sigma_diag, vcov_sigma_diag_l)
n |
Positive integer. Number of replications. |
sigma_diag |
Numeric matrix.
The covariance matrix
( |
vcov_sigma_diag_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random diagonal covariance matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 sigma_diag <- c(1, 1, 1) vcov_sigma_diag_l <- t(chol(0.001 * diag(3))) SimCovDiagN( n = n, sigma_diag = sigma_diag, vcov_sigma_diag_l = vcov_sigma_diag_l )n <- 10 sigma_diag <- c(1, 1, 1) vcov_sigma_diag_l <- t(chol(0.001 * diag(3))) SimCovDiagN( n = n, sigma_diag = sigma_diag, vcov_sigma_diag_l = vcov_sigma_diag_l )
This function simulates random covariance matrices from the multivariate normal distribution. The function ensures that the generated covariance matrices are positive semi-definite.
SimCovN(n, sigma, vcov_sigma_vech_l)SimCovN(n, sigma, vcov_sigma_vech_l)
n |
Positive integer. Number of replications. |
sigma |
Numeric matrix.
The covariance matrix
( |
vcov_sigma_vech_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random covariance matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 sigma <- matrix( data = c( 1.0, 0.5, 0.3, 0.5, 1.0, 0.4, 0.3, 0.4, 1.0 ), nrow = 3 ) vcov_sigma_vech_l <- t( chol( 0.001 * diag(3 * (3 + 1) / 2) ) ) SimCovN( n = n, sigma = sigma, vcov_sigma_vech_l = vcov_sigma_vech_l )n <- 10 sigma <- matrix( data = c( 1.0, 0.5, 0.3, 0.5, 1.0, 0.4, 0.3, 0.4, 1.0 ), nrow = 3 ) vcov_sigma_vech_l <- t( chol( 0.001 * diag(3 * (3 + 1) / 2) ) ) SimCovN( n = n, sigma = sigma, vcov_sigma_vech_l = vcov_sigma_vech_l )
This function simulates random intercept vectors in a continuous-time vector autoregressive model from the multivariate normal distribution.
SimIotaN(n, iota, vcov_iota_l)SimIotaN(n, iota, vcov_iota_l)
n |
Positive integer. Number of replications. |
iota |
Numeric vector.
Intercept ( |
vcov_iota_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random intercept vectors.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 iota <- c(0, 0, 0) vcov_iota_l <- t(chol(0.001 * diag(3))) SimIotaN(n = n, iota = iota, vcov_iota_l = vcov_iota_l)n <- 10 iota <- c(0, 0, 0) vcov_iota_l <- t(chol(0.001 * diag(3))) SimIotaN(n = n, iota = iota, vcov_iota_l = vcov_iota_l)
This function simulates random set point vectors from the multivariate normal distribution.
SimMuN(n, mu, vcov_mu_l)SimMuN(n, mu, vcov_mu_l)
n |
Positive integer. Number of replications. |
mu |
Numeric vector.
Set point ( |
vcov_mu_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random set point vectors.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 mu <- c(0, 0, 0) vcov_mu_l <- t(chol(0.001 * diag(3))) SimMuN(n = n, mu = mu, vcov_mu_l = vcov_mu_l)n <- 10 mu <- c(0, 0, 0) vcov_mu_l <- t(chol(0.001 * diag(3))) SimMuN(n = n, mu = mu, vcov_mu_l = vcov_mu_l)
This function simulates random vectors from the multivariate normal distribution.
SimMVN(n, mu, sigma_l)SimMVN(n, mu, sigma_l)
n |
Positive integer. Number of replications. |
mu |
Numeric vector.
Mean vector ( |
sigma_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random vectors.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 mu <- c(0, 0, 0) sigma_l <- t(chol(0.001 * diag(3))) SimMVN(n = n, mu = mu, sigma_l = sigma_l)n <- 10 mu <- c(0, 0, 0) sigma_l <- t(chol(0.001 * diag(3))) SimMVN(n = n, mu = mu, sigma_l = sigma_l)
This function simulates random intercept vectors in a discrete-time vector autoregressive model from the multivariate normal distribution.
SimNuN(n, nu, vcov_nu_l)SimNuN(n, nu, vcov_nu_l)
n |
Positive integer. Number of replications. |
nu |
Numeric vector.
Intercept ( |
vcov_nu_l |
Numeric matrix.
Cholesky factorization ( |
Returns a list of random intercept vectors.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 10 nu <- c(0, 0, 0) vcov_nu_l <- t(chol(0.001 * diag(3))) SimNuN(n = n, nu = nu, vcov_nu_l = vcov_nu_l)n <- 10 nu <- c(0, 0, 0) vcov_nu_l <- t(chol(0.001 * diag(3))) SimNuN(n = n, nu = nu, vcov_nu_l = vcov_nu_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, margin = 0, auto_ubound = 0, phi_lbound = NULL, phi_ubound = NULL, bound = FALSE, max_iter = 100000L )SimPhiN( n, phi, vcov_phi_vec_l, margin = 0, auto_ubound = 0, phi_lbound = NULL, phi_ubound = NULL, bound = FALSE, max_iter = 100000L )
n |
Positive integer. Number of replications. |
phi |
Numeric matrix.
The drift matrix ( |
vcov_phi_vec_l |
Numeric matrix.
Cholesky factorization ( |
margin |
Numeric scalar specifying the stability threshold
for the real part of the eigenvalues.
The default |
auto_ubound |
Numeric scalar specifying the upper bound
for the diagonal elements of |
phi_lbound |
Optional numeric matrix of same dim as |
phi_ubound |
Optional numeric matrix of same dim as |
bound |
Logical; if TRUE, resample until all elements respect bounds (NA bounds ignored). |
max_iter |
Safety cap on resampling attempts per draw. |
Returns a list of random drift matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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 random dirft matrices
from the multivariate normal distribution
then projects each draw to the Hurwitz-stable region
using ProjectToHurwitz().
SimPhiN2(n, phi, vcov_phi_vec_l, margin = 0.001)SimPhiN2(n, phi, vcov_phi_vec_l, margin = 0.001)
n |
Positive integer. Number of replications. |
phi |
Numeric matrix.
The drift matrix ( |
vcov_phi_vec_l |
Numeric matrix.
Cholesky factorization ( |
margin |
Positive numeric.
Target buffer so that the spectral abscissa
is |
Returns a list of random drift matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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))) SimPhiN2(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))) SimPhiN2(n = n, phi = phi, vcov_phi_vec_l = vcov_phi_vec_l)
This function simulates random drift matrices
from the multivariate normal distribution,
allowing the mean drift matrix to vary
as a linear function of a covariate
The function ensures that the generated drift matrices are stable
using TestPhi().
SimPhiNCovariate( n, phi0, vcov_phi_vec_l, phi1, x, margin = 0, auto_ubound = 0, phi_lbound = NULL, phi_ubound = NULL, bound = FALSE, max_iter = 100000L )SimPhiNCovariate( n, phi0, vcov_phi_vec_l, phi1, x, margin = 0, auto_ubound = 0, phi_lbound = NULL, phi_ubound = NULL, bound = FALSE, max_iter = 100000L )
n |
Positive integer. Number of replications. |
phi0 |
Numeric matrix.
Baseline drift matrix ( |
vcov_phi_vec_l |
Numeric matrix.
Cholesky factorization ( |
phi1 |
Numeric matrix.
Matrix of covariate effects mapping |
x |
List of numeric vectors. Covariate values. |
margin |
Numeric scalar specifying the stability threshold
for the real part of the eigenvalues.
The default |
auto_ubound |
Numeric scalar specifying the upper bound
for the diagonal elements of |
phi_lbound |
Optional numeric matrix of same dim as |
phi_ubound |
Optional numeric matrix of same dim as |
bound |
Logical; if TRUE, resample until all elements respect bounds (NA bounds ignored). |
max_iter |
Safety cap on resampling attempts per draw. |
Returns a list of random drift matrices.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
n <- 5 phi0 <- 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))) # One scalar covariate per replication phi1 <- matrix(data = 0, nrow = 9, ncol = 1) phi1[1, 1] <- 0.10 # x shifts phi[1,1] x <- list(c(0), c(1), c(-1), c(0.5), c(2)) SimPhiNCovariate( n = n, phi0 = phi0, vcov_phi_vec_l = vcov_phi_vec_l, phi1 = phi1, x = x )n <- 5 phi0 <- 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))) # One scalar covariate per replication phi1 <- matrix(data = 0, nrow = 9, ncol = 1) phi1[1, 1] <- 0.10 # x shifts phi[1,1] x <- list(c(0), c(1), c(-1), c(0.5), c(2)) SimPhiNCovariate( n = n, phi0 = phi0, vcov_phi_vec_l = vcov_phi_vec_l, phi1 = phi1, x = x )
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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) { 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) { 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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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)
Returns the maximum real part of the eigenvalues of a square matrix. For continuous-time stability (Hurwitz), a matrix is stable if the spectral abscissa is strictly less than 0.
SpectralAbscissa(x)SpectralAbscissa(x)
x |
Numeric square matrix. |
Numeric value .
Ivan Jacob Agaloos Pesigan
# Hurwitz-stable (spectral abscissa < 0): x <- matrix( data = c( -0.5, -0.2, 1.0, -0.3 ), nrow = 2 ) SpectralAbscissa(x = x) # < 0 # Unstable (spectral abscissa > 0): x <- matrix( data = c( 0.10, 0.50, -0.40, 0.20 ), nrow = 2 ) SpectralAbscissa(x = x) # > 0# Hurwitz-stable (spectral abscissa < 0): x <- matrix( data = c( -0.5, -0.2, 1.0, -0.3 ), nrow = 2 ) SpectralAbscissa(x = x) # < 0 # Unstable (spectral abscissa > 0): x <- matrix( data = c( 0.10, 0.50, -0.40, 0.20 ), nrow = 2 ) SpectralAbscissa(x = x) # > 0
Computes the spectral radius of a square matrix, defined as the maximum modulus (absolute value) of its eigenvalues. The spectral radius is often used to assess the stability of systems such as vector autoregressive (VAR) models: a system is considered stationary if the spectral radius of its transition matrix is strictly less than 1.
SpectralRadius(x)SpectralRadius(x)
x |
Numeric square matrix. |
Numeric value representing the spectral radius of x.
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
# Matrix with eigenvalues less than 1 x <- matrix( data = c( 0.5, 0.3, 0.2, 0.4 ), nrow = 2 ) SpectralRadius(x) # Matrix with eigenvalues greater than 1 y <- matrix( data = c( 1.2, 0.3, 0.4, 0.9 ), nrow = 2 ) SpectralRadius(y)# Matrix with eigenvalues less than 1 x <- matrix( data = c( 0.5, 0.3, 0.2, 0.4 ), nrow = 2 ) SpectralRadius(x) # Matrix with eigenvalues greater than 1 y <- matrix( data = c( 1.2, 0.3, 0.4, 0.9 ), nrow = 2 ) SpectralRadius(y)
The steady-state covariance matrix
for the latent variables
in the state space model
is given by
where
is the transition matrix relating the values of the latent variables
at the previous to the current time point
and
is the covariance matrix
of volatility or randomness in the process.
SSMCovEta(beta, psi)SSMCovEta(beta, psi)
beta |
Numeric matrix.
Transition matrix relating the values of the latent variables
at the previous to the current time point
( |
psi |
Numeric matrix.
The covariance matrix
of the process noise
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) psi <- 0.1 * diag(3) SSMCovEta( beta = beta, psi = psi )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) psi <- 0.1 * diag(3) SSMCovEta( beta = beta, psi = psi )
The steady-state covariance matrix
for the observed variables
in the state space model
is given by
where
is the matrix of factor loadings,
is the covariance matrix of
the measurement error,
and
is the steady-state covariance matrix
for the latent variables.
SSMCovY(lambda, theta, cov_eta)SSMCovY(lambda, theta, cov_eta)
lambda |
Numeric matrix.
Factor loading matrix linking the latent variables
to the observed variables
( |
theta |
Numeric matrix.
The covariance matrix of
the measurement error
( |
cov_eta |
Numeric matrix. The steady-state covariance matrix for the latent variables in the state space model |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) psi <- 0.1 * diag(3) lambda <- diag(3) theta <- diag(3) cov_eta <- SSMCovEta( beta = beta, psi = psi ) SSMCovY( lambda = lambda, theta = theta, cov_eta = cov_eta )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) psi <- 0.1 * diag(3) lambda <- diag(3) theta <- diag(3) cov_eta <- SSMCovEta( beta = beta, psi = psi ) SSMCovY( lambda = lambda, theta = theta, cov_eta = cov_eta )
The intercept vector
for the latent variables
in the state space model
is given by
where
is the transition matrix relating the values of the latent variables
at the previous to the current time point and
is the steady-state mean vector
for the latent variables.
SSMInterceptEta(beta, mean_eta)SSMInterceptEta(beta, mean_eta)
beta |
Numeric matrix.
Transition matrix relating the values of the latent variables
at the previous to the current time point
( |
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) SSMInterceptEta( beta = beta, mean_eta = mean_eta )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) SSMInterceptEta( beta = beta, mean_eta = mean_eta )
The intercept vector
for the observed variables
in the state space model
is given by
where
is the matrix of factor loadings,
is the steady-state mean vector
for the observed variables,
and
is the steady-state mean vector
for the latent variables.
SSMInterceptY(mean_y, mean_eta, lambda)SSMInterceptY(mean_y, mean_eta, lambda)
mean_y |
Numeric vector.
Steady-state mean vector
of the observed variables
|
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
lambda |
Numeric matrix.
Factor loading matrix linking the latent variables
to the observed variables
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) mean_y <- SSMMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta ) SSMInterceptY( mean_y = mean_y, mean_eta = mean_eta, lambda = lambda )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) mean_y <- SSMMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta ) SSMInterceptY( mean_y = mean_y, mean_eta = mean_eta, lambda = lambda )
The steady-state mean vector
for the latent variables
in the state space model
is given by
where
is the transition matrix relating the values of the latent variables
at the previous to the current time point,
is a vector of constant values for the dynamic model,
and
is an identity matrix.
SSMMeanEta(beta, alpha)SSMMeanEta(beta, alpha)
beta |
Numeric matrix.
Transition matrix relating the values of the latent variables
at the previous to the current time point
( |
alpha |
Numeric vector.
Vector of constant values for the dynamic model
( |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) SSMMeanEta( beta = beta, alpha = alpha )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) SSMMeanEta( beta = beta, alpha = alpha )
The steady-state mean vector
for the observed variables
in the state space model
is given by
where
is the vector of intercept values
for the measurement model,
is the matrix of factor loadings,
and
is the steady-state mean vector
for the latent variables.
SSMMeanY(nu, lambda, mean_eta)SSMMeanY(nu, lambda, mean_eta)
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
( |
mean_eta |
Numeric vector.
Steady-state mean vector
of the latent variables
|
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) SSMMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta )beta <- matrix( data = c( 0.7, 0.5, -0.1, 0.0, 0.6, 0.4, 0.0, 0.0, 0.5 ), nrow = 3 ) alpha <- rep(x = 1, times = 3) lambda <- diag(3) nu <- rep(x = 1, times = 3) mean_eta <- SSMMeanEta( beta = beta, alpha = alpha ) SSMMeanY( nu = nu, lambda = lambda, mean_eta = mean_eta )
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, margin = 0, auto_ubound = 0)TestPhi(phi, margin = 0, auto_ubound = 0)
phi |
Numeric matrix.
The drift matrix ( |
margin |
Numeric scalar specifying the stability threshold
for the real part of the eigenvalues.
The default |
auto_ubound |
Numeric scalar specifying the upper bound
for the diagonal elements of |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhiHurwitz(),
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)
Returns TRUE iff the drift matrix
is Hurwitz-stable,
i.e., all eigenvalues have real parts strictly less than -eps.
Setting eps = 0 enforces the usual strict condition
.
A small positive eps (e.g., 1e-12) can be used
to guard against floating-point round-off.
TestPhiHurwitz(phi, eps = 0)TestPhiHurwitz(phi, eps = 0)
phi |
Numeric matrix.
The drift matrix ( |
eps |
Nonnegative numeric tolerance (default |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestStability(),
TestStationarity()
# Unstable example (spectral abscissa >= 0): phi <- matrix( data = c( 0.10, -0.40, 0.50, 0.20 ), nrow = 2 ) TestPhiHurwitz(phi = phi) # FALSE # Stable example (all real parts < 0): phi <- matrix( data = c( -0.50, -0.20, 1.00, -0.30 ), nrow = 2 ) TestPhiHurwitz(phi = phi) # TRUE TestPhiHurwitz(phi = phi, eps = 1e-12) # also TRUE with tolerance# Unstable example (spectral abscissa >= 0): phi <- matrix( data = c( 0.10, -0.40, 0.50, 0.20 ), nrow = 2 ) TestPhiHurwitz(phi = phi) # FALSE # Stable example (all real parts < 0): phi <- matrix( data = c( -0.50, -0.20, 1.00, -0.30 ), nrow = 2 ) TestPhiHurwitz(phi = phi) # TRUE TestPhiHurwitz(phi = phi, eps = 1e-12) # also TRUE with tolerance
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, margin = 0)TestStability(x, margin = 0)
x |
Numeric matrix. |
margin |
Numeric scalar specifying the stability threshold
for the real part of the eigenvalues.
The default |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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, margin = 1)TestStationarity(x, margin = 1)
x |
Numeric matrix. |
margin |
Numeric scalar specifying the stationarity threshold. Values less than 1 indicate stricter stationarity criteria. |
Ivan Jacob Agaloos Pesigan
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
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)