This is the family of models that models a dynamic factor model on time-series. There are two covariance structures that can be modeled in different ways: contemporaneous
for the contemporaneous model and residual
for the residual model. These can be set to "cov"
for covariances, "prec"
for a precision matrix, "ggm"
for a Gaussian graphical model and "chol"
for a Cholesky decomposition. The ts_lvgvar
wrapper function sets contemporaneous = "ggm"
for the graphical VAR model.
tsdlvm1(data, lambda, contemporaneous = c("cov", "chol",
"prec", "ggm"), residual = c("cov", "chol", "prec",
"ggm"), beta = "full", omega_zeta = "full", delta_zeta
= "diag", kappa_zeta = "full", sigma_zeta = "full",
lowertri_zeta = "full", omega_epsilon = "zero",
delta_epsilon = "diag", kappa_epsilon = "diag",
sigma_epsilon = "diag", lowertri_epsilon = "diag", nu,
mu_eta, identify = TRUE, identification =
c("loadings", "variance"), latents, beepvar, dayvar,
idvar, vars, groups, covs, means, nobs, missing =
"listwise", equal = "none", baseline_saturated = TRUE,
estimator = "ML", optimizer, storedata = FALSE,
sampleStats, covtype = c("choose", "ML", "UB"),
centerWithin = FALSE, standardize = c("none", "z",
"quantile"), verbose = FALSE, bootstrap = FALSE,
boot_sub, boot_resample)ts_lvgvar(...)
An object of the class psychonetrics (psychonetrics-class)
A data frame encoding the data used in the analysis. Can be missing if covs
and nobs
are supplied.
A model matrix encoding the factor loading structure. Each row indicates an indicator and each column a latent. A 0 encodes a fixed to zero element, a 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
The type of contemporaneous model used. See description.
The type of residual model used. See description.
A model matrix encoding the temporal relationships (transpose of temporal network) between latent variables. A 0 encodes a fixed to zero element, a 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix. Can also be "full"
for a full temporal network or "zero"
for an empty temporal network.
Only used when contemporaneous = "ggm"
. Either "full"
to estimate every element freely, "zero"
to set all elements to zero, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when contemporaneous = "ggm"
. Either "diag"
or "zero"
(not recommended), or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when contemporaneous = "prec"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when contemporaneous = "cov"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when contemporaneous = "chol"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when residual = "ggm"
. Either "full"
to estimate every element freely, "zero"
to set all elements to zero, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when residual = "ggm"
. Either "diag"
or "zero"
(not recommended), or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when residual = "prec"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when residual = "cov"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Only used when residual = "chol"
. Either "full"
to estimate every element freely, "diag"
to only include diagonal elements, or a matrix of the dimensions node x node with 0 encoding a fixed to zero element, 1 encoding a free to estimate element, and higher integers encoding equality constrains. For multiple groups, this argument can be a list or array with each element/slice encoding such a matrix.
Optional vector encoding the intercepts of the observed variables. Set elements to 0 to indicate fixed to zero constrains, 1 to indicate free intercepts, and higher integers to indicate equality constrains. For multiple groups, this argument can be a list or array with each element/column encoding such a vector.
Optional vector encoding the means of the latent variables. Set elements to 0 to indicate fixed to zero constrains, 1 to indicate free intercepts, and higher integers to indicate equality constrains. For multiple groups, this argument can be a list or array with each element/column encoding such a vector.
Logical, should the model be automatically identified?
Type of identification used. "loadings"
to fix the first factor loadings to 1, and "variance"
to fix the diagonal of the latent variable model matrix (sigma_zeta, lowertri_zeta, delta_zeta or kappa_zeta) to 1.
An optional character vector with names of the latent variables.
Optional string indicating assessment beep per day. Adding this argument will cause non-consecutive beeps to be treated as missing!
Optional string indicating assessment day. Adding this argument makes sure that the first measurement of a day is not regressed on the last measurement of the previous day. IMPORTANT: only add this if the data has multiple observations per day.
Optional string indicating the subject ID
An optional character vector encoding the variables used in the analyis. Must equal names of the dataset in data
.
An optional string indicating the name of the group variable in data
.
A sample variance--covariance matrix, or a list/array of such matrices for multiple groups. Make sure covtype
argument is set correctly to the type of covariances used.
A vector of sample means, or a list/matrix containing such vectors for multiple groups.
The number of observations used in covs
and means
, or a vector of such numbers of observations for multiple groups.
How should missingness be handled in computing the sample covariances and number of observations when data
is used. Can be "listwise"
for listwise deletion, or "pairwise"
for pairwise deletion.
A character vector indicating which matrices should be constrained equal across groups.
A logical indicating if the baseline and saturated model should be included. Mostly used internally and NOT Recommended to be used manually.
The estimator to be used. Currently implemented are "ML"
for maximum likelihood estimation, "FIML"
for full-information maximum likelihood estimation, "ULS"
for unweighted least squares estimation, "WLS"
for weighted least squares estimation, and "DWLS"
for diagonally weighted least squares estimation.
The optimizer to be used. Can be one of "nlminb"
(the default R nlminb
function), "ucminf"
(from the optimr
package), and C++ based optimizers "cpp_L-BFGS-B"
, "cpp_BFGS"
, "cpp_CG"
, "cpp_SANN"
, and "cpp_Nelder-Mead"
. The C++ optimizers are faster but slightly less stable. Defaults to "nlminb"
.
Logical, should the raw data be stored? Needed for bootstrapping (see bootstrap
).
Which standardization method should be used? "none"
(default) for no standardization, "z"
for z-scores, and "quantile"
for a non-parametric transformation to the quantiles of the marginal standard normal distribution.
An optional sample statistics object. Mostly used internally.
Logical, should data be within-person centered?
If 'covs' is used, this is the type of covariance (maximum likelihood or unbiased) the input covariance matrix represents. Set to "ML"
for maximum likelihood estimates (denominator n) and "UB"
to unbiased estimates (denominator n-1). The default will try to find the type used, by investigating which is most likely to result from integer valued datasets.
Logical, should messages be printed?
Should the data be bootstrapped? If TRUE
the data are resampled and a bootstrap sample is created. These must be aggregated using aggregate_bootstraps
! Can be TRUE
or FALSE
. Can also be "nonparametric"
(which sets boot_sub = 1
and boot_resample = TRUE
) or "case"
(which sets boot_sub = 0.75
and boot_resample = FALSE
).
Proportion of cases to be subsampled (round(boot_sub * N)
).
Logical, should the bootstrap be with replacement (TRUE
) or without replacement (FALSE
)
Arguments sent to tsdlvm1
Sacha Epskamp
# Note: this example is wrapped in a dontrun environment because the data is not
# available locally.
if (FALSE) {
# Obtain the data from:
#
# Epskamp, S., van Borkulo, C. D., van der Veen, D. C., Servaas, M. N., Isvoranu, A. M.,
# Riese, H., & Cramer, A. O. (2018). Personalized network modeling in psychopathology:
# The importance of contemporaneous and temporal connections. Clinical Psychological
# Science, 6(3), 416-427.
#
# Available here: https://osf.io/c8wjz/
tsdata <- read.csv("Supplementary2_data.csv")
# Encode time variable in a way R understands:
tsdata$time <- as.POSIXct(tsdata$time, tz = "Europe/Amsterdam")
# Extract days:
tsdata$Day <- as.Date(tsdata$time, tz = "Europe/Amsterdam")
# Variables to use:
vars <- c("relaxed", "sad", "nervous", "concentration", "tired", "rumination",
"bodily.discomfort")
# Create lambda matrix (in this case: one factor):
Lambda <- matrix(1,7,1)
# Estimate dynamical factor model:
model <- tsdlvm1(
tsdata,
lambda = Lambda,
vars = vars,
dayvar = "Day",
estimator = "FIML"
)
# Run model:
model <- model %>% runmodel
# Look at fit:
model %>% print
model %>% fit # Pretty bad fit
}
Run the code above in your browser using DataLab