Skip to contents

Two latent processes, one measured by a continuous variable and the other by a yes or no answer, with the first process driving the second and with stable differences between people. This article simulates such data, fits the model, and shows the predictions for the binary variable. vignette('measurement-models') covers the other kinds of variable ctsem can use: ordinal, count and censored.

Data

ctGenerate() simulates from a model with every parameter given. The first process affects the second with a cross effect of 0.5, and each process has a continuous time intercept (CINT) that differs between people, with a standard deviation of 1. The binary variable is 1 with probability inv_logit(eta2), and the continuous one has measurement error with a standard deviation of 0.2:

set.seed(1)
gm <- ctModel(type = 'ct',
  manifestNames = c('Y1', 'Y2binary'), latentNames = c('eta1', 'eta2'),
  manifesttype = c(0, 1),
  LAMBDA = diag(2),
  DRIFT = matrix(c(
    -1, 0,
    0.5, -1), 2, 2, byrow = TRUE),
  DIFFUSION = diag(2),
  CINT = c('cint1', 'cint2'),
  T0MEANS = 0, T0VAR = diag(2),
  MANIFESTMEANS = 0,
  MANIFESTVAR = diag(c(0.2, 0)))
dat <- data.frame(ctGenerate(gm, n = 100, Tpoints = 50, dtmean = 0.1,
  backend = 'julia',
  values = list(popmeans = c(cint1 = 0, cint2 = 0),
    popsd = c(cint1 = 1, cint2 = 1))))
head(dat)
#>   id time          Y1 Y2binary
#> 1  1  0.0  0.35792836        1
#> 2  1  0.1  0.72744830        1
#> 3  1  0.2  0.16506388        1
#> 4  1  0.3 -0.06762921        1
#> 5  1  0.4 -0.09212704        1
#> 6  1  0.5  0.39294392        1

Each of the 100 people is observed 50 times, 0.1 time units apart.

Model

The estimation model gives the second variable manifesttype = 1, binary, and leaves the dynamics free. Stable differences between people could be put on the measurement intercepts (MANIFESTMEANS) or on the latent processes (CINT). Here they belong to the processes, so the measurement intercepts are fixed to 0 and the CINT parameters are free, and by default they vary over people. With continuous indicators the two choices often fit the same. With a binary one they differ. A shift in the latent process carries through the dynamics, while a shift in the intercept of the binary variable changes only its probability of a 1.

m <- ctModel(type = 'ct',
  manifestNames = c('Y1', 'Y2binary'), latentNames = c('eta1', 'eta2'),
  manifesttype = c(0, 1),
  LAMBDA = diag(2),
  MANIFESTMEANS = 0,
  CINT = c('cint1', 'cint2'))

A binary variable has no measurement error parameter: its variance given the latent process follows from the probability of a 1.

f <- ctFit(dat, m, cores = 2)
s <- summary(f)
s$popmeans
#>                   mean    sd   2.5%    50%  97.5%   mode
#> T0m_eta1        -0.055 0.093 -0.241 -0.049  0.127 -0.057
#> T0m_eta2         0.176 0.133 -0.096  0.179  0.430  0.175
#> drift_eta1      -1.062 0.107 -1.271 -1.058 -0.870 -1.061
#> drift_eta1_eta2 -0.220 0.109 -0.432 -0.218 -0.008 -0.221
#> drift_eta2_eta1  0.214 0.192 -0.169  0.221  0.576  0.218
#> drift_eta2      -0.897 0.238 -1.432 -0.878 -0.502 -0.873
#> diff_eta1        1.023 0.027  0.970  1.023  1.080  1.022
#> diff_eta2_eta1   0.077 0.115 -0.144  0.075  0.302  0.077
#> diff_eta2        0.902 0.171  0.619  0.883  1.264  0.890
#> mvarY1           0.198 0.007  0.183  0.199  0.213  0.198
#> cint1            0.007 0.125 -0.246  0.006  0.257  0.000
#> cint2            0.027 0.118 -0.213  0.026  0.257  0.025

The auto effects (drift_eta1, drift_eta2) are close to the generating -1. The cross effects are much less certain. The effect of eta1 on eta2 (drift_eta2_eta1), generated as 0.5, comes out at 0.21 with a standard error of 0.19, and the effect of eta2 on eta1, generated as 0, at -0.22. A yes or no answer says much less about the process than a continuous measurement would, so effects that involve a process measured only that way need many more observations to pin down. A second binary item for eta2, or a continuous one, would help most.

The standard deviations of the intercepts over people are close to the generating 1:

s$popsd
#>           mean    sd  2.5%   50% 97.5%  mode
#> T0m_eta1 0.940 0.068 0.815 0.939 1.083 0.940
#> T0m_eta2 0.867 0.194 0.555 0.846 1.303 0.844
#> cint1    1.147 0.134 0.901 1.140 1.427 1.146
#> cint2    1.041 0.248 0.631 1.026 1.601 1.015

Dynamics

ctDiscretePars() shows the effect of a change in one process on both, over time. Here a change in eta1 raises eta2 a little over the next few time units, and a change in eta2 lowers eta1 a little, both with wide intervals, as the cross effects above suggest:

ctDiscretePars(f, plot = TRUE)

Predictions for the binary variable

For the binary variable, yprior is the predicted probability of a 1, given the person’s earlier answers and their continuous measurements. Its band is 1.96 standard deviations of a yes or no answer either side, so it covers both answers:

ctPredict(f, subjects = c(2, 5), timestep = 0.02, plot = TRUE,
  kalmanvec = c('y', 'yprior'))

The smoothed latent processes use all of each person’s observations:

ctPredict(f, subjects = c(2, 5), timestep = 0.02, plot = TRUE,
  kalmanvec = 'etasmooth')

The binary answers carry less information than the continuous measurements, so the estimates of eta2 are less certain than those of eta1.