rregressionhierarchical-bayesianbrms

What is the meaning of bf() in brms package when we do cumulative regression analysis?


I was trying to run a Bayesian multilevel cumulative model on ordinal data and was reading the documentation of brms online. My model looks something like

model <- brm(bf(y ~ Condition + (Condition|item) + (Condition|subject)),
                    data = df, 
                    family = cumulative(link="probit", threshold="flexible"),
                    chains=4,cores=4,iter=2000, prior = prior) 

I saw that some documentations do not have the bf() function when specifying the formula but some do. Could someone explain to me what is bf() doing here? Thanks!


Solution

  • The bf() function is just to specify a formula, and using it for simple models inside the brm() function is not something you need to do. You could remove it in your example.

    However, you can use the bf() function to save a formula as an object to pass to the brm() function, like this:

    model_formula <- bf(y ~ Condition + (Condition|item) + (Condition|subject))
    
    model <- brm(model_formula,
                 data = df, 
                 family = cumulative(link="probit", threshold="flexible"),
                 chains=4,cores=4,iter=2000, prior = prior) 
    

    For more advanced formulas, you may need to use the bf() function to separate different parts of your model. For example, a linear model like this would not run if you didn't wrap the formula in bf():

    model <- brm(bf(y ~ x + (1+x|random_effect), sigma ~ x), ...)
    

    Here are some links to pages describing more complex models that all use the bf() function to specify the formulas:

    https://cran.r-project.org/web/packages/brms/vignettes/brms_distreg.html

    https://paul-buerkner.github.io/brms/reference/mixture.html