nlmixr2 ordinal effect model
Ocular itching after an allergen challenge, as a differential odds model
By Matthew Fidler in nlmixr2 rxode2
November 30, 2026
Ordinal effect models
Within the last few weeks, I have had a few questions about whether
nlmixr2 can do types of models other than the standard PK/PD
models. I will be trying more types of models so there are more
examples of them. In this case, I will be trying non-linear ordinal
effect regression.
Currently there aren’t any examples of ordinal effect regression on the blog or in the vignettes, so I thought I would simulate and estimate an example.
Rather than making up a model, I will use one that I published a few years ago: the ocular itching model (Fidler et al., Projected 24-hour post-dose ocular itching scores post-treatment with olopatadine 0.7% versus 0.2%, J Pharmacokinet Pharmacodyn 2018;45(4):593–605).
The conjunctival allergen challenge
In a conjunctival allergen challenge (CAC), an allergen the patient is sensitive to is put directly in the eye. The patient then rates their itching at 3, 5 and 7 minutes after the challenge, from 0 (no itching) to 4 (incapacitating itch), in steps of 0.5. That gives 9 possible scores.
A typical CAC study has:
a baseline challenge with no treatment, to confirm the patient reacts;
then challenges at different times after an eye drop of either vehicle or drug. In the olopatadine studies these were at 27 minutes (onset of action), 16 hours and 24 hours (duration of action).
The itching score is not a continuous measurement. A move from 0 to 0.5 is not necessarily the same as a move from 3.5 to 4, so instead of modeling the mean score, we model the probability of each score.
Cumulative logits and differential odds
An ordinal model describes the probability that the score is at least \(s\), on the logit scale:
\[ \text{logit}\, P(Y_{ij} \ge s \mid \eta_i) = f_s + V_e(s) + D_e(s) \]
- \(f_s = \alpha_{0.5} + \alpha_1 + \dots + \alpha_s + \eta_i\) is the baseline cumulative log-odds for patient \(i\). The \(\alpha\)s after the first are negative, so higher scores are less likely. The single random effect \(\eta_i\) shifts all the categories for a patient up or down, so some patients itch more than others.
- \(V_e(s)\) is the vehicle effect. The drop itself relieves itching (it washes out the eye), and the relief wears off with time after the drop \(t\): \(V_e = V_b + V_m t\).
- \(D_e(s)\) is the drug effect, an \(E_{max}\) model on a theoretical drug amount in the eye that is lost with a half-life \(t_{1/2}\) (a kinetic-pharmacodynamic, or KPD, model): \(D_e = -E_{max} C(t) / (EC_{50} + C(t))\).
If \(V_e\) and \(D_e\) shift every category by the same amount, this is a proportional odds model. The paper uses a differential odds model instead, where the effect can be smaller for some categories. Each effect is multiplied by a running product of \(\text{expit}()\) terms:
\[ V_e(s) = (V_b + V_m t) \prod_{m \le s} \text{expit}(v_m) \qquad D_e(s) = -\frac{E_{max} C(t)}{EC_{50} + C(t)} \prod_{m \le s} \text{expit}(\delta_m) \]
When \(v_m\) or \(\delta_m\) is large (say 10), \(\text{expit}(10) \approx 1\) and the effect carries through to that category unchanged. At \(-10\), \(\text{expit}(-10) \approx 0\) and the effect stops there. In the paper, any differential odds parameter that went past \(\pm 10\) was fixed at \(\pm 10\); I’ll come back to that when we fit the model.
The model in nlmixr2
Here is the model with the final estimates from Table 5 of the paper. I have left out the paper’s baseline-severity covariates to keep the example readable.
olo.cac <- function() {
ini({
# Baseline cumulative log-odds
a_0.5 <- 8.79
a_1 <- -1.47
a_1.5 <- -1.03
a_2 <- -0.85
a_2.5 <- -1.88
a_3 <- -2.88
a_3.5 <- -3.02
a_4 <- -2.14
# Vehicle differential log-odds
v_1 <- fix(10)
v_1.5 <- fix(10)
v_2 <- fix(10)
v_2.5 <- 2.38
v_3 <- 1.07
v_3.5 <- fix(10)
v_4 <- fix(10)
# Drug differential log-odds
d_1 <- fix(10)
d_1.5 <- fix(10)
d_2 <- 3.64
d_2.5 <- 1.56
d_3 <- fix(10)
d_3.5 <- fix(-10)
d_4 <- fix(10)
# Vehicle effect
Vb <- -4.98
Vm <- 0.06
# Olopatadine KPD model
lthalf <- log(18.46)
lEC50 <- log(0.03)
Emax <- 3.40
eta ~ 1.38^2
})
model({
# Baseline cumulative log-odds. The eta is added to the first
# category so it applies to every category (and keeps
# mu-referencing)
asum_0.5 <- a_0.5 + eta
asum_1 <- a_1 + asum_0.5
asum_1.5 <- a_1.5 + asum_1
asum_2 <- a_2 + asum_1.5
asum_2.5 <- a_2.5 + asum_2
asum_3 <- a_3 + asum_2.5
asum_3.5 <- a_3.5 + asum_3
asum_4 <- a_4 + asum_3.5
# Differential odds multipliers (running products of expit())
vs_1 <- expit(v_1)
vs_1.5 <- expit(v_1.5) * vs_1
vs_2 <- expit(v_2) * vs_1.5
vs_2.5 <- expit(v_2.5) * vs_2
vs_3 <- expit(v_3) * vs_2.5
vs_3.5 <- expit(v_3.5) * vs_3
vs_4 <- expit(v_4) * vs_3.5
ds_1 <- expit(d_1)
ds_1.5 <- expit(d_1.5) * ds_1
ds_2 <- expit(d_2) * ds_1.5
ds_2.5 <- expit(d_2.5) * ds_2
ds_3 <- expit(d_3) * ds_2.5
ds_3.5 <- expit(d_3.5) * ds_3
ds_4 <- expit(d_4) * ds_3.5
# Drug amount in the eye (the dose is the concentration in %)
kel <- log(2) / exp(lthalf)
EC50 <- exp(lEC50)
d/dt(eye) <- -kel * eye
De <- -Emax * eye / (EC50 + eye)
# Vehicle effect; Vi is 1 after a drop and 0 at baseline, and
# tdrop is the time since the drop (h)
Ve <- Vi * (Vb + Vm * tdrop)
fs_0.5 <- asum_0.5 + Ve + De
fs_1 <- asum_1 + Ve * vs_1 + De * ds_1
fs_1.5 <- asum_1.5 + Ve * vs_1.5 + De * ds_1.5
fs_2 <- asum_2 + Ve * vs_2 + De * ds_2
fs_2.5 <- asum_2.5 + Ve * vs_2.5 + De * ds_2.5
fs_3 <- asum_3 + Ve * vs_3 + De * ds_3
fs_3.5 <- asum_3.5 + Ve * vs_3.5 + De * ds_3.5
fs_4 <- asum_4 + Ve * vs_4 + De * ds_4
# P(itch >= s)
ps_0.5 <- expit(fs_0.5)
ps_1 <- expit(fs_1)
ps_1.5 <- expit(fs_1.5)
ps_2 <- expit(fs_2)
ps_2.5 <- expit(fs_2.5)
ps_3 <- expit(fs_3)
ps_3.5 <- expit(fs_3.5)
ps_4 <- expit(fs_4)
# P(itch == s)
p_0 <- 1 - ps_0.5
p_0.5 <- ps_0.5 - ps_1
p_1 <- ps_1 - ps_1.5
p_1.5 <- ps_1.5 - ps_2
p_2 <- ps_2 - ps_2.5
p_2.5 <- ps_2.5 - ps_3
p_3 <- ps_3 - ps_3.5
p_3.5 <- ps_3.5 - ps_4
itch ~ c(p_0, p_0.5, p_1, p_1.5, p_2, p_2.5, p_3, p_3.5)
})
}
The last line is where the model becomes ordinal. itch ~ c(...)
lists the probabilities of the first 8 categories; the probability of
the last category is whatever is left (1 - p_0 - ... - p_3.5). The
observations are the category numbers 1 to 9, so a score of \(s\) is
recorded as \(2s + 1\).
Each category’s probability is the difference between two cumulative probabilities, so it stays between 0 and 1 as long as the cumulative logits decrease with \(s\).
What the model predicts
Before simulating a study, it helps to look at the typical patient (\(\eta = 0\)) after each eye drop:
arms <- data.frame(arm = factor(c("Vehicle", "0.1%", "0.2%", "0.7%"),
levels = c("Vehicle", "0.1%", "0.2%", "0.7%")),
conc = c(0, 0.1, 0.2, 0.7))
tgrid <- seq(0.25, 24, by = 0.25)
ev <- do.call(rbind, lapply(seq_len(nrow(arms)), function(i) {
rbind(data.frame(id = i, time = 0, amt = arms$conc[i], evid = 1,
cmt = "eye", Vi = 1, tdrop = 0),
data.frame(id = i, time = tgrid, amt = 0, evid = 0,
cmt = "itch", Vi = 1, tdrop = tgrid))
}))
typ <- rxSolve(olo.cac |> zeroRe(), ev, returnType = "data.frame") |>
mutate(arm = arms$arm[id])
scores <- seq(0, 4, by = 0.5)
pcols <- paste0("p_", scores[-9])
typ$p_4 <- 1 - rowSums(typ[, pcols])
typ$mean <- as.numeric(as.matrix(typ[, c(pcols, "p_4")]) %*% scores)
# untreated (Vi = 0) typical patient, for reference
base <- rxSolve(olo.cac |> zeroRe(),
data.frame(id = 1, time = 1, amt = 0, evid = 0, cmt = "itch",
Vi = 0, tdrop = 0),
returnType = "data.frame")
baseMean <- sum(c(unlist(base[, pcols]), 1 - sum(base[, pcols])) * scores)
ggplot(typ, aes(time, mean, color = arm)) +
geom_hline(yintercept = baseMean, linetype = "dashed", color = "gray40") +
annotate("text", x = 24, y = baseMean, label = "No drop (baseline)",
hjust = 1, vjust = -0.5, size = 3, color = "gray40") +
geom_line(linewidth = 1) +
labs(x = "Time after the drop (h)", y = "Expected itching score",
color = NULL,
title = "Typical patient: itching relief wears off over 24 hours")

