Posterior Distribution of Total, Direct, and Indirect Effects of X on Y Through M Over a Specific Time Interval or a Range of Time Intervals
Source:R/cTMed-posterior-med.R
PosteriorMed.Rd
This function generates a posterior distribution of the total, direct and indirect effects of the independent variable \(X\) on the dependent variable \(Y\) through mediator variables \(\mathbf{m}\) over a specific time interval \(\Delta t\) or a range of time intervals using the posterior distribution of the first-order stochastic differential equation model drift matrix \(\boldsymbol{\Phi}\).
Arguments
- phi
List of numeric matrices. Each element of the list is a sample from the posterior distribution of the drift matrix (\(\boldsymbol{\Phi}\)). Each matrix should have row and column names pertaining to the variables in the system.
- delta_t
Numeric. Time interval (\(\Delta t\)).
- from
Character string. Name of the independent variable \(X\) in
phi
.- to
Character string. Name of the dependent variable \(Y\) in
phi
.- med
Character vector. Name/s of the mediator variable/s in
phi
.- 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 ("PosteriorMed").
- 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
Mean of the posterior distribution of the total, direct, and indirect effects.
- thetahatstar
Posterior distribution of the total, direct, and indirect effects.
Details
See Total()
,
Direct()
, and
Indirect()
for more details.
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()
,
ExpCov()
,
ExpMean()
,
Indirect()
,
IndirectCentral()
,
IndirectStd()
,
MCBeta()
,
MCBetaStd()
,
MCIndirectCentral()
,
MCMed()
,
MCMedStd()
,
MCPhi()
,
MCPhiSigma()
,
MCTotalCentral()
,
Med()
,
MedStd()
,
PosteriorBeta()
,
PosteriorIndirectCentral()
,
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 ----------------------------------------------------
PosteriorMed(
phi = phi,
delta_t = 1,
from = "x",
to = "y",
med = "m"
)
#>
#> Total, Direct, and Indirect Effects
#>
#> $`1`
#> interval est se R 2.5% 97.5%
#> total 1 -0.1009 0.0321 1000 -0.1646 -0.0369
#> direct 1 -0.2672 0.0412 1000 -0.3519 -0.1864
#> indirect 1 0.1664 0.0178 1000 0.1341 0.2019
#>
# Range of time intervals ---------------------------------------------------
posterior <- PosteriorMed(
phi = phi,
delta_t = 1:5,
from = "x",
to = "y",
med = "m"
)
# Methods -------------------------------------------------------------------
# PosteriorMed 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%
#> total 1 -0.1009 0.0321 1000 -0.1646 -0.0369
#> direct 1 -0.2672 0.0412 1000 -0.3519 -0.1864
#> indirect 1 0.1664 0.0178 1000 0.1341 0.2019
#>
#> $`2`
#> interval est se R 2.5% 97.5%
#> total 2 0.0771 0.0359 1000 0.0067 0.1431
#> direct 2 -0.3231 0.0588 1000 -0.4503 -0.2173
#> indirect 2 0.4001 0.0476 1000 0.3181 0.4944
#>
#> $`3`
#> interval est se R 2.5% 97.5%
#> total 3 0.2477 0.0363 1000 0.1763 0.3161
#> direct 3 -0.2966 0.0659 1000 -0.4448 -0.1861
#> indirect 3 0.5443 0.0737 1000 0.4196 0.7083
#>
#> $`4`
#> interval est se R 2.5% 97.5%
#> total 4 0.3429 0.0403 1000 0.2720 0.4240
#> direct 4 -0.2452 0.0669 1000 -0.4024 -0.1399
#> indirect 4 0.5880 0.0905 1000 0.4403 0.7986
#>
#> $`5`
#> interval est se R 2.5% 97.5%
#> total 5 0.3688 0.0452 1000 0.2892 0.4669
#> direct 5 -0.1924 0.0639 1000 -0.3493 -0.0978
#> indirect 5 0.5613 0.0974 1000 0.4058 0.7886
#>
summary(posterior)
#> effect interval est se R 2.5% 97.5%
#> 1 total 1 -0.10086696 0.03207527 1000 -0.164639300 -0.03693203
#> 2 direct 1 -0.26721948 0.04116205 1000 -0.351915196 -0.18636417
#> 3 indirect 1 0.16635252 0.01783894 1000 0.134057398 0.20187363
#> 4 total 2 0.07708603 0.03591505 1000 0.006701073 0.14307396
#> 5 direct 2 -0.32305468 0.05875878 1000 -0.450341327 -0.21733528
#> 6 indirect 2 0.40014071 0.04758784 1000 0.318069431 0.49442469
#> 7 total 3 0.24767797 0.03634671 1000 0.176293976 0.31605233
#> 8 direct 3 -0.29661770 0.06592929 1000 -0.444837849 -0.18605237
#> 9 indirect 3 0.54429567 0.07372348 1000 0.419642984 0.70832341
#> 10 total 4 0.34285731 0.04027285 1000 0.272023199 0.42401092
#> 11 direct 4 -0.24517689 0.06687169 1000 -0.402406436 -0.13986536
#> 12 indirect 4 0.58803421 0.09050212 1000 0.440284103 0.79855677
#> 13 total 5 0.36884839 0.04521101 1000 0.289211206 0.46693840
#> 14 direct 5 -0.19244653 0.06389833 1000 -0.349267540 -0.09779297
#> 15 indirect 5 0.56129492 0.09736703 1000 0.405791502 0.78861468
confint(posterior, level = 0.95)
#> effect interval 2.5 % 97.5 %
#> 1 total 1 -0.164639300 -0.03693203
#> 2 direct 1 -0.351915196 -0.18636417
#> 3 indirect 1 0.134057398 0.20187363
#> 4 total 2 0.006701073 0.14307396
#> 5 direct 2 -0.450341327 -0.21733528
#> 6 indirect 2 0.318069431 0.49442469
#> 7 total 3 0.176293976 0.31605233
#> 8 direct 3 -0.444837849 -0.18605237
#> 9 indirect 3 0.419642984 0.70832341
#> 10 total 4 0.272023199 0.42401092
#> 11 direct 4 -0.402406436 -0.13986536
#> 12 indirect 4 0.440284103 0.79855677
#> 13 total 5 0.289211206 0.46693840
#> 14 direct 5 -0.349267540 -0.09779297
#> 15 indirect 5 0.405791502 0.78861468
plot(posterior)