Posterior Sampling Distribution for the Elements of the Matrix of Lagged Coefficients Over a Specific Time Interval or a Range of Time Intervals
Source:R/cTMed-posterior-beta.R
PosteriorBeta.Rd
This function generates a posterior sampling distribution for the elements of the 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}\).
Arguments
- phi
Numeric matrix. The drift matrix (\(\boldsymbol{\Phi}\)).
phi
should have row and column names pertaining to the variables in the system.- delta_t
Numeric. Time interval (\(\Delta t\)).
- 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.- 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 ("PosteriorBeta").
- 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 Total()
.
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:
BootBeta()
,
BootBetaStd()
,
BootIndirectCentral()
,
BootMed()
,
BootMedStd()
,
BootTotalCentral()
,
DeltaBeta()
,
DeltaBetaStd()
,
DeltaIndirectCentral()
,
DeltaMed()
,
DeltaMedStd()
,
DeltaTotalCentral()
,
Direct()
,
DirectStd()
,
Indirect()
,
IndirectCentral()
,
IndirectStd()
,
MCBeta()
,
MCBetaStd()
,
MCIndirectCentral()
,
MCMed()
,
MCMedStd()
,
MCPhi()
,
MCPhiSigma()
,
MCTotalCentral()
,
Med()
,
MedStd()
,
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")
vcov_phi_vec <- matrix(
data = c(
0.00843, 0.00040, -0.00151,
-0.00600, -0.00033, 0.00110,
0.00324, 0.00020, -0.00061,
0.00040, 0.00374, 0.00016,
-0.00022, -0.00273, -0.00016,
0.00009, 0.00150, 0.00012,
-0.00151, 0.00016, 0.00389,
0.00103, -0.00007, -0.00283,
-0.00050, 0.00000, 0.00156,
-0.00600, -0.00022, 0.00103,
0.00644, 0.00031, -0.00119,
-0.00374, -0.00021, 0.00070,
-0.00033, -0.00273, -0.00007,
0.00031, 0.00287, 0.00013,
-0.00014, -0.00170, -0.00012,
0.00110, -0.00016, -0.00283,
-0.00119, 0.00013, 0.00297,
0.00063, -0.00004, -0.00177,
0.00324, 0.00009, -0.00050,
-0.00374, -0.00014, 0.00063,
0.00495, 0.00024, -0.00093,
0.00020, 0.00150, 0.00000,
-0.00021, -0.00170, -0.00004,
0.00024, 0.00214, 0.00012,
-0.00061, 0.00012, 0.00156,
0.00070, -0.00012, -0.00177,
-0.00093, 0.00012, 0.00223
),
nrow = 9
)
phi <- MCPhi(
phi = phi,
vcov_phi_vec = vcov_phi_vec,
R = 1000L
)$output
# Specific time interval ----------------------------------------------------
PosteriorBeta(
phi = phi,
delta_t = 1
)
#>
#> Total, Direct, and Indirect Effects
#>
#> $`1`
#> interval est se R 2.5% 97.5%
#> from x to x 1 0.7007 0.0488 1000 0.6088 0.8038
#> from x to m 1 0.5022 0.0351 1000 0.4361 0.5713
#> from x to y 1 -0.1011 0.0318 1000 -0.1678 -0.0433
#> from m to x 1 -0.0001 0.0440 1000 -0.0901 0.0794
#> from m to m 1 0.5999 0.0332 1000 0.5334 0.6655
#> from m to y 1 0.4008 0.0282 1000 0.3472 0.4588
#> from y to x 1 0.0001 0.0402 1000 -0.0801 0.0798
#> from y to m 1 0.0007 0.0319 1000 -0.0637 0.0631
#> from y to y 1 0.4995 0.0277 1000 0.4446 0.5535
#>
# Range of time intervals ---------------------------------------------------
posterior <- PosteriorBeta(
phi = phi,
delta_t = 1:5
)
plot(posterior)
#> NULL
# Methods -------------------------------------------------------------------
# PosteriorBeta has a number of methods including
# print, summary, confint, and plot
print(posterior)
#>
#> Total, Direct, and Indirect Effects
#>
#> $`1`
#> interval est se R 2.5% 97.5%
#> from x to x 1 0.7007 0.0488 1000 0.6088 0.8038
#> from x to m 1 0.5022 0.0351 1000 0.4361 0.5713
#> from x to y 1 -0.1011 0.0318 1000 -0.1678 -0.0433
#> from m to x 1 -0.0001 0.0440 1000 -0.0901 0.0794
#> from m to m 1 0.5999 0.0332 1000 0.5334 0.6655
#> from m to y 1 0.4008 0.0282 1000 0.3472 0.4588
#> from y to x 1 0.0001 0.0402 1000 -0.0801 0.0798
#> from y to m 1 0.0007 0.0319 1000 -0.0637 0.0631
#> from y to y 1 0.4995 0.0277 1000 0.4446 0.5535
#>
#> $`2`
#> interval est se R 2.5% 97.5%
#> from x to x 2 0.4909 0.0572 1000 0.3899 0.6175
#> from x to m 2 0.6530 0.0545 1000 0.5520 0.7660
#> from x to y 2 0.0799 0.0348 1000 0.0074 0.1436
#> from m to x 2 -0.0001 0.0531 1000 -0.1129 0.0945
#> from m to m 2 0.3601 0.0517 1000 0.2555 0.4611
#> from m to y 2 0.4407 0.0325 1000 0.3817 0.5102
#> from y to x 2 0.0001 0.0484 1000 -0.0963 0.0965
#> from y to m 2 0.0008 0.0494 1000 -0.1009 0.0992
#> from y to y 2 0.2498 0.0327 1000 0.1846 0.3119
#>
#> $`3`
#> interval est se R 2.5% 97.5%
#> from x to x 3 0.3439 0.0568 1000 0.2462 0.4674
#> from x to m 3 0.6383 0.0673 1000 0.5159 0.7808
#> from x to y 3 0.2521 0.0343 1000 0.1835 0.3203
#> from m to x 3 -0.0001 0.0521 1000 -0.1111 0.0953
#> from m to m 3 0.2162 0.0635 1000 0.0864 0.3347
#> from m to y 3 0.3645 0.0329 1000 0.3076 0.4421
#> from y to x 3 0.0001 0.0443 1000 -0.0899 0.0867
#> from y to m 3 0.0007 0.0581 1000 -0.1192 0.1182
#> from y to y 3 0.1251 0.0311 1000 0.0667 0.1868
#>
#> $`4`
#> interval est se R 2.5% 97.5%
#> from x to x 4 0.2409 0.0554 1000 0.1459 0.3639
#> from x to m 4 0.5558 0.0741 1000 0.4306 0.7278
#> from x to y 4 0.3470 0.0383 1000 0.2738 0.4232
#> from m to x 4 -0.0001 0.0479 1000 -0.0995 0.0879
#> from m to m 4 0.1299 0.0686 1000 -0.0070 0.2599
#> from m to y 4 0.2688 0.0361 1000 0.2035 0.3518
#> from y to x 4 0.0000 0.0365 1000 -0.0735 0.0694
#> from y to m 4 0.0005 0.0591 1000 -0.1193 0.1187
#> from y to y 4 0.0628 0.0318 1000 0.0034 0.1238
#>
#> $`5`
#> interval est se R 2.5% 97.5%
#> from x to x 5 0.1688 0.0546 1000 0.0729 0.2879
#> from x to m 5 0.4546 0.0774 1000 0.3254 0.6292
#> from x to y 5 0.3718 0.0438 1000 0.2943 0.4644
#> from m to x 5 -0.0001 0.0422 1000 -0.0815 0.0809
#> from m to m 5 0.0781 0.0685 1000 -0.0525 0.2114
#> from m to y 5 0.1863 0.0400 1000 0.1114 0.2737
#> from y to x 5 0.0000 0.0286 1000 -0.0569 0.0575
#> from y to m 5 0.0004 0.0549 1000 -0.1088 0.1073
#> from y to y 5 0.0316 0.0342 1000 -0.0346 0.1011
#>
summary(posterior)
#> effect interval est se R 2.5% 97.5%
#> 1 from x to x 1 7.007027e-01 0.04882035 1000 0.608787051 0.80378813
#> 2 from x to m 1 5.021645e-01 0.03505208 1000 0.436064479 0.57132115
#> 3 from x to y 1 -1.011031e-01 0.03180126 1000 -0.167796773 -0.04326155
#> 4 from m to x 1 -1.081038e-04 0.04396821 1000 -0.090079034 0.07937652
#> 5 from m to m 1 5.998799e-01 0.03316288 1000 0.533435183 0.66546062
#> 6 from m to y 1 4.008409e-01 0.02817051 1000 0.347168412 0.45878600
#> 7 from y to x 1 5.258813e-05 0.04017575 1000 -0.080056287 0.07978015
#> 8 from y to m 1 6.917300e-04 0.03186636 1000 -0.063707352 0.06310006
#> 9 from y to y 1 4.995377e-01 0.02767362 1000 0.444602501 0.55350513
#> 10 from x to x 2 4.909247e-01 0.05723987 1000 0.389924244 0.61745605
#> 11 from x to m 2 6.530365e-01 0.05452560 1000 0.552019346 0.76595378
#> 12 from x to y 2 7.994006e-02 0.03484961 1000 0.007428498 0.14362689
#> 13 from m to x 2 -1.195185e-04 0.05309901 1000 -0.112880337 0.09448921
#> 14 from m to m 2 3.600788e-01 0.05167527 1000 0.255538051 0.46107483
#> 15 from m to y 2 4.407025e-01 0.03247461 1000 0.381729198 0.51020117
#> 16 from y to x 2 6.304362e-05 0.04841310 1000 -0.096318730 0.09650717
#> 17 from y to m 2 7.869080e-04 0.04943475 1000 -0.100925545 0.09923590
#> 18 from y to y 2 2.498099e-01 0.03265125 1000 0.184619235 0.31190796
#> 19 from x to x 3 3.439259e-01 0.05675848 1000 0.246244665 0.46744703
#> 20 from x to m 3 6.383237e-01 0.06732114 1000 0.515931515 0.78083560
#> 21 from x to y 3 2.520628e-01 0.03427930 1000 0.183482045 0.32030654
#> 22 from m to x 3 -9.949712e-05 0.05214545 1000 -0.111051444 0.09527531
#> 23 from m to m 3 2.162489e-01 0.06346513 1000 0.086414909 0.33471993
#> 24 from m to y 3 3.644939e-01 0.03292416 1000 0.307606096 0.44212186
#> 25 from y to x 3 5.722680e-05 0.04430135 1000 -0.089874598 0.08673445
#> 26 from y to m 3 6.765096e-04 0.05811794 1000 -0.119201092 0.11818032
#> 27 from y to y 3 1.250985e-01 0.03113602 1000 0.066709045 0.18682793
#> 28 from x to x 4 2.409341e-01 0.05544705 1000 0.145868037 0.36392793
#> 29 from x to m 4 5.557993e-01 0.07412562 1000 0.430579036 0.72776025
#> 30 from x to y 4 3.470092e-01 0.03826137 1000 0.273844483 0.42324830
#> 31 from m to x 4 -7.392718e-05 0.04789684 1000 -0.099504140 0.08789835
#> 32 from m to m 4 1.299255e-01 0.06860803 1000 -0.007041697 0.25985299
#> 33 from m to y 4 2.687699e-01 0.03607068 1000 0.203499233 0.35175941
#> 34 from y to x 4 4.660454e-05 0.03651210 1000 -0.073517152 0.06936475
#> 35 from y to m 4 5.210961e-04 0.05910302 1000 -0.119285966 0.11874055
#> 36 from y to y 4 6.275682e-02 0.03179384 1000 0.003430247 0.12376572
#> 37 from x to x 5 1.687813e-01 0.05461302 1000 0.072856859 0.28794674
#> 38 from x to m 5 4.546414e-01 0.07742230 1000 0.325389617 0.62922260
#> 39 from x to y 5 3.717721e-01 0.04378236 1000 0.294271102 0.46444840
#> 40 from m to x 5 -5.171232e-05 0.04219824 1000 -0.081548606 0.08088403
#> 41 from m to m 5 7.808849e-02 0.06845988 1000 -0.052475127 0.21139200
#> 42 from m to y 5 1.863477e-01 0.04003730 1000 0.111397347 0.27366291
#> 43 from y to x 5 3.589986e-05 0.02862934 1000 -0.056895751 0.05752033
#> 44 from y to m 5 3.794090e-04 0.05485610 1000 -0.108784640 0.10727889
#> 45 from y to y 5 3.155357e-02 0.03418168 1000 -0.034643790 0.10113604
confint(posterior, level = 0.95)
#> effect interval 2.5 % 97.5 %
#> 1 from x to x 1 0.608787051 0.80378813
#> 2 from x to m 1 0.436064479 0.57132115
#> 3 from x to y 1 -0.167796773 -0.04326155
#> 4 from x to x 2 0.389924244 0.61745605
#> 5 from x to m 2 0.552019346 0.76595378
#> 6 from x to y 2 0.007428498 0.14362689
#> 7 from x to x 3 0.246244665 0.46744703
#> 8 from x to m 3 0.515931515 0.78083560
#> 9 from x to y 3 0.183482045 0.32030654
#> 10 from x to x 4 0.145868037 0.36392793
#> 11 from x to m 4 0.430579036 0.72776025
#> 12 from x to y 4 0.273844483 0.42324830
#> 13 from x to x 5 0.072856859 0.28794674
#> 14 from x to m 5 0.325389617 0.62922260
#> 15 from x to y 5 0.294271102 0.46444840
plot(posterior)
#> NULL