Meta-Regression
Ivan Jacob Agaloos Pesigan
2026-01-07
Source:vignettes/covariate-1000.Rmd
covariate-1000.RmdDynamics Description
The Stable Persistence with Baseline-Moderated Autoregression process represents a bivariate dynamic system in which two latent psychological constructs (e.g., positive and negative affect) exhibit within-construct persistence over time through autoregressive dynamics. The transition matrix is diagonal, implying that each construct evolves according to its own self-regulatory process and there are no cross-lagged (reciprocal) influences between the constructs in the systematic dynamics.
Between-person heterogeneity in persistence is captured via a time-invariant baseline covariate with one value per individual. The individual-specific transition matrix is modeled as so that individuals with follows , whereas individuals with follow . Under the current specification, increases the diagonal autoregressive parameters, implying that the group exhibits greater persistenceβdeviations from an individualβs equilibrium decay more slowlyβwhile remaining dynamically stable.
Between-person heterogeneity in baseline levels is also captured via the same time-invariant covariate through the person-specific measurement intercept vector so that individuals with follow , whereas individuals with follow .
The process noise covariance allows for small disturbances that may be correlated across constructs, permitting coordinated innovations even though the lagged dynamics are decoupled. Measurement errors are assumed to be minimal and symmetric across indicators.
Model
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 person-specific intercepts while denotes a matrix of factor loadings, and the covariance matrix of that is invariant across individuals. In this model, is an identity matrix and is a symmetric matrix.
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 . is a matrix of autoregression and cross regression coefficients for individual , and the covariance matrix of that is invariant across all individuals. In this model, is a symmetric matrix.
Data Generation
Notation
Let be the number of time points and be the number of individuals. We simulate a total of time points per individual, discarding the first as burn-in. The analysis uses the final measurement occasions.
Let the measurement model intercept vector when be
Let the measurement model intercept vector when be
Let the covariance matrix be
Let the factor loadings matrix be given by
Let the measurement error covariance matrix be given by
Let the initial condition be given by
and are functions of and .
Let the transition matrix when be
Let the transition matrix when be
Let the covariance matrix be
Let the intercept vector be fixed to a zero vector.
The SimNuN and SimBetaN functions from the
simStateSpace package generate random intercept vectors and
transition matrices from the multivariate normal distribution. Note that
the SimBetaN function generates transition matrices that
are weakly stationary with an option to set lower and upper bounds.
Let the dynamic process noise be given by
R Function Arguments
n
#> [1] 1000
time
#> [1] 11000
burnin
#> [1] 10000
# first mu0 in the list of length n
mu0[[1]]
#> [1] 0 0
# first sigma0 in the list of length n
sigma0[[1]]
#> [,1] [,2]
#> [1,] 0.262246668 -0.001346401
#> [2,] -0.001346401 0.308495216
# first sigma0_l in the list of length n
sigma0_l[[1]] # sigma0_l <- t(chol(sigma0))
#> [,1] [,2]
#> [1,] 0.512100252 0.0000000
#> [2,] -0.002629174 0.5554172
alpha
#> [[1]]
#> [1] 0 0
# first beta in the list of length n
beta[[1]]
#> [,1] [,2]
#> [1,] 0.42483430 0.221745
#> [2,] 0.04454242 0.644272
# first psi in the list of length n
psi[[1]]
#> [,1] [,2]
#> [1,] 0.20 -0.05
#> [2,] -0.05 0.18
psi_l[[1]] # psi_l <- t(chol(psi))
#> [,1] [,2]
#> [1,] 0.4472136 0.0000000
#> [2,] -0.1118034 0.4092676
# first nu in the list of length n
nu[[1]]
#> [1] 0.2385858 -0.4148773
lambda
#> [[1]]
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 0 1
# first theta in the list of length n
theta[[1]]
#> [,1] [,2]
#> [1,] 0.5 0.0
#> [2,] 0.0 0.5
theta_l[[1]] # theta_l <- t(chol(theta))
#> [,1] [,2]
#> [1,] 0.7071068 0.0000000
#> [2,] 0.0000000 0.7071068Visualizing the Dynamics Without Process Noise and Measurement Error (n = 5 with Different Initial Condition)
Using the SimSSMIVary Function from the
simStateSpace Package to Simulate Data
library(simStateSpace)
sim <- 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
)
data <- as.data.frame(sim, burnin = burnin)
head(data)
#> id time y1 y2
#> 1 1 0 0.2872498 -0.6916122
#> 2 1 1 0.2706470 -1.9931501
#> 3 1 2 -0.3722643 -1.7091924
#> 4 1 3 -0.9400761 -0.6043939
#> 5 1 4 0.1432300 -0.1997853
#> 6 1 5 -0.8617044 -1.4859587
plot(sim, burnin = burnin)

