bwn: Density evaluation, sampling, and parameter estimation of the...

bwnR Documentation

Density evaluation, sampling, and parameter estimation of the bivariate wrapped normal distribution

Description

Computation of the density of the bivariate wrapped normal.

Simulation of pairs of samples from a bivariate wrapped normal.

Maximum likelihood estimation of the parameters (\boldsymbol{\mu}, \boldsymbol{\Sigma}).

Usage

d_bwn(x, mu, Sigma, kmax = 2)

r_bwn(n, mu, Sigma)

fit_bwn_mle(
  x,
  kmax = 2,
  lower = c(-pi, -pi, 0.001, 0.001, -1),
  upper = c(pi, pi, 20, 20, 1),
  ...
)

Arguments

x

matrix of size c(nx, 2) with the angles on which the density is evaluated.

mu

circular means of the density, a vector of length 2.

Sigma

covariance matrix of size c(2, 2).

kmax

integer number up to truncate the wrapped normal series in -kmax:kmax. Defaults to 2.

n

sample size.

lower, upper

vector of length 5 with the bounds of the parameters for the maximum likelihood optimizer.

...

further parameters passed to mleOptimWrapper.

Value

  • d_bwn: a vector of length nx with the density evaluated at x.

  • r_bwn: a matrix of size c(n, 2) with the random sample.

  • fit_bwn_mle: a list with the parameters (\boldsymbol{\mu}, \boldsymbol{\Sigma}) and the object opt containing the optimization summary.

See Also

bvm and bwc for the toroidal distributions used by ridge_pca, and ridge_bwn for the density ridge of this model.

Examples

## Density evaluation

mu <- c(0, 0)
Sigma <- 3 * matrix(c(1.5, 0.75, 0.75, 1), nrow = 2, ncol = 2)
nth <- 50
th <- seq(-pi, pi, l = nth)
x <- as.matrix(expand.grid(th, th))
d <- d_bwn(x = x, mu = mu, Sigma = Sigma)
filled.contour(th, th, matrix(d, nth, nth), col = viridisLite::viridis(31),
               levels = seq(0, max(d), l = 30))

## Sampling and estimation

n <- 100
samp <- r_bwn(n = 100, mu = mu, Sigma = Sigma)
(param_mle <- fit_bwn_mle(samp)$opt$par)

ridgetorus documentation built on July 24, 2026, 5:07 p.m.