Package 'cTMed'

Title: Continuous Time Mediation
Description: Calculates standard errors and confidence intervals for effects in continuous-time mediation models. This package extends the work of Deboeck and Preacher (2015) <doi:10.1080/10705511.2014.973960> and Ryan and Hamaker (2021) <doi:10.1007/s11336-021-09767-0> by providing methods to generate standard errors and confidence intervals for the total, direct, and indirect effects in these models.
Authors: Ivan Jacob Agaloos Pesigan [aut, cre, cph]
Maintainer: Ivan Jacob Agaloos Pesigan <[email protected]>
License: GPL (>= 3)
Version: 1.0.1.9000
Built: 2024-10-22 17:21:04 UTC
Source: https://github.com/jeksterslab/cTMed

Help Index


Delta Method Confidence Intervals

Description

Delta Method Confidence Intervals

Usage

## S3 method for class 'ctmeddelta'
confint(object, parm = NULL, level = 0.95, ...)

Arguments

object

Object of class ctmeddelta.

parm

a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered.

level

the confidence level required.

...

additional arguments.

Value

Returns a data frame of confidence intervals.

Author(s)

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
)

# Specific time interval ----------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)
confint(delta, level = 0.95)

# Range of time intervals ---------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
confint(delta, level = 0.95)

Monte Carlo Method Confidence Intervals

Description

Monte Carlo Method Confidence Intervals

Usage

## S3 method for class 'ctmedmc'
confint(object, parm = NULL, level = 0.95, ...)

Arguments

object

Object of class ctmedmc.

parm

a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered.

level

the confidence level required.

...

additional arguments.

Value

Returns a data frame of confidence intervals.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
confint(mc, level = 0.95)

# Range of time intervals ---------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
confint(mc, level = 0.95)

Delta Method Sampling Variance-Covariance Matrix for the Elements of the Matrix of Lagged Coefficients Over a Specific Time Interval or a Range of Time Intervals

Description

This function computes the delta method sampling variance-covariance matrix for the elements of the matrix of lagged coefficients β\boldsymbol{\beta} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

DeltaBeta(phi, vcov_phi_vec, delta_t, ncores = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

ncores

Positive integer. Number of cores to use. If ncores = NULL, use a single core. Consider using multiple cores when the length of delta_t is long.

Details

See Total().

Delta Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). By the multivariate central limit theory, the function g\mathbf{g} using θ^\hat{\boldsymbol{\theta}} as input can be expressed as:

n(g(θ^)g(θ))DN(0,JΓJ)\sqrt{n} \left( \mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) - \mathbf{g} \left( \boldsymbol{\theta} \right) \right) \xrightarrow[]{ \mathrm{D} } \mathcal{N} \left( 0, \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

where J\mathbf{J} is the matrix of first-order derivatives of the function g\mathbf{g} with respect to the elements of θ\boldsymbol{\theta} and Γ\boldsymbol{\Gamma} is the asymptotic variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}.

From the former, we can derive the distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) as follows:

g(θ^)N(g(θ),n1JΓJ)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , n^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

The uncertainty associated with the estimator g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is, therefore, given by n1JΓJn^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} . When Γ\boldsymbol{\Gamma} is unknown, by substitution, we can use the estimated sampling variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}, that is, V^(θ^)\hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) for n1Γn^{-1} \boldsymbol{\Gamma}. Therefore, the sampling variance-covariance matrix of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is given by

g(θ^)N(g(θ),JV^(θ^)J).\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , \mathbf{J} \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \mathbf{J}^{\prime} \right) .

Value

Returns an object of class ctmeddelta which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("DeltaBeta").

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:

delta_t

Time interval.

jacobian

Jacobian matrix.

est

Estimated elements of the matrix of lagged coefficients.

vcov

Sampling variance-covariance matrix of estimated elements of the matrix of lagged coefficients.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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
)

# Specific time interval ----------------------------------------------------
DeltaBeta(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
delta <- DeltaBeta(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5
)
plot(delta)

# Methods -------------------------------------------------------------------
# DeltaBeta has a number of methods including
# print, summary, confint, and plot
print(delta)
summary(delta)
confint(delta, level = 0.95)
plot(delta)

Delta Method Sampling Variance-Covariance Matrix for the Indirect Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function computes the delta method sampling variance-covariance matrix for the indirect effect centrality over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

DeltaIndirectCentral(phi, vcov_phi_vec, delta_t, ncores = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

ncores

Positive integer. Number of cores to use. If ncores = NULL, use a single core. Consider using multiple cores when the length of delta_t is long.

Details

See IndirectCentral() more details.

Delta Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). By the multivariate central limit theory, the function g\mathbf{g} using θ^\hat{\boldsymbol{\theta}} as input can be expressed as:

n(g(θ^)g(θ))DN(0,JΓJ)\sqrt{n} \left( \mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) - \mathbf{g} \left( \boldsymbol{\theta} \right) \right) \xrightarrow[]{ \mathrm{D} } \mathcal{N} \left( 0, \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

where J\mathbf{J} is the matrix of first-order derivatives of the function g\mathbf{g} with respect to the elements of θ\boldsymbol{\theta} and Γ\boldsymbol{\Gamma} is the asymptotic variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}.

From the former, we can derive the distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) as follows:

g(θ^)N(g(θ),n1JΓJ)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , n^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

The uncertainty associated with the estimator g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is, therefore, given by n1JΓJn^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} . When Γ\boldsymbol{\Gamma} is unknown, by substitution, we can use the estimated sampling variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}, that is, V^(θ^)\hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) for n1Γn^{-1} \boldsymbol{\Gamma}. Therefore, the sampling variance-covariance matrix of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is given by

g(θ^)N(g(θ),JV^(θ^)J).\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , \mathbf{J} \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \mathbf{J}^{\prime} \right) .

Value

Returns an object of class ctmeddelta which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("DeltaIndirectCentral").

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:

delta_t

Time interval.

jacobian

Jacobian matrix.

est

Estimated indirect effect centrality.

vcov

Sampling variance-covariance matrix of estimated indirect effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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
)

# Specific time interval ----------------------------------------------------
DeltaIndirectCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
delta <- DeltaIndirectCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5
)
plot(delta)

# Methods -------------------------------------------------------------------
# DeltaIndirectCentral has a number of methods including
# print, summary, confint, and plot
print(delta)
summary(delta)
confint(delta, level = 0.95)
plot(delta)

Delta Method Sampling Variance-Covariance Matrix for the Total, Direct, and Indirect Effects of X on Y Through M Over a Specific Time Interval or a Range of Time Intervals

Description

This function computes the delta method sampling variance-covariance matrix for the total, direct, and indirect effects of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