Model Fitting
The FitDTVARMxID function fits a DT-VAR model on each
individual
.
To set up the estimation, we first provide starting
values for each parameter matrix.
Autoregressive Parameters (beta)
We initialize the autoregressive coefficient matrix with the true values used in simulation.
beta_values <- betaLDLβ-parameterized covariance matrices
Covariances such as psi and theta are
estimated using the LDLβ decomposition of a positive definite covariance
matrix. The decomposition expresses a covariance matrix
as
where:
-
is a strictly lower-triangular matrix of free parameters
(
l_mat_strict),
-
is the identity matrix,
-
is an unconstrained vector,
- ensures strictly positive diagonal entries.
The LDL() function extracts this decomposition from a
positive definite covariance matrix. It returns:
-
d_uc: unconstrained diagonal parameters, equal toInvSoftplus(d_vec),
-
d_vec: diagonal entries, equal toSoftplus(d_uc),
-
l_mat_strict: the strictly lower-triangular factor.
sigma <- matrix(
data = c(1.0, 0.5, 0.5, 1.0),
nrow = 2,
ncol = 2
)
ldl_sigma <- LDL(sigma)
d_uc <- ldl_sigma$d_uc
l_mat_strict <- ldl_sigma$l_mat_strict
I <- diag(2)
sigma_reconstructed <- (l_mat_strict + I) %*% diag(log1p(exp(d_uc)), 2) %*% t(l_mat_strict + I)
sigma_reconstructed
#> [,1] [,2]
#> [1,] 1.0 0.5
#> [2,] 0.5 1.0Process Noise Covariance Matrix (psi)
Starting values for the process noise covariance matrix are given below, with corresponding LDLβ parameters.
psi_values <- psi[[1]]
ldl_psi_values <- LDL(psi_values)
psi_d_values <- ldl_psi_values$d_uc
psi_l_values <- ldl_psi_values$l_mat_strict
psi_d_values
#> [1] -1.507772 -1.701853
psi_l_values
#> [,1] [,2]
#> [1,] 0.00 0
#> [2,] -0.25 0Measurement Error Covariance Matrix (theta)
Starting values for the measurement error covariance matrix are given below, with corresponding LDLβ parameters.
theta_values <- theta[[1]]
ldl_theta_values <- LDL(theta_values)
theta_d_values <- ldl_theta_values$d_uc
theta_l_values <- ldl_theta_values$l_mat_strict
theta_d_values
#> [1] -0.4327521 -0.4327521
theta_l_values
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 0Initial mean vector (mu_0) and covariance matrix
(sigma_0)
The initial mean vector
and covariance matrix
are fixed using mu0 and sigma0.
mu0_values <- mu0
FitDTVARMxID
fit <- FitDTVARMxID(
data = data,
observed = c("y1", "y2"),
id = "id",
beta_values = beta_values,
psi_d_values = psi_d_values,
psi_l_values = psi_l_values,
nu_values = nu_values,
theta_d_values = theta_d_values,
mu0_values = mu0_values,
sigma0_d_values = sigma0_d_values,
sigma0_l_values = sigma0_l_values,
ncores = parallel::detectCores()
)Parameter estimates
head(summary(fit))
#> beta_1_1 beta_2_1 beta_1_2 beta_2_2
#> FitDTVARMxID_DTVAR_ID1.Rds 0.33644408 -0.03209863 0.318846292 0.6807778
#> FitDTVARMxID_DTVAR_ID2.Rds 0.62567783 -0.17846007 0.123453552 0.6296121
#> FitDTVARMxID_DTVAR_ID3.Rds 0.09819451 0.08962127 -0.002754802 0.4383317
#> FitDTVARMxID_DTVAR_ID4.Rds 0.28742898 -0.03281429 -0.169973672 0.6842083
#> FitDTVARMxID_DTVAR_ID5.Rds 0.08558152 -0.07288266 -0.267141770 0.4906759
#> FitDTVARMxID_DTVAR_ID6.Rds 0.22670586 0.06997922 0.019772706 0.7480872
#> nu_1_1 nu_2_1 psi_l_2_1 psi_d_1_1
#> FitDTVARMxID_DTVAR_ID1.Rds 0.2583896 -0.3564194 -0.16301521 -1.08509141
#> FitDTVARMxID_DTVAR_ID2.Rds 0.2656604 -0.4698957 -0.28730189 -1.52500886
#> FitDTVARMxID_DTVAR_ID3.Rds 0.2478289 -0.3466180 -0.11594453 0.14494750
#> FitDTVARMxID_DTVAR_ID4.Rds 0.5153719 -0.9226855 -0.10097599 -0.79071180
#> FitDTVARMxID_DTVAR_ID5.Rds 1.1084806 -0.6444617 -0.06681118 0.05789134
#> FitDTVARMxID_DTVAR_ID6.Rds -0.3088867 -0.3694615 -0.01724393 -0.42154417
#> psi_d_2_1 theta_d_1_1 theta_d_2_1
#> FitDTVARMxID_DTVAR_ID1.Rds -1.945558 -0.4447790 -0.4494438
#> FitDTVARMxID_DTVAR_ID2.Rds -1.745820 -0.3231276 -0.4200812
#> FitDTVARMxID_DTVAR_ID3.Rds -1.600583 -15.4682616 -0.4306897
#> FitDTVARMxID_DTVAR_ID4.Rds -1.481722 -0.8214105 -0.5045569
#> FitDTVARMxID_DTVAR_ID5.Rds -1.672542 -15.9901651 -0.4509705
#> FitDTVARMxID_DTVAR_ID6.Rds -2.211068 -1.3495034 -0.4493015Proportion of converged cases
converged(
fit,
theta_tol = 0.01,
prop = TRUE
)
#> [1] 0.911Fixed-Effect Meta-Analysis of Measurement Error
When fitting DT-VAR models per person, separating process noise () from measurement error () can be unstable for some individuals. To stabilize inference, we first pool the person-level estimates from only the converged fits using a fixed-effect meta-analysis. This yields a high-precision estimate of the common measurement-error covariance that we will then hold fixed in a second pass of model fitting.
What the code does: - Selects individuals that converged and whose
diagonals exceed a small threshold (theta_tol), filtering
out near-zero or ill-conditioned solutions. - Extracts each personβs
LDLβ diagonal parameters for
and their sampling covariance matrices. - Computes the
inverse-variance-weighted pooled estimate (fixed effect), returning it
on the same LDLβ parameterization used by
FitDTVARMxID().
library(metaVAR)
fixed_theta <- MetaVARMx(
fit,
random = FALSE, # TRUE by default
effects = FALSE, # TRUE by default
cov_meas = TRUE, # FALSE by default
theta_tol = 0.01,
ncores = parallel::detectCores()
)You can read summary(fixed_theta) as providing the
pooled (fixed) measurement-error scale that is common across persons. If
individual instruments truly share the same reliability structure,
fixing
to this pooled value improves stability and often reduces bias in the
dynamic parameters.
Note: Fixed-effect pooling assumes a common across individuals.
coef(fixed_theta)
#> alpha_1_1 alpha_2_1
#> -0.3800600 -0.3939168
summary(fixed_theta)
#> [1] 0
#> Call:
#> MetaVARMx(object = fit, random = FALSE, effects = FALSE, cov_meas = TRUE,
#> theta_tol = 0.01, ncores = parallel::detectCores())
#>
#> CI type = "normal"
#> est se z p 2.5% 97.5%
#> alpha[1,1] -0.3801 0.0045 -84.0134 0 -0.3889 -0.3712
#> alpha[2,1] -0.3939 0.0043 -90.9131 0 -0.4024 -0.3854
theta_d_values <- coef(fixed_theta)Refit the model with fixed measurement error covariance matrix
We refit the individual models using the pooled as a fixed measurement-error covariance matrix.
fit <- FitDTVARMxID(
data = data,
observed = c("y1", "y2"),
id = "id",
beta_values = beta_values,
psi_d_values = psi_d_values,
psi_l_values = psi_l_values,
nu_values = nu_values,
theta_fixed = TRUE,
theta_d_values = theta_d_values,
mu0_values = mu0_values,
sigma0_d_values = sigma0_d_values,
sigma0_l_values = sigma0_l_values,
ncores = parallel::detectCores()
)With fixed, the re-estimation focuses on the dynamic structure (, ) and intercepts (). In practice, this often increases the proportion of converged fits and yields more stable cross-lag estimates.
Proportion of converged cases
converged(
fit,
prop = TRUE
)
#> Error in `x$output`:
#> ! $ operator is invalid for atomic vectorsMixed-Effects Meta-Analysis of Person-Specific Dynamics and Means
Having stabilized , we synthesize the person-specific estimates to recover population-level effects, between-person variability, and systematic covariate-related differences. We fit a mixed-effects meta-analytic model in which each individualβs estimate is weighted by its within-person sampling uncertainty, random effects capture residual heterogeneity across individuals, and fixed effects quantify the association between covariate and the person-specific dynamic parameters.
mixed <- MetaVARMx(
fit,
x = x,
effects = TRUE,
int_meas = TRUE,
robust_v = FALSE,
robust = TRUE,
ncores = parallel::detectCores()
)
#> Error in `x$output`:
#> ! $ operator is invalid for atomic vectors
summary(mixed)
#> Error:
#> ! object 'mixed' not foundNormal Theory Confidence Intervals
confint(mixed, level = 0.95, lb = FALSE)
#> Error:
#> ! object 'mixed' not found
confint(mixed, level = 0.99, lb = FALSE)
#> Error:
#> ! object 'mixed' not foundRobust Confidence Intervals
confint(mixed, level = 0.95, lb = FALSE, robust = TRUE)
#> Error:
#> ! object 'mixed' not found
confint(mixed, level = 0.99, lb = FALSE, robust = TRUE)
#> Error:
#> ! object 'mixed' not foundProfile-Likelihood Confidence Intervals
confint(mixed, level = 0.95, lb = TRUE)
#> Error:
#> ! object 'mixed' not found
confint(mixed, level = 0.99, lb = TRUE)
#> Error:
#> ! object 'mixed' not found- The fixed part of the random-effects model gives pooled means .
- The random part yields between-person covariances () quantifying heterogeneity in dynamics () and means () across individuals.
means <- extract(mixed, what = "alpha")
#> Error:
#> ! object 'mixed' not found
means
#> Error:
#> ! object 'means' not found
covariances <- extract(mixed, what = "tau_sqr")
#> Error:
#> ! object 'mixed' not found
covariances
#> Error:
#> ! object 'covariances' not foundFinally, we compare the meta-analytic population estimates to the known generating values.
beta_pop_mean
#> [1] 0.608857758 -0.007162951 -0.003195778 0.618151352
beta_pop_cov
#> [,1] [,2] [,3] [,4]
#> [1,] 0.031250377 0.0084594085 -0.001357726 0.0126662858
#> [2,] 0.008459408 0.0139070808 -0.001129366 -0.0006591882
#> [3,] -0.001357726 -0.0011293659 0.010097588 0.0047962721
#> [4,] 0.012666286 -0.0006591882 0.004796272 0.0281857098
nu_mu
#> [1] 0.625 -0.625
nu_sigma
#> [,1] [,2]
#> [1,] 0.10 -0.05
#> [2,] -0.05 0.10Summary
This vignette demonstrates a two-stage hierarchical estimation approach for dynamic systems: 1. Individual-level DT-VAR estimation with stabilized measurement error. 2. Population-level meta-analysis of person-specific dynamics and means. 3. Estimation and interpretation of covariate effects, where predicts systematic between-person differences in dynamics and baseline levels.



