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.Rd
This 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}\)).
phi
should 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 replicationsR
is 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
A vector of total, direct, and indirect effects.
- thetahatstar
A matrix of Monte Carlo total, direct, and indirect effects.
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
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:
DeltaBeta()
,
DeltaBetaStd()
,
DeltaIndirectCentral()
,
DeltaMed()
,
DeltaMedStd()
,
DeltaTotalCentral()
,
Direct()
,
DirectStd()
,
ExpCov()
,
ExpMean()
,
Indirect()
,
IndirectCentral()
,
IndirectStd()
,
MCBeta()
,
MCIndirectCentral()
,
MCMed()
,
MCMedStd()
,
MCPhi()
,
MCTotalCentral()
,
Med()
,
MedStd()
,
PosteriorBeta()
,
PosteriorIndirectCentral()
,
PosteriorMed()
,
PosteriorPhi()
,
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
)
#>
#> Total, Direct, and Indirect Effects
#>
#> $`1`
#> interval est se R 2.5% 97.5%
#> from x to x 1 0.6998 0.0493 100 0.5952 0.8043
#> from x to m 1 0.6431 0.0602 100 0.5296 0.7398
#> from x to y 1 -0.0936 0.0293 100 -0.1598 -0.0374
#> from m to x 1 0.0000 0.0300 100 -0.0597 0.0539
#> from m to m 1 0.5999 0.0307 100 0.5578 0.6694
#> from m to y 1 0.2910 0.0334 100 0.2267 0.3586
#> from y to x 1 0.0000 0.0406 100 -0.0868 0.0679
#> from y to m 1 0.0000 0.0402 100 -0.0903 0.0675
#> 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)
#>
#> Total, Direct, and Indirect Effects
#>
#> $`1`
#> interval est se R 2.5% 97.5%
#> from x to x 1 0.6998 0.0458 100 0.6098 0.7961
#> from x to m 1 0.6431 0.0611 100 0.5191 0.7461
#> from x to y 1 -0.0936 0.0308 100 -0.1478 -0.0331
#> from m to x 1 0.0000 0.0329 100 -0.0700 0.0663
#> from m to m 1 0.5999 0.0323 100 0.5396 0.6545
#> from m to y 1 0.2910 0.0343 100 0.2239 0.3534
#> from y to x 1 0.0000 0.0491 100 -0.0906 0.0967
#> from y to m 1 0.0000 0.0437 100 -0.0783 0.0921
#> from y to y 1 0.5001 0.0265 100 0.4555 0.5554
#>
#> $`2`
#> interval est se R 2.5% 97.5%
#> from x to x 2 0.4897 0.0530 100 0.4098 0.6038
#> from x to m 2 0.8358 0.0888 100 0.6649 1.0185
#> from x to y 2 0.0748 0.0335 100 0.0168 0.1327
#> from m to x 2 0.0000 0.0380 100 -0.0759 0.0709
#> from m to m 2 0.3599 0.0482 100 0.2711 0.4316
#> from m to y 2 0.3201 0.0422 100 0.2401 0.3978
#> from y to x 2 0.0000 0.0593 100 -0.1127 0.1189
#> from y to m 2 0.0000 0.0710 100 -0.1387 0.1536
#> from y to y 2 0.2501 0.0307 100 0.1958 0.3056
#>
#> $`3`
#> interval est se R 2.5% 97.5%
#> from x to x 3 0.3427 0.0528 100 0.2622 0.4434
#> from x to m 3 0.8163 0.1018 100 0.6309 1.0390
#> from x to y 3 0.2347 0.0402 100 0.1531 0.3107
#> from m to x 3 0.0000 0.0368 100 -0.0757 0.0662
#> from m to m 3 0.2159 0.0565 100 0.1054 0.3108
#> from m to y 3 0.2648 0.0408 100 0.2010 0.3370
#> from y to x 3 0.0000 0.0545 100 -0.1086 0.1092
#> from y to m 3 0.0000 0.0863 100 -0.1674 0.1770
#> from y to y 3 0.1251 0.0288 100 0.0732 0.1724
#>
#> $`4`
#> interval est se R 2.5% 97.5%
#> from x to x 4 0.2398 0.0514 100 0.1597 0.3290
#> from x to m 4 0.7100 0.1056 100 0.5187 0.9042
#> from x to y 4 0.3228 0.0484 100 0.2308 0.4005
#> from m to x 4 0.0000 0.0341 100 -0.0606 0.0648
#> from m to m 4 0.1295 0.0593 100 0.0053 0.2421
#> from m to y 4 0.1952 0.0371 100 0.1379 0.2667
#> from y to x 4 0.0000 0.0451 100 -0.0931 0.0901
#> from y to m 4 0.0000 0.0895 100 -0.1726 0.1834
#> from y to y 4 0.0625 0.0304 100 0.0085 0.1241
#>
#> $`5`
#> interval est se R 2.5% 97.5%
#> from x to x 5 0.1678 0.0499 100 0.0819 0.2714
#> from x to m 5 0.5801 0.1042 100 0.4017 0.7781
#> from x to y 5 0.3456 0.0533 100 0.2481 0.4319
#> from m to x 5 0.0000 0.0306 100 -0.0463 0.0624
#> from m to m 5 0.0777 0.0586 100 -0.0316 0.2029
#> from m to y 5 0.1353 0.0333 100 0.0801 0.2110
#> from y to x 5 0.0000 0.0355 100 -0.0742 0.0717
#> from y to m 5 0.0000 0.0842 100 -0.1631 0.1751
#> from y to y 5 0.0313 0.0342 100 -0.0316 0.0922
#>
summary(mc)
#> effect interval est se R 2.5% 97.5%
#> 1 from x to x 1 0.69977250 0.04584153 100 0.609800263 0.79613691
#> 2 from x to m 1 0.64305123 0.06107286 100 0.519148738 0.74607761
#> 3 from x to y 1 -0.09362266 0.03082226 100 -0.147833303 -0.03305380
#> 4 from m to x 1 0.00000000 0.03285078 100 -0.069992148 0.06627580
#> 5 from m to m 1 0.59989538 0.03228086 100 0.539629131 0.65446006
#> 6 from m to y 1 0.29097114 0.03431410 100 0.223884728 0.35336463
#> 7 from y to x 1 0.00000000 0.04906143 100 -0.090584175 0.09665912
#> 8 from y to m 1 0.00000000 0.04374754 100 -0.078297350 0.09211496
#> 9 from y to y 1 0.50007360 0.02653763 100 0.455466431 0.55535984
#> 10 from x to x 2 0.48968155 0.05301609 100 0.409792609 0.60379349
#> 11 from x to m 2 0.83575303 0.08882911 100 0.664948568 1.01848001
#> 12 from x to y 2 0.07477656 0.03349774 100 0.016831311 0.13266731
#> 13 from m to x 2 0.00000000 0.03799167 100 -0.075854198 0.07087936
#> 14 from m to m 2 0.35987447 0.04819742 100 0.271065357 0.43159309
#> 15 from m to y 2 0.32005923 0.04216573 100 0.240076590 0.39777384
#> 16 from y to x 2 0.00000000 0.05925698 100 -0.112688188 0.11891119
#> 17 from y to m 2 0.00000000 0.07101512 100 -0.138685595 0.15360907
#> 18 from y to y 2 0.25007360 0.03074378 100 0.195824888 0.30557324
#> 19 from x to x 3 0.34266568 0.05281164 100 0.262187269 0.44344399
#> 20 from x to m 3 0.81625470 0.10176909 100 0.630919685 1.03896483
#> 21 from x to y 3 0.23472850 0.04020028 100 0.153064797 0.31066530
#> 22 from m to x 3 0.00000000 0.03678810 100 -0.075735196 0.06618000
#> 23 from m to m 3 0.21588703 0.05650342 100 0.105419527 0.31077230
#> 24 from m to y 3 0.26476625 0.04084706 100 0.201014046 0.33696528
#> 25 from y to x 3 0.00000000 0.05445263 100 -0.108583370 0.10916445
#> 26 from y to m 3 0.00000000 0.08625937 100 -0.167431878 0.17704028
#> 27 from y to y 3 0.12505520 0.02884224 100 0.073229218 0.17243310
#> 28 from x to x 4 0.23978802 0.05135378 100 0.159681273 0.32901570
#> 29 from x to m 4 0.71001902 0.10557275 100 0.518734763 0.90421448
#> 30 from x to y 4 0.32280682 0.04838026 100 0.230816624 0.40048630
#> 31 from m to x 4 0.00000000 0.03412011 100 -0.060587700 0.06484830
#> 32 from m to m 4 0.12950963 0.05928525 100 0.005256487 0.24206241
#> 33 from m to y 4 0.19521951 0.03708142 100 0.137908648 0.26666072
#> 34 from y to x 4 0.00000000 0.04510787 100 -0.093080065 0.09007644
#> 35 from y to m 4 0.00000000 0.08952871 100 -0.172617173 0.18342496
#> 36 from y to y 4 0.06253681 0.03037461 100 0.008546347 0.12408688
#> 37 from x to x 5 0.16779706 0.04985991 100 0.081882464 0.27142605
#> 38 from x to m 5 0.58013311 0.10422186 100 0.401698957 0.77806584
#> 39 from x to y 5 0.34557261 0.05327086 100 0.248137200 0.43188522
#> 40 from m to x 5 0.00000000 0.03064022 100 -0.046282326 0.06237870
#> 41 from m to m 5 0.07769223 0.05857726 100 -0.031648320 0.20294748
#> 42 from m to y 5 0.13530769 0.03333196 100 0.080096851 0.21099729
#> 43 from y to x 5 0.00000000 0.03552980 100 -0.074199603 0.07173185
#> 44 from y to m 5 0.00000000 0.08423069 100 -0.163089957 0.17514459
#> 45 from y to y 5 0.03127301 0.03419857 100 -0.031634742 0.09222349
confint(mc, level = 0.95)
#> effect interval 2.5 % 97.5 %
#> 1 from x to x 1 0.60980026 0.7961369
#> 2 from x to m 1 0.51914874 0.7460776
#> 3 from x to y 1 -0.14783330 -0.0330538
#> 4 from x to x 2 0.40979261 0.6037935
#> 5 from x to m 2 0.66494857 1.0184800
#> 6 from x to y 2 0.01683131 0.1326673
#> 7 from x to x 3 0.26218727 0.4434440
#> 8 from x to m 3 0.63091969 1.0389648
#> 9 from x to y 3 0.15306480 0.3106653
#> 10 from x to x 4 0.15968127 0.3290157
#> 11 from x to m 4 0.51873476 0.9042145
#> 12 from x to y 4 0.23081662 0.4004863
#> 13 from x to x 5 0.08188246 0.2714260
#> 14 from x to m 5 0.40169896 0.7780658
#> 15 from x to y 5 0.24813720 0.4318852
plot(mc)