DeltaMed(phi, vcov_phi_vec, delta_t, from, to, med, ncores = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY 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 the length of delta_t is long.

Details

See Total(), Direct(), and Indirect() for more details.

Delta Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). By the multivariate central limit theory, the function g\mathbf{g} using θ^\hat{\boldsymbol{\theta}} as input can be expressed as:

n(g(θ^)g(θ))DN(0,JΓJ)\sqrt{n} \left( \mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) - \mathbf{g} \left( \boldsymbol{\theta} \right) \right) \xrightarrow[]{ \mathrm{D} } \mathcal{N} \left( 0, \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

where J\mathbf{J} is the matrix of first-order derivatives of the function g\mathbf{g} with respect to the elements of θ\boldsymbol{\theta} and Γ\boldsymbol{\Gamma} is the asymptotic variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}.

From the former, we can derive the distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) as follows:

g(θ^)N(g(θ),n1JΓJ)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , n^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

The uncertainty associated with the estimator g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is, therefore, given by n1JΓJn^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} . When Γ\boldsymbol{\Gamma} is unknown, by substitution, we can use the estimated sampling variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}, that is, V^(θ^)\hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) for n1Γn^{-1} \boldsymbol{\Gamma}. Therefore, the sampling variance-covariance matrix of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is given by

g(θ^)N(g(θ),JV^(θ^)J).\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , \mathbf{J} \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \mathbf{J}^{\prime} \right) .

Value

Returns an object of class ctmeddelta which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("DeltaMed").

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:

delta_t

Time interval.

jacobian

Jacobian matrix.

est

Estimated total, direct, and indirect effects.

vcov

Sampling variance-covariance matrix of the estimated total, direct, and indirect effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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
)

# Specific time interval ----------------------------------------------------
DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)

# Range of time intervals ---------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
plot(delta)

# Methods -------------------------------------------------------------------
# DeltaMed has a number of methods including
# print, summary, confint, and plot
print(delta)
summary(delta)
confint(delta, level = 0.95)
plot(delta)

Delta Method Sampling Variance-Covariance Matrix for the Total Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function computes the delta method sampling variance-covariance matrix for the total effect centrality over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

DeltaTotalCentral(phi, vcov_phi_vec, delta_t, ncores = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

ncores

Positive integer. Number of cores to use. If ncores = NULL, use a single core. Consider using multiple cores when the length of delta_t is long.

Details

See TotalCentral() more details.

Delta Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). By the multivariate central limit theory, the function g\mathbf{g} using θ^\hat{\boldsymbol{\theta}} as input can be expressed as:

n(g(θ^)g(θ))DN(0,JΓJ)\sqrt{n} \left( \mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) - \mathbf{g} \left( \boldsymbol{\theta} \right) \right) \xrightarrow[]{ \mathrm{D} } \mathcal{N} \left( 0, \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

where J\mathbf{J} is the matrix of first-order derivatives of the function g\mathbf{g} with respect to the elements of θ\boldsymbol{\theta} and Γ\boldsymbol{\Gamma} is the asymptotic variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}.

From the former, we can derive the distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) as follows:

g(θ^)N(g(θ),n1JΓJ)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , n^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} \right)

The uncertainty associated with the estimator g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is, therefore, given by n1JΓJn^{-1} \mathbf{J} \boldsymbol{\Gamma} \mathbf{J}^{\prime} . When Γ\boldsymbol{\Gamma} is unknown, by substitution, we can use the estimated sampling variance-covariance matrix of θ^\hat{\boldsymbol{\theta}}, that is, V^(θ^)\hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) for n1Γn^{-1} \boldsymbol{\Gamma}. Therefore, the sampling variance-covariance matrix of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) is given by

g(θ^)N(g(θ),JV^(θ^)J).\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) \approx \mathcal{N} \left( \mathbf{g} \left( \boldsymbol{\theta} \right) , \mathbf{J} \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \mathbf{J}^{\prime} \right) .

Value

Returns an object of class ctmeddelta which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("DeltaTotalCentral").

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:

delta_t

Time interval.

jacobian

Jacobian matrix.

est

Estimated total effect centrality.

vcov

Sampling variance-covariance matrix of estimated total effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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
)

# Specific time interval ----------------------------------------------------
DeltaTotalCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
delta <- DeltaTotalCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5
)
plot(delta)

# Methods -------------------------------------------------------------------
# DeltaTotalCentral has a number of methods including
# print, summary, confint, and plot
print(delta)
summary(delta)
confint(delta, level = 0.95)
plot(delta)

Direct Effect of X on Y Over a Specific Time Interval

Description

This function computes the direct effect of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\Delta t using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

Direct(phi, delta_t, from, to, med)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Numeric. Time interval (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY in phi.

med

Character vector. Name/s of the mediator variable/s in phi.

Details

The direct effect of the independent variable XX on the dependent variable YY relative to some mediator variables m\mathbf{m} is given by

DirectΔti,j,m=exp(ΔtDΦD)i,j\mathrm{Direct}_{{\Delta t}_{i, j, \mathrm{\mathbf{m}}}} = \exp \left( \Delta t \mathbf{D} \boldsymbol{\Phi} \mathbf{D} \right)_{i, j}

where Φ\boldsymbol{\Phi} denotes the drift matrix, D\mathbf{D} a diagonal matrix where the diagonal elements corresponding to mediator variables m\mathbf{m} are set to zero and the rest to one, ii the row index of YY in Φ\boldsymbol{\Phi}, jj the column index of XX in Φ\boldsymbol{\Phi}, and Δt\Delta t the time interval.

Linear Stochastic Differential Equation Model

The measurement model is given by

yi,t=ν+Ληi,t+εi,t,withεi,tN(0,Θ)\mathbf{y}_{i, t} = \boldsymbol{\nu} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta} \right)

where yi,t\mathbf{y}_{i, t}, ηi,t\boldsymbol{\eta}_{i, t}, and εi,t\boldsymbol{\varepsilon}_{i, t} are random variables and ν\boldsymbol{\nu}, Λ\boldsymbol{\Lambda}, and Θ\boldsymbol{\Theta} are model parameters. yi,t\mathbf{y}_{i, t} represents a vector of observed random variables, ηi,t\boldsymbol{\eta}_{i, t} a vector of latent random variables, and εi,t\boldsymbol{\varepsilon}_{i, t} a vector of random measurement errors, at time tt and individual ii. ν\boldsymbol{\nu} denotes a vector of intercepts, Λ\boldsymbol{\Lambda} a matrix of factor loadings, and Θ\boldsymbol{\Theta} the covariance matrix of ε\boldsymbol{\varepsilon}.

An alternative representation of the measurement error is given by

