Ordinal regression model code not compiling via brms "Argument 'family' is invalid"

At some point the brms commands to fit ordinal regression models using Stan stopped compiling. A minimal example is the code below, and it would also fail for the cumulative family or if I specified the link function within the family argument. When I run brms code that used to estimate ordinal mixed models without issues, it no longer works without my changing anything. The error message is always “Error: Argument ‘family’ is invalid.” The model fit by the MASS::polr function works. Other brms models like logistic regression also work.

sampled_values <- as.factor(sample(1:4,size = 200,replace = TRUE))
mod_outcome_brms <- brm(sampled_values ~ 1,family = sratio(),chains = 2,iter = 500)
  
mod_outcome_polr <- polr(sampled_values ~ 1,method = "logistic")

The sampled values are just dummy uniform distributed values. It doesn’t make sense for a proportional odds model and I’m only using it to provide example code.

I am running brms version 2.21.0 and R version 4.3.1 on a Windows computer.

Thank you!

I’m using brms 2.22.0, so perhaps there are a few differences in the newer version, but a few things that could be an issue:

  • I think brms will want you to supply the data argument to brm(). At least when I try your example with v2.22.0 the error I get is about the missing data argument.
  • If I put sampled_values in a data frame and pass it to data I get an error that family=sratio() wants either positive integers or an ordered factor. Right now you just have a regular factor. So you could try either getting rid of as.factor() and just passing the integers or you could use as.ordered() instead of as.factor().

Does that work?

Thank you for the quick response!

Unfortunately these suggestions didn’t work for me. Before updating to 2.22.0 I tried passing in the sampled_values as an ordered factor, passing it in via a data argument, and doing both. And then I updated my brms to 2.22.0 and tried the below steps again and I’m still getting the same error message, same as when I use the cumulative family. The code to estimate the third model (logistic regression) works as intended.

sampled_values <- as.ordered(sample(1:4,size = 200,replace = TRUE))
mod_outcome_brms <- brm(sampled_values ~ 1,
                        family = sratio(),
                        chains = 2,
                        iter = 500)
  
sampled_values_df <- data.frame(sampled_values = as.ordered(sample(1:4,size = 200,replace = TRUE)))
mod_outcome_brms <- brm(sampled_values ~ 1,
                        family = sratio(),
                        data = sampled_values_df,
                        chains = 2,
                        iter = 500)

binary_values_df <- data.frame(binary_values = ifelse(sample(1:4,size = 200,replace = TRUE) <=2,1,0))
mod_outcome_brms <- brm(binary_values ~ 1,
                        family = bernoulli(),
                        data = binary_values_df,
                        chains = 2,
                        iter = 500)

I made sure to restart R and RStudio after updating my brms package. I can try doing the latest RStudio update but I wouldn’t expect that to make a difference.

That’s strange. If I make sample_values ordered and put it in a data frame then this works fine for me:

sampled_values <- as.ordered(sample(1:4, size = 200, replace = TRUE))
mod_outcome_brms <- brm(
  sampled_values ~ 1,
  family = sratio(),
  chains = 2,
  iter = 500,
  data = data.frame(sampled_values)
)

That compiles fine for me and runs MCMC. If you run exactly that you get “Error: Argument ‘family’ is invalid.”?

After testing this out on my personal computer and updating my R version on my work computer, I think the issue is due to importing the VGAM library. The code you gave above runs correctly when only brms is loaded, but fails when the VGAM library is loaded. I’m busy right now with other tasks but I will formalize this test later and share the minimal code example here.

1 Like

This is happening because loading VGAM after loading brms causes a bunch of brms functions, including functions needed for ordinal regression, to be masked by VGAM. Here’s what I get when I load both packages:

> library(brms)
Loading required package: Rcpp
Loading 'brms' package (version 2.22.11). Useful instructions
can be found by typing help('brms'). A more detailed introduction
to the package is available through vignette('brms_overview').

Attaching package: ‘brms’

The following object is masked from ‘package:stats’:

    ar

> library(VGAM)
Loading required package: stats4
Loading required package: splines

Attaching package: ‘VGAM’

The following objects are masked from ‘package:brms’:

    acat, cratio, cumulative, dfrechet, dirichlet, exponential, frechet, geometric,
    lognormal, multinomial, negbinomial, pfrechet, qfrechet, rfrechet, s, sratio
1 Like

Thanks @joels, yes that seems like the cause. In that case, it should be possible to still load VGAM after brms as long as you prefix the functions with brms:: to make sure the brms version is used. So @Robert_Miller, changing family = sratio() to family = brms::sratio() should allow you to run your original example while still loading VGAM after brms.

Great, brms::sratio() worked perfectly. Next time I’ll make sure to run the example code with only the necessary libraries when debugging on my own. I greatly appreciate your quick responses.

1 Like