Skip to contents

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}\).

Usage

PosteriorMed(phi, delta_t, from, to, med, ncores = NULL)

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 replications R is a large value.

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

Author

Ivan Jacob Agaloos Pesigan

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.002704274, -0.001475275, 0.000949122,
    -0.001619422, 0.000885122, -0.000569404,
    0.00085493, -0.000465824, 0.000297815,
    -0.001475275, 0.004428442, -0.002642303,
    0.000980573, -0.00271817, 0.001618805,
    -0.000586921, 0.001478421, -0.000871547,
    0.000949122, -0.002642303, 0.006402668,
    -0.000697798, 0.001813471, -0.004043138,
    0.000463086, -0.001120949, 0.002271711,
    -0.001619422, 0.000980573, -0.000697798,
    0.002079286, -0.001152501, 0.000753,
    -0.001528701, 0.000820587, -0.000517524,
    0.000885122, -0.00271817, 0.001813471,
    -0.001152501, 0.00342605, -0.002075005,
    0.000899165, -0.002532849, 0.001475579,
    -0.000569404, 0.001618805, -0.004043138,
    0.000753, -0.002075005, 0.004984032,
    -0.000622255, 0.001634917, -0.003705661,
    0.00085493, -0.000586921, 0.000463086,
    -0.001528701, 0.000899165, -0.000622255,
    0.002060076, -0.001096684, 0.000686386,
    -0.000465824, 0.001478421, -0.001120949,
    0.000820587, -0.002532849, 0.001634917,
    -0.001096684, 0.003328692, -0.001926088,
    0.000297815, -0.000871547, 0.002271711,
    -0.000517524, 0.001475579, -0.003705661,
    0.000686386, -0.001926088, 0.004726235
  ),
  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.0987 0.0343 1000 -0.1701 -0.0300
#> direct          1 -0.2641 0.0446 1000 -0.3502 -0.1702
#> indirect        1  0.1653 0.0193 1000  0.1286  0.2053
#> 

# 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.0987 0.0343 1000 -0.1701 -0.0300
#> direct          1 -0.2641 0.0446 1000 -0.3502 -0.1702
#> indirect        1  0.1653 0.0193 1000  0.1286  0.2053
#> 
#> $`2`
#>          interval     est     se    R    2.5%   97.5%
#> total           2  0.0785 0.0393 1000  0.0000  0.1517
#> direct          2 -0.3180 0.0535 1000 -0.4308 -0.2088
#> indirect        2  0.3964 0.0390 1000  0.3195  0.4767
#> 
#> $`3`
#>          interval     est     se    R    2.5%   97.5%
#> total           3  0.2477 0.0384 1000  0.1714  0.3179
#> direct          3 -0.2903 0.0517 1000 -0.4047 -0.1909
#> indirect        3  0.5380 0.0498 1000  0.4431  0.6380
#> 
#> $`4`
#>          interval     est     se    R    2.5%   97.5%
#> total           4  0.3418 0.0360 1000  0.2754  0.4139
#> direct          4 -0.2381 0.0468 1000 -0.3407 -0.1511
#> indirect        4  0.5799 0.0557 1000  0.4771  0.6990
#> 
#> $`5`
#>          interval     est     se    R    2.5%   97.5%
#> total           5  0.3672 0.0345 1000  0.3061  0.4371
#> direct          5 -0.1849 0.0412 1000 -0.2781 -0.1139
#> indirect        5  0.5522 0.0585 1000  0.4486  0.6830
#> 
summary(posterior)
#>      effect interval         est         se    R          2.5%       97.5%
#> 1     total        1 -0.09874978 0.03427846 1000 -1.700557e-01 -0.03002761
#> 2    direct        1 -0.26407276 0.04455356 1000 -3.502412e-01 -0.17021325
#> 3  indirect        1  0.16532298 0.01933558 1000  1.286486e-01  0.20525832
#> 4     total        2  0.07845305 0.03927390 1000  2.223319e-05  0.15171207
#> 5    direct        2 -0.31798223 0.05351151 1000 -4.307985e-01 -0.20877122
#> 6  indirect        2  0.39643528 0.03904472 1000  3.195414e-01  0.47673554
#> 7     total        3  0.24765137 0.03839409 1000  1.714414e-01  0.31791498
#> 8    direct        3 -0.29031802 0.05167949 1000 -4.047201e-01 -0.19085616
#> 9  indirect        3  0.53796940 0.04982119 1000  4.430896e-01  0.63799533
#> 10    total        4  0.34181243 0.03596326 1000  2.754323e-01  0.41387188
#> 11   direct        4 -0.23809561 0.04681167 1000 -3.407235e-01 -0.15107266
#> 12 indirect        4  0.57990804 0.05574685 1000  4.771289e-01  0.69903936
#> 13    total        5  0.36723237 0.03449657 1000  3.061464e-01  0.43714997
#> 14   direct        5 -0.18492755 0.04120676 1000 -2.780756e-01 -0.11385791
#> 15 indirect        5  0.55215992 0.05846350 1000  4.485900e-01  0.68301642
confint(posterior, level = 0.95)
#>      effect interval         2.5 %      97.5 %
#> 1     total        1 -1.700557e-01 -0.03002761
#> 2    direct        1 -3.502412e-01 -0.17021325
#> 3  indirect        1  1.286486e-01  0.20525832
#> 4     total        2  2.223319e-05  0.15171207
#> 5    direct        2 -4.307985e-01 -0.20877122
#> 6  indirect        2  3.195414e-01  0.47673554
#> 7     total        3  1.714414e-01  0.31791498
#> 8    direct        3 -4.047201e-01 -0.19085616
#> 9  indirect        3  4.430896e-01  0.63799533
#> 10    total        4  2.754323e-01  0.41387188
#> 11   direct        4 -3.407235e-01 -0.15107266
#> 12 indirect        4  4.771289e-01  0.69903936
#> 13    total        5  3.061464e-01  0.43714997
#> 14   direct        5 -2.780756e-01 -0.11385791
#> 15 indirect        5  4.485900e-01  0.68301642
plot(posterior)