εi,t=Θ12zi,t,withzi,tN(0,I)\boldsymbol{\varepsilon}_{i, t} = \boldsymbol{\Theta}^{\frac{1}{2}} \mathbf{z}_{i, t}, \quad \mathrm{with} \quad \mathbf{z}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \mathbf{I} \right)

where zi,t\mathbf{z}_{i, t} is a vector of independent standard normal random variables and (Θ12)(Θ12)=Θ.\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right) \left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Theta} .

The dynamic structure is given by

dηi,t=(ι+Φηi,t)dt+Σ12dWi,t\mathrm{d} \boldsymbol{\eta}_{i, t} = \left( \boldsymbol{\iota} + \boldsymbol{\Phi} \boldsymbol{\eta}_{i, t} \right) \mathrm{d}t + \boldsymbol{\Sigma}^{\frac{1}{2}} \mathrm{d} \mathbf{W}_{i, t}

where ι\boldsymbol{\iota} is a term which is unobserved and constant over time, Φ\boldsymbol{\Phi} is the drift matrix which represents the rate of change of the solution in the absence of any random fluctuations, Σ\boldsymbol{\Sigma} is the matrix of volatility or randomness in the process, and dW\mathrm{d}\boldsymbol{W} is a Wiener process or Brownian motion, which represents random fluctuations.

Value

Returns an object of class ctmedeffect which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("Direct").

output

The direct effect.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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")
delta_t <- 1
Direct(
  phi = phi,
  delta_t = delta_t,
  from = "x",
  to = "y",
  med = "m"
)
phi <- matrix(
  data = c(
    -6, 5.5, 0, 0,
    1.25, -2.5, 5.9, -7.3,
    0, 0, -6, 2.5,
    5, 0, 0, -6
  ),
  nrow = 4
)
colnames(phi) <- rownames(phi) <- paste0("y", 1:4)
Direct(
  phi = phi,
  delta_t = delta_t,
  from = "y2",
  to = "y4",
  med = c("y1", "y3")
)

Indirect Effect of X on Y Through M Over a Specific Time Interval

Description

This function computes the indirect effect of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\Delta t using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

Indirect(phi, delta_t, from, to, med)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Numeric. Time interval (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY in phi.

med

Character vector. Name/s of the mediator variable/s in phi.

Details

The indirect effect of the independent variable XX on the dependent variable YY relative to some mediator variables m\mathbf{m} over a specific time interval Δt\Delta t is given by

IndirectΔt=exp(ΔtΦ)i,jexp(ΔtDmΦDm)i,j\mathrm{Indirect}_{\Delta t} = \exp \left( \Delta t \boldsymbol{\Phi} \right)_{i, j} - \exp \left( \Delta t \mathbf{D}_{\mathbf{m}} \boldsymbol{\Phi} \mathbf{D}_{\mathbf{m}} \right)_{i, j}

where Φ\boldsymbol{\Phi} denotes the drift matrix, Dm\mathbf{D}_{\mathbf{m}} a matrix where the off diagonal elements are zeros and the diagonal elements are zero for the index/indices of mediator variables m\mathbf{m} and one otherwise, ii the row index of YY in Φ\boldsymbol{\Phi}, jj the column index of XX in Φ\boldsymbol{\Phi}, and Δt\Delta t the time interval.

Linear Stochastic Differential Equation Model

The measurement model is given by

yi,t=ν+Ληi,t+εi,t,withεi,tN(0,Θ)\mathbf{y}_{i, t} = \boldsymbol{\nu} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta} \right)

where yi,t\mathbf{y}_{i, t}, ηi,t\boldsymbol{\eta}_{i, t}, and εi,t\boldsymbol{\varepsilon}_{i, t} are random variables and ν\boldsymbol{\nu}, Λ\boldsymbol{\Lambda}, and Θ\boldsymbol{\Theta} are model parameters. yi,t\mathbf{y}_{i, t} represents a vector of observed random variables, ηi,t\boldsymbol{\eta}_{i, t} a vector of latent random variables, and εi,t\boldsymbol{\varepsilon}_{i, t} a vector of random measurement errors, at time tt and individual ii. ν\boldsymbol{\nu} denotes a vector of intercepts, Λ\boldsymbol{\Lambda} a matrix of factor loadings, and Θ\boldsymbol{\Theta} the covariance matrix of ε\boldsymbol{\varepsilon}.

An alternative representation of the measurement error is given by

εi,t=Θ12zi,t,withzi,tN(0,I)\boldsymbol{\varepsilon}_{i, t} = \boldsymbol{\Theta}^{\frac{1}{2}} \mathbf{z}_{i, t}, \quad \mathrm{with} \quad \mathbf{z}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \mathbf{I} \right)

where zi,t\mathbf{z}_{i, t} is a vector of independent standard normal random variables and (Θ12)(Θ12)=Θ.\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right) \left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Theta} .

The dynamic structure is given by

dηi,t=(ι+Φηi,t)dt+Σ12dWi,t\mathrm{d} \boldsymbol{\eta}_{i, t} = \left( \boldsymbol{\iota} + \boldsymbol{\Phi} \boldsymbol{\eta}_{i, t} \right) \mathrm{d}t + \boldsymbol{\Sigma}^{\frac{1}{2}} \mathrm{d} \mathbf{W}_{i, t}

where ι\boldsymbol{\iota} is a term which is unobserved and constant over time, Φ\boldsymbol{\Phi} is the drift matrix which represents the rate of change of the solution in the absence of any random fluctuations, Σ\boldsymbol{\Sigma} is the matrix of volatility or randomness in the process, and dW\mathrm{d}\boldsymbol{W} is a Wiener process or Brownian motion, which represents random fluctuations.

Value

Returns an object of class ctmedeffect which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("Indirect").

output

The indirect effect.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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")
delta_t <- 1
Indirect(
  phi = phi,
  delta_t = delta_t,
  from = "x",
  to = "y",
  med = "m"
)
phi <- matrix(
  data = c(
    -6, 5.5, 0, 0,
    1.25, -2.5, 5.9, -7.3,
    0, 0, -6, 2.5,
    5, 0, 0, -6
  ),
  nrow = 4
)
colnames(phi) <- rownames(phi) <- paste0("y", 1:4)
Indirect(
  phi = phi,
  delta_t = delta_t,
  from = "y2",
  to = "y4",
  med = c("y1", "y3")
)

Indirect Effect Centrality

Description

Indirect Effect Centrality

Usage

IndirectCentral(phi, delta_t)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

Details

Indirect effect centrality is the sum of all possible indirect effects between different pairs of variables in which a specific variable serves as the only mediator.

Value

Returns an object of class ctmedmed which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("IndirectCentral").

output

A matrix of indirect effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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")

