Skip to contents

A rating scale can be modelled two ways in ctsem: manifesttype = 0 puts a Gaussian residual on the observed code, manifesttype = 2 puts a cumulative logit on it. Ordinal indicators require backend = 'julia'; the other indicator types are covered in the measurement models vignette.

To see what the first choice changes, we simulate from a known process, categorise it, and fit the same dynamic model both ways. One simulated sample carries its own sampling error, so every comparison with the generating values below is shown with its uncertainty: a fit is doing its job when its interval covers the truth, wherever its point estimate happens to fall.

Code that only generates or draws is folded throughout; unfold it if you want to reproduce the figures.

The data

Two Ornstein-Uhlenbeck processes, one five point item each. eta1 affects eta2 and not the reverse, the innovations correlate at 0.4, people differ moderately in where their processes sit, and four thresholds at ±1\pm1 and ±2.8\pm2.8 cut each process into categories.

Code

DRIFT <- matrix(c(-0.5, 0,
                  0.3, -0.5), 2, 2, byrow = TRUE)   # eta1 -> eta2 is 0.3
diffsd <- 2.2
diffcor <- 0.4
thresholds <- c(-2.8, -1.0, 1.0, 2.8)

# covmattransform='z' makes a covariance matrix's off-diagonal exactly
# atanh(correlation), so the generating values can be written down.
zmat <- function(sd1, sd2, r) matrix(c(sd1, 0, atanh(r), sd2), 2, 2, byrow = TRUE)

# Stationary covariance, solving A S + S A' + Q = 0: its standard deviations
# are what the true standardised cross effect is scaled by.
Q <- diag(diffsd, 2) %*% matrix(c(1, diffcor, diffcor, 1), 2) %*% diag(diffsd, 2)
S <- matrix(solve(kronecker(diag(2), DRIFT) + kronecker(DRIFT, diag(2)),
  -as.vector(Q)), 2, 2)
latentsd <- sqrt(diag(S))

gen <- ctModel(type = 'ct', n.latent = 2, n.manifest = 2,
  manifestNames = c('eta1', 'eta2'), latentNames = c('eta1', 'eta2'),
  LAMBDA = diag(1, 2), DRIFT = DRIFT,
  DIFFUSION = zmat(diffsd, diffsd, diffcor),
  T0VAR = diag(1,2),
  T0MEANS = matrix(1, 2, 1), CINT = matrix(0, 2, 1),
  MANIFESTMEANS = matrix(0, 2, 1),
  MANIFESTVAR = diag(1e-6, 2),          # no measurement error: manifest = state
  Tpoints = 30)
gen$covmattransform <- 'z'

# backend='julia' because the R generator reads DIFFUSION and T0VAR as square
# roots whatever covmattransform says, while the julia generator applies the
# declared transform, as ctFit() does.
set.seed(2)
d <- data.frame(ctGenerate(gen, n = 150, Tpoints = 30, dtmean = 0.7,
  backend = 'julia'))

# The cumulative logit: the response falls in category k or below when the
# state plus a logistic disturbance is below threshold k.
ordinalise <- function(eta)
  1 + rowSums(outer(eta + rlogis(length(eta)), thresholds, '>'))
# Moderate individual differences: each person's process sits a little high or
# low. Added to the states, before they are categorised.
set.seed(3)
shift <- matrix(stats::rnorm(150 * 2, 0, 0.8), 150, 2)
d$eta1 <- d$eta1 + shift[d$id, 1]
d$eta2 <- d$eta2 + shift[d$id, 2]

set.seed(502)
d$y1 <- ordinalise(d$eta1)
d$y2 <- ordinalise(d$eta2)

One subject. The line is the latent process, the dotted lines are the thresholds, and the points are the recorded answers at the middle of the band each category stands for:

Code

mid <- c(-3.8, -1.9, 0, 1.9, 3.8)             # band midpoints, for display
s <- d[d$id == 1, ]

ggplot(s, aes(time)) +
  geom_hline(yintercept = thresholds, linetype = 3, colour = 'grey55') +
  geom_line(aes(y = eta1, colour = 'latent eta1')) +
  geom_point(aes(y = mid[y1], colour = 'recorded category y1'), size = 1.9) +
  scale_y_continuous(sec.axis = sec_axis(~., breaks = mid, labels = 1:5,
    name = 'category')) +
  scale_colour_manual(values = c('latent eta1' = 'grey35',
    'recorded category y1' = '#c0392b')) +
  theme_bw() + theme(legend.position = 'bottom') +
  labs(x = 'time', y = 'latent scale', colour = NULL)

The points follow the line, but only to the resolution of the bands, and they cross a threshold early or late depending on the disturbance. Both items use the whole scale, with no category so rare that it carries nothing:

Code

