Circular data model

I have a repeated measures design, with a variable Theta (an angle that goes from -pi to + pi) and 2 predictors, A (6 levels, nominal) and B(3 levels, continuous).

These are my priors (i am using BRMS)

            Prior_Theta = c(set_prior('normal(0, 3)', class='b',lb = -pi, ub = pi),
            set_prior("lkj(2)", class = "cor"),

            set_prior("gamma(2, 0.01)", class = "kappa"),

            set_prior("student_t(3, 0, 10)", class = "sd"))

and this is my model

               Model_Theta = brm(Theta ~ 0 + A + A:B + (0 + A|Subject) + (0 + A:B|Subject),

               data = dataframe,

               family = von_mises(),

               prior = Prior_Theta,

               sample_prior= TRUE,

               warmup = 500,

               iter = 1000,

               control = list(adapt_delta = 0.9),

               chains = 4,

               cores = 4)

the problem is that it takes ages to run and te chains don’t converge. I’ve tried to set an inits to 0 but again, the chains don’t converge. I’ve seen another topic on this (Divergent transitions when modeling changing circular concentration (von Mises dist)) but none of the solution suggested worked.

OS X El Capitan 10.11.6
Brms version version 2.18.1

How does your data look like? For instance, how many observations you have per subject?

There are a total of 180 observation per subject. 30 in each condition (i.e., each level of the predictor A). This is because each level of A has 3 sub-levels (my predictor B), whose have 10 observation each.

Therefore i have a 6 (predictor A) X 3 (predictor B) X 10 number of observations for each subject

Does the model convergence if you replace von_mises() by gaussian()? Just to narrow down the problem.

Setting the distribution as gaussian drastically reduce the time of computation and chains converge even with a small number of iteration (i tried with a warmup of 100 and iter of 400).

Can also try making a more informative prior for kappa, into the range which is relevant for your data (probably moving probability mass away from high values of kappa - e.g. for animal behavior data, I have typically seen kappa estimates in the range 0-3) to achieve convergence. It may still take some time and require plenty of warmup. (And make sure that all other priors are well specified.)

The prior for kappa, sd and lkj are the output of the function “get_prior”. The other priors (i.e. class = “b”) is the prior for my angle data.

This is a simulation of my dataset

data <- expand.grid(TrialN=1:10,
                Size = c(40,50,60),
                Condition = c("A","B","C","D","E","F"))


  data$Theta = c(
  # Condition A Size 40
  # Condition A Size 50
  # Condition A Size 60

  # Condition B Size 40
  # Condition B Size 50
  # Condition B Size 60

  # Condition C Size 40
  # Condition C Size 50,
  # Condition C Size 60

  # Condition D Size 40
  # Condition D Size 50
  # Condition D Size 60

  # Condition E Size 40
  # Condition E Size 50
  # Condition E Size 60

  # Condition F Size 40
  # Condition F Size 50
  # Condition F Size 60

Could you try with the following more informative prior for kappa?

set_prior(“gamma(2, 0.2)”, class = “kappa”)

From a cursory look at your simulated data, this prior should not be so informative as to guide the model too much and may allow it to converge.

I tried to create a model with a more informative prior for kappa as you suggested (gamma(2,0.2)), with warmup = 100 and iter = 400. It takes a lot to run (almost an hour vs ~6 minutes when i used a gaussian distribution) and the chains don’t converge.

These models frequently take a long time, and this formulation will invariably take longer than the Gaussian version, but it would of course need to converge. You could try making the gamma prior quite restrictive ( e.g. gamma(2,0.5) ) to see if that works, first and foremost. Other than that, you could perhaps look very carefully at optimal priors for the other parameters.
I hope that that is of some help.

I’ve already tried to narrow the priors for all the parameters i have, but it was unsuccessful. I think the problem could be something related to the von_mises distribution itself, and the use of a random variable (subjects) and an interaction. Since data are circular, the mean has to be calculated in a different way compared to a classic gaussian distribution. This could generate some problems during the shrinkage process, which influences how the starting value for each MCM chain is selected. It seems that the von mises distribution cause a problem in the sampling process for the chains. It looks like that, due to the selection of a wrong starting value caused by a wrong shrinkage process, the NUTS process starts from a value that is too far from my distribution, and remain in that zone for a while.

I found a discussion on stack exchange on glm and circular statistics. There is a specific package for the circular glm,

In this case if you use the “lm.circular” command, from what i understood, the interactions have to be calculated by hand, otherwise the “circularGLM” command from this package should calculate the interaction by itself. However, it seems that it doesn’t work with random variables (i tried to put the subjects as random factor and the code doesn’t work).