# Specific time interval ----------------------------------------------------
IndirectCentral(
  phi = phi,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
indirect_central <- IndirectCentral(
  phi = phi,
  delta_t = 1:30
)
plot(indirect_central)

# Methods -------------------------------------------------------------------
# IndirectCentral has a number of methods including
# print, summary, and plot
indirect_central <- IndirectCentral(
  phi = phi,
  delta_t = 1:5
)
print(indirect_central)
summary(indirect_central)
plot(indirect_central)

Monte Carlo Sampling Distribution for the Elements of the Matrix of Lagged Coefficients Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a Monte Carlo method sampling distribution for the elements of the matrix of lagged coefficients β\boldsymbol{\beta} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model drift matrix Φ\boldsymbol{\Phi}.

Usage

MCBeta(
  phi,
  vcov_phi_vec,
  delta_t,
  R,
  test_phi = TRUE,
  ncores = NULL,
  seed = NULL
)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Numeric. Time interval (Δt\Delta t).

R

Positive integer. Number of replications.

test_phi

Logical. If test_phi = TRUE, the function tests the stability of the generated drift matrix Φ\boldsymbol{\Phi}. If the test returns FALSE, the function generates a new drift matrix Φ\boldsymbol{\Phi} and runs the test recursively until the test returns TRUE.

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.

seed

Random seed.

Details

See Total().

Monte Carlo Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters.

θ^N(θ,V(θ^))\hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right)

Using this distributional assumption, a sampling distribution of θ^\hat{\boldsymbol{\theta}} which we refer to as θ^\hat{\boldsymbol{\theta}}^{\ast} can be generated by replacing the population parameters with sample estimates, that is,

θ^N(θ^,V^(θ^)).\hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) .

Let g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) be a parameter that is a function of the estimated parameters. A sampling distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) , which we refer to as g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}}^{\ast} \right) , can be generated by using the simulated estimates to calculate g\mathbf{g}. The standard deviations of the simulated estimates are the standard errors. Percentiles corresponding to 100(1α)%100 \left( 1 - \alpha \right) \% are the confidence intervals.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("MCBeta").

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

A vector of total, direct, and indirect effects.

thetahatstar

A matrix of Monte Carlo total, direct, and indirect effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
MCBeta(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  R = 100L # use a large value for R in actual research
)

# Range of time intervals ---------------------------------------------------
mc <- MCBeta(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  R = 100L # use a large value for R in actual research
)
plot(mc)

# Methods -------------------------------------------------------------------
# MCBeta has a number of methods including
# print, summary, confint, and plot
print(mc)
summary(mc)
confint(mc, level = 0.95)
plot(mc)

Monte Carlo Sampling Distribution of Indirect Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a Monte Carlo method sampling distribution of the indirect effect centrality at a particular time interval Δt\Delta t using the first-order stochastic differential equation model drift matrix Φ\boldsymbol{\Phi}.

Usage

MCIndirectCentral(
  phi,
  vcov_phi_vec,
  delta_t,
  R,
  test_phi = TRUE,
  ncores = NULL,
  seed = NULL
)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Numeric. Time interval (Δt\Delta t).

R

Positive integer. Number of replications.

test_phi

Logical. If test_phi = TRUE, the function tests the stability of the generated drift matrix Φ\boldsymbol{\Phi}. If the test returns FALSE, the function generates a new drift matrix Φ\boldsymbol{\Phi} and runs the test recursively until the test returns TRUE.

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.

seed

Random seed.

Details

See IndirectCentral() for more details.

Monte Carlo Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters.

θ^N(θ,V(θ^))\hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right)

Using this distributional assumption, a sampling distribution of θ^\hat{\boldsymbol{\theta}} which we refer to as θ^\hat{\boldsymbol{\theta}}^{\ast} can be generated by replacing the population parameters with sample estimates, that is,

θ^N(θ^,V^(θ^)).\hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) .

Let g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) be a parameter that is a function of the estimated parameters. A sampling distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) , which we refer to as g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}}^{\ast} \right) , can be generated by using the simulated estimates to calculate g\mathbf{g}. The standard deviations of the simulated estimates are the standard errors. Percentiles corresponding to 100(1α)%100 \left( 1 - \alpha \right) \% are the confidence intervals.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("MCIndirectCentral").

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

A vector of indirect effect centrality.

thetahatstar

A matrix of Monte Carlo indirect effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
MCIndirectCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  R = 100L # use a large value for R in actual research
)

# Range of time intervals ---------------------------------------------------
mc <- MCIndirectCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  R = 100L # use a large value for R in actual research
)
plot(mc)

# Methods -------------------------------------------------------------------
# MCIndirectCentral has a number of methods including
# print, summary, confint, and plot
print(mc)
summary(mc)
confint(mc, level = 0.95)
plot(mc)

Monte Carlo 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

Description

This function generates a Monte Carlo method sampling distribution of the total, direct and indirect effects of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model drift matrix Φ\boldsymbol{\Phi}.

Usage

MCMed(
  phi,
  vcov_phi_vec,
  delta_t,
  from,
  to,
  med,
  R,
  test_phi = TRUE,
  ncores = NULL,
  seed = NULL
)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Numeric. Time interval (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY in phi.

med

Character vector. Name/s of the mediator variable/s in phi.

R

Positive integer. Number of replications.

test_phi

Logical. If test_phi = TRUE, the function tests the stability of the generated drift matrix Φ\boldsymbol{\Phi}. If the test returns FALSE, the function generates a new drift matrix Φ\boldsymbol{\Phi} and runs the test recursively until the test returns TRUE.

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.

seed

Random seed.

Details

See Total(), Direct(), and Indirect() for more details.

Monte Carlo Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters.

θ^N(θ,V(θ^))\hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right)

Using this distributional assumption, a sampling distribution of θ^\hat{\boldsymbol{\theta}} which we refer to as θ^\hat{\boldsymbol{\theta}}^{\ast} can be generated by replacing the population parameters with sample estimates, that is,

θ^N(θ^,V^(θ^)).\hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) .

Let g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) be a parameter that is a function of the estimated parameters. A sampling distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) , which we refer to as g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}}^{\ast} \right) , can be generated by using the simulated estimates to calculate g\mathbf{g}. The standard deviations of the simulated estimates are the standard errors. Percentiles corresponding to 100(1α)%100 \left( 1 - \alpha \right) \% are the confidence intervals.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("MCMed").

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 Monte Carlo total, direct, and indirect effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)

# Range of time intervals ---------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
plot(mc)

# Methods -------------------------------------------------------------------
# MCMed has a number of methods including
# print, summary, confint, and plot
print(mc)
summary(mc)
confint(mc, level = 0.95)

Generate Random Drift Matrices Using the Monte Carlo Method