freq <- rbind(data.frame(item = 'y1', category = factor(d$y1)),
  data.frame(item = 'y2', category = factor(d$y2)))

ggplot(freq, aes(category)) + geom_bar() + facet_wrap(~item) +
  theme_bw() + labs(x = NULL, y = NULL)

Fitting it as ordinal

This is the whole of it. Two arguments do the work: manifesttype = 2 asks for the cumulative logit, and ncategories says how many thresholds to estimate, which the model has to know before it sees the data.

ordinalmodel <- ctModel(type = 'ct', n.latent = 2, n.manifest = 2,
  manifestNames = c('y1', 'y2'), latentNames = c('eta1', 'eta2'),
  manifesttype = c(2, 2),             # ordinal
  ncategories = c(5, 5),              # five point scale
  LAMBDA = diag(1, 2))

ordinalfit <- ctFit(d[, c('id', 'time', 'y1', 'y2')], ordinalmodel,
  backend = 'julia')

Everything else is left at its default, and the defaults are the ones you want. CINT is already zero, so the process mean lives in T0MEANS, which is freely estimated and individually varying – as is MANIFESTMEANS, giving each person their own level and their own item locations. MANIFESTVAR is diagonal by default and ctFit() fixes it for a binary or ordinal indicator anyway, since the cumulative logit already supplies the randomness and a residual variance on top of it is not identified.

ncategories when the indicators are mixed

ncategories takes one entry per manifest variable, or a single value for all of them, and only the ordinal entries are read. For a model with a Gaussian, an ordinal and a binary indicator, all three of these are the same thing:

ncategories = c(NA, 5, NA)    # NA where it does not apply
ncategories = c(0, 5, 0)      # or zero
ncategories = 5               # or one value, since the rest are ignored

NA is the clearest of the three, because it says the number is not merely zero but meaningless for that variable. Whatever you pass for a non-ordinal variable is overwritten with zero. Omitting the argument entirely while any variable is ordinal is an error that names the variables, because the model has to know how many thresholds to estimate before it sees the data.

summary() reports the thresholds on the latent scale, one row per category boundary:

summary(ordinalfit)$thresholds
#>          mean    sd   2.5%    50%  97.5%
#> y1 1|2 -3.110 0.190 -3.467 -3.113 -2.728
#> y1 2|3 -1.177 0.126 -1.425 -1.178 -0.938
#> y1 3|4  0.984 0.124  0.755  0.984  1.231
#> y1 4|5  2.930 0.184  2.590  2.930  3.300
#> y2 1|2 -3.197 0.207 -3.611 -3.200 -2.778
#> y2 2|3 -1.218 0.156 -1.534 -1.213 -0.920
#> y2 3|4  0.850 0.144  0.545  0.848  1.119
#> y2 4|5  2.746 0.172  2.390  2.748  3.081

Those are recovered against generating values of −2.8, −1, 1 and 2.8.

Fitting it as continuous

The Gaussian version is the same call with manifesttype = 0, no ncategories, and a free residual variance per item instead of thresholds:

gaussianmodel <- ctModel(type = 'ct', n.latent = 2, n.manifest = 2,
  manifestNames = c('y1', 'y2'), latentNames = c('eta1', 'eta2'),
  LAMBDA = diag(1, 2))

gaussianfit <- ctFit(d[, c('id', 'time', 'y1', 'y2')], gaussianmodel,
  backend = 'julia')

What should and should not agree

The two fits place the latent processes on different scales. Both are set by the same convention – LAMBDA is fixed at 1, so the latent takes its units from the indicator – but the units differ: the Gaussian fit measures eta1 in answer codes, the ordinal fit in logits, because the cumulative logit’s own scale is fixed and the latent is measured against it.

The thresholds do not fix that scale; they would rescale along with the process. What pins it is the link. Free the loadings as well and nothing pins it at all, which is the identification problem the item response vignette deals with.

A parameter can therefore only be compared across the two fits if it is invariant to rescaling the latent processes.

Expected to agree

  • Auto effects (drift_eta1, drift_eta2). Their unit is inverse time, and a rate of reversion does not change when the process is measured in other units.
  • The diffusion correlation, being a correlation.
  • The standardised cross effect, the effect in stationary standard deviations, ã21=a21sd(η1)/sd(η2)\tilde{a}_{21} = a_{21}\,\text{sd}(\eta_1)/\text{sd}(\eta_2).

Not expected to agree

  • The raw cross effect drift_eta2_eta1, whose unit is eta2 per unit of eta1 per unit time. Note this is already true between the two processes within a single fit: eta2 is the more variable because it accumulates eta1, so the same effect takes different numbers on differently scaled processes.
  • DIFFUSION and T0VAR on their own, and the residual variances.
  • MANIFESTMEANS, a location on the latent scale in the Gaussian fit and the thresholds’ anchor in the ordinal one.

