Sampling Error - Von Mises distribution in brms for Simple Model

Hello,

I am working towards running a GLMM with a Von Mises distribution in brms but have been running into issues while fitting even simple models. I have tried setting priors that better reflect the kappa and mu values of my variable of interest, but the model consistently fails. I am able to run Gaussian models with the same response without issues, which makes me think I am not properly setting up the model with the Von Mises distribution. However, I’m still new to modeling circular data and am having trouble finding useful resources to guide me in the proper setup.

Any insight regarding what is going wrong, or how I can improve my methods would be much appreciated.

library(rstan)
library(brms)
library(BAMBI)

# Generate von Mises distributed data, with mu and kappa reflective of my real data
set.seed(123)
data <- data.frame(
  angle = as.numeric(rvonmises(200, mu = circular(.22), kappa = 16)), 
  group = factor(rep(c("A", "B"), each = 100))
)

# Wrap angles to the range [-pi, pi]
data$angle <- minuspi_to_pi(data$angle)

# Fit Bayesian regression model
sim_model <- brm(angle ~ group, data = data, family = von_mises(link = "tan_half", link_kappa = "log"))

Compiling Stan program...
Start sampling

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000871 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 8.71 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
[1] "Error in sampler$call_sampler(args_list[[i]]) : " "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done

sim_model1 <- brm(angle ~ 1, data = data, family = von_mises(link = "tan_half", link_kappa = "log"))


SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 6e-05 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.6 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
[1] "Chain 1: Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                        
[2] "Chain 1: Exception: gamma_lpdf: Random variable is inf, but must be positive finite! (in 'anon_model', line 54, column 2 to column 40)"         
[3] "Chain 1: If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"
[4] "Chain 1: but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                              
[5] "Chain 1: "                                                                                                                                      
[6] "Error in sampler$call_sampler(args_list[[i]]) : "                                                                                               
[7] "  c++ exception (unknown reason)"                                                                                                               
error occurred during calling the sampler; sampling not done

  • Operating System: macOS Sequoia
  • brms Version: 2.22.0
  • Rstan Version: 2.32.6

Hey @janderson, I tried reproducing your error but the following run without issues both with rstan and cmdstanr as backend…

library(rstan)
library(brms)
library(circular)
library(BAMBI)

# Generate von Mises distributed data, with mu and kappa reflective of my real data
set.seed(123)
data <- data.frame(
  angle = as.numeric(rvon_mises(200, mu = circular(.22), kappa = 16)), 
  group = factor(rep(c("A", "B"), each = 100))
)

# Wrap angles to the range [-pi, pi]
data$angle <- minuspi_to_pi(data$angle)

# Fit Bayesian regression model
sim_model <- brm(angle ~ group, 
                 data = data, 
                 family = von_mises(link = "tan_half", 
                                    link_kappa = "log")
                 ,backend = "cmdstanr"
                 )

R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

[1] circular_0.5-1 BAMBI_2.3.6 brms_2.22.8
[4] Rcpp_1.0.14 rstan_2.36.0.9000 StanHeaders_2.36.0.9000