Description

This function generates random drift matrices Φ\boldsymbol{\Phi} using the Monte Carlo method.

Usage

MCPhi(phi, vcov_phi_vec, R, test_phi = TRUE, ncores = NULL, seed = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

R

Positive integer. Number of replications.

test_phi

Logical. If test_phi = TRUE, the function tests the stability of the generated drift matrix Φ\boldsymbol{\Phi}. If the test returns FALSE, the function generates a new drift matrix Φ\boldsymbol{\Phi} and runs the test recursively until the test returns TRUE.

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.

seed

Random seed.

Details

Monte Carlo Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters.

θ^N(θ,V(θ^))\hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right)

Using this distributional assumption, a sampling distribution of θ^\hat{\boldsymbol{\theta}} which we refer to as θ^\hat{\boldsymbol{\theta}}^{\ast} can be generated by replacing the population parameters with sample estimates, that is,

θ^N(θ^,V^(θ^)).\hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) .

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("MCPhi").

output

A list simulated drift matrices.

Author(s)

Ivan Jacob Agaloos Pesigan

See Also

Other Continuous Time Mediation Functions: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()

Examples

set.seed(42)
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")
MCPhi(
  phi = phi,
  vcov_phi_vec = 0.1 * diag(9),
  R = 100L # use a large value for R in actual research
)
phi <- matrix(
  data = c(
    -6, 5.5, 0, 0,
    1.25, -2.5, 5.9, -7.3,
    0, 0, -6, 2.5,
    5, 0, 0, -6
  ),
  nrow = 4
)
colnames(phi) <- rownames(phi) <- paste0("y", 1:4)
MCPhi(
  phi = phi,
  vcov_phi_vec = 0.1 * diag(16),
  R = 100L, # use a large value for R in actual research
  test_phi = FALSE
)

Monte Carlo Sampling Distribution of Total Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a Monte Carlo method sampling distribution of the total effect centrality at a particular time interval Δt\Delta t using the first-order stochastic differential equation model drift matrix Φ\boldsymbol{\Phi}.

Usage

MCTotalCentral(
  phi,
  vcov_phi_vec,
  delta_t,
  R,
  test_phi = TRUE,
  ncores = NULL,
  seed = NULL
)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

vcov_phi_vec

Numeric matrix. The sampling variance-covariance matrix of vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right).

delta_t

Numeric. Time interval (Δt\Delta t).

R

Positive integer. Number of replications.

test_phi

Logical. If test_phi = TRUE, the function tests the stability of the generated drift matrix Φ\boldsymbol{\Phi}. If the test returns FALSE, the function generates a new drift matrix Φ\boldsymbol{\Phi} and runs the test recursively until the test returns TRUE.

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.

seed

Random seed.

Details

See TotalCentral() for more details.

Monte Carlo Method

Let θ\boldsymbol{\theta} be vec(Φ)\mathrm{vec} \left( \boldsymbol{\Phi} \right), that is, the elements of the Φ\boldsymbol{\Phi} matrix in vector form sorted column-wise. Let θ^\hat{\boldsymbol{\theta}} be vec(Φ^)\mathrm{vec} \left( \hat{\boldsymbol{\Phi}} \right). Based on the asymptotic properties of maximum likelihood estimators, we can assume that estimators are normally distributed around the population parameters.

θ^N(θ,V(θ^))\hat{\boldsymbol{\theta}} \sim \mathcal{N} \left( \boldsymbol{\theta}, \mathbb{V} \left( \hat{\boldsymbol{\theta}} \right) \right)

Using this distributional assumption, a sampling distribution of θ^\hat{\boldsymbol{\theta}} which we refer to as θ^\hat{\boldsymbol{\theta}}^{\ast} can be generated by replacing the population parameters with sample estimates, that is,

θ^N(θ^,V^(θ^)).\hat{\boldsymbol{\theta}}^{\ast} \sim \mathcal{N} \left( \hat{\boldsymbol{\theta}}, \hat{\mathbb{V}} \left( \hat{\boldsymbol{\theta}} \right) \right) .

Let g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) be a parameter that is a function of the estimated parameters. A sampling distribution of g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}} \right) , which we refer to as g(θ^)\mathbf{g} \left( \hat{\boldsymbol{\theta}}^{\ast} \right) , can be generated by using the simulated estimates to calculate g\mathbf{g}. The standard deviations of the simulated estimates are the standard errors. Percentiles corresponding to 100(1α)%100 \left( 1 - \alpha \right) \% are the confidence intervals.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("MCTotalCentral").

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

A vector of total effect centrality.

thetahatstar

A matrix of Monte Carlo total effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
MCTotalCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  R = 100L # use a large value for R in actual research
)

# Range of time intervals ---------------------------------------------------
mc <- MCTotalCentral(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  R = 100L # use a large value for R in actual research
)
plot(mc)

# Methods -------------------------------------------------------------------
# MCTotalCentral has a number of methods including
# print, summary, confint, and plot
print(mc)
summary(mc)
confint(mc, level = 0.95)
plot(mc)

Total, Direct, and Indirect Effects of X on Y Through M Over a Specific Time Interval or a Range of Time Intervals

Description

This function computes the total, direct, and indirect effects of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

Med(phi, delta_t, from, to, med)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY in phi.

med

Character vector. Name/s of the mediator variable/s in phi.

Details

See Total(), Direct(), and Indirect() for more details.

Linear Stochastic Differential Equation Model

The measurement model is given by

yi,t=ν+Ληi,t+εi,t,withεi,tN(0,Θ)\mathbf{y}_{i, t} = \boldsymbol{\nu} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta} \right)

where yi,t\mathbf{y}_{i, t}, ηi,t\boldsymbol{\eta}_{i, t}, and εi,t\boldsymbol{\varepsilon}_{i, t} are random variables and ν\boldsymbol{\nu}, Λ\boldsymbol{\Lambda}, and Θ\boldsymbol{\Theta} are model parameters. yi,t\mathbf{y}_{i, t} represents a vector of observed random variables, ηi,t\boldsymbol{\eta}_{i, t} a vector of latent random variables, and εi,t\boldsymbol{\varepsilon}_{i, t} a vector of random measurement errors, at time tt and individual ii. ν\boldsymbol{\nu} denotes a vector of intercepts, Λ\boldsymbol{\Lambda} a matrix of factor loadings, and Θ\boldsymbol{\Theta} the covariance matrix of ε\boldsymbol{\varepsilon}.

An alternative representation of the measurement error is given by

εi,t=Θ12zi,t,withzi,tN(0,I)\boldsymbol{\varepsilon}_{i, t} = \boldsymbol{\Theta}^{\frac{1}{2}} \mathbf{z}_{i, t}, \quad \mathrm{with} \quad \mathbf{z}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \mathbf{I} \right)

