Difficulty adding loo criterion to longitudinal truncated normal model

I am analysing data from a clinical trial comparing placebo to active medication at multiple timepoint. One of my outcomes has a pronounced right-skew. The overwhelming majority of observations are between 0 and 0.03 but some are just below 0.5.

I was advised by someone on these forums to try a truncated normal regression. I have never run one of these before and am having trouble with the step adding the loo criterion. I would appreciate some advice on whether my difficulties are simply me not understanding how to set the right priors (for example).

Here are the data.
d.RData (10.6 KB)

And here is the model, a longitudinal truncated normal regression comparing the effect of group (placebo vs x) at each of six timepoints (week 0, 3, 6, 9, 12, and 24) with participant id nested within treatment site as the random effect.

fit_trunc <- brm(formula = outcome | trunc(lb = 0, ub = 1) ~ group*week + (1|site/id),
                 data = df,
                 family = gaussian(), # truncated family
                 prior = c(prior(normal(0.2, 1),
                                 class = Intercept),
                           prior(normal(0, 1),
                                 class = b)),
                 save_pars = save_pars(all=TRUE),
                 seed = 1234)

fit_trunc

Here is the output

# Regression Coefficients:
#               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
# Intercept        -0.39      0.10    -0.60    -0.22 1.00      841     1033
# groupx            0.04      0.07    -0.10     0.17 1.00      416      923
# week3            -0.06      0.03    -0.11    -0.01 1.00     2104     2534
# week6            -0.02      0.03    -0.07     0.03 1.00     1776     2388
# week9            -0.03      0.03    -0.09     0.02 1.00     1989     2529
# week12           -0.08      0.03    -0.13    -0.02 1.00     1908     2081
# week24           -0.07      0.05    -0.17     0.02 1.00     2400     2531
# groupx:week3     -0.04      0.04    -0.11     0.04 1.00     2108     2656
# groupx:week6     -0.13      0.04    -0.21    -0.05 1.00     1844     1951
# groupx:week9     -0.02      0.04    -0.09     0.06 1.00     1652     2372
# groupx:week12     0.04      0.04    -0.04     0.12 1.00     1540     2601
# groupx:week24    -0.03      0.06    -0.15     0.09 1.00     2033     2419

Looks as if there is a notable difference between the groups at week 6. 28 divergent transitions is a bit of a concern so some advice on modelling would be appreciated (different priors or even different family maybe) but is not the main thing I am interested in.

Now, I would like to compare this model to a Gaussian or Gamma model so I need to add the loo criterion with moment matching, with a view to performing loo-cv. However when I add the criterion.

fit_trunc_thc <- add_criterion(x = fit_trunc,
                               criterion = "loo",
                               save_psis = TRUE,
                               moment_match = TRUE)

I get an error message

Error in if (varx == 0) { : missing value where TRUE/FALSE needed

I’ve gone online to source solutions and some suggested using a single core but I still get the error. Any advice much appreciated.

Can you try using the loo package directly instead of using add_criterion? If you extract the log likelihood from the brms fit you can pass it to the loo function. I’d be curious to know if that avoids the error.

Do you mean, via

loo(x = fit_trunc,
    save_psis = TRUE,
    moment_match = TRUE,
    reloo = TRUE) -> loo_trunc

It worked but I’m not sure the moment-matching/relooing worked. It was very fast.