I want to fit a model using a custom beta family function. The function called bbeta = beta(a,b)*m, where beta(a,b) is the beta distribution with parameters an and b, and m is a scaling parameter. Here is the custom_family() code:

# Define the custom beta family function

bbeta ← custom_family(

“bbeta”,

dpars = c(“a”, “phi”, “mu”), # Changed “m” to “mu”

links = c(“logit”, “logit”, “identity”),

lb = c(0, 0, 0),

ub = c(Inf, Inf, Inf),

)

stan_density_vec ← "

real bbeta_lpmf(real a, real phi, real mu) {

return dbeta(a, phi) * mu;

}

"

I’m training the model on a dataset d with outcome variable PU and independent variable time. PU has an upper bound that varies exponentially with time, and that is a relationship that the model needs to estimate (through parameter m). Thus, m~intercept +exp^(time*c)

Here is the code to fit the model:

# Define the model formula

model_formula ← PU ~ time

# Define the model

model ← brm(

data = d,

family = bbeta,

formula = model_formula,

cores = 4,

chains = 4

)

When I run it, I get the following error message:

Compiling Stan program…

Error in stanc(file = file, model_code = model_code, model_name = model_name, :

0

Semantic error in ‘string’, line 37, column 16 to column 51:

A returning function was expected but an undeclared identifier ‘bbeta_lpdf’ was supplied.

I’m running R 4.3.2 on MacOs Ventura 13.6.1. Stan_2.32.3 and latest brms package.

Any help would be appreciated.

Thank you,

Charles