Without treatment (the dashed line), the typical patient’s expected score is 2.86. The vehicle drop alone brings that down, and olopatadine brings it down further, with more relief at higher concentrations and a slow return toward the vehicle curve over 24 hours.
The expected score hides how the probabilities move. At the 24-hour challenge:
typ |>
filter(time == 24) |>
select(arm, all_of(pcols), p_4) |>
pivot_longer(-arm, names_to = "score", values_to = "p") |>
mutate(score = factor(as.numeric(sub("p_", "", score)))) |>
ggplot(aes(arm, p, fill = score)) +
geom_col() +
scale_fill_viridis_d(direction = -1) +
labs(x = NULL, y = "Probability", fill = "Itching\nscore",
title = "Probability of each itching score, 24 hours after the drop")

Simulating a study
Now I’ll simulate a study similar to the ones in the paper: 100 patients in each of 4 arms (vehicle, 0.1%, 0.2% and 0.7% olopatadine). Each patient has a baseline challenge with no drop, then three visits two weeks apart with a drop followed by a challenge at 24 hours, 16 hours or 27 minutes. Itching is scored 3, 5 and 7 minutes after each challenge.
The time since the drop is put in the data as tdrop, which is how
this is often done in CAC datasets. It is 0 at the baseline visit,
where Vi = 0 turns off the vehicle effect anyway.
visits <- data.frame(visit = factor(c("Baseline", "24 h", "16 h", "27 min"),
levels = c("Baseline", "27 min", "16 h", "24 h")),
dose = c(NA, 7, 21, 35) * 24, # drop time (h)
cac = c(NA, 24, 16, 27 / 60)) # challenge after drop (h)
min3 <- c(3, 5, 7) / 60
nper <- 100
onePatient <- function(id, conc) {
obs <- do.call(rbind, lapply(seq_len(nrow(visits)), function(i) {
if (i == 1) {
data.frame(id = id, time = min3, amt = 0, evid = 0, cmt = "itch",
Vi = 0, tdrop = 0, visit = visits$visit[i])
} else {
data.frame(id = id, time = visits$dose[i] + visits$cac[i] + min3,
amt = 0, evid = 0, cmt = "itch", Vi = 1,
tdrop = visits$cac[i] + min3, visit = visits$visit[i])
}
}))
drops <- data.frame(id = id, time = visits$dose[-1], amt = conc,
evid = 1, cmt = "eye", Vi = 1, tdrop = 0,
visit = visits$visit[-1])
rbind(drops, obs) |> arrange(time, desc(evid))
}
design <- do.call(rbind, lapply(seq_len(nrow(arms) * nper), function(id) {
a <- (id - 1) %/% nper + 1
onePatient(id, arms$conc[a]) |> mutate(arm = arms$arm[a])
}))
set.seed(2018)
sim <- rxSolve(olo.cac, design, keep = c("arm", "visit", "tdrop"),
addDosing = TRUE, returnType = "data.frame")
dat <- sim |>
mutate(dv = ifelse(evid == 0, sim, NA)) |>
select(id, time, evid, amt, cmt, dv, Vi, tdrop, arm, visit)
dat |>
filter(evid == 0) |>
mutate(score = (dv - 1) / 2) |>
group_by(arm, visit) |>
summarize(mean = round(mean(score), 2), .groups = "drop") |>
pivot_wider(names_from = visit, values_from = mean) |>
knitr::kable()
| arm | Baseline | 27 min | 16 h | 24 h |
|---|---|---|---|---|
| Vehicle | 2.84 | 1.69 | 2.04 | 2.16 |
| 0.1% | 2.91 | 0.87 | 1.44 | 1.66 |
| 0.2% | 2.81 | 0.81 | 1.11 | 1.31 |
| 0.7% | 2.84 | 0.75 | 1.06 | 1.27 |
This looks like a CAC study: everyone itches at baseline, the vehicle gives some relief, and olopatadine gives more, especially at the onset challenge.
It also helps to look at how often each score was observed, against the olopatadine concentration, at each challenge:
dat |>
filter(evid == 0, visit != "Baseline") |>
droplevels() |>
mutate(score = factor((dv - 1) / 2),
conc = arms$conc[match(arm, arms$arm)]) |>
count(visit, conc, score) |>
complete(visit, conc, score, fill = list(n = 0)) |>
group_by(visit, conc) |>
mutate(p = n / sum(n)) |>
ungroup() |>
ggplot(aes(conc, p, color = score)) +
geom_line() +
geom_point() +
facet_wrap(~visit) +
scale_color_viridis_d(direction = -1) +
labs(x = "Olopatadine concentration (%)", y = "Observed proportion",
color = "Itching\nscore",
title = "Observed itching score proportions by concentration")

