Skip to contents

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.

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)
#>    time       y1        y2          y3   effect
#> 1   0.0 3.000000 3.0000000 -3.00000000    total
#> 2   0.1 2.894789 3.0720294 -2.71331237    total
#> 3   0.2 2.793268 3.1327033 -2.43666332    total
#> 4   0.3 2.695307 3.1828597 -2.17030792    total
#> 5   0.4 2.600782 3.2232855 -1.91442143    total
#> 6   0.5 2.509572 3.2547189 -1.66910840    total
#> 7   0.6 2.421561 3.2778528 -1.43441085    total
#> 8   0.7 2.336636 3.2933366 -1.21031580    total
#> 9   0.8 2.254690 3.3017795 -0.99676204    total
#> 10  0.9 2.175617 3.3037519 -0.79364635    total
#> 11  1.0 2.099317 3.2997885 -0.60082904    total
#> 12  1.1 2.025694 3.2903896 -0.41813908    total
#> 13  1.2 1.954652 3.2760236 -0.24537862    total
#> 14  1.3 1.886102 3.2571286 -0.08232717    total
#> 15  1.4 1.819956 3.2341140  0.07125470    total
#> 16  1.5 1.756130 3.2073626  0.21562200    total
#> 17  1.6 1.694542 3.1772318  0.35104230    total
#> 18  1.7 1.635114 3.1440552  0.47779306    total
#> 19  1.8 1.577770 3.1081440  0.59615920    total
#> 20  1.9 1.522437 3.0697883  0.70643095    total
#> 21  2.0 1.469045 3.0292583  0.80890195    total
#> 22  2.1 1.417525 2.9868056  0.90386756    total
#> 23  2.2 1.367812 2.9426643  0.99162335    total
#> 24  2.3 1.319842 2.8970518  1.07246380    total
#> 25  2.4 1.273555 2.8501701  1.14668113    total
#> 26  0.0 3.000000 3.0000000 -3.00000000   direct
#> 27  0.1 2.894789 2.8505509 -2.92724153   direct
#> 28  0.2 2.793268 2.7085469 -2.85486193   direct
#> 29  0.3 2.695307 2.5736170 -2.78299339   direct
#> 30  0.4 2.600782 2.4454088 -2.71175371   direct
#> 31  0.5 2.509572 2.3235874 -2.64124750   direct
#> 32  0.6 2.421561 2.2078348 -2.57156720   direct
#> 33  0.7 2.336636 2.0978485 -2.50279409   direct
#> 34  0.8 2.254690 1.9933413 -2.43499924   direct
#> 35  0.9 2.175617 1.8940403 -2.36824433   direct
#> 36  1.0 2.099317 1.7996862 -2.30258245   direct
#> 37  1.1 2.025694 1.7100324 -2.23805882   direct
#> 38  1.2 1.954652 1.6248448 -2.17471149   direct
#> 39  1.3 1.886102 1.5439009 -2.11257197   direct
#> 40  1.4 1.819956 1.4669894 -2.05166577   direct
#> 41  1.5 1.756130 1.3939094 -1.99201297   direct
#> 42  1.6 1.694542 1.3244699 -1.93362870   direct
#> 43  1.7 1.635114 1.2584896 -1.87652362   direct
#> 44  1.8 1.577770 1.1957963 -1.82070431   direct
#> 45  1.9 1.522437 1.1362261 -1.76617367   direct
#> 46  2.0 1.469045 1.0796234 -1.71293131   direct
#> 47  2.1 1.417525 1.0258405 -1.66097382   direct
#> 48  2.2 1.367812 0.9747369 -1.61029513   direct
#> 49  2.3 1.319842 0.9261790 -1.56088678   direct
#> 50  2.4 1.273555 0.8800402 -1.51273817   direct
#> 51  0.0 3.000000 3.0000000 -3.00000000 indirect
#> 52  0.1 2.894789 3.0720294 -2.58521101 indirect
#> 53  0.2 2.793268 3.1327033 -2.19352996 indirect
#> 54  0.3 2.695307 3.1828597 -1.82417931 indirect
#> 55  0.4 2.600782 3.2232855 -1.47637642 indirect
#> 56  0.5 2.509572 3.2547189 -1.14933736 indirect
#> 57  0.6 2.421561 3.2778528 -0.84228031 indirect
#> 58  0.7 2.336636 3.2933366 -0.55442860 indirect
#> 59  0.8 2.254690 3.3017795 -0.28501322 indirect
#> 60  0.9 2.175617 3.3037519 -0.03327518 indirect
#> 61  1.0 2.099317 3.2997885  0.20153262 indirect
#> 62  1.1 2.025694 3.2903896  0.42014365 indirect
#> 63  1.2 1.954652 3.2760236  0.62327638 indirect
#> 64  1.3 1.886102 3.2571286  0.81163307 indirect
#> 65  1.4 1.819956 3.2341140  0.98589878 indirect
#> 66  1.5 1.756130 3.2073626  1.14674061 indirect
#> 67  1.6 1.694542 3.1772318  1.29480700 indirect
#> 68  1.7 1.635114 3.1440552  1.43072731 indirect
#> 69  1.8 1.577770 3.1081440  1.55511147 indirect
#> 70  1.9 1.522437 3.0697883  1.66854971 indirect
#> 71  2.0 1.469045 3.0292583  1.77161245 indirect
#> 72  2.1 1.417525 2.9868056  1.86485031 indirect
#> 73  2.2 1.367812 2.9426643  1.94879411 indirect
#> 74  2.3 1.319842 2.8970518  2.02395503 indirect
#> 75  2.4 1.273555 2.8501701  2.09082478 indirect
summary(traj)
#>    time       y1        y2          y3   effect
#> 1   0.0 3.000000 3.0000000 -3.00000000    total
#> 2   0.1 2.894789 3.0720294 -2.71331237    total
#> 3   0.2 2.793268 3.1327033 -2.43666332    total
#> 4   0.3 2.695307 3.1828597 -2.17030792    total
#> 5   0.4 2.600782 3.2232855 -1.91442143    total
#> 6   0.5 2.509572 3.2547189 -1.66910840    total
#> 7   0.6 2.421561 3.2778528 -1.43441085    total
#> 8   0.7 2.336636 3.2933366 -1.21031580    total
#> 9   0.8 2.254690 3.3017795 -0.99676204    total
#> 10  0.9 2.175617 3.3037519 -0.79364635    total
#> 11  1.0 2.099317 3.2997885 -0.60082904    total
#> 12  1.1 2.025694 3.2903896 -0.41813908    total
#> 13  1.2 1.954652 3.2760236 -0.24537862    total
#> 14  1.3 1.886102 3.2571286 -0.08232717    total
#> 15  1.4 1.819956 3.2341140  0.07125470    total
#> 16  1.5 1.756130 3.2073626  0.21562200    total
#> 17  1.6 1.694542 3.1772318  0.35104230    total
#> 18  1.7 1.635114 3.1440552  0.47779306    total
#> 19  1.8 1.577770 3.1081440  0.59615920    total
#> 20  1.9 1.522437 3.0697883  0.70643095    total
#> 21  2.0 1.469045 3.0292583  0.80890195    total
#> 22  2.1 1.417525 2.9868056  0.90386756    total
#> 23  2.2 1.367812 2.9426643  0.99162335    total
#> 24  2.3 1.319842 2.8970518  1.07246380    total
#> 25  2.4 1.273555 2.8501701  1.14668113    total
#> 26  0.0 3.000000 3.0000000 -3.00000000   direct
#> 27  0.1 2.894789 2.8505509 -2.92724153   direct
#> 28  0.2 2.793268 2.7085469 -2.85486193   direct
#> 29  0.3 2.695307 2.5736170 -2.78299339   direct
#> 30  0.4 2.600782 2.4454088 -2.71175371   direct
#> 31  0.5 2.509572 2.3235874 -2.64124750   direct
#> 32  0.6 2.421561 2.2078348 -2.57156720   direct
#> 33  0.7 2.336636 2.0978485 -2.50279409   direct
#> 34  0.8 2.254690 1.9933413 -2.43499924   direct
#> 35  0.9 2.175617 1.8940403 -2.36824433   direct
#> 36  1.0 2.099317 1.7996862 -2.30258245   direct
#> 37  1.1 2.025694 1.7100324 -2.23805882   direct
#> 38  1.2 1.954652 1.6248448 -2.17471149   direct
#> 39  1.3 1.886102 1.5439009 -2.11257197   direct
#> 40  1.4 1.819956 1.4669894 -2.05166577   direct
#> 41  1.5 1.756130 1.3939094 -1.99201297   direct
#> 42  1.6 1.694542 1.3244699 -1.93362870   direct
#> 43  1.7 1.635114 1.2584896 -1.87652362   direct
#> 44  1.8 1.577770 1.1957963 -1.82070431   direct
#> 45  1.9 1.522437 1.1362261 -1.76617367   direct
#> 46  2.0 1.469045 1.0796234 -1.71293131   direct
#> 47  2.1 1.417525 1.0258405 -1.66097382   direct
#> 48  2.2 1.367812 0.9747369 -1.61029513   direct
#> 49  2.3 1.319842 0.9261790 -1.56088678   direct
#> 50  2.4 1.273555 0.8800402 -1.51273817   direct
#> 51  0.0 3.000000 3.0000000 -3.00000000 indirect
#> 52  0.1 2.894789 3.0720294 -2.58521101 indirect
#> 53  0.2 2.793268 3.1327033 -2.19352996 indirect
#> 54  0.3 2.695307 3.1828597 -1.82417931 indirect
#> 55  0.4 2.600782 3.2232855 -1.47637642 indirect
#> 56  0.5 2.509572 3.2547189 -1.14933736 indirect
#> 57  0.6 2.421561 3.2778528 -0.84228031 indirect
#> 58  0.7 2.336636 3.2933366 -0.55442860 indirect
#> 59  0.8 2.254690 3.3017795 -0.28501322 indirect
#> 60  0.9 2.175617 3.3037519 -0.03327518 indirect
#> 61  1.0 2.099317 3.2997885  0.20153262 indirect
#> 62  1.1 2.025694 3.2903896  0.42014365 indirect
#> 63  1.2 1.954652 3.2760236  0.62327638 indirect
#> 64  1.3 1.886102 3.2571286  0.81163307 indirect
#> 65  1.4 1.819956 3.2341140  0.98589878 indirect
#> 66  1.5 1.756130 3.2073626  1.14674061 indirect
#> 67  1.6 1.694542 3.1772318  1.29480700 indirect
#> 68  1.7 1.635114 3.1440552  1.43072731 indirect
#> 69  1.8 1.577770 3.1081440  1.55511147 indirect
#> 70  1.9 1.522437 3.0697883  1.66854971 indirect
#> 71  2.0 1.469045 3.0292583  1.77161245 indirect
#> 72  2.1 1.417525 2.9868056  1.86485031 indirect
#> 73  2.2 1.367812 2.9426643  1.94879411 indirect
#> 74  2.3 1.319842 2.8970518  2.02395503 indirect
#> 75  2.4 1.273555 2.8501701  2.09082478 indirect
plot(traj)