Learn R Programming

simStateSpace (version 1.2.15)

SimSSMIVary: Simulate Data from a State Space Model (Individual-Varying Parameters)

Description

This function simulates data using a state space model. It assumes that the parameters can vary across individuals.

Usage

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
)

Arguments

Value

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.

Details

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.

References

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. tools:::Rd_expr_doi("10.1080/10705511003661553")

See Also

Other Simulation of State Space Models Data Functions: LinSDE2SSM(), LinSDECovEta(), LinSDECovY(), LinSDEMeanEta(), LinSDEMeanY(), ProjectToHurwitz(), ProjectToStability(), SSMCovEta(), SSMCovY(), SSMInterceptEta(), SSMInterceptY(), SSMMeanEta(), SSMMeanY(), SimAlphaN(), SimBetaN(), SimBetaN2(), SimBetaNCovariate(), SimCovDiagN(), SimCovN(), SimIotaN(), SimNuN(), SimPhiN(), SimPhiN2(), SimPhiNCovariate(), SimSSMFixed(), SimSSMLinGrowth(), SimSSMLinGrowthIVary(), SimSSMLinSDEFixed(), SimSSMLinSDEIVary(), SimSSMOUFixed(), SimSSMOUIVary(), SimSSMVARFixed(), SimSSMVARIVary(), SpectralRadius(), TestPhi(), TestPhiHurwitz(), TestStability(), TestStationarity()

Examples

Run this code
# 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)

Run the code above in your browser using DataLab