0

I'm trying to run the ordinal logit model with the brms package, and I got the error "The function "cumulative" could not be found. I changed it to family = "cumulative" and was able to get it to work. Are these different?

 bmodel<- brms::brm(pop ~  RDB2000pop + Temperature2003 + Population2003 +  
                              (1+RDB2000pop+Temperature2003+Population2003|species_id),
                 data      = dfpop_chenv,
                 family    = cumulative(link = "logit", threshold = "flexible"),
                 warmup    = 100,
                 iter      = 500,
                 chains    = 4,
                 cores     = 2) 
marie
  • 315
  • 1
  • 9

1 Answers1

1

This is occurring because you are calling the function brm() through specifying brms::brm(). This means that the other functions included with the package like cumulative() have not been loaded.

I made some toy ordinal data from the mtcars package to reproduce the error with the following code:

mtcars$cyl <- as.ordered(mtcars$cyl)

I then get the same error if I try and fit a model with code similar to yours:

m1 <- brms::brm(cyl ~ mpg,
          data = mtcars,
          family = cumulative(link = "logit", threshold = "flexible"))

Error in cumulative(link = "logit", threshold = "flexible") : 
  could not find function "cumulative"

However, if instead, I load the package using library(), I can call code similar to yours and the model fits with no problems. This is because the family functions available from Stan though brms are often not available in base R.

library(brms)
m1 <- brm(cyl ~ mpg,
          data = mtcars,
          family = cumulative(link = "logit", threshold = "flexible"))

Now the model doesn't make too much sense here, but it fits without issues.

summary(m1)
 Family: cumulative 
  Links: mu = logit; disc = identity 
Formula: cyl ~ mpg 
   Data: mtcars (Number of observations: 32) 
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup samples = 4000

Population-Level Effects: 
             Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept[1]   -39.51     13.40   -72.37   -19.61 1.01      775      821
Intercept[2]   -34.24     11.83   -63.63   -16.48 1.01      827      863
mpg             -1.85      0.63    -3.42    -0.91 1.01      803      884

Family Specific Parameters: 
     Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
disc     1.00      0.00     1.00     1.00 1.00     4000     4000

Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
sjp
  • 820
  • 1
  • 5
  • 10