Bootstrap Sampling 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-boot-med.R
BootMed.Rd
This function generates a bootstrap method sampling 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 first-order stochastic differential equation model drift matrix \(\boldsymbol{\Phi}\).
Arguments
- phi
List of numeric matrices. Each element of the list is a bootstrap estimate of the drift matrix (\(\boldsymbol{\Phi}\)).
- phi_hat
Numeric matrix. The estimated drift matrix (\(\hat{\boldsymbol{\Phi}}\)) from the original data set.
phi_hat
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 ctmedboot
which is a list with the following elements:
- call
Function call.
- args
Function arguments.
- fun
Function used ("BootMed").
- output
A list with length of
length(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 bootstrap 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()
,
BootMedStd()
,
BootTotalCentral()
,
DeltaBeta()
,
DeltaBetaStd()
,
DeltaIndirectCentral()
,
DeltaMed()
,
DeltaMedStd()
,
DeltaTotalCentral()
,
Direct()
,
DirectStd()
,
Indirect()
,
IndirectCentral()
,
IndirectStd()
,
MCBeta()
,
MCBetaStd()
,
MCIndirectCentral()
,
MCMed()
,
MCMedStd()
,
MCPhi()
,
MCPhiSigma()
,
MCTotalCentral()
,
Med()
,
MedStd()
,
PosteriorBeta()
,
PosteriorIndirectCentral()
,
PosteriorMed()
,
PosteriorTotalCentral()
,
Total()
,
TotalCentral()
,
TotalStd()
,
Trajectory()
Examples
# \donttest{
library(bootStateSpace)
# prepare parameters
## number of individuals
n <- 50
## time points
time <- 100
delta_t <- 0.10
## dynamic structure
p <- 3
mu0 <- rep(x = 0, times = p)
sigma0 <- matrix(
data = c(
1.0,
0.2,
0.2,
0.2,
1.0,
0.2,
0.2,
0.2,
1.0
),
nrow = p
)
sigma0_l <- t(chol(sigma0))
mu <- rep(x = 0, times = p)
phi <- matrix(
data = c(
-0.357,
0.771,
-0.450,
0.0,
-0.511,
0.729,
0,
0,
-0.693
),
nrow = p
)
sigma <- matrix(
data = c(
0.24455556,
0.02201587,
-0.05004762,
0.02201587,
0.07067800,
0.01539456,
-0.05004762,
0.01539456,
0.07553061
),
nrow = p
)
sigma_l <- t(chol(sigma))
## measurement model
k <- 3
nu <- rep(x = 0, times = k)
lambda <- diag(k)
theta <- 0.2 * diag(k)
theta_l <- t(chol(theta))
boot <- PBSSMOUFixed(
R = 10L, # use at least 1000 in actual research
path = getwd(),
prefix = "ou",
n = n,
time = time,
delta_t = delta_t,
mu0 = mu0,
sigma0_l = sigma0_l,
mu = mu,
phi = phi,
sigma_l = sigma_l,
nu = nu,
lambda = lambda,
theta_l = theta_l,
ncores = NULL, # consider using multiple cores
seed = 42
)
phi_hat <- phi
colnames(phi_hat) <- rownames(phi_hat) <- c("x", "m", "y")
phi <- extract(object = boot, what = "phi")
# Specific time interval ----------------------------------------------------
BootMed(
phi = phi,
phi_hat = phi_hat,
delta_t = 1,
from = "x",
to = "y",
med = "m"
)
#>
#> Total, Direct, and Indirect Effects
#> type = pc
#> $`1`
#> interval est se R 2.5% 97.5%
#> total 1 -0.1000 0.0135 10 -0.1302 -0.0931
#> direct 1 -0.2675 0.0235 10 -0.3051 -0.2387
#> indirect 1 0.1674 0.0140 10 0.1449 0.1826
#>
# Range of time intervals ---------------------------------------------------
boot <- BootMed(
phi = phi,
phi_hat = phi_hat,
delta_t = 1:5,
from = "x",
to = "y",
med = "m"
)
plot(boot)
plot(boot, type = "bc") # bias-corrected
# Methods -------------------------------------------------------------------
# BootMed has a number of methods including
# print, summary, confint, and plot
print(boot)
#>
#> Total, Direct, and Indirect Effects
#> type = pc
#> $`1`
#> interval est se R 2.5% 97.5%
#> total 1 -0.1000 0.0135 10 -0.1302 -0.0931
#> direct 1 -0.2675 0.0235 10 -0.3051 -0.2387
#> indirect 1 0.1674 0.0140 10 0.1449 0.1826
#>
#> $`2`
#> interval est se R 2.5% 97.5%
#> total 2 0.0799 0.0159 10 0.0406 0.0879
#> direct 2 -0.3209 0.0367 10 -0.3745 -0.2717
#> indirect 2 0.4008 0.0354 10 0.3411 0.4391
#>
#> $`3`
#> interval est se R 2.5% 97.5%
#> total 3 0.2508 0.0187 10 0.2164 0.2668
#> direct 3 -0.2914 0.0441 10 -0.3521 -0.2338
#> indirect 3 0.5423 0.0539 10 0.4524 0.6029
#>
#> $`4`
#> interval est se R 2.5% 97.5%
#> total 4 0.3449 0.0247 10 0.2959 0.3704
#> direct 4 -0.2374 0.0455 10 -0.2993 -0.1775
#> indirect 4 0.5823 0.0657 10 0.4754 0.6638
#>
#> $`5`
#> interval est se R 2.5% 97.5%
#> total 5 0.3693 0.0323 10 0.3088 0.4065
#> direct 5 -0.1828 0.0426 10 -0.2425 -0.1273
#> indirect 5 0.5521 0.0710 10 0.4361 0.6438
#>
summary(boot)
#> effect interval est se R 2.5% 97.5%
#> 1 total 1 -0.1000384 0.01352470 10 -0.13021799 -0.09314403
#> 2 direct 1 -0.2674539 0.02346151 10 -0.30506209 -0.23871488
#> 3 indirect 1 0.1674155 0.01401604 10 0.14494208 0.18255013
#> 4 total 2 0.0799008 0.01591422 10 0.04064558 0.08786268
#> 5 direct 2 -0.3209035 0.03672873 10 -0.37450426 -0.27173260
#> 6 indirect 2 0.4008043 0.03541841 10 0.34113848 0.43908776
#> 7 total 3 0.2508138 0.01873463 10 0.21635512 0.26676004
#> 8 direct 3 -0.2914426 0.04411314 10 -0.35208890 -0.23382113
#> 9 indirect 3 0.5422564 0.05386335 10 0.45235059 0.60293039
#> 10 total 4 0.3449279 0.02474916 10 0.29592103 0.37042957
#> 11 direct 4 -0.2373900 0.04547156 10 -0.29927095 -0.17754396
#> 12 indirect 4 0.5823179 0.06568261 10 0.47544857 0.66375150
#> 13 total 5 0.3692538 0.03226131 10 0.30878766 0.40647923
#> 14 direct 5 -0.1828447 0.04263584 10 -0.24246640 -0.12727444
#> 15 indirect 5 0.5520985 0.07097678 10 0.43606210 0.64375063
confint(boot, level = 0.95)
#> effect interval 2.5 % 97.5 %
#> 1 total 1 -0.13021799 -0.09314403
#> 2 direct 1 -0.30506209 -0.23871488
#> 3 indirect 1 0.14494208 0.18255013
#> 4 total 2 0.04064558 0.08786268
#> 5 direct 2 -0.37450426 -0.27173260
#> 6 indirect 2 0.34113848 0.43908776
#> 7 total 3 0.21635512 0.26676004
#> 8 direct 3 -0.35208890 -0.23382113
#> 9 indirect 3 0.45235059 0.60293039
#> 10 total 4 0.29592103 0.37042957
#> 11 direct 4 -0.29927095 -0.17754396
#> 12 indirect 4 0.47544857 0.66375150
#> 13 total 5 0.30878766 0.40647923
#> 14 direct 5 -0.24246640 -0.12727444
#> 15 indirect 5 0.43606210 0.64375063
print(boot, type = "bc") # bias-corrected
#>
#> Total, Direct, and Indirect Effects
#> type = bc
#> $`1`
#> interval est se R 2.5% 97.5%
#> total 1 -0.1000 0.0135 10 -0.1193 -0.0928
#> direct 1 -0.2675 0.0235 10 -0.2886 -0.2386
#> indirect 1 0.1674 0.0140 10 0.1449 0.1826
#>
#> $`2`
#> interval est se R 2.5% 97.5%
#> total 2 0.0799 0.0159 10 0.0682 0.0888
#> direct 2 -0.3209 0.0367 10 -0.3662 -0.2699
#> indirect 2 0.4008 0.0354 10 0.3440 0.4398
#>
#> $`3`
#> interval est se R 2.5% 97.5%
#> total 3 0.2508 0.0187 10 0.2205 0.2683
#> direct 3 -0.2914 0.0441 10 -0.3368 -0.2290
#> indirect 3 0.5423 0.0539 10 0.4451 0.5950
#>
#> $`4`
#> interval est se R 2.5% 97.5%
#> total 4 0.3449 0.0247 10 0.3148 0.3716
#> direct 4 -0.2374 0.0455 10 -0.2836 -0.1738
#> indirect 4 0.5823 0.0657 10 0.4605 0.6425
#>
#> $`5`
#> interval est se R 2.5% 97.5%
#> total 5 0.3693 0.0323 10 0.2942 0.3981
#> direct 5 -0.1828 0.0426 10 -0.2298 -0.1242
#> indirect 5 0.5521 0.0710 10 0.4184 0.6273
#>
summary(boot, type = "bc")
#> effect interval est se R 2.5% 97.5%
#> 1 total 1 -0.1000384 0.01352470 10 -0.1192826 -0.09276853
#> 2 direct 1 -0.2674539 0.02346151 10 -0.2885540 -0.23858310
#> 3 indirect 1 0.1674155 0.01401604 10 0.1449421 0.18255013
#> 4 total 2 0.0799008 0.01591422 10 0.0681527 0.08882083
#> 5 direct 2 -0.3209035 0.03672873 10 -0.3661783 -0.26985895
#> 6 indirect 2 0.4008043 0.03541841 10 0.3439750 0.43979905
#> 7 total 3 0.2508138 0.01873463 10 0.2204864 0.26829406
#> 8 direct 3 -0.2914426 0.04411314 10 -0.3368455 -0.22903334
#> 9 indirect 3 0.5422564 0.05386335 10 0.4450868 0.59498768
#> 10 total 4 0.3449279 0.02474916 10 0.3148344 0.37160448
#> 11 direct 4 -0.2373900 0.04547156 10 -0.2835681 -0.17381101
#> 12 indirect 4 0.5823179 0.06568261 10 0.4605166 0.64249685
#> 13 total 5 0.3692538 0.03226131 10 0.2941828 0.39806967
#> 14 direct 5 -0.1828447 0.04263584 10 -0.2297977 -0.12421649
#> 15 indirect 5 0.5520985 0.07097678 10 0.4183993 0.62725485
confint(boot, level = 0.95, type = "bc")
#> effect interval 2.5 % 97.5 %
#> 1 total 1 -0.1192826 -0.09276853
#> 2 direct 1 -0.2885540 -0.23858310
#> 3 indirect 1 0.1449421 0.18255013
#> 4 total 2 0.0681527 0.08882083
#> 5 direct 2 -0.3661783 -0.26985895
#> 6 indirect 2 0.3439750 0.43979905
#> 7 total 3 0.2204864 0.26829406
#> 8 direct 3 -0.3368455 -0.22903334
#> 9 indirect 3 0.4450868 0.59498768
#> 10 total 4 0.3148344 0.37160448
#> 11 direct 4 -0.2835681 -0.17381101
#> 12 indirect 4 0.4605166 0.64249685
#> 13 total 5 0.2941828 0.39806967
#> 14 direct 5 -0.2297977 -0.12421649
#> 15 indirect 5 0.4183993 0.62725485
# }