Brms non-linear model no log-likelihood

Dear Stan/brms experts,

I am using the brms to fit a expected utility / prospect theory model to the choice data of risky decision-making task. However, when i tried to compare different types of model, i found the brms did not return the log-likelihood. Here is my model syntax:

## fit expected utility model with brms

# model1: simple expected utility model
m1 = bf(choice ~ inv_logit(5*inv_logit(gamma) * (P1 * (O1^(2*inv_logit(alpha)))-P2 * (O2^(2*inv_logit(alpha))))),
                gamma ~ (1|sub), 
                alpha ~ (1|sub),
                nl = TRUE)

m1_explict_fit = brm(m1,
               data = exp1_explict, family = bernoulli(link='identity'),
               prior = c(prior(normal(0,3), class = "b", nlpar = 'alpha'), 
                         prior(normal(0,3),class = "b", nlpar = 'gamma')),
               init = "0", 
               chains = 4, iter = 6000, warmup=2000, cores = 4)

I have the following error when i try to compute waic or get the log-likelihood:

Error in inv_logit(5 * inv_logit(gamma) * (P1 * (O1^(2 * inv_logit(alpha))) -  : 
  could not find function "inv_logit"
 Most likely this is because you used a Stan function in the non-linear model formula that is not defined in R. If this is a user-defined function, please run 'expose_functions(., vectorize = TRUE)' on your fitted model and try again.
Error in dim(eta) <- dim_eta : 
  dims [product 63360000] do not match the length of object [1]

Thanks in advance!


The answer is in the error message:

inv_logit() is not defined in R, and you can fix this by defining it, for example,

inv_logit <- plogis
1 Like