Error: logml needs to be numeric

  • Operating System: Windows 10
  • brms Version: 2.5.0
  • R Version: 3.5.2
  • RStudio Version: 1.2.5033

I am successfully fitting logistic regressions with a random effect - e.g.,

cop0 <- brm(g_samp ~ s_legg_add + (1 + s_legg_add|site), data = p_cop,
family = bernoulli(“logit”),
prior = c(set_prior(“normal(0,10)”, class = “b”, coef = “s_legg_add”)),
warmup = 1000, iter = 2000, chains = 4,
control = list(adapt_delta = 0.99, max_treedepth = 10), save_all_pars = TRUE )

But, as soon as I try to run a hurdle model - e.g.,

cop.o0 <- brm(bf(no_eggs ~ s_legg_add + (1 + s_legg_add|site) + offset(log(mass)),
hu ~ s_legg_add + s_lmass + (1 |site)),
data = p_cop, family = hurdle_negbinomial(),
prior = c(set_prior(“normal(0,10)”, class = “b”, coef = “s_legg_add”),
set_prior(“gamma(0.01,0.01)”, class = “shape”),
set_prior(“normal(0,10)”, class = “b”, coef = “s_legg_add”, dpar=“hu”),
set_prior(“normal(0,10)”, class = “b”, coef = “s_lmass”, dpar=“hu”)),
warmup = 1000, iter = 2000, chains = 4,
control = list(adapt_delta = 0.99, max_treedepth = 10), save_all_pars = TRUE)

I am hit with the following message:

Error: logml values need to be numeric

This is completely baffling given that these hurdle models were working earlier today. I have tried updating R and Stan and brms but I found that this actually lead to a series of other problems with compiling models, so I have gone back to the previous version of R that was working with Stan and brms. I have also started a new Rproject and moved everything in to it, but that has not solved the problem. Currently, I can get the first model to run without an issue, but the second model errors out immediately.

Can you provide a minimal reproducible example for the error?

Hi, thanks for responding! I have attached a .csv for the data and pasted my r-code below…

p_cop_ex.csv (21.5 KB)

knitr::opts_chunk$set(echo = TRUE)

library(ggplot2)
library(dplyr)
library(tidyr)
library(stringi)
library(rstan)
library(shinystan)
library(brms)
library(bayesplot)
library(devtools)
library(pkgbuild)
library(bridgesampling)

pkgbuild::has_build_tools(debug = TRUE)

rstan_options(auto_write=T)

options(mc.cores = parallel::detectCores())

(auto_write = TRUE)

p_cop_ex <- read.csv("p_cop_ex.csv")


#model that works:

cop0 <- brm(g_samp ~ s_legg_add + (1 + s_legg_add|site), data = p_cop_ex,
          family = bernoulli("logit"),
          prior = c(set_prior("normal(0,10)", class = "b", coef = "s_legg_add")),
          warmup = 1000, iter = 2000, chains = 4,
          control = list(adapt_delta = 0.99, max_treedepth = 10), save_all_pars = TRUE )


#model that doesn't work:

cop.o0 <- brm(bf(no_eggs ~ s_legg_add + (1 + s_legg_add|site) + offset(log(mass)),
           hu ~ s_legg_add + s_lmass + (1 |site)),
           data = p_cop_ex, family = hurdle_negbinomial(),
           prior = c(set_prior("normal(0,10)", class = "b", coef = "s_legg_add"),
                     set_prior("gamma(0.01,0.01)", class = "shape"),
                     set_prior("normal(0,10)", class = "b", coef = "s_legg_add", dpar="hu"),
                     set_prior("normal(0,10)", class = "b", coef = "s_lmass", dpar="hu")),
           warmup = 1000, iter = 2000, chains = 4,
           control = list(adapt_delta = 0.99, max_treedepth = 10), save_all_pars = TRUE)



You loaded bridgesampling after brms, with the former masking the bf function of the latter. Avoid loading bridgesampling or loading it before brms will solve this problem.

Thanks! Everything is working now.