Only the ordinal fit’s scale means anything outside the questionnaire, so where the raw quantities differ it is the ordinal fit to report.

Comparison

ctDiscretePars() turns each fit’s DRIFT into the regressions it implies at every time interval, once per draw from the fit’s uncertainty. Standardised, those are comparable across the two fits. The line is the median over draws, the band holds 95% of them, and the dashed line is the generating process:

Code

times <- seq(0, 6, .1)

crossband <- function(fit, label) {
  a <- ctDiscretePars(fit, times = times, standardise = TRUE,
    nsamples = 500)[, 1, , 2, 1]                 # draws x intervals, eta1 -> eta2
  data.frame(time = times, model = label,
    median = apply(a, 2, median, na.rm = TRUE),
    lo = apply(a, 2, quantile, .025, na.rm = TRUE),
    hi = apply(a, 2, quantile, .975, na.rm = TRUE))
}

bands <- rbind(crossband(gaussianfit, 'gaussian on the codes'),
  crossband(ordinalfit, 'ordinal'))
truth <- data.frame(time = times, value = sapply(times,
  function(u) expm::expm(DRIFT * u)[2, 1] * latentsd[1] / latentsd[2]))

ggplot(bands, aes(time)) +
  geom_ribbon(aes(ymin = lo, ymax = hi), fill = 'grey82') +
  geom_line(aes(y = median, colour = 'estimate', linetype = 'estimate'),
    linewidth = .9) +
  geom_line(data = truth, aes(y = value, colour = 'truth', linetype = 'truth'),
    linewidth = .9) +
  facet_wrap(~ model) +
  scale_colour_manual(values = c(estimate = 'grey15', truth = '#c0392b')) +
  scale_linetype_manual(values = c(estimate = 1, truth = 2)) +
  theme_bw() + theme(legend.position = 'bottom') +
  labs(x = 'time interval', y = 'standardised cross effect, eta1 -> eta2',
    colour = NULL, linetype = NULL)

The auto effect, the stationary standard deviation of eta1 and the diffusion correlation come from the same draws, through ctExtract(): pop_DRIFT, pop_asymDIFFUSIONcov, the stationary covariance the model implies, and pop_DIFFUSIONcov, the innovation covariance. Each cell is the median with a 95% interval:

Code

comparable <- function(fit, label) {
  e <- ctExtract(fit)
  q <- e$pop_DIFFUSIONcov
  draws <- cbind(drift_eta1 = e$pop_DRIFT[, 1, 1],
    latentsd1 = sqrt(e$pop_asymDIFFUSIONcov[, 1, 1]),
    diffcor = q[, 1, 2] / sqrt(q[, 1, 1] * q[, 2, 2]))
  s <- apply(draws, 2, quantile, c(.5, .025, .975))
  out <- data.frame(label, t(sprintf('%.2f [%.2f, %.2f]', s[1, ], s[2, ], s[3, ])))
  setNames(out, c('model', colnames(draws)))
}

knitr::kable(rbind(comparable(gaussianfit, 'gaussian on the codes'),
  comparable(ordinalfit, 'ordinal'),
  data.frame(model = 'truth', drift_eta1 = sprintf('%.2f', DRIFT[1, 1]),
    latentsd1 = sprintf('%.2f', latentsd[1]), diffcor = sprintf('%.2f', diffcor))))
model drift_eta1 latentsd1 diffcor
gaussian on the codes -0.59 [-0.80, -0.40] 0.98 [0.91, 1.04] 0.36 [0.23, 0.49]
ordinal -0.60 [-0.80, -0.44] 2.41 [2.05, 2.75] 0.36 [0.21, 0.48]
truth -0.50 2.20 0.40

latentsd1 is in answer-code units for the Gaussian fit and in logits for the ordinal fit, so the two fitted values are not comparable with each other. The ordinal one is comparable with the truth, because the link fixes its units: it estimates a real quantity rather than a convention, and checking it is worth doing before reading anything else.

Every interval in the table that should cover its generating value does, in both fits. The bands say the same with one qualification: the Gaussian band covers the true curve throughout, while beyond an interval of about three the true curve runs along the upper edge of the ordinal band rather than inside it. Both estimated curves sit below the truth, by similar amounts, which is what sampling error shared by two fits of the same sample looks like rather than something either measurement model does.

On this design the Gaussian approximation costs little on the scale-invariant quantities. Categorisation is a monotone transformation plus noise that is independent across items and occasions given the latent state, and a Gaussian residual can absorb a good deal of that. What differs is what the remaining numbers are about: the Gaussian fit’s raw effects, variances and locations describe the answer codes of this questionnaire, while the ordinal fit’s are on a scale the link fixes, and those are the ones to report.