Monte Carlo Sampling Distribution for the Elements of the Standardized Matrix of Lagged Coefficients Over a Specific Time Interval or a Range of Time Intervals
Source:R/cTMed-mc-beta-std.R
MCBetaStd.RdThis function generates a Monte Carlo method sampling distribution for the elements of the standardized matrix of lagged coefficients \(\boldsymbol{\beta}\) over a specific time interval \(\Delta t\) or a range of time intervals using the first-order stochastic differential equation model drift matrix \(\boldsymbol{\Phi}\) and process noise covariance matrix \(\boldsymbol{\Sigma}\).
Usage
MCBetaStd(
phi,
sigma,
vcov_theta,
delta_t,
R,
test_phi = TRUE,
ncores = NULL,
seed = NULL,
tol = 0.01
)Arguments
- phi
Numeric matrix. The drift matrix (\(\boldsymbol{\Phi}\)).
phishould have row and column names pertaining to the variables in the system.- sigma
Numeric matrix. The process noise covariance matrix (\(\boldsymbol{\Sigma}\)).
- vcov_theta
Numeric matrix. The sampling variance-covariance matrix of \(\mathrm{vec} \left( \boldsymbol{\Phi} \right)\) and \(\mathrm{vech} \left( \boldsymbol{\Sigma} \right)\)
- delta_t
Numeric. Time interval (\(\Delta t\)).
- R
Positive integer. Number of replications.
- test_phi
Logical. If
test_phi = TRUE, the function tests the stability of the generated drift matrix \(\boldsymbol{\Phi}\). If the test returnsFALSE, the function generates a new drift matrix \(\boldsymbol{\Phi}\) and runs the test recursively until the test returnsTRUE.- ncores
Positive integer. Number of cores to use. If
ncores = NULL, use a single core. Consider using multiple cores when number of replicationsRis a large value.- seed
Random seed.
- tol
Numeric. Smallest possible time interval to allow.
Value
Returns an object
of class ctmedmc which is a list with the following elements:
- call
Function call.
- args
Function arguments.
- fun
Function used ("MCBetaStd").
- output
A list the length of which is equal to the length of
delta_t.
Each element in the output list has the following elements:
- est
Estimated elements of the standardized matrix of lagged coefficients.
- thetahatstar
A matrix of Monte Carlo elements of the standardized matrix of lagged coefficients.
Details
See TotalStd().
Monte Carlo Method
Let \(\boldsymbol{\theta}\) be a vector that combines \(\mathrm{vec} \left( \boldsymbol{\Phi} \right)\), that is, the elements of the \(\boldsymbol{\Phi}\) matrix in vector form sorted column-wise and \(\mathrm{vech} \left( \boldsymbol{\Sigma} \right)\), that is, the unique elements of the \(\boldsymbol{\Sigma}\) matrix in vector form sorted column-wise. Let \(\hat{\boldsymbol{\theta}}\) be a vector that combines \(\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right)\) and \(\mathrm{vech} \left( \hat{\boldsymbol{\Sigma}} \right)\). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters. $$ \hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right) $$ Using this distributional assumption, a sampling distribution of \(\hat{\boldsymbol{\theta}}\) which we refer to as \(\hat{\boldsymbol{\theta}}^{\ast}\) can be generated by replacing the population parameters with sample estimates, that is, $$ \hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) . $$ Let \(\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right)\) be a parameter that is a function of the estimated parameters. A sampling distribution of \(\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right)\) , which we refer to as \(\mathbf{g} \left( \hat{\boldsymbol{\theta}}^{\ast} \right)\) , can be generated by using the simulated estimates to calculate \(\mathbf{g}\). The standard deviations of the simulated estimates are the standard errors. Percentiles corresponding to \(100 \left( 1 - \alpha \right) \%\) are the confidence intervals.
References
Bollen, K. A. (1987). Total, direct, and indirect effects in structural equation models. Sociological Methodology, 17, 37. doi:10.2307/271028
Deboeck, P. R., & Preacher, K. J. (2015). No need to be discrete: A method for continuous time mediation analysis. Structural Equation Modeling: A Multidisciplinary Journal, 23 (1), 61–75. doi:10.1080/10705511.2014.973960
Pesigan, I. J. A., Russell, M. A., & Chow, S.-M. (2025). Inferences and effect sizes for direct, indirect, and total effects in continuous-time mediation models. Psychological Methods. doi:10.1037/met0000779
Ryan, O., & Hamaker, E. L. (2021). Time to intervene: A continuous-time approach to network analysis and centrality. Psychometrika, 87 (1), 214–252. doi:10.1007/s11336-021-09767-0
See also
Other Continuous-Time Mediation Functions:
BootBeta(),
BootBetaStd(),
BootIndirectCentral(),
BootMed(),
BootMedStd(),
BootTotalCentral(),
DeltaBeta(),
DeltaBetaStd(),
DeltaIndirectCentral(),
DeltaMed(),
DeltaMedStd(),
DeltaTotalCentral(),
Direct(),
DirectStd(),
Indirect(),
IndirectCentral(),
IndirectStd(),
MCBeta(),
MCIndirectCentral(),
MCMed(),
MCMedStd(),
MCPhi(),
MCPhiSigma(),
MCTotalCentral(),
Med(),
MedStd(),
PosteriorBeta(),
PosteriorIndirectCentral(),
PosteriorMed(),
PosteriorTotalCentral(),
Total(),
TotalCentral(),
TotalStd(),
Trajectory()
Examples
phi <- matrix(
data = c(
-0.357, 0.771, -0.450,
0.0, -0.511, 0.729,
0, 0, -0.693
),
nrow = 3
)
colnames(phi) <- rownames(phi) <- c("x", "m", "y")
sigma <- matrix(
data = c(
0.24455556, 0.02201587, -0.05004762,
0.02201587, 0.07067800, 0.01539456,
-0.05004762, 0.01539456, 0.07553061
),
nrow = 3
)
vcov_theta <- matrix(
data = c(
0.00843, 0.00040, -0.00151, -0.00600, -0.00033,
0.00110, 0.00324, 0.00020, -0.00061, -0.00115,
0.00011, 0.00015, 0.00001, -0.00002, -0.00001,
0.00040, 0.00374, 0.00016, -0.00022, -0.00273,
-0.00016, 0.00009, 0.00150, 0.00012, -0.00010,
-0.00026, 0.00002, 0.00012, 0.00004, -0.00001,
-0.00151, 0.00016, 0.00389, 0.00103, -0.00007,
-0.00283, -0.00050, 0.00000, 0.00156, 0.00021,
-0.00005, -0.00031, 0.00001, 0.00007, 0.00006,
-0.00600, -0.00022, 0.00103, 0.00644, 0.00031,
-0.00119, -0.00374, -0.00021, 0.00070, 0.00064,
-0.00015, -0.00005, 0.00000, 0.00003, -0.00001,
-0.00033, -0.00273, -0.00007, 0.00031, 0.00287,
0.00013, -0.00014, -0.00170, -0.00012, 0.00006,
0.00014, -0.00001, -0.00015, 0.00000, 0.00001,
0.00110, -0.00016, -0.00283, -0.00119, 0.00013,
0.00297, 0.00063, -0.00004, -0.00177, -0.00013,
0.00005, 0.00017, -0.00002, -0.00008, 0.00001,
0.00324, 0.00009, -0.00050, -0.00374, -0.00014,
0.00063, 0.00495, 0.00024, -0.00093, -0.00020,
0.00006, -0.00010, 0.00000, -0.00001, 0.00004,
0.00020, 0.00150, 0.00000, -0.00021, -0.00170,
-0.00004, 0.00024, 0.00214, 0.00012, -0.00002,
-0.00004, 0.00000, 0.00006, -0.00005, -0.00001,
-0.00061, 0.00012, 0.00156, 0.00070, -0.00012,
-0.00177, -0.00093, 0.00012, 0.00223, 0.00004,
-0.00002, -0.00003, 0.00001, 0.00003, -0.00013,
-0.00115, -0.00010, 0.00021, 0.00064, 0.00006,
-0.00013, -0.00020, -0.00002, 0.00004, 0.00057,
0.00001, -0.00009, 0.00000, 0.00000, 0.00001,
0.00011, -0.00026, -0.00005, -0.00015, 0.00014,
0.00005, 0.00006, -0.00004, -0.00002, 0.00001,
0.00012, 0.00001, 0.00000, -0.00002, 0.00000,
0.00015, 0.00002, -0.00031, -0.00005, -0.00001,
0.00017, -0.00010, 0.00000, -0.00003, -0.00009,
0.00001, 0.00014, 0.00000, 0.00000, -0.00005,
0.00001, 0.00012, 0.00001, 0.00000, -0.00015,
-0.00002, 0.00000, 0.00006, 0.00001, 0.00000,
0.00000, 0.00000, 0.00010, 0.00001, 0.00000,
-0.00002, 0.00004, 0.00007, 0.00003, 0.00000,
-0.00008, -0.00001, -0.00005, 0.00003, 0.00000,
-0.00002, 0.00000, 0.00001, 0.00005, 0.00001,
-0.00001, -0.00001, 0.00006, -0.00001, 0.00001,
0.00001, 0.00004, -0.00001, -0.00013, 0.00001,
0.00000, -0.00005, 0.00000, 0.00001, 0.00012
),
nrow = 15
)
# Specific time interval ----------------------------------------------------
MCBetaStd(
phi = phi,
sigma = sigma,
vcov_theta = vcov_theta,
delta_t = 1,
R = 100L # use a large value for R in actual research
)
#> Call:
#> MCBetaStd(phi = phi, sigma = sigma, vcov_theta = vcov_theta,
#> delta_t = 1, R = 100L)
#>
#> Total, Direct, and Indirect Effects
#>
#> effect interval est se R 2.5% 97.5%
#> 1 from x to x 1 0.6998 0.0493 100 0.5952 0.8043
#> 2 from x to m 1 0.3888 0.0275 100 0.3294 0.4295
#> 3 from x to y 1 -0.1069 0.0353 100 -0.1865 -0.0383
#> 4 from m to x 1 0.0000 0.0501 100 -0.0907 0.0962
#> 5 from m to m 1 0.5999 0.0307 100 0.5578 0.6694
#> 6 from m to y 1 0.5494 0.0394 100 0.4636 0.6343
#> 7 from y to x 1 0.0000 0.0358 100 -0.0736 0.0636
#> 8 from y to m 1 0.0000 0.0217 100 -0.0488 0.0367
#> 9 from y to y 1 0.5001 0.0286 100 0.4538 0.5538
# Range of time intervals ---------------------------------------------------
mc <- MCBetaStd(
phi = phi,
sigma = sigma,
vcov_theta = vcov_theta,
delta_t = 1:5,
R = 100L # use a large value for R in actual research
)
plot(mc)
# Methods -------------------------------------------------------------------
# MCBetaStd has a number of methods including
# print, summary, confint, and plot
print(mc)
#> Call:
#> MCBetaStd(phi = phi, sigma = sigma, vcov_theta = vcov_theta,
#> delta_t = 1:5, R = 100L)
#>
#> Total, Direct, and Indirect Effects
#>
#> effect interval est se R 2.5% 97.5%
#> 1 from x to x 1 0.6998 0.0458 100 0.6098 0.7961
#> 2 from x to m 1 0.3888 0.0277 100 0.3403 0.4361
#> 3 from x to y 1 -0.1069 0.0337 100 -0.1713 -0.0391
#> 4 from m to x 1 0.0000 0.0541 100 -0.1146 0.1092
#> 5 from m to m 1 0.5999 0.0323 100 0.5396 0.6545
#> 6 from m to y 1 0.5494 0.0359 100 0.4864 0.6221
#> 7 from y to x 1 0.0000 0.0416 100 -0.0700 0.0842
#> 8 from y to m 1 0.0000 0.0229 100 -0.0385 0.0466
#> 9 from y to y 1 0.5001 0.0265 100 0.4555 0.5554
#> 10 from x to x 2 0.4897 0.0530 100 0.4098 0.6038
#> 11 from x to m 2 0.5053 0.0376 100 0.4387 0.5810
#> 12 from x to y 2 0.0854 0.0385 100 0.0165 0.1550
#> 13 from m to x 2 0.0000 0.0620 100 -0.1285 0.1200
#> 14 from m to m 2 0.3599 0.0482 100 0.2711 0.4316
#> 15 from m to y 2 0.6044 0.0409 100 0.5299 0.6692
#> 16 from y to x 2 0.0000 0.0502 100 -0.0870 0.1036
#> 17 from y to m 2 0.0000 0.0364 100 -0.0627 0.0748
#> 18 from y to y 2 0.2501 0.0307 100 0.1958 0.3056
#> 19 from x to x 3 0.3427 0.0528 100 0.2622 0.4434
#> 20 from x to m 3 0.4936 0.0427 100 0.4220 0.5822
#> 21 from x to y 3 0.2680 0.0363 100 0.1941 0.3368
#> 22 from m to x 3 0.0000 0.0597 100 -0.1136 0.1074
#> 23 from m to m 3 0.2159 0.0565 100 0.1054 0.3108
#> 24 from m to y 3 0.4999 0.0450 100 0.4214 0.5896
#> 25 from y to x 3 0.0000 0.0460 100 -0.0806 0.0938
#> 26 from y to m 3 0.0000 0.0438 100 -0.0759 0.0835
#> 27 from y to y 3 0.1251 0.0288 100 0.0732 0.1724
#> 28 from x to x 4 0.2398 0.0514 100 0.1597 0.3290
#> 29 from x to m 4 0.4293 0.0454 100 0.3589 0.5204
#> 30 from x to y 4 0.3686 0.0358 100 0.3038 0.4534
#> 31 from m to x 4 0.0000 0.0555 100 -0.0927 0.1129
#> 32 from m to m 4 0.1295 0.0593 100 0.0053 0.2421
#> 33 from m to y 4 0.3686 0.0495 100 0.2854 0.4576
#> 34 from y to x 4 0.0000 0.0380 100 -0.0671 0.0769
#> 35 from y to m 4 0.0000 0.0452 100 -0.0817 0.0864
#> 36 from y to y 4 0.0625 0.0304 100 0.0085 0.1241
#> 37 from x to x 5 0.1678 0.0499 100 0.0819 0.2714
#> 38 from x to m 5 0.3508 0.0468 100 0.2665 0.4416
#> 39 from x to y 5 0.3946 0.0385 100 0.3385 0.4786
#> 40 from m to x 5 0.0000 0.0502 100 -0.0711 0.1098
#> 41 from m to m 5 0.0777 0.0586 100 -0.0316 0.2029
#> 42 from m to y 5 0.2555 0.0518 100 0.1590 0.3509
#> 43 from y to x 5 0.0000 0.0299 100 -0.0516 0.0589
#> 44 from y to m 5 0.0000 0.0425 100 -0.0761 0.0825
#> 45 from y to y 5 0.0313 0.0342 100 -0.0316 0.0922
summary(mc)
#> Call:
#> MCBetaStd(phi = phi, sigma = sigma, vcov_theta = vcov_theta,
#> delta_t = 1:5, R = 100L)
#>
#> Total, Direct, and Indirect Effects
#>
#> effect interval est se R 2.5% 97.5%
#> 1 from x to x 1 0.6998 0.0458 100 0.6098 0.7961
#> 2 from x to m 1 0.3888 0.0277 100 0.3403 0.4361
#> 3 from x to y 1 -0.1069 0.0337 100 -0.1713 -0.0391
#> 4 from m to x 1 0.0000 0.0541 100 -0.1146 0.1092
#> 5 from m to m 1 0.5999 0.0323 100 0.5396 0.6545
#> 6 from m to y 1 0.5494 0.0359 100 0.4864 0.6221
#> 7 from y to x 1 0.0000 0.0416 100 -0.0700 0.0842
#> 8 from y to m 1 0.0000 0.0229 100 -0.0385 0.0466
#> 9 from y to y 1 0.5001 0.0265 100 0.4555 0.5554
#> 10 from x to x 2 0.4897 0.0530 100 0.4098 0.6038
#> 11 from x to m 2 0.5053 0.0376 100 0.4387 0.5810
#> 12 from x to y 2 0.0854 0.0385 100 0.0165 0.1550
#> 13 from m to x 2 0.0000 0.0620 100 -0.1285 0.1200
#> 14 from m to m 2 0.3599 0.0482 100 0.2711 0.4316
#> 15 from m to y 2 0.6044 0.0409 100 0.5299 0.6692
#> 16 from y to x 2 0.0000 0.0502 100 -0.0870 0.1036
#> 17 from y to m 2 0.0000 0.0364 100 -0.0627 0.0748
#> 18 from y to y 2 0.2501 0.0307 100 0.1958 0.3056
#> 19 from x to x 3 0.3427 0.0528 100 0.2622 0.4434
#> 20 from x to m 3 0.4936 0.0427 100 0.4220 0.5822
#> 21 from x to y 3 0.2680 0.0363 100 0.1941 0.3368
#> 22 from m to x 3 0.0000 0.0597 100 -0.1136 0.1074
#> 23 from m to m 3 0.2159 0.0565 100 0.1054 0.3108
#> 24 from m to y 3 0.4999 0.0450 100 0.4214 0.5896
#> 25 from y to x 3 0.0000 0.0460 100 -0.0806 0.0938
#> 26 from y to m 3 0.0000 0.0438 100 -0.0759 0.0835
#> 27 from y to y 3 0.1251 0.0288 100 0.0732 0.1724
#> 28 from x to x 4 0.2398 0.0514 100 0.1597 0.3290
#> 29 from x to m 4 0.4293 0.0454 100 0.3589 0.5204
#> 30 from x to y 4 0.3686 0.0358 100 0.3038 0.4534
#> 31 from m to x 4 0.0000 0.0555 100 -0.0927 0.1129
#> 32 from m to m 4 0.1295 0.0593 100 0.0053 0.2421
#> 33 from m to y 4 0.3686 0.0495 100 0.2854 0.4576
#> 34 from y to x 4 0.0000 0.0380 100 -0.0671 0.0769
#> 35 from y to m 4 0.0000 0.0452 100 -0.0817 0.0864
#> 36 from y to y 4 0.0625 0.0304 100 0.0085 0.1241
#> 37 from x to x 5 0.1678 0.0499 100 0.0819 0.2714
#> 38 from x to m 5 0.3508 0.0468 100 0.2665 0.4416
#> 39 from x to y 5 0.3946 0.0385 100 0.3385 0.4786
#> 40 from m to x 5 0.0000 0.0502 100 -0.0711 0.1098
#> 41 from m to m 5 0.0777 0.0586 100 -0.0316 0.2029
#> 42 from m to y 5 0.2555 0.0518 100 0.1590 0.3509
#> 43 from y to x 5 0.0000 0.0299 100 -0.0516 0.0589
#> 44 from y to m 5 0.0000 0.0425 100 -0.0761 0.0825
#> 45 from y to y 5 0.0313 0.0342 100 -0.0316 0.0922
confint(mc, level = 0.95)
#> effect interval 2.5 % 97.5 %
#> 1 from x to x 1 0.60980026 0.79613691
#> 2 from x to m 1 0.34030143 0.43607954
#> 3 from x to y 1 -0.17134324 -0.03910697
#> 4 from x to x 2 0.40979261 0.60379349
#> 5 from x to m 2 0.43870397 0.58099242
#> 6 from x to y 2 0.01652097 0.15495342
#> 7 from x to x 3 0.26218727 0.44344399
#> 8 from x to m 3 0.42197725 0.58218446
#> 9 from x to y 3 0.19406457 0.33680333
#> 10 from x to x 4 0.15968127 0.32901570
#> 11 from x to m 4 0.35892031 0.52043922
#> 12 from x to y 4 0.30375980 0.45341980
#> 13 from x to x 5 0.08188246 0.27142605
#> 14 from x to m 5 0.26647254 0.44158762
#> 15 from x to y 5 0.33845203 0.47862426
plot(mc)