where zi,t\mathbf{z}_{i, t} is a vector of independent standard normal random variables and (Θ12)(Θ12)=Θ.\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right) \left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Theta} .

The dynamic structure is given by

dηi,t=(ι+Φηi,t)dt+Σ12dWi,t\mathrm{d} \boldsymbol{\eta}_{i, t} = \left( \boldsymbol{\iota} + \boldsymbol{\Phi} \boldsymbol{\eta}_{i, t} \right) \mathrm{d}t + \boldsymbol{\Sigma}^{\frac{1}{2}} \mathrm{d} \mathbf{W}_{i, t}

where ι\boldsymbol{\iota} is a term which is unobserved and constant over time, Φ\boldsymbol{\Phi} is the drift matrix which represents the rate of change of the solution in the absence of any random fluctuations, Σ\boldsymbol{\Sigma} is the matrix of volatility or randomness in the process, and dW\mathrm{d}\boldsymbol{W} is a Wiener process or Brownian motion, which represents random fluctuations.

Value

Returns an object of class ctmedmed which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("Med").

output

A matrix of total, direct, and indirect effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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")

# Specific time interval ----------------------------------------------------
Med(
  phi = phi,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)

# Range of time intervals ---------------------------------------------------
med <- Med(
  phi = phi,
  delta_t = 1:30,
  from = "x",
  to = "y",
  med = "m"
)
plot(med)

# Methods -------------------------------------------------------------------
# Med has a number of methods including
# print, summary, and plot
med <- Med(
  phi = phi,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
print(med)
summary(med)
plot(med)

Plot Method for an Object of Class ctmeddelta

Description

Plot Method for an Object of Class ctmeddelta

Usage

## S3 method for class 'ctmeddelta'
plot(x, alpha = 0.05, col = NULL, ...)

Arguments

x

Object of class ctmeddelta.

alpha

Numeric. Significance level

col

Character vector. Optional argument. Character vector of colors.

...

Additional arguments.

Value

Displays plots of point estimates and confidence intervals.

Author(s)

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
)

# Range of time intervals ---------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
plot(delta)

Plot Method for an Object of Class ctmedmc

Description

Plot Method for an Object of Class ctmedmc

Usage

## S3 method for class 'ctmedmc'
plot(x, alpha = 0.05, col = NULL, ...)

Arguments

x

Object of class ctmedmc.

alpha

Numeric. Significance level

col

Character vector. Optional argument. Character vector of colors.

...

Additional arguments.

Value

Displays plots of point estimates and confidence intervals.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
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
)

# Range of time intervals ---------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
plot(mc)

Plot Method for an Object of Class ctmedmed

Description

Plot Method for an Object of Class ctmedmed

Usage

## S3 method for class 'ctmedmed'
plot(x, col = NULL, legend_pos = "topright", ...)

Arguments

x

Object of class ctmedmed.

col

Character vector. Optional argument. Character vector of colors.

legend_pos

Character vector. Optional argument. Legend position.

...

Additional arguments.

Value

Displays plots of point estimates and confidence intervals.

Author(s)

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")

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

Plot Method for an Object of Class ctmedtraj

Description

Plot Method for an Object of Class ctmedtraj

Usage

## S3 method for class 'ctmedtraj'
plot(x, legend_pos = "topright", total = TRUE, ...)

Arguments

x

Object of class ctmedtraj.

legend_pos

Character vector. Optional argument. Legend position.

total

Logical. If total = TRUE, include the total effect trajectory. If total = FALSE, exclude the total effect trajectory.

...

Additional arguments.

Value

Displays trajectory plots of the effects.

Author(s)

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")

traj <- Trajectory(
  mu0 = c(3, 3, -3),
  time = 150,
  phi = phi,
  med = "m"
)

plot(traj)

Posterior Sampling Distribution for the Elements of the Matrix of Lagged Coefficients Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a posterior sampling distribution for the elements of the matrix of lagged coefficients β\boldsymbol{\beta} over a specific time interval Δt\Delta t or a range of time intervals using the first-order stochastic differential equation model drift matrix Φ\boldsymbol{\Phi}.

Usage

PosteriorBeta(phi, delta_t, ncores = NULL)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Numeric. Time interval (Δt\Delta t).

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.

Details

See Total().

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("PosteriorBeta").

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

A vector of total, direct, and indirect effects.

thetahatstar

