I am conducting a multivariate ordinal regression examining the effect of number of days of amphetamine-type-stimulant use in the 28 days prior to starting treatment (variable ats_baseline) on three outcomes: psychological health, physical health, and quality of life, all measured on a 0-10 integer scale (variables psych, phys, qol) during the first years of treatment (variable yearsFromStart, a continuous variable between 0 and 1). Data are grouped by encounter (variable encID) which defines a block of treatment. For our purposes this can be considered equivalent to a participant ID number. The minimum number of measurements per encID is two. All encounters have the three outcomes measured at start of treatment (i.e. yearsFromStart= 0) and at least one other time. When these non start of treatment measurements occur is irregular. Here are the data
amphUseInOTP_mvr_ppq.RData (23.8 KB)
Here’s code to run the model but I strongly advise against running it: it takes hours.
# nicer name for dataset
mvrppq <- amphUseInOTP_mvr_ppq
# need to transform outcome vars to positive integers
mvrppq %<>%
mutate(across(.cols = psych:qol,
.fns = ~as.integer(.x+1)))
bform_ord_mvr_ppq <- bf(mvbind(psych, phys, qol) ~ ats_baseline*yearsFromStart + (1|p|encID))
# ordinal model
fit_ordinal_mvr_ppq <- brm(bform_ord_mvr_ppq,
family = cumulative("probit"),
data = mvrppq,
save_pars = save_pars(all=TRUE),
seed = 1234,
refresh = 0,
chains = 4,
warmup = 1e3,
iter = 3e3)
And this is the output
Family: MV(cumulative, cumulative, cumulative)
Links: mu = probit
mu = probit
mu = probit
Formula: psych ~ ats_baseline * yearsFromStart + (1 | p | encID)
phys ~ ats_baseline * yearsFromStart + (1 | p | encID)
qol ~ ats_baseline * yearsFromStart + (1 | p | encID)
Data: mvrppq (Number of observations: 2056)
Draws: 4 chains, each with iter = 3000; warmup = 1000; thin = 1;
total post-warmup draws = 8000
Multilevel Hyperparameters:
~encID (Number of levels: 670)
Estimate Est.Error l-95% CI u-95% CI Rhat
sd(psych_Intercept) 0.82 0.04 0.75 0.90 1.00
sd(phys_Intercept) 0.76 0.04 0.69 0.84 1.00
sd(qol_Intercept) 0.86 0.04 0.78 0.94 1.00
cor(psych_Intercept,phys_Intercept) 0.93 0.03 0.87 0.98 1.01
cor(psych_Intercept,qol_Intercept) 0.99 0.01 0.97 1.00 1.00
cor(phys_Intercept,qol_Intercept) 0.94 0.03 0.89 0.98 1.00
Bulk_ESS Tail_ESS
sd(psych_Intercept) 3347 5567
sd(phys_Intercept) 2686 4782
sd(qol_Intercept) 3428 5103
cor(psych_Intercept,phys_Intercept) 936 1704
cor(psych_Intercept,qol_Intercept) 1945 3076
cor(phys_Intercept,qol_Intercept) 2416 3308
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
psych_Intercept[1] -3.28 0.15 -3.59 -3.00 1.00 7232
psych_Intercept[2] -2.74 0.10 -2.94 -2.54 1.00 7601
psych_Intercept[3] -2.10 0.07 -2.25 -1.96 1.00 4931
psych_Intercept[4] -1.59 0.06 -1.72 -1.47 1.00 4705
psych_Intercept[5] -1.15 0.06 -1.27 -1.04 1.00 4589
psych_Intercept[6] -0.42 0.05 -0.53 -0.32 1.00 4266
psych_Intercept[7] 0.12 0.05 0.01 0.22 1.00 4133
psych_Intercept[8] 0.83 0.06 0.73 0.94 1.00 4311
psych_Intercept[9] 1.87 0.07 1.73 2.00 1.00 5365
psych_Intercept[10] 2.55 0.08 2.39 2.71 1.00 6595
phys_Intercept[1] -3.09 0.13 -3.35 -2.84 1.00 6969
phys_Intercept[2] -2.81 0.11 -3.02 -2.60 1.00 7420
phys_Intercept[3] -2.28 0.08 -2.44 -2.13 1.00 6472
phys_Intercept[4] -1.77 0.07 -1.90 -1.64 1.00 5815
phys_Intercept[5] -1.29 0.06 -1.40 -1.18 1.00 5668
phys_Intercept[6] -0.58 0.05 -0.68 -0.48 1.00 5593
phys_Intercept[7] 0.01 0.05 -0.09 0.11 1.00 5490
phys_Intercept[8] 0.74 0.05 0.64 0.85 1.00 5609
phys_Intercept[9] 1.71 0.06 1.59 1.83 1.00 6197
phys_Intercept[10] 2.39 0.08 2.24 2.55 1.00 7233
qol_Intercept[1] -3.32 0.15 -3.62 -3.04 1.00 7671
qol_Intercept[2] -2.71 0.10 -2.91 -2.52 1.00 7930
qol_Intercept[3] -2.17 0.08 -2.33 -2.03 1.00 6522
qol_Intercept[4] -1.71 0.07 -1.84 -1.58 1.00 5718
qol_Intercept[5] -1.32 0.06 -1.44 -1.20 1.00 5297
qol_Intercept[6] -0.57 0.05 -0.68 -0.47 1.00 4439
qol_Intercept[7] 0.01 0.05 -0.10 0.11 1.00 4289
qol_Intercept[8] 0.80 0.06 0.69 0.91 1.00 4563
qol_Intercept[9] 1.71 0.06 1.59 1.83 1.00 4735
qol_Intercept[10] 2.31 0.07 2.16 2.45 1.00 5786
psych_ats_baseline -0.04 0.01 -0.06 -0.02 1.00 3409
psych_yearsFromStart 0.47 0.09 0.30 0.64 1.00 10453
psych_ats_baseline:yearsFromStart 0.05 0.02 0.02 0.08 1.00 10556
phys_ats_baseline -0.03 0.01 -0.04 -0.01 1.00 3769
phys_yearsFromStart 0.31 0.09 0.14 0.48 1.00 12132
phys_ats_baseline:yearsFromStart 0.03 0.02 -0.00 0.06 1.00 9863
qol_ats_baseline -0.04 0.01 -0.06 -0.02 1.00 2974
qol_yearsFromStart 0.52 0.08 0.35 0.68 1.00 12127
qol_ats_baseline:yearsFromStart 0.05 0.02 0.02 0.09 1.00 10553
Tail_ESS
psych_Intercept[1] 5264
psych_Intercept[2] 5713
psych_Intercept[3] 5343
psych_Intercept[4] 6288
psych_Intercept[5] 6033
psych_Intercept[6] 6122
psych_Intercept[7] 6134
psych_Intercept[8] 6418
psych_Intercept[9] 5814
psych_Intercept[10] 6264
phys_Intercept[1] 5747
phys_Intercept[2] 6073
phys_Intercept[3] 6461
phys_Intercept[4] 6048
phys_Intercept[5] 6566
phys_Intercept[6] 6269
phys_Intercept[7] 6065
phys_Intercept[8] 6416
phys_Intercept[9] 6873
phys_Intercept[10] 5979
qol_Intercept[1] 5957
qol_Intercept[2] 6325
qol_Intercept[3] 6788
qol_Intercept[4] 6631
qol_Intercept[5] 6383
qol_Intercept[6] 6100
qol_Intercept[7] 6167
qol_Intercept[8] 5953
qol_Intercept[9] 6369
qol_Intercept[10] 6001
psych_ats_baseline 4634
psych_yearsFromStart 6243
psych_ats_baseline:yearsFromStart 6259
phys_ats_baseline 5436
phys_yearsFromStart 6305
phys_ats_baseline:yearsFromStart 6080
qol_ats_baseline 5078
qol_yearsFromStart 6547
qol_ats_baseline:yearsFromStart 5849
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
disc_psych 1.00 0.00 1.00 1.00 NA NA NA
disc_phys 1.00 0.00 1.00 1.00 NA NA NA
disc_qol 1.00 0.00 1.00 1.00 NA NA NA
Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
So the model appears to converge ok. But when I run this through add_criterion()
fit_ordinal_mvr_ppq <- add_criterion(fit_ordinal_mvr_ppq,
criterion="loo",
save_psis = TRUE,
moment_match = T,
reloo = T,
recompile = TRUE)
It runs for a long long time then fails, with this error
rsession-arm64(54828) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.
Recompiling the model with 'rstan'
Recompilation done
Error : Exception: lub_free: Correlation variable is -1.00007, but must be in the interval [-1, 1] (in 'anon_model', line 125, column 2 to column 32)
Error in `loo_moment_match.brmsfit()`:
! Moment matching failed. Perhaps you did not set 'save_pars = save_pars(all = TRUE)' when fitting your model? If you are running moment matching on another machine than the one used to fit the model, you may need to set recompile = TRUE.
I have no idea what the error message means. Can anyone give me some advice?
The add_criterion() is run in the same session on the same machine, and, as you can see, I definitely set save_pars = save_pars(all=TRUE)