Higher concentrations move patients toward the lower scores, most at the onset challenge and less by 24 hours.
Fitting with focei
Fitting an ordinal model is the same as fitting any other model. The
:= operator from nlmixr2save saves the fit, so it only has to run
once:
fitF := nlmixr2(olo.cac, dat, "focei",
control = foceiControl(print = 0),
table = tableControl(npde = FALSE))
print(fitF)
## ── nlmixr² log-likelihood FOCEi (outer: bobyqa) ──
##
## OBJF AIC BIC Log-likelihood
## lFOCEi 6144.131 15001.94 15118.52 -7482.97
##
## ── Time (sec $time): ──
##
## setup optimize covariance preprocess postprocess table compress
## elapsed 4.974702 204.5707 171.4799 0.084 0.048 0.173 0.002
## other
## elapsed 0.3176155
##
## ── Population Parameters ($parFixed or $parFixedDf): ──
##
## Est. SE %RSE Back-transformed(95%CI) BSV(SD) Shrink(SD)%
## a_0.5 7.93 7.93 1.36 6.79
## a_1 -1.48 -1.48
## a_1.5 -1.04 -1.04
## a_2 -0.825 -0.825
## a_2.5 -1.36 -1.36
## a_3 -2.56 -2.56
## a_3.5 -2.90 -2.90
## a_4 -2.06 -2.06
## v_1 10.0 FIXED FIXED 1.00
## v_1.5 10.0 FIXED FIXED 1.00
## v_2 10.0 FIXED FIXED 1.00
## v_2.5 16.8 1.00
## v_3 1.35 0.794
## v_3.5 10.0 FIXED FIXED 1.00
## v_4 10.0 FIXED FIXED 1.00
## d_1 10.0 FIXED FIXED 1.00
## d_1.5 10.0 FIXED FIXED 1.00
## d_2 102 1.00
## d_2.5 1.94 0.874
## d_3 10.0 FIXED FIXED 1.00
## d_3.5 -10.0 FIXED FIXED 4.54e-5
## d_4 10.0 FIXED FIXED 1.00
## Vb -4.26 -4.26
## Vm 0.0574 0.0574
## lthalf 2.87 17.6
## lEC50 -3.62 0.0267
## Emax 3.09 3.09
##
## Covariance Type ($covMethod): failed
## No correlations in between subject variability (BSV) matrix
## Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs)
## Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink
## Information about run found ($runInfo):
## • gradient problems with covariance; see $scaleInfo
## • covariance step failed
## • "r,s" not usable (R not PD; S not PD); no covariance
## Censoring ($censInformation): No censoring
## Minimization message ($message):
## Normal exit from bobyqa
##
## ── Fit Data (object is a modified tibble): ──
## # A tibble: 4,800 × 51
## ID TIME DV PRED IPRED eta eye asum_0.5 asum_1 asum_1.5 asum_2
## <fct> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 0.05 6 -1.20 -0.991 -0.371 0 7.56 6.08 5.05 4.22
## 2 1 0.0833 6 -1.20 -0.991 -0.371 0 7.56 6.08 5.05 4.22
## 3 1 0.117 7 -0.571 -0.682 -0.371 0 7.56 6.08 5.05 4.22
## # ℹ 4,797 more rows
## # ℹ 40 more variables: asum_2.5 <dbl>, asum_3 <dbl>, asum_3.5 <dbl>,
## # asum_4 <dbl>, vs_2.5 <dbl>, vs_3 <dbl>, ds_2 <int>, ds_2.5 <dbl>,
## # kel <dbl>, EC50 <dbl>, De <dbl>, Ve <dbl>, fs_0.5 <dbl>, fs_1 <dbl>,
## # fs_1.5 <dbl>, fs_2 <dbl>, fs_2.5 <dbl>, fs_3 <dbl>, fs_3.5 <dbl>,
## # fs_4 <dbl>, ps_0.5 <dbl>, ps_1 <dbl>, ps_1.5 <dbl>, ps_2 <dbl>,
## # ps_2.5 <dbl>, ps_3 <dbl>, ps_3.5 <dbl>, ps_4 <dbl>, p_0 <dbl>, …
ini0 <- fitF$ui$iniDf
cand <- ini0$name[grepl("^[vd]_", ini0$name) & !ini0$fix]
over <- cand[abs(fitF$theta[cand]) > 10]
fitF$theta[cand]
## v_2.5 v_3 d_2 d_2.5
## 16.782310 1.351887 101.647626 1.935758
Applying the paper’s \(\pm 10\) rule
Look at the free differential odds parameters above. v_2.5 and d_2
went past 10. At that point \(\text{expit}()\) is essentially 1, so the
data can’t tell these values apart and they wander off. This is
exactly what happened in the paper, and the solution there was to fix
any differential odds parameter beyond \(\pm 10\) at \(\pm 10\):
olo.cac2 <- olo.cac
if (length(over) > 0) {
fixTen <- paste0(over, " = fix(", sign(fitF$theta[over]) * 10, ")",
collapse = ", ")
olo.cac2 <- eval(str2lang(paste0("ini(olo.cac, ", fixTen, ")")))
}
fitF2 := nlmixr2(olo.cac2, dat, "focei",
control = foceiControl(print = 0),
table = tableControl(npde = FALSE))
print(fitF2)
## ── nlmixr² log-likelihood FOCEi (outer: bobyqa) ──
##
## OBJF AIC BIC Log-likelihood Condition#(Cov)
## lFOCEi 6144.134 14997.94 15101.57 -7482.972 45771.34
## Condition#(Cor)
## lFOCEi 101.4263
##
## ── Time (sec $time): ──
##
## setup optimize covariance preprocess postprocess table compress
## elapsed 10.04084 154.898 323.7491 0.24 0.129 0.225 0.002
## other
## elapsed 0.2940569
##
## ── Population Parameters ($parFixed or $parFixedDf): ──
##
## Est. SE %RSE Back-transformed(95%CI) BSV(SD) Shrink(SD)%
## a_0.5 7.92 0.167 2.10 7.92 (7.60, 8.25) 1.36 6.78
## a_1 -1.48 0.0546 3.70 -1.48 (-1.58, -1.37)
## a_1.5 -1.04 0.0398 3.84 -1.04 (-1.11, -0.958)
## a_2 -0.825 0.0360 4.37 -0.825 (-0.896, -0.754)
## a_2.5 -1.36 0.0784 5.78 -1.36 (-1.51, -1.20)
## a_3 -2.56 0.110 4.29 -2.56 (-2.77, -2.34)
## a_3.5 -2.90 0.104 3.57 -2.90 (-3.10, -2.70)
## a_4 -2.06 0.168 8.14 -2.06 (-2.39, -1.74)
## v_1 10.0 FIXED FIXED 1.00
## v_1.5 10.0 FIXED FIXED 1.00
## v_2 10.0 FIXED FIXED 1.00
## v_2.5 10.0 FIXED FIXED 1.00
## v_3 1.36 0.208 15.3 0.795 (0.721, 0.854)
## v_3.5 10.0 FIXED FIXED 1.00
## v_4 10.0 FIXED FIXED 1.00
## d_1 10.0 FIXED FIXED 1.00
## d_1.5 10.0 FIXED FIXED 1.00
## d_2 10.0 FIXED FIXED 1.00
## d_2.5 1.94 0.314 16.2 0.874 (0.790, 0.928)
## d_3 10.0 FIXED FIXED 1.00
## d_3.5 -10.0 FIXED FIXED 4.54e-5
## d_4 10.0 FIXED FIXED 1.00
## Vb -4.26 0.154 3.61 -4.26 (-4.56, -3.96)
## Vm 0.0576 0.00479 8.31 0.0576 (0.0482, 0.0670)
## lthalf 2.88 0.357 12.4 17.9 (8.89, 36.0)
## lEC50 -3.61 0.381 10.5 0.0270 (0.0128, 0.0569)
## Emax 3.08 0.168 5.44 3.08 (2.75, 3.41)
##
## Covariance Type ($covMethod): r,s (full)
## other calculated covs (setCov()): r; s; r,s; r (full); s (full)
## Some strong fixed parameter correlations exist ($cor) :
## cor:a_1,a_0.5 cor:a_1.5,a_0.5 cor:a_2,a_0.5 cor:a_2.5,a_0.5
## -0.402 -0.271 -0.221 -0.451
## cor:a_3,a_0.5 cor:a_3.5,a_0.5 cor:a_4,a_0.5 cor:v_3,a_0.5
## -0.487 -0.161 0.0244 -0.407
## cor:d_2.5,a_0.5 cor:Vb,a_0.5 cor:Vm,a_0.5 cor:lthalf,a_0.5
## -0.327 -0.590 0.168 0.0571
## cor:lEC50,a_0.5 cor:Emax,a_0.5 cor:om.eta,a_0.5 cor:a_1.5,a_1
## 0.0459 0.344 0.135 -0.0655
## cor:a_2,a_1 cor:a_2.5,a_1 cor:a_3,a_1 cor:a_3.5,a_1
## 0.0361 0.0277 0.0891 0.108
## cor:a_4,a_1 cor:v_3,a_1 cor:d_2.5,a_1 cor:Vb,a_1
## 0.0218 0.0415 0.000449 0.0991
## cor:Vm,a_1 cor:lthalf,a_1 cor:lEC50,a_1 cor:Emax,a_1
## -0.0849 -0.0124 -0.0374 -0.177
## cor:om.eta,a_1 cor:a_2,a_1.5 cor:a_2.5,a_1.5 cor:a_3,a_1.5
## -0.156 -0.0429 0.0538 0.109
## cor:a_3.5,a_1.5 cor:a_4,a_1.5 cor:v_3,a_1.5 cor:d_2.5,a_1.5
## 0.0187 -0.0136 0.130 0.0250
## cor:Vb,a_1.5 cor:Vm,a_1.5 cor:lthalf,a_1.5 cor:lEC50,a_1.5
## 0.112 -0.165 -0.0379 -0.0210
## cor:Emax,a_1.5 cor:om.eta,a_1.5 cor:a_2.5,a_2 cor:a_3,a_2
## -0.181 -0.140 -0.0979 0.0170
## cor:a_3.5,a_2 cor:a_4,a_2 cor:v_3,a_2 cor:d_2.5,a_2
## 0.121 0.0219 -0.0185 -0.0681
## cor:Vb,a_2 cor:Vm,a_2 cor:lthalf,a_2 cor:lEC50,a_2
## 0.0984 -0.0523 0.0502 0.0468
## cor:Emax,a_2 cor:om.eta,a_2 cor:a_3,a_2.5 cor:a_3.5,a_2.5
## -0.0887 -0.0938 -0.0615 0.0447
## cor:a_4,a_2.5 cor:v_3,a_2.5 cor:d_2.5,a_2.5 cor:Vb,a_2.5
## -0.0935 0.214 0.821 0.327
## cor:Vm,a_2.5 cor:lthalf,a_2.5 cor:lEC50,a_2.5 cor:Emax,a_2.5
## -0.0862 -0.0588 -0.0292 -0.191
## cor:om.eta,a_2.5 cor:a_3.5,a_3 cor:a_4,a_3 cor:v_3,a_3
## 0.00273 -0.233 -0.0360 0.682
## cor:d_2.5,a_3 cor:Vb,a_3 cor:Vm,a_3 cor:lthalf,a_3
## -0.106 0.490 -0.108 -0.0617
## cor:lEC50,a_3 cor:Emax,a_3 cor:om.eta,a_3 cor:a_4,a_3.5
## -0.0692 -0.203 -0.0810 -0.127
## cor:v_3,a_3.5 cor:d_2.5,a_3.5 cor:Vb,a_3.5 cor:Vm,a_3.5
## -0.338 -0.0274 0.0393 -0.106
## cor:lthalf,a_3.5 cor:lEC50,a_3.5 cor:Emax,a_3.5 cor:om.eta,a_3.5
## -0.0296 0.0207 -0.110 -0.177
## cor:v_3,a_4 cor:d_2.5,a_4 cor:Vb,a_4 cor:Vm,a_4
## 0.00745 -0.0833 -0.0953 0.0863
## cor:lthalf,a_4 cor:lEC50,a_4 cor:Emax,a_4 cor:om.eta,a_4
## 0.0444 -0.00408 -0.0515 -0.0927
## cor:d_2.5,v_3 cor:Vb,v_3 cor:Vm,v_3 cor:lthalf,v_3
## 0.165 0.283 -0.0934 -0.120
## cor:lEC50,v_3 cor:Emax,v_3 cor:om.eta,v_3 cor:Vb,d_2.5
## -0.111 -0.336 -0.0243 0.295
## cor:Vm,d_2.5 cor:lthalf,d_2.5 cor:lEC50,d_2.5 cor:Emax,d_2.5
## -0.0467 -0.0237 -0.0159 -0.0465
## cor:om.eta,d_2.5 cor:Vm,Vb cor:lthalf,Vb cor:lEC50,Vb
## 0.0306 -0.554 -0.345 -0.270
## cor:Emax,Vb cor:om.eta,Vb cor:lthalf,Vm cor:lEC50,Vm
## 0.0967 -0.0568 0.625 0.333
## cor:Emax,Vm cor:om.eta,Vm cor:lEC50,lthalf cor:Emax,lthalf
## 0.000288 0.0628 0.837 0.292
## cor:om.eta,lthalf cor:Emax,lEC50 cor:om.eta,lEC50 cor:om.eta,Emax
## -0.0160 0.502 -0.0254 0.0917
##
##
## No correlations in between subject variability (BSV) matrix
## Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs)
## Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink
## Information about run found ($runInfo):
## • gradient problems with covariance; see $scaleInfo
## Censoring ($censInformation): No censoring
## Minimization message ($message):
## Normal exit from bobyqa
##
## ── Fit Data (object is a modified tibble): ──
## # A tibble: 4,800 × 49
## ID TIME DV PRED IPRED eta eye asum_0.5 asum_1 asum_1.5 asum_2
## <fct> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 0.05 6 -1.20 -0.993 -0.368 0 7.55 6.08 5.04 4.22
## 2 1 0.0833 6 -1.20 -0.993 -0.368 0 7.55 6.08 5.04 4.22
## 3 1 0.117 7 -0.571 -0.681 -0.368 0 7.55 6.08 5.04 4.22
## # ℹ 4,797 more rows
## # ℹ 38 more variables: asum_2.5 <dbl>, asum_3 <dbl>, asum_3.5 <dbl>,
## # asum_4 <dbl>, vs_3 <dbl>, ds_2.5 <dbl>, kel <dbl>, EC50 <dbl>, De <dbl>,
## # Ve <dbl>, fs_0.5 <dbl>, fs_1 <dbl>, fs_1.5 <dbl>, fs_2 <dbl>, fs_2.5 <dbl>,
## # fs_3 <dbl>, fs_3.5 <dbl>, fs_4 <dbl>, ps_0.5 <dbl>, ps_1 <dbl>,
## # ps_1.5 <dbl>, ps_2 <dbl>, ps_2.5 <dbl>, ps_3 <dbl>, ps_3.5 <dbl>,
## # ps_4 <dbl>, p_0 <dbl>, p_0.5 <dbl>, p_1 <dbl>, p_1.5 <dbl>, p_2 <dbl>, …
Fixing these parameters costs almost nothing in the fit: the objective function goes from 6144.131 to 6144.134. It also helps the covariance step, which failed in the first fit and succeeded after the parameters were fixed. The paper ran into the same problem with the covariance step in NONMEM.
Fitting with adaptive Gaussian quadrature
focei approximates each patient’s likelihood by integrating over \(\eta_i\) with a single point. For categorical data with a large between-patient variability
(\(\omega = 1.38\) here), that approximation can be poor, so it is worth
checking. Adaptive Gaussian quadrature (agq) integrates with more
points. With only one \(\eta\) per patient, using 5 points is still cheap:
fitA := nlmixr2(olo.cac2, dat, "agq",
control = agqControl(nAGQ = 5, print = 0),
table = tableControl(npde = FALSE))
print(fitA)
## ── nlmixr² log-likelihood AGQi (outer: bobyqa; nAGQ=5) ──
##
## OBJF AIC BIC Log-likelihood Condition#(Cov) Condition#(Cor)
## AGQ5 6140.298 14994.11 15097.73 -7481.054 44895.2 100.5123
##
## ── Time (sec $time): ──
##
## setup optimize covariance preprocess postprocess table compress
## elapsed 6.379818 196.8645 367.6623 0.144 0.06 0.126 0.002
## other
## elapsed 0.1524338
##
## ── Population Parameters ($parFixed or $parFixedDf): ──
##
## Est. SE %RSE Back-transformed(95%CI) BSV(SD) Shrink(SD)%
## a_0.5 7.92 0.167 2.10 7.92 (7.60, 8.25) 1.36 6.90
## a_1 -1.48 0.0545 3.70 -1.48 (-1.58, -1.37)
## a_1.5 -1.04 0.0398 3.84 -1.04 (-1.11, -0.958)
## a_2 -0.825 0.0360 4.37 -0.825 (-0.896, -0.754)
## a_2.5 -1.36 0.0785 5.78 -1.36 (-1.51, -1.20)
## a_3 -2.56 0.110 4.28 -2.56 (-2.77, -2.34)
## a_3.5 -2.90 0.104 3.58 -2.90 (-3.10, -2.70)
## a_4 -2.07 0.168 8.14 -2.07 (-2.39, -1.74)
## v_1 10.0 FIXED FIXED 1.00
## v_1.5 10.0 FIXED FIXED 1.00
## v_2 10.0 FIXED FIXED 1.00
## v_2.5 10.0 FIXED FIXED 1.00
## v_3 1.36 0.208 15.3 0.795 (0.721, 0.854)
## v_3.5 10.0 FIXED FIXED 1.00
## v_4 10.0 FIXED FIXED 1.00
## d_1 10.0 FIXED FIXED 1.00
## d_1.5 10.0 FIXED FIXED 1.00
## d_2 10.0 FIXED FIXED 1.00
## d_2.5 1.94 0.314 16.2 0.874 (0.790, 0.928)
## d_3 10.0 FIXED FIXED 1.00
## d_3.5 -10.0 FIXED FIXED 4.54e-5
## d_4 10.0 FIXED FIXED 1.00
## Vb -4.26 0.153 3.60 -4.26 (-4.56, -3.96)
## Vm 0.0575 0.00477 8.29 0.0575 (0.0482, 0.0668)
## lthalf 2.88 0.351 12.2 17.8 (8.92, 35.4)
## lEC50 -3.62 0.379 10.5 0.0268 (0.0128, 0.0564)
## Emax 3.08 0.168 5.44 3.08 (2.75, 3.41)
##
## Covariance Type ($covMethod): r,s (full)
## other calculated covs (setCov()): r; s; r,s; r (full); s (full)
## Some strong fixed parameter correlations exist ($cor) :
## cor:a_1,a_0.5 cor:a_1.5,a_0.5 cor:a_2,a_0.5 cor:a_2.5,a_0.5
## -0.402 -0.271 -0.221 -0.451
## cor:a_3,a_0.5 cor:a_3.5,a_0.5 cor:a_4,a_0.5 cor:v_3,a_0.5
## -0.486 -0.161 0.0244 -0.407
## cor:d_2.5,a_0.5 cor:Vb,a_0.5 cor:Vm,a_0.5 cor:lthalf,a_0.5
## -0.327 -0.590 0.168 0.0571
## cor:lEC50,a_0.5 cor:Emax,a_0.5 cor:om.eta,a_0.5 cor:a_1.5,a_1
## 0.0453 0.344 0.134 -0.0655
## cor:a_2,a_1 cor:a_2.5,a_1 cor:a_3,a_1 cor:a_3.5,a_1
## 0.0360 0.0277 0.0886 0.108
## cor:a_4,a_1 cor:v_3,a_1 cor:d_2.5,a_1 cor:Vb,a_1
## 0.0217 0.0412 0.000552 0.0990
## cor:Vm,a_1 cor:lthalf,a_1 cor:lEC50,a_1 cor:Emax,a_1
## -0.0855 -0.0130 -0.0379 -0.177
## cor:om.eta,a_1 cor:a_2,a_1.5 cor:a_2.5,a_1.5 cor:a_3,a_1.5
## -0.155 -0.0429 0.0540 0.109
## cor:a_3.5,a_1.5 cor:a_4,a_1.5 cor:v_3,a_1.5 cor:d_2.5,a_1.5
## 0.0188 -0.0137 0.130 0.0251
## cor:Vb,a_1.5 cor:Vm,a_1.5 cor:lthalf,a_1.5 cor:lEC50,a_1.5
## 0.112 -0.166 -0.0381 -0.0209
## cor:Emax,a_1.5 cor:om.eta,a_1.5 cor:a_2.5,a_2 cor:a_3,a_2
## -0.181 -0.140 -0.0978 0.0170
## cor:a_3.5,a_2 cor:a_4,a_2 cor:v_3,a_2 cor:d_2.5,a_2
## 0.121 0.0218 -0.0185 -0.0681
## cor:Vb,a_2 cor:Vm,a_2 cor:lthalf,a_2 cor:lEC50,a_2
## 0.0987 -0.0529 0.0501 0.0466
## cor:Emax,a_2 cor:om.eta,a_2 cor:a_3,a_2.5 cor:a_3.5,a_2.5
## -0.0890 -0.0935 -0.0621 0.0447
## cor:a_4,a_2.5 cor:v_3,a_2.5 cor:d_2.5,a_2.5 cor:Vb,a_2.5
## -0.0934 0.214 0.821 0.327
## cor:Vm,a_2.5 cor:lthalf,a_2.5 cor:lEC50,a_2.5 cor:Emax,a_2.5
## -0.0863 -0.0585 -0.0281 -0.190
## cor:om.eta,a_2.5 cor:a_3.5,a_3 cor:a_4,a_3 cor:v_3,a_3
## 0.00288 -0.232 -0.0360 0.681
## cor:d_2.5,a_3 cor:Vb,a_3 cor:Vm,a_3 cor:lthalf,a_3
## -0.107 0.490 -0.107 -0.0616
## cor:lEC50,a_3 cor:Emax,a_3 cor:om.eta,a_3 cor:a_4,a_3.5
## -0.0691 -0.203 -0.0798 -0.127
## cor:v_3,a_3.5 cor:d_2.5,a_3.5 cor:Vb,a_3.5 cor:Vm,a_3.5
## -0.337 -0.0273 0.0387 -0.106
## cor:lthalf,a_3.5 cor:lEC50,a_3.5 cor:Emax,a_3.5 cor:om.eta,a_3.5
## -0.0290 0.0214 -0.110 -0.177
## cor:v_3,a_4 cor:d_2.5,a_4 cor:Vb,a_4 cor:Vm,a_4
## 0.00768 -0.0831 -0.0953 0.0864
## cor:lthalf,a_4 cor:lEC50,a_4 cor:Emax,a_4 cor:om.eta,a_4
## 0.0439 -0.00470 -0.0517 -0.0923
## cor:d_2.5,v_3 cor:Vb,v_3 cor:Vm,v_3 cor:lthalf,v_3
## 0.165 0.283 -0.0927 -0.120
## cor:lEC50,v_3 cor:Emax,v_3 cor:om.eta,v_3 cor:Vb,d_2.5
## -0.111 -0.336 -0.0236 0.295
## cor:Vm,d_2.5 cor:lthalf,d_2.5 cor:lEC50,d_2.5 cor:Emax,d_2.5
## -0.0467 -0.0230 -0.0148 -0.0464
## cor:om.eta,d_2.5 cor:Vm,Vb cor:lthalf,Vb cor:lEC50,Vb
## 0.0304 -0.552 -0.341 -0.266
## cor:Emax,Vb cor:om.eta,Vb cor:lthalf,Vm cor:lEC50,Vm
## 0.0989 -0.0560 0.619 0.325
## cor:Emax,Vm cor:om.eta,Vm cor:lEC50,lthalf cor:Emax,lthalf
## -0.00286 0.0626 0.836 0.293
## cor:om.eta,lthalf cor:Emax,lEC50 cor:om.eta,lEC50 cor:om.eta,Emax
## -0.0158 0.502 -0.0251 0.0917
##
##
## No correlations in between subject variability (BSV) matrix
## Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs)
## Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink
## Information about run found ($runInfo):
## • gradient problems with covariance; see $scaleInfo
## Censoring ($censInformation): No censoring
## Minimization message ($message):
## Normal exit from bobyqa
##
## ── Fit Data (object is a modified tibble): ──
## # A tibble: 4,800 × 49
## ID TIME DV PRED IPRED eta eye asum_0.5 asum_1 asum_1.5 asum_2
## <fct> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 0.05 6 -1.21 -0.993 -0.370 0 7.55 6.08 5.04 4.22
## 2 1 0.0833 6 -1.21 -0.993 -0.370 0 7.55 6.08 5.04 4.22
## 3 1 0.117 7 -0.571 -0.681 -0.370 0 7.55 6.08 5.04 4.22
## # ℹ 4,797 more rows
## # ℹ 38 more variables: asum_2.5 <dbl>, asum_3 <dbl>, asum_3.5 <dbl>,
## # asum_4 <dbl>, vs_3 <dbl>, ds_2.5 <dbl>, kel <dbl>, EC50 <dbl>, De <dbl>,
## # Ve <dbl>, fs_0.5 <dbl>, fs_1 <dbl>, fs_1.5 <dbl>, fs_2 <dbl>, fs_2.5 <dbl>,
## # fs_3 <dbl>, fs_3.5 <dbl>, fs_4 <dbl>, ps_0.5 <dbl>, ps_1 <dbl>,
## # ps_1.5 <dbl>, ps_2 <dbl>, ps_2.5 <dbl>, ps_3 <dbl>, ps_3.5 <dbl>,
## # ps_4 <dbl>, p_0 <dbl>, p_0.5 <dbl>, p_1 <dbl>, p_1.5 <dbl>, p_2 <dbl>, …
Comparing the estimates to the truth
truth <- olo.cac()$theta
iniF <- fitF2$ui$iniDf
free <- iniF$name[!is.na(iniF$ntheta) & !iniF$fix]
est <- function(fit, method) {
data.frame(parameter = free,
est = sprintf("%.3g (%.0f%%)", fit$theta[free],
fit$parFixedDf[free, "%RSE"])) |>
setNames(c("parameter", method))
}
data.frame(parameter = free, truth = sprintf("%.3g", truth[free])) |>
left_join(est(fitF2, "FOCEi"), by = "parameter") |>
left_join(est(fitA, "AGQ (5 points)"), by = "parameter") |>
rbind(data.frame(parameter = "omega (SD)", truth = "1.38",
FOCEi = sprintf("%.3g", sqrt(fitF2$omega[1, 1])),
`AGQ (5 points)` = sprintf("%.3g", sqrt(fitA$omega[1, 1])),
check.names = FALSE)) |>
knitr::kable(row.names = FALSE)
| parameter | truth | FOCEi | AGQ (5 points) |
|---|---|---|---|
| a_0.5 | 8.79 | 7.92 (2%) | 7.92 (2%) |
| a_1 | -1.47 | -1.48 (4%) | -1.48 (4%) |
| a_1.5 | -1.03 | -1.04 (4%) | -1.04 (4%) |
| a_2 | -0.85 | -0.825 (4%) | -0.825 (4%) |
| a_2.5 | -1.88 | -1.36 (6%) | -1.36 (6%) |
| a_3 | -2.88 | -2.56 (4%) | -2.56 (4%) |
| a_3.5 | -3.02 | -2.9 (4%) | -2.9 (4%) |
| a_4 | -2.14 | -2.06 (8%) | -2.07 (8%) |
| v_3 | 1.07 | 1.36 (15%) | 1.36 (15%) |
| d_2.5 | 1.56 | 1.94 (16%) | 1.94 (16%) |
| Vb | -4.98 | -4.26 (4%) | -4.26 (4%) |
| Vm | 0.06 | 0.0576 (8%) | 0.0575 (8%) |
| lthalf | 2.92 | 2.88 (12%) | 2.88 (12%) |
| lEC50 | -3.51 | -3.61 (11%) | -3.62 (10%) |
| Emax | 3.4 | 3.08 (5%) | 3.08 (5%) |
| omega (SD) | 1.38 | 1.36 | 1.36 |
The focei and agq estimates are nearly identical. With 12 observations per patient across 9 categories, the focei approximation is already good here, and the extra quadrature points don’t change the answer.
Some estimates are a few standard errors from the values used to
simulate the data (for example a_0.5, a_2.5, Vb and Emax).
Since both methods agree, this is not an approximation problem. It is
an identifiability problem: the baseline, vehicle and drug effects all
shift the same cumulative logits, so several parameters can trade off
against each other with almost no change in the fit. The estimated
correlations show this:
pars <- c("a_0.5", "a_2.5", "Vb", "Emax", "v_3", "d_2.5")
round(cov2cor(fitA$cov)[pars, pars], 2)
## a_0.5 a_2.5 Vb Emax v_3 d_2.5
## a_0.5 1.00 -0.45 -0.59 0.34 -0.41 -0.33
## a_2.5 -0.45 1.00 0.33 -0.19 0.21 0.82
## Vb -0.59 0.33 1.00 0.10 0.28 0.30
## Emax 0.34 -0.19 0.10 1.00 -0.34 -0.05
## v_3 -0.41 0.21 0.28 -0.34 1.00 0.17
## d_2.5 -0.33 0.82 0.30 -0.05 0.17 1.00
A single study of 400 patients can therefore land some distance from the true values along this ridge, while still predicting the itching scores well, as the next section shows. This is the same reason the paper had to fix the differential odds parameters that wandered past \(\pm 10\): the model has more flexibility than one study can pin down.
Checking the fit
In the paper (Figure 2), the model was checked by comparing the observed frequency of each itching score with the model predictions, in each treatment arm and at each challenge. There are two kinds of prediction:
With between-patient variability: the predicted probabilities are averaged over many simulated patients, each with their own \(\eta_i\). The paper calls these “individual predicted”, but they are really population-averaged (marginal) frequencies, not individual predictions in the usual
IPREDsense.Typical patient: the probabilities for \(\eta = 0\) (the paper’s “population predicted”).
Because the model gives the probability of every score directly, there
is no need to draw random scores; averaging p_0 … p_3.5 (and
p_4 = 1 - p_0 - ... - p_3.5) over 10,000
simulated patients per arm gives smooth predicted frequencies. The final
estimates are in fitA$finalUi:
nsim <- 10000
simDesign <- do.call(rbind, lapply(seq_len(nrow(arms)), function(a) {
onePatient(a, arms$conc[a]) |> mutate(arm = arms$arm[a])
}))
simDesign <- do.call(rbind, lapply(seq_len(nsim), function(r) {
simDesign |> mutate(id = id + (r - 1) * nrow(arms))
}))
predFreq <- function(ui, type) {
rxSolve(ui, simDesign, keep = c("arm", "visit"),
returnType = "data.frame") |>
mutate(p_4 = 1 - rowSums(across(all_of(pcols)))) |>
group_by(arm, visit) |>
summarize(across(all_of(c(pcols, "p_4")), mean), .groups = "drop") |>
pivot_longer(starts_with("p_"), names_to = "score", values_to = "freq") |>
mutate(score = as.numeric(sub("p_", "", score)), type = type)
}
set.seed(42)
pred <- rbind(predFreq(fitA$finalUi, "With variability"),
predFreq(fitA$finalUi |> zeroRe(), "Typical patient"))
obsFreq <- dat |>
filter(evid == 0) |>
mutate(score = (dv - 1) / 2) |>
count(arm, visit, score) |>
complete(arm, visit, score = scores, fill = list(n = 0)) |>
group_by(arm, visit) |>
mutate(freq = n / sum(n)) |>
ungroup()
# mean (SD) of the scores in each panel
meanSd <- function(d) {
d |>
group_by(arm, visit) |>
summarize(m = sum(score * freq),
s = sqrt(sum(score^2 * freq) - sum(score * freq)^2),
.groups = "drop")
}
lab <- meanSd(obsFreq) |>
left_join(meanSd(filter(pred, type == "With variability")),
by = c("arm", "visit"), suffix = c(".obs", ".ipred")) |>
mutate(label = sprintf("Obs %.2f (%.2f)\nPred %.2f (%.2f)",
m.obs, s.obs, m.ipred, s.ipred))
ggplot(obsFreq, aes(score, freq)) +
geom_col(fill = "gray75", width = 0.4) +
geom_line(data = pred, aes(color = type, linetype = type)) +
geom_point(data = pred, aes(color = type), size = 1) +
geom_text(data = lab, aes(x = 4.2, y = Inf, label = label),
hjust = 1, vjust = 1.2, size = 2.6, lineheight = 0.9) +
facet_grid(arm ~ visit) +
scale_x_continuous(breaks = 0:4) +
scale_y_continuous(expand = expansion(mult = c(0.02, 0.4))) +
scale_color_manual(values = c("With variability" = "#1b6ca8",
"Typical patient" = "#d1495b")) +
labs(x = "Itching score", y = "Frequency", color = NULL, linetype = NULL,
title = "Observed (bars) vs predicted itching score frequencies") +
theme(legend.position = "bottom")

