library(cTMed)Total and Indirect Effect Centrality Measures in CT-Med
Installing Required Packages
Before proceeding, ensure that the necessary package are installed and loaded. We use cTMed for calculating total, direct, and indirect effects in continuous-time mediation model.
Extracting Matrices for Use in cTMed
We begin by defining the drift matrix phi (\(\boldsymbol{\Phi}\)).
phi <- matrix(
data = c(
-0.357, 0.771, -0.450,
0.000, -0.511, 0.729,
0.000, 0.000, -0.693
),
nrow = 3,
ncol = 3
)
phi [,1] [,2] [,3]
[1,] -0.357 0.000 0.000
[2,] 0.771 -0.511 0.000
[3,] -0.450 0.729 -0.693
Next, we assign row and column names to phi (\(\boldsymbol{\Phi}\)), which will be used to index the matrix.
colnames(phi) <- rownames(phi) <- c("x", "m", "y")
phi x m y
x -0.357 0.000 0.000
m 0.771 -0.511 0.000
y -0.450 0.729 -0.693
We then create a sequence of time intervals delta_t (\(\Delta t\)) ranging from 0.01 to 10, with a total of 1,000 equally spaced values.
delta_t <- seq(from = 0.01, to = 10, length.out = 1000)Let’s calculate total and indirect effects centrality for the sequence of delta_t (\(\Delta t\)). We plot to visualize the dynamics.
Total Effect Centrality
total_central <- TotalCentral(
phi = phi,
delta_t = delta_t
)
plot(total_central)Indirect Effect Centrality
indirect_central <- IndirectCentral(
phi = phi,
delta_t = delta_t
)
plot(indirect_central)