Warnings after running brm

I am running a phylogenetic logistic regression using brm from brms package. My data consists on a categorical predictor (values 0, 1 and 2) and a binary response variabe (values 1 and 2) plus adding the effect of phylogeny as a predictor (1Ispecies). Here is my code:

options(scipen=999) #to avoid scientific notation
#setwd("C:/Users/User/OneDrive - ufabc.edu.br/Doutorado/Tentando de novo/Projeto_pos_FAPESP/Leonardo/Cap_2_Tese/")
setwd("C:\\Users\\leona\\OneDrive - ufabc.edu.br\\Doutorado\\Tentando de novo\\Projeto_pos_FAPESP\\Leonardo\\Cap_2_Tese")

data_neot<-read.csv("Visual_display_data.csv", sep = ";")

visdisp<-data.frame(data_neot$Scientific_Name, data_neot$VisDisp, data_neot$Activity.cat)
colnames(visdisp)<-c("species", "visdisp", "activity") #activity 0=nocturnal; 1=diurnal; 2=both
visdisp_data<-na.omit(visdisp)
row.names(visdisp_data)<-visdisp_data$species
visdisp_data<-visdisp_data[visdisp_data$activity != "" ,]


tree<-read.tree("C:\\Users\\leona\\OneDrive - ufabc.edu.br\\Doutorado\\Tentando de novo\\Projeto_pos_FAPESP\\Leonardo\\Cap_2_Tese\\teste_phylo_logist\\amph_shl_new_Posterior_7238.10000.trees")
class(tree)

namecheck_activity <- name.check(tree[[1]], visdisp_data) # checking which species
# are in the phylogeny but not in our data frame

trees_activity <- lapply(tree, drop.tip, namecheck_activity$tree_not_data) # pruning
# these species from all the 1,000 trees
class(trees_activity) <- "multiPhylo"

nrow(visdisp_data)

length(trees_activity[[1]]$tip.label) # number of tips in the phylogenic trees



  if(any(is.ultrametric(trees_activity)) == FALSE) {
    trees_activity <- lapply(trees_activity, chronoMPL)
    class(trees_activity) <- "multiPhylo"
  }

####Bayesian phylogenetic logistic regression####
div_prior<-get_prior(visdisp ~ activity + (1|species),
                     data = visdisp_data, family = bernoulli("logit"))

final_prior<-c(set_prior("student_t(3, 0, 2.5)", class = "sd", coef = "Intercept", group = "species"),
               set_prior("student_t(3, 0, 2.5)", class = "sd", group = "species"), 
               set_prior("student_t(3, 0, 2.5)", class = "Intercept", group = "species"))


ntrees = 50
brms_activity <- rep(list(NA),ntrees) # list that will contain brm output for each tree
for(i in 1:ntrees){
  # handling phylogeny to incorporate in brm
  inv.phylo <- inverseA(trees_activity[[i]], nodes = "TIPS", scale = TRUE)
  A <- solve(inv.phylo$Ainv)
  rownames(A) <- rownames(inv.phylo$Ainv)
  brms_activity[[i]] <- brm(
    visdisp ~ activity + (1|species),
    data = visdisp_data, sample_prior = "yes", prior = div_prior,  family = bernoulli("logit"),
    cov_ranef = list(species = A), # incorporating phylogeny
    chains = 6, cores = 6, iter = 3000, warmup = 1000,
    refresh = 0, control = list(max_treedepth = 21,  adapt_delta=0.9999999999999999, stepsize = 0.0001)
  )
}

However, I am having several warnings in the output. The warnings are:

Mensagens de aviso:
1: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
2: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
3: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
4: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
5: There were 1 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
6: Examine the pairs() plot to diagnose sampling problems

7: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
8: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
9: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
10: There were 6 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
11: Examine the pairs() plot to diagnose sampling problems

12: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
13: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
14: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
15: The largest R-hat is 1.07, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat
16: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
17: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
18: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
19: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
20: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
21: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
22: There were 2 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
23: Examine the pairs() plot to diagnose sampling problems

24: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
25: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
26: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
27: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
28: There were 1 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
29: Examine the pairs() plot to diagnose sampling problems

30: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
31: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
32: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
33: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
34: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
35: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
36: There were 1 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
37: Examine the pairs() plot to diagnose sampling problems

38: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
39: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
40: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
41: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
42: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
43: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
44: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
45: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
46: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
47: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
48: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
49: Argument 'cov_ranef' is deprecated and will be removed in the future. Please use argument 'cov' in function 'gr' instead.
50: There were 1 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.

As you guys can see, I put adapt_delta in its max value, changed iterations number, max_treedepth and stepsize values, and I got the warnings. What more should I do?

Well, perhaps you can’t estimate the parameters in this model very well with the data that you have, and you might need to specify your model differently.

However, you might want to start with some prior predictive checks. The student t priors that you specify for the varying intercepts are very heavy tailed for the logit scale. Using prior predictive checks, see if something like normal(0, 1.5) or normal(0, 1) would be better. Depending on your data, even normal(0, 0.5) could be a very wide prior on the logit scale (all of these are obviously half-normal).

Typically, I think it’s not so useful for adapt_delta to be more than 0.99 or max_treedepth to be more than 12 or so.

1 Like

Thanks for replying! I’ll try your suggestions and let you know if worked. Cheers!

1 Like

Hi! I tried to set the prior to normal (0,1) but got the error:

Error: The following priors do not correspond to any model parameter: 
Intercept_species ~ normal(0,1)
Function 'get_prior' might be helpful to you.

Just to let you know, the priors I set before was from get_prior function

So unfortunately you didn’t specify the correct name for the parameter or some bit of information for setting the prior, so brms doesn’t recognize it. Using the get_prior() function will give you the information that you need. You will need to use the name exactly as written by get_prior() when you specify the prior in your model.

final_prior<-c(prior(normal(0, 1), class = sd))

should work

Hi! I believe it worked.Now I only had the cov_ranef warning, but it’s okay. Many thanks!

1 Like