This is an old version, view current version.

20.1 Von Mises distribution

20.1.1 Probability density function

If μR and κR+, then for yR, VonMises(y|μ,κ)=exp(κcos(yμ))2πI0(κ). In order for this density to properly normalize, y must be restricted to some interval (c,c+2π) of length 2π, because c+2πcVonMises(y|μ,κ)dy=1. Similarly, if μ is a parameter, it will typically be restricted to the same range as y.

If κ>0, a von Mises distribution with its 2π interval of support centered around its location μ will have a single mode at μ; for example, restricting y to (π,π) and taking μ=0 leads to a single local optimum at the mode μ. If the location μ is not in the center of the support, the density is circularly translated and there will be a second local maximum at the boundary furthest from the mode. Ideally, the parameterization and support will be set up so that the bulk of the probability mass is in a continuous interval around the mean μ.

For κ=0, the Von Mises distribution corresponds to the circular uniform distribution with density 1/(2π) (independently of the values of y or μ).

20.1.2 Sampling statement

y ~ von_mises(mu, kappa)

Increment target log probability density with von_mises_lupdf(y | mu, kappa).

20.1.3 Stan functions

R von_mises_lpdf(reals y | reals mu, reals kappa)
The log of the von mises density of y given location mu and scale kappa.

R von_mises_lupdf(reals y | reals mu, reals kappa)
The log of the von mises density of y given location mu and scale kappa dropping constant additive terms.

R von_mises_rng(reals mu, reals kappa)
Generate a Von Mises variate with location mu and scale kappa (i.e. returns values in the interval [(\mu \mod 2\pi)-\pi,(\mu \mod 2\pi)+\pi]); may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.

20.1.4 Numerical stability

Evaluating the Von Mises distribution for \kappa > 100 is numerically unstable in the current implementation. Nathanael I. Lichti suggested the following workaround on the Stan users group, based on the fact that as \kappa \rightarrow \infty, \text{VonMises}(y|\mu,\kappa) \rightarrow \text{Normal}(\mu, \sqrt{1 / \kappa}). The workaround is to replace y ~ von_mises(mu,kappa) with

 if (kappa < 100)
   y ~ von_mises(mu, kappa);
 else
   y ~ normal(mu, sqrt(1 / kappa));