The function fits the first-order vector autoregressive model for each unit ID.
FitVARMxID(
data,
observed,
id,
time = NULL,
ct = FALSE,
center = TRUE,
mu_fixed = FALSE,
mu_free = NULL,
mu_values = NULL,
mu_lbound = NULL,
mu_ubound = NULL,
alpha_fixed = FALSE,
alpha_free = NULL,
alpha_values = NULL,
alpha_lbound = NULL,
alpha_ubound = NULL,
beta_fixed = FALSE,
beta_free = NULL,
beta_values = NULL,
beta_lbound = NULL,
beta_ubound = NULL,
psi_diag = FALSE,
psi_fixed = FALSE,
psi_d_free = NULL,
psi_d_values = NULL,
psi_d_lbound = NULL,
psi_d_ubound = NULL,
psi_d_equal = FALSE,
psi_l_free = NULL,
psi_l_values = NULL,
psi_l_lbound = NULL,
psi_l_ubound = NULL,
nu_fixed = TRUE,
nu_free = NULL,
nu_values = NULL,
nu_lbound = NULL,
nu_ubound = NULL,
theta_diag = TRUE,
theta_fixed = TRUE,
theta_d_free = NULL,
theta_d_values = NULL,
theta_d_lbound = NULL,
theta_d_ubound = NULL,
theta_d_equal = FALSE,
theta_l_free = NULL,
theta_l_values = NULL,
theta_l_lbound = NULL,
theta_l_ubound = NULL,
mu0_fixed = TRUE,
mu0_func = TRUE,
mu0_free = NULL,
mu0_values = NULL,
mu0_lbound = NULL,
mu0_ubound = NULL,
sigma0_fixed = TRUE,
sigma0_func = TRUE,
sigma0_diag = FALSE,
sigma0_d_free = NULL,
sigma0_d_values = NULL,
sigma0_d_lbound = NULL,
sigma0_d_ubound = NULL,
sigma0_d_equal = FALSE,
sigma0_l_free = NULL,
sigma0_l_values = NULL,
sigma0_l_lbound = NULL,
sigma0_l_ubound = NULL,
robust = FALSE,
seed = NULL,
tries_explore = 100,
tries_local = 100,
max_attempts = 10,
silent = FALSE,
ncores = NULL
)Returns an object of class varmxid which is
a list with the following elements:
Function call.
List of function arguments.
Function used ("FitVARMxID").
A list of generated OpenMx models.
A list of fitted OpenMx models.
A logical vector indicating converged cases.
A list of output from OpenMx::imxRobustSE()
with argument details = TRUE for each id
if robust = TRUE.
Data frame. A data frame object of data for potentially multiple subjects that contain a column of subject ID numbers (i.e., an ID variable), and at least one column of observed values.
Character vector. A vector of character strings of the names of the observed variables in the data.
Character string. A character string of the name of the ID variable in the data.
Character string.
A character string of the name of the TIME variable in the data.
Used when ct = TRUE.
Logical. If TRUE, fit a continuous-time vector autoregressive model. If FALSE, fit a discrete-time vector autoregressive model.
Logical.
If TRUE, use the mean-centered (mean-reverting) state equation.
When center = TRUE, alpha is implied and the set-point mu is
estimated. When center = FALSE,
alpha is estimated and mu is implied.
Logical.
If TRUE, the set-point mean vector mu
is fixed to mu_values.
If mu_fixed = TRUE and mu_values = NULL,
mu is fixed to a zero vector.
If FALSE, mu is estimated.
Logical vector indicating
which elements of mu are freely estimated.
If NULL, all elements are free.
Ignored if mu_fixed = TRUE.
Numeric vector of values for mu.
If mu_fixed = TRUE, these are fixed values.
If mu_fixed = FALSE, these are starting values.
If NULL, defaults to a vector of zeros.
Numeric vector of lower bounds for mu.
Ignored if mu_fixed = TRUE.
Numeric vector of upper bounds for mu.
Ignored if mu_fixed = TRUE.
Logical.
If TRUE,
the dynamic model intercept vector alpha
is fixed to alpha_values.
If FALSE, alpha is estimated.
Logical vector indicating
which elements of alpha are freely estimated.
If NULL, all elements are free.
Ignored if alpha_fixed = TRUE.
Numeric vector of values for alpha.
If alpha_fixed = TRUE, these are fixed values.
If alpha_fixed = FALSE, these are starting values.
If NULL, defaults to a vector of zeros.
Numeric vector of lower bounds for alpha.
Ignored if alpha_fixed = TRUE.
Numeric vector of upper bounds for alpha.
Ignored if alpha_fixed = TRUE.
Logical.
If TRUE, the dynamic model coefficient matrix beta is fixed.
If FALSE, beta is estimated.
Logical matrix indicating
which elements of beta are freely estimated.
If NULL, all elements are free.
Ignored if beta_fixed = TRUE.
Numeric matrix.
Values for beta.
If beta_fixed = TRUE, these are fixed values;
if beta_fixed = FALSE, these are starting values.
If NULL, defaults to a diagonal matrix
with -0.001 when ct = TRUE and 0.001 when ct = FALSE.
Numeric matrix.
Lower bounds for beta.
Ignored if beta_fixed = TRUE.
If NULL and ct = FALSE,
defaults to -2.5.
If NULL and ct = TRUE,
defaults to NA.
Numeric matrix.
Upper bounds for beta.
Ignored if beta_fixed = TRUE.
If NULL and ct = FALSE,
defaults to +2.5.
If NULL and ct = TRUE,
diagonal upper bounds are set to -1e-05
and the off-diagonals are set to NA.
Logical.
If TRUE, psi is diagonal.
If FALSE, psi is symmetric.
Logical.
If TRUE, the process noise covariance matrix psi
is fixed using psi_d_values and psi_l_values.
If psi_d_values is NULL it is fixed to a zero matrix.
If FALSE, psi is estimated.
Logical vector
indicating free/fixed status of the elements of psi_d.
If NULL, all element of psi_d are free.
Numeric vector
with starting values for psi_d.
If psi_fixed = TRUE, these are fixed values.
If psi_fixed = FALSE, these are starting values.
Numeric vector
with lower bounds for psi_d.
Numeric vector
with upper bounds for psi_d.
Logical.
When TRUE, all free diagonal elements of psi_d are constrained
to be equal and estimated as a single shared parameter.
Ignored if no diagonal elements are free.
Logical matrix
indicating which strictly-lower-triangular elements of psi_l are free.
If NULL, all element of psi_l are free.
Ignored if psi_diag = TRUE.
Numeric matrix
of starting values
for the strictly-lower-triangular elements of psi_l.
Numeric matrix
with lower bounds for psi_l.
Numeric matrix
with upper bounds for psi_l.
Logical.
If TRUE,
the measurement model intercept vector nu
is fixed to nu_values.
If FALSE, nu is estimated.
Logical vector indicating
which elements of nu are freely estimated.
If NULL, all elements are free.
Ignored if nu_fixed = TRUE.
Numeric vector of values for nu.
If nu_fixed = TRUE, these are fixed values.
If nu_fixed = FALSE, these are starting values.
If NULL, defaults to a vector of zeros.
Numeric vector of lower bounds for nu.
Ignored if nu_fixed = TRUE.
Numeric vector of upper bounds for nu.
Ignored if nu_fixed = TRUE.
Logical.
If TRUE, theta is diagonal.
If FALSE, theta is symmetric.
Logical.
If TRUE, the measurement error covariance matrix theta
is fixed using theta_d_values and theta_l_values.
If theta_d_values is NULL it is fixed to a zero matrix.
If FALSE, theta is estimated.
Logical vector
indicating free/fixed status of the diagonal parameters theta_d.
If NULL, all element of theta_d are free.
Numeric vector
with starting values for theta_d.
If theta_fixed = TRUE, these are fixed values.
If theta_fixed = FALSE, these are starting values.
Numeric vector
with lower bounds for theta_d.
Numeric vector
with upper bounds for theta_d.
Logical.
When TRUE, all free diagonal elements of theta_d are constrained
to be equal and estimated as a single shared parameter.
Ignored if no diagonal elements are free.
Logical matrix
indicating which strictly-lower-triangular elements of theta_l are free.
If NULL, all element of theta_l are free.
Ignored if theta_diag = TRUE.
Numeric matrix
of starting values
for the strictly-lower-triangular elements of theta_l.
Numeric matrix
with lower bounds for theta_l.
Numeric matrix
with upper bounds for theta_l.
Logical.
If TRUE, the initial mean vector mu0 is fixed.
If mu0_fixed = TRUE and mu0_func = TRUE,
mu0 is fixed to the implied stable mean vector.
If mu0_fixed = TRUE and mu0_values = NULL,
mu0 is fixed to a zero vector.
If FALSE, mu0 is estimated.
Logical.
If TRUE and mu0_fixed = TRUE,
mu0 is fixed to the implied stable mean vector.
Logical vector indicating
which elements of mu0 are free.
Ignored if mu0_fixed = TRUE.
Numeric vector of values for mu0.
If mu0_fixed = TRUE, these are fixed values.
If mu0_fixed = FALSE, these are starting values.
If NULL, defaults to a vector of zeros.
Ignored if mu0_fixed = TRUE and mu0_func = TRUE.
Numeric vector of lower bounds for mu0.
Ignored if mu0_fixed = TRUE.
Numeric vector of upper bounds for mu0.
Ignored if mu0_fixed = TRUE.
Logical.
If TRUE, the initial condition covariance matrix sigma0
is fixed using sigma0_d_values and sigma0_l_values.
If sigma0_fixed = TRUE and sigma0_func = TRUE,
sigma0 is fixed to the implied stable covariance matrix.
If sigma0_fixed = TRUE and sigma0_d_values = NULL,
sigma0 is fixed to a diffused matrix.
Logical.
If TRUE and sigma0_fixed = TRUE, sigma0 is fixed to
the implied stable covariance matrix.
Logical.
If TRUE, sigma0 is diagonal.
If FALSE, sigma0 is symmetric.
Logical vector
indicating free/fixed status of the elements of sigma0_d.
If NULL, all element of sigma0_d are free.
Numeric vector
with starting values for sigma0_d.
If sigma0_fixed = TRUE, these are fixed values.
If sigma0_fixed = FALSE, these are starting values.
Numeric vector
with lower bounds for sigma0_d.
Numeric vector
with upper bounds for sigma0_d.
Logical.
When TRUE, all free diagonal elements of sigma0_d are constrained
to be equal and estimated as a single shared parameter.
Ignored if no diagonal elements are free.
Logical matrix
indicating which strictly-lower-triangular elements of sigma0_l are free.
If NULL, all element of sigma0_l are free.
Ignored if sigma0_diag = TRUE.
Numeric matrix
of starting values
for the strictly-lower-triangular elements of sigma0_l.
Numeric matrix
with lower bounds for sigma0_l.
Numeric matrix
with upper bounds for sigma0_l.
Logical.
If TRUE, calculate robust (sandwich) sampling variance-covariance matrix.
Random seed for reproducibility.
Integer. Number of extra tries for the wide exploration phase.
Integer. Number of extra tries for local polishing.
Integer. Maximum number of remediation attempts after the first Hessian computation fails the criteria.
Logical.
If TRUE, suppresses messages during the model fitting stage.
Positive integer. Number of cores to use.
Ivan Jacob Agaloos Pesigan
By default, the measurement model is given by $$ \mathbf{y}_{i, t} = \boldsymbol{\eta}_{i, t} . $$ However, the full measurement model can be parameterized as follows $$ \mathbf{y}_{i, t} = \boldsymbol{\nu}_{i} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta}_{i} \right) $$ where \(\mathbf{y}_{i, t}\), \(\boldsymbol{\eta}_{i, t}\), and \(\boldsymbol{\varepsilon}_{i, t}\) are random variables and \(\boldsymbol{\nu}_{i}\), \(\boldsymbol{\Lambda}\), and \(\boldsymbol{\Theta}_{i}\) are model parameters. \(\mathbf{y}_{i, t}\) represents a vector of observed random variables, \(\boldsymbol{\eta}_{i, t}\) a vector of latent random variables, and \(\boldsymbol{\varepsilon}_{i, t}\) a vector of random measurement errors, at time \(t\) and individual \(i\). \(\boldsymbol{\nu}_{i}\), denotes a vector of intercepts (fixed to a null vector by default), \(\boldsymbol{\Lambda}\) a matrix of factor loadings, and \(\boldsymbol{\Theta}_{i}\) the covariance matrix of \(\boldsymbol{\varepsilon}\). In this model, \(\boldsymbol{\Lambda}\) is an identity matrix and \(\boldsymbol{\Theta}_{i}\) is a diagonal matrix.
The dynamic structure is given by $$ \boldsymbol{\eta}_{i, t} = \boldsymbol{\alpha}_{i} + \boldsymbol{\beta}_{i} \boldsymbol{\eta}_{i, t - 1} + \boldsymbol{\zeta}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\zeta}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Psi}_{i} \right) $$ where \(\boldsymbol{\eta}_{i, t}\), \(\boldsymbol{\eta}_{i, t - 1}\), and \(\boldsymbol{\zeta}_{i, t}\) are random variables, and \(\boldsymbol{\alpha}_{i}\), \(\boldsymbol{\beta}_{i}\), and \(\boldsymbol{\Psi}_{i}\) are model parameters. Here, \(\boldsymbol{\eta}_{i, t}\) is a vector of latent variables at time \(t\) and individual \(i\), \(\boldsymbol{\eta}_{i, t - 1}\) represents a vector of latent variables at time \(t - 1\) and individual \(i\), and \(\boldsymbol{\zeta}_{i, t}\) represents a vector of dynamic noise at time \(t\) and individual \(i\). \(\boldsymbol{\alpha}_{i}\) denotes a vector of intercepts, \(\boldsymbol{\beta}_{i}\) a matrix of autoregression and cross regression coefficients, and \(\boldsymbol{\Psi}_{i}\) the covariance matrix of \(\boldsymbol{\zeta}_{i, t}\).
If center = TRUE, the dynamic structure is parameterized as follows
$$
\boldsymbol{\eta}_{i, t}
=
\boldsymbol{\mu}_{i}
+
\boldsymbol{\beta}_{i}
\left(
\boldsymbol{\eta}_{i, t - 1}
-
\boldsymbol{\mu}_{i}
\right)
+
\boldsymbol{\zeta}_{i, t}
$$
where \(\boldsymbol{\mu}_{i}\)
is equilibrium level of the latent state
toward which the system is pulled over time.
The continuous-time parameterization, when ct = TRUE,
for the dynamic structure is given by
$$
\mathrm{d}
\boldsymbol{\eta}_{i, t}
=
\left(
\boldsymbol{\alpha}_{i}
+
\boldsymbol{\beta}_{i}
\boldsymbol{\eta}_{i, t}
\right)
\mathrm{d} t
+
\boldsymbol{\Psi}_{i}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t}
$$
note that \(\mathrm{d}\boldsymbol{W}\)
is a Wiener process or Brownian motion,
which represents random fluctuations.
If center = TRUE, the dynamic structure is parameterized as follows
$$
\mathrm{d}
\boldsymbol{\eta}_{i, t}
=
\boldsymbol{\beta}_{i}
\left(
\boldsymbol{\eta}_{i, t}
-
\boldsymbol{\mu}_{i}
\right)
\mathrm{d} t
+
\boldsymbol{\Psi}_{i}^{\frac{1}{2}}
\mathrm{d}
\mathbf{W}_{i, t}
$$
Hunter, M. D. (2017). State space modeling in an open source, modular, structural equation modeling environment. Structural Equation Modeling: A Multidisciplinary Journal, 25(2), 307–324. tools:::Rd_expr_doi("10.1080/10705511.2017.1369354")
Neale, M. C., Hunter, M. D., Pritikin, J. N., Zahery, M., Brick, T. R., Kirkpatrick, R. M., Estabrook, R., Bates, T. C., Maes, H. H., & Boker, S. M. (2015). OpenMx 2.0: Extended structural equation and statistical modeling. Psychometrika, 81(2), 535–549. tools:::Rd_expr_doi("10.1007/s11336-014-9435-8")
Other VAR Functions:
LDL(),
Softplus()
# \donttest{
# Generate data using the simStateSpace package-------------------------
library(simStateSpace)
set.seed(42)
n <- 5
time <- 100
p <- 2
alpha <- rep(x = 0, times = p)
beta <- 0.50 * diag(p)
psi <- 0.001 * diag(p)
psi_l <- t(chol(psi))
mu0 <- SSMMeanEta(
beta = beta,
alpha = alpha
)
sigma0 <- SSMCovEta(
beta = beta,
psi = psi
)
sigma0_l <- t(chol(sigma0))
sim <- SimSSMVARFixed(
n = n,
time = time,
mu0 = mu0,
sigma0_l = sigma0_l,
alpha = alpha,
beta = beta,
psi_l = psi_l
)
data <- as.data.frame(sim)
# Fit the model---------------------------------------------------------
# center = TRUE
library(fitVARMxID)
fit <- FitVARMxID(
data = data,
observed = paste0("y", seq_len(p)),
id = "id",
center = TRUE
)
print(fit)
summary(fit)
coef(fit)
vcov(fit)
converged(fit)
# Fit the model---------------------------------------------------------
# center = FALSE
library(fitVARMxID)
fit <- FitVARMxID(
data = data,
observed = paste0("y", seq_len(p)),
id = "id",
center = FALSE
)
print(fit)
summary(fit)
coef(fit)
vcov(fit)
converged(fit)
# }
Run the code above in your browser using DataLab