The predictions with between-patient variability follow the observed frequencies, and the observed and predicted means and SDs agree, in every arm and at every challenge. The typical-patient predictions are close too, but they are a little more peaked: they describe the typical patient, not the average patient. With a between-patient SD of 1.36 on the log-odds scale, real patients spread out more across the scores, which is why the paper included the between-patient variability when predicting the clinical outcome.
More goodness-of-fit plots
The same comparison can be shown as stacked bars, which is how categorical fits are often presented. The fitted bars are the predictions with between-patient variability from above:
stack <- rbind(
obsFreq |> select(arm, visit, score, freq) |> mutate(source = "Observed"),
pred |> filter(type == "With variability") |>
select(arm, visit, score, freq) |> mutate(source = "Fitted")
) |>
mutate(source = factor(source, levels = c("Observed", "Fitted")),
score = factor(score))
ggplot(stack, aes(arm, freq, fill = score)) +
geom_col() +
facet_grid(source ~ visit) +
scale_fill_viridis_d(direction = -1) +
labs(x = NULL, y = "Proportion", fill = "Itching\nscore",
title = "Observed and fitted itching score distributions") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

A categorical visual predictive check (VPC) asks whether the observed
proportion of each score falls inside what the model predicts for a
study of this size. Here I simulate 200 copies of the study from the
final estimates (each with new patients, so new \(\eta_i\)), and use
vpc_cat() from the vpc package for the 24-hour challenge, the
endpoint the paper focused on:
nrep <- 200
obs24 <- dat |>
filter(evid == 0, visit == "24 h") |>
transmute(id, conc = arms$conc[match(arm, arms$arm)], dv = (dv - 1) / 2)
set.seed(8675)
sim24 <- rxSolve(fitA$finalUi, dat |> select(-dv), nStud = nrep,
returnType = "data.frame") |>
left_join(dat |> filter(evid == 0) |> distinct(id, time, arm, visit),
by = c("id", "time")) |>
filter(visit == "24 h") |>
transmute(rep = sim.id, id, conc = arms$conc[match(arm, arms$arm)],
dv = (sim - 1) / 2)
vpc_cat(
obs = obs24, sim = sim24,
obs_cols = list(id = "id", idv = "conc", dv = "dv"),
sim_cols = list(id = "id", idv = "conc", dv = "dv", sim = "rep"),
bins = c(-0.05, 0.05, 0.15, 0.45, 0.75), # one bin per concentration
smooth = FALSE,
xlab = "Olopatadine concentration (%)", ylab = "Proportion",
title = "Categorical VPC at the 24-hour challenge"
)

Each panel is one itching score. The solid line is the observed proportion, the dashed line is the median of the simulated studies, and the shaded boxes are the 90% prediction intervals.
Summary
Ordinal endpoints like itching scores are written in
nlmixr2withy ~ c(p1, p2, ...), listing all but the last category’s probability.A differential odds model is just more model code: running products of
expit()terms let an effect fade out for some categories.Parameters that run off to \(\pm \infty\) on the logit scale can be fixed, the same way the paper did.
For categorical data with large variability,
agqis an easy way to check a more robust objective approximation; here it gave the same answer asfocei.Comparing the predicted and observed frequency of each score, with and without the between-patient variability, is a natural diagnostic for an ordinal model.