A matrix of Monte Carlo total, direct, and indirect effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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 ----------------------------------------------------
PosteriorBeta(
  phi = phi,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
posterior <- PosteriorBeta(
  phi = phi,
  delta_t = 1:5
)
plot(posterior)

# Methods -------------------------------------------------------------------
# PosteriorBeta has a number of methods including
# print, summary, confint, and plot
print(posterior)
summary(posterior)
confint(posterior, level = 0.95)
plot(posterior)

Posterior Distribution of the Indirect Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a posterior distribution of the indirect effect centrality over a specific time interval Δt\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

PosteriorIndirectCentral(phi, delta_t, 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 (Δt\Delta t).

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.

Details

See TotalCentral() for more details.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("PosteriorIndirectCentral").

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.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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 ----------------------------------------------------
PosteriorIndirectCentral(
  phi = phi,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
posterior <- PosteriorIndirectCentral(
  phi = phi,
  delta_t = 1:5
)

# Methods -------------------------------------------------------------------
# PosteriorIndirectCentral has a number of methods including
# print, summary, confint, and plot
print(posterior)
summary(posterior)
confint(posterior, level = 0.95)
plot(posterior)

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

Description

This function generates a posterior distribution of the total, direct and indirect effects of the independent variable XX on the dependent variable YY through mediator variables m\mathbf{m} over a specific time interval Δt\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 (Δt\Delta t).

from

Character string. Name of the independent variable XX in phi.

to

Character string. Name of the dependent variable YY 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.

Details

See Total(), Direct(), and Indirect() for more details.

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.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral(), 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.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"
)

# 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)
summary(posterior)
confint(posterior, level = 0.95)
plot(posterior)

Extract the Posterior Samples of the Drift Matrix

Description

The function extracts the posterior samples of the drift matrix from a fitted model from the ctsem::ctStanFit() function.

Usage

PosteriorPhi(object)

Arguments

object

Object of class ctStanFit. Output of the ctsem::ctStanFit() function.

Value

Returns an object of class ctmedposteriorphi which is a list drift matrices sampled from the posterior distribution.

Author(s)

Ivan Jacob Agaloos Pesigan

See Also

Other Continuous Time Mediation Functions: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorTotalCentral(), Total(), TotalCentral(), Trajectory()


Posterior Distribution of the Total Effect Centrality Over a Specific Time Interval or a Range of Time Intervals

Description

This function generates a posterior distribution of the total effect centrality over a specific time interval Δt\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

PosteriorTotalCentral(phi, delta_t, 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 (Δt\Delta t).

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.

Details

See TotalCentral() for more details.

Value

Returns an object of class ctmedmc which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("PosteriorTotalCentral").

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.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), Total(), TotalCentral(), 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.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 ----------------------------------------------------
PosteriorTotalCentral(
  phi = phi,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
posterior <- PosteriorTotalCentral(
  phi = phi,
  delta_t = 1:5
)

# Methods -------------------------------------------------------------------
# PosteriorTotalCentral has a number of methods including
# print, summary, confint, and plot
print(posterior)
summary(posterior)
confint(posterior, level = 0.95)
plot(posterior)

Print Method for Object of Class ctmeddelta

Description

Print Method for Object of Class ctmeddelta

Usage

## S3 method for class 'ctmeddelta'
print(x, alpha = 0.05, digits = 4, ...)

Arguments

x

an object of class ctmeddelta.

alpha

Numeric vector. Significance level α\alpha.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Prints a list of matrices of time intervals, estimates, standard errors, test statistics, p-values, and confidence intervals.

Author(s)

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
)

# Specific time interval ----------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)
print(delta)

# Range of time intervals ---------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
print(delta)

Print Method for Object of Class ctmedeffect

Description

Print Method for Object of Class ctmedeffect

Usage

## S3 method for class 'ctmedeffect'
print(x, digits = 4, ...)

Arguments

x

an object of class ctmedeffect.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Prints the effects.

Author(s)

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")
delta_t <- 1

# Time Interval of One -----------------------------------------------------

## Total Effect ------------------------------------------------------------
total_dt <- Total(
  phi = phi,
  delta_t = delta_t
)
print(total_dt)

## Direct Effect -----------------------------------------------------------
direct_dt <- Direct(
  phi = phi,
  delta_t = delta_t,
  from = "x",
  to = "y",
  med = "m"
)
print(direct_dt)

## Indirect Effect ---------------------------------------------------------
indirect_dt <- Indirect(
  phi = phi,
  delta_t = delta_t,
  from = "x",
  to = "y",
  med = "m"
)
print(indirect_dt)

Print Method for Object of Class ctmedmc

Description

Print Method for Object of Class ctmedmc

Usage

## S3 method for class 'ctmedmc'
print(x, alpha = 0.05, digits = 4, ...)

Arguments

x

an object of class ctmedmc.

alpha

Numeric vector. Significance level α\alpha.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Prints a list of matrices of time intervals, estimates, standard errors, number of Monte Carlo replications, and confidence intervals.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
print(mc)

# Range of time intervals ---------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
print(mc)

Print Method for Object of Class ctmedmcphi

Description

Print Method for Object of Class ctmedmcphi

Usage

## S3 method for class 'ctmedmcphi'
print(x, digits = 4, ...)

Arguments

x

an object of class ctmedmcphi.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Prints a list of drift matrices.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
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")
mc <- MCPhi(
  phi = phi,
  vcov_phi_vec = 0.1 * diag(9),
  R = 100L # use a large value for R in actual research
)
print(mc)

Print Method for Object of Class ctmedmed

Description

Print Method for Object of Class ctmedmed

Usage

## S3 method for class 'ctmedmed'
print(x, digits = 4, ...)

Arguments

x

an object of class ctmedmed.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Prints a matrix of effects.

Author(s)

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")

# Specific time interval ----------------------------------------------------
med <- Med(
  phi = phi,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)
print(med)

# Range of time intervals ---------------------------------------------------
med <- Med(
  phi = phi,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
print(med)

Print Method for Object of Class ctmedtraj

Description

Print Method for Object of Class ctmedtraj

Usage

## S3 method for class 'ctmedtraj'
print(x, ...)

Arguments

x

an object of class ctmedtraj.

...

further arguments.

Value

Prints a data frame of simulated data.

Author(s)

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")

traj <- Trajectory(
  mu0 = c(3, 3, -3),
  time = 150,
  phi = phi,
  med = "m"
)

print(traj)

Summary Method for an Object of Class ctmeddelta

Description

Summary Method for an Object of Class ctmeddelta

Usage

## S3 method for class 'ctmeddelta'
summary(object, alpha = 0.05, ...)

Arguments

object

Object of class ctmeddelta.

alpha

Numeric vector. Significance level α\alpha.

...

additional arguments.

Value

Returns a data frame of effects, time intervals, estimates, standard errors, test statistics, p-values, and confidence intervals.

Author(s)

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
)

# Specific time interval ----------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)
summary(delta)

# Range of time intervals ---------------------------------------------------
delta <- DeltaMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
summary(delta)

Summary Method for an Object of Class ctmedmc

Description

Summary Method for an Object of Class ctmedmc

Usage

## S3 method for class 'ctmedmc'
summary(object, alpha = 0.05, ...)

Arguments

object

Object of class ctmedmc.

alpha

Numeric vector. Significance level α\alpha.

...

additional arguments.

Value

Returns a data frame of effects, time intervals, estimates, standard errors, number of Monte Carlo replications, and confidence intervals.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
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
)

# Specific time interval ----------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
summary(mc)

# Range of time intervals ---------------------------------------------------
mc <- MCMed(
  phi = phi,
  vcov_phi_vec = vcov_phi_vec,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m",
  R = 100L # use a large value for R in actual research
)
summary(mc)

Summary Method for an Object of Class ctmedmed

Description

Summary Method for an Object of Class ctmedmed

Usage

## S3 method for class 'ctmedmed'
summary(object, digits = 4, ...)

Arguments

object

an object of class ctmedmed.

digits

Integer indicating the number of decimal places to display.

...

further arguments.

Value

Returns a matrix of effects.

Author(s)

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")

# Specific time interval ----------------------------------------------------
med <- Med(
  phi = phi,
  delta_t = 1,
  from = "x",
  to = "y",
  med = "m"
)
summary(med)

# Range of time intervals ---------------------------------------------------
med <- Med(
  phi = phi,
  delta_t = 1:5,
  from = "x",
  to = "y",
  med = "m"
)
summary(med)

Summary Method for Object of Class ctmedposteriorphi

Description

Summary Method for Object of Class ctmedposteriorphi

Usage

## S3 method for class 'ctmedposteriorphi'
summary(object, ...)

Arguments

object

an object of class ctmedposteriorphi.

...

further arguments.

Value

Returns a list of the posterior means (in matrix form) and covariance matrix.

Author(s)

Ivan Jacob Agaloos Pesigan


Summary Method for an Object of Class ctmedtraj

Description

Summary Method for an Object of Class ctmedtraj

Usage

## S3 method for class 'ctmedtraj'
summary(object, ...)

Arguments

object

an object of class ctmedtraj.

...

further arguments.

Value

Returns a data frame of simulated data.

Author(s)

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")

traj <- Trajectory(
  mu0 = c(3, 3, -3),
  time = 150,
  phi = phi,
  med = "m"
)

summary(traj)

Total Effect Matrix Over a Specific Time Interval

Description

This function computes the total effects matrix over a specific time interval Δt\Delta t using the first-order stochastic differential equation model's drift matrix Φ\boldsymbol{\Phi}.

Usage

Total(phi, delta_t)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Numeric. Time interval (Δt\Delta t).

Details

The total effect matrix over a specific time interval Δt\Delta t is given by

TotalΔt=exp(ΔtΦ)\mathrm{Total}_{\Delta t} = \exp \left( \Delta t \boldsymbol{\Phi} \right)

where Φ\boldsymbol{\Phi} denotes the drift matrix, and Δt\Delta t the time interval.

Linear Stochastic Differential Equation Model

The measurement model is given by

yi,t=ν+Ληi,t+εi,t,withεi,tN(0,Θ)\mathbf{y}_{i, t} = \boldsymbol{\nu} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta} \right)

where yi,t\mathbf{y}_{i, t}, ηi,t\boldsymbol{\eta}_{i, t}, and εi,t\boldsymbol{\varepsilon}_{i, t} are random variables and ν\boldsymbol{\nu}, Λ\boldsymbol{\Lambda}, and Θ\boldsymbol{\Theta} are model parameters. yi,t\mathbf{y}_{i, t} represents a vector of observed random variables, ηi,t\boldsymbol{\eta}_{i, t} a vector of latent random variables, and εi,t\boldsymbol{\varepsilon}_{i, t} a vector of random measurement errors, at time tt and individual ii. ν\boldsymbol{\nu} denotes a vector of intercepts, Λ\boldsymbol{\Lambda} a matrix of factor loadings, and Θ\boldsymbol{\Theta} the covariance matrix of ε\boldsymbol{\varepsilon}.

An alternative representation of the measurement error is given by

εi,t=Θ12zi,t,withzi,tN(0,I)\boldsymbol{\varepsilon}_{i, t} = \boldsymbol{\Theta}^{\frac{1}{2}} \mathbf{z}_{i, t}, \quad \mathrm{with} \quad \mathbf{z}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \mathbf{I} \right)

where zi,t\mathbf{z}_{i, t} is a vector of independent standard normal random variables and (Θ12)(Θ12)=Θ.\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right) \left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Theta} .

The dynamic structure is given by

dηi,t=(ι+Φηi,t)dt+Σ12dWi,t\mathrm{d} \boldsymbol{\eta}_{i, t} = \left( \boldsymbol{\iota} + \boldsymbol{\Phi} \boldsymbol{\eta}_{i, t} \right) \mathrm{d}t + \boldsymbol{\Sigma}^{\frac{1}{2}} \mathrm{d} \mathbf{W}_{i, t}

where ι\boldsymbol{\iota} is a term which is unobserved and constant over time, Φ\boldsymbol{\Phi} is the drift matrix which represents the rate of change of the solution in the absence of any random fluctuations, Σ\boldsymbol{\Sigma} is the matrix of volatility or randomness in the process, and dW\mathrm{d}\boldsymbol{W} is a Wiener process or Brownian motion, which represents random fluctuations.

Value

Returns an object of class ctmedeffect which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("Total").

output

The matrix of total effects.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), TotalCentral(), 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")
delta_t <- 1
Total(
  phi = phi,
  delta_t = delta_t
)
phi <- matrix(
  data = c(
    -6, 5.5, 0, 0,
    1.25, -2.5, 5.9, -7.3,
    0, 0, -6, 2.5,
    5, 0, 0, -6
  ),
  nrow = 4
)
colnames(phi) <- rownames(phi) <- paste0("y", 1:4)
Total(
  phi = phi,
  delta_t = delta_t
)

Total Effect Centrality

Description

Total Effect Centrality

Usage

TotalCentral(phi, delta_t)

Arguments

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

delta_t

Vector of positive numbers. Time interval (Δt\Delta t).

Details

The total effect centrality of a variable is the sum of the total effects of a variable on all other variables at a particular time interval.

Value

Returns an object of class ctmedmed which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("TotalCentral").

output

A matrix of total effect centrality.

Author(s)

Ivan Jacob Agaloos Pesigan

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: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), 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")

# Specific time interval ----------------------------------------------------
TotalCentral(
  phi = phi,
  delta_t = 1
)

# Range of time intervals ---------------------------------------------------
total_central <- TotalCentral(
  phi = phi,
  delta_t = 1:30
)
plot(total_central)

# Methods -------------------------------------------------------------------
# TotalCentral has a number of methods including
# print, summary, and plot
total_central <- TotalCentral(
  phi = phi,
  delta_t = 1:5
)
print(total_central)
summary(total_central)
plot(total_central)

Simulate Trajectories of Variables

Description

This function simulates trajectories of variables without measurement error or process noise. Total corresponds to the total effect and Direct corresponds to the portion of the total effect where the indirect effect is removed.

Usage

Trajectory(mu0, time, phi, med)

Arguments

mu0

Numeric vector. Initial values of the variables.

time

Positive integer. Number of time points.

phi

Numeric matrix. The drift matrix (Φ\boldsymbol{\Phi}). phi should have row and column names pertaining to the variables in the system.

med

Character vector. Name/s of the mediator variable/s in phi.

Value

Returns an object of class ctmedtraj which is a list with the following elements:

call

Function call.

args

Function arguments.

fun

Function used ("Trajectory").

output

A data frame of simulated data.

See Also

Other Continuous Time Mediation Functions: DeltaBeta(), DeltaIndirectCentral(), DeltaMed(), DeltaTotalCentral(), Direct(), Indirect(), IndirectCentral(), MCBeta(), MCIndirectCentral(), MCMed(), MCPhi(), MCTotalCentral(), Med(), PosteriorBeta(), PosteriorIndirectCentral(), PosteriorMed(), PosteriorPhi(), PosteriorTotalCentral(), Total(), TotalCentral()

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")

traj <- Trajectory(
  mu0 = c(3, 3, -3),
  time = 150,
  phi = phi,
  med = "m"
)
plot(traj)

# Methods -------------------------------------------------------------------
# Trajectory has a number of methods including
# print, summary, and plot

traj <- Trajectory(
  mu0 = c(3, 3, -3),
  time = 25,
  phi = phi,
  med = "m"
)
print(traj)
summary(traj)
plot(traj)