Skip to contents

This function generates a bootstrap method sampling distribution of the standardized 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}\).

Usage

BootMedStd(
  phi,
  sigma,
  phi_hat,
  sigma_hat,
  delta_t,
  from,
  to,
  med,
  ncores = NULL,
  tol = 0.01
)

Arguments

phi

List of numeric matrices. Each element of the list is a bootstrap estimate of the drift matrix (\(\boldsymbol{\Phi}\)).

sigma

List of numeric matrices. Each element of the list is a bootstrap estimate of the process noise covariance matrix (\(\boldsymbol{\Sigma}\)).

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.

sigma_hat

Numeric matrix. The estimated process noise covariance matrix (\(\hat{\boldsymbol{\Sigma}}\)) from the original data set.

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 replications R 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 ("BootMedStd").

output

A list with length of length(delta_t).

Each element in the output list has the following elements:

est

A vector of standardized total, direct, and indirect effects.

thetahatstar

A matrix of bootstrap standardized total, direct, and indirect effects.

Details

See TotalStd(), DirectStd(), and IndirectStd() 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

Author

Ivan Jacob Agaloos Pesigan

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")
sigma_hat <- sigma
phi <- extract(object = boot, what = "phi")
sigma <- extract(object = boot, what = "sigma")

# Specific time interval ----------------------------------------------------
BootMedStd(
  phi = phi,
  sigma = sigma,
  phi_hat = phi_hat,
  sigma_hat = sigma_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.1069 0.0146 10 -0.1388 -0.0966
#> direct          1 -0.2858 0.0253 10 -0.3243 -0.2469
#> indirect        1  0.1789 0.0150 10  0.1503  0.1942
#> 

# Range of time intervals ---------------------------------------------------
boot <- BootMedStd(
  phi = phi,
  sigma = sigma,
  phi_hat = phi_hat,
  sigma_hat = sigma_hat,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
plot(boot)



plot(boot, type = "bc") # bias-corrected




# Methods -------------------------------------------------------------------
# BootMedStd 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.1069 0.0146 10 -0.1388 -0.0966
#> direct          1 -0.2858 0.0253 10 -0.3243 -0.2469
#> indirect        1  0.1789 0.0150 10  0.1503  0.1942
#> 
#> $`2`
#>          interval     est     se  R    2.5%   97.5%
#> total           2  0.0854 0.0170 10  0.0435  0.0934
#> direct          2 -0.3429 0.0377 10 -0.3992 -0.2927
#> indirect        2  0.4283 0.0357 10  0.3631  0.4672
#> 
#> $`3`
#>          interval     est     se  R    2.5%   97.5%
#> total           3  0.2680 0.0175 10  0.2321  0.2816
#> direct          3 -0.3114 0.0448 10 -0.3753 -0.2592
#> indirect        3  0.5794 0.0520 10  0.4956  0.6410
#> 
#> $`4`
#>          interval     est     se  R    2.5%   97.5%
#> total           4  0.3686 0.0193 10  0.3339  0.3881
#> direct          4 -0.2537 0.0464 10 -0.3190 -0.2022
#> indirect        4  0.6222 0.0621 10  0.5375  0.7023
#> 
#> $`5`
#>          interval     est     se  R    2.5%   97.5%
#> total           5  0.3946 0.0256 10  0.3507  0.4268
#> direct          5 -0.1954 0.0438 10 -0.2582 -0.1449
#> indirect        5  0.5899 0.0670 10  0.4959  0.6850
#> 
summary(boot)
#>      effect interval         est         se  R        2.5%       97.5%
#> 1     total        1 -0.10689374 0.01457135 10 -0.13880836 -0.09659594
#> 2    direct        1 -0.28578179 0.02529125 10 -0.32425418 -0.24692193
#> 3  indirect        1  0.17888805 0.01501523 10  0.15032599  0.19423592
#> 4     total        2  0.08537619 0.01700777 10  0.04354753  0.09341638
#> 5    direct        2 -0.34289417 0.03767149 10 -0.39919679 -0.29269604
#> 6  indirect        2  0.42827036 0.03567801 10  0.36311846  0.46719542
#> 7     total        3  0.26800143 0.01745794 10  0.23207899  0.28160738
#> 8    direct        3 -0.31141439 0.04484809 10 -0.37530743 -0.25920762
#> 9  indirect        3  0.57941582 0.05195313 10  0.49557494  0.64103369
#> 10    total        4  0.36856490 0.01930720 10  0.33393489  0.38807815
#> 11   direct        4 -0.25365773 0.04641205 10 -0.31900345 -0.20220264
#> 12 indirect        4  0.62222263 0.06210392 10  0.53751803  0.70230444
#> 13    total        5  0.39455777 0.02561383 10  0.35066698  0.42679774
#> 14   direct        5 -0.19537458 0.04380528 10 -0.25821798 -0.14491886
#> 15 indirect        5  0.58993235 0.06697139 10  0.49590450  0.68501572
confint(boot, level = 0.95)
#>      effect interval       2.5 %      97.5 %
#> 1     total        1 -0.13880836 -0.09659594
#> 2    direct        1 -0.32425418 -0.24692193
#> 3  indirect        1  0.15032599  0.19423592
#> 4     total        2  0.04354753  0.09341638
#> 5    direct        2 -0.39919679 -0.29269604
#> 6  indirect        2  0.36311846  0.46719542
#> 7     total        3  0.23207899  0.28160738
#> 8    direct        3 -0.37530743 -0.25920762
#> 9  indirect        3  0.49557494  0.64103369
#> 10    total        4  0.33393489  0.38807815
#> 11   direct        4 -0.31900345 -0.20220264
#> 12 indirect        4  0.53751803  0.70230444
#> 13    total        5  0.35066698  0.42679774
#> 14   direct        5 -0.25821798 -0.14491886
#> 15 indirect        5  0.49590450  0.68501572
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.1069 0.0146 10 -0.1156 -0.0966
#> direct          1 -0.2858 0.0253 10 -0.3153 -0.2451
#> indirect        1  0.1789 0.0150 10  0.1503  0.1942
#> 
#> $`2`
#>          interval     est     se  R    2.5%   97.5%
#> total           2  0.0854 0.0170 10  0.0711  0.0945
#> direct          2 -0.3429 0.0377 10 -0.3918 -0.2883
#> indirect        2  0.4283 0.0357 10  0.3811  0.4680
#> 
#> $`3`
#>          interval     est     se  R    2.5%   97.5%
#> total           3  0.2680 0.0175 10  0.2652  0.2856
#> direct          3 -0.3114 0.0448 10 -0.3572 -0.2573
#> indirect        3  0.5794 0.0520 10  0.4956  0.6410
#> 
#> $`4`
#>          interval     est     se  R    2.5%   97.5%
#> total           4  0.3686 0.0193 10  0.3357  0.3882
#> direct          4 -0.2537 0.0464 10 -0.3031 -0.2021
#> indirect        4  0.6222 0.0621 10  0.5352  0.6764
#> 
#> $`5`
#>          interval     est     se  R    2.5%   97.5%
#> total           5  0.3946 0.0256 10  0.3440  0.4258
#> direct          5 -0.1954 0.0438 10 -0.2459 -0.1444
#> indirect        5  0.5899 0.0670 10  0.4864  0.6564
#> 
summary(boot, type = "bc")
#>      effect interval         est         se  R       2.5%       97.5%
#> 1     total        1 -0.10689374 0.01457135 10 -0.1155678 -0.09656558
#> 2    direct        1 -0.28578179 0.02529125 10 -0.3152692 -0.24508672
#> 3  indirect        1  0.17888805 0.01501523 10  0.1503260  0.19423592
#> 4     total        2  0.08537619 0.01700777 10  0.0710742  0.09450813
#> 5    direct        2 -0.34289417 0.03767149 10 -0.3917760 -0.28834452
#> 6  indirect        2  0.42827036 0.03567801 10  0.3811289  0.46795924
#> 7     total        3  0.26800143 0.01745794 10  0.2651976  0.28556433
#> 8    direct        3 -0.31141439 0.04484809 10 -0.3572391 -0.25725837
#> 9  indirect        3  0.57941582 0.05195313 10  0.4955749  0.64103369
#> 10    total        4  0.36856490 0.01930720 10  0.3357085  0.38818798
#> 11   direct        4 -0.25365773 0.04641205 10 -0.3030705 -0.20208727
#> 12 indirect        4  0.62222263 0.06210392 10  0.5352207  0.67638552
#> 13    total        5  0.39455777 0.02561383 10  0.3439980  0.42575955
#> 14   direct        5 -0.19537458 0.04380528 10 -0.2458567 -0.14442231
#> 15 indirect        5  0.58993235 0.06697139 10  0.4864169  0.65638861
confint(boot, level = 0.95, type = "bc")
#>      effect interval      2.5 %      97.5 %
#> 1     total        1 -0.1155678 -0.09656558
#> 2    direct        1 -0.3152692 -0.24508672
#> 3  indirect        1  0.1503260  0.19423592
#> 4     total        2  0.0710742  0.09450813
#> 5    direct        2 -0.3917760 -0.28834452
#> 6  indirect        2  0.3811289  0.46795924
#> 7     total        3  0.2651976  0.28556433
#> 8    direct        3 -0.3572391 -0.25725837
#> 9  indirect        3  0.4955749  0.64103369
#> 10    total        4  0.3357085  0.38818798
#> 11   direct        4 -0.3030705 -0.20208727
#> 12 indirect        4  0.5352207  0.67638552
#> 13    total        5  0.3439980  0.42575955
#> 14   direct        5 -0.2458567 -0.14442231
#> 15 indirect        5  0.4864169  0.65638861
# }