## Package vMF: Generate random draws from von Mises-Fisher distribution

Description

vMF samples from von Mises-Fisher distribution and performs some operations. Unlike the movMF package, vMF does not consider mixtures of von Mises-Fisher distrubution. vFM focuses particularly on sampling the distribution and realizes it very quickly. This is useful for quickly performing simulations in directional statistics. The vMF also calculates the density and the normalization constant of the von Mises-Fisher distribution.

Note that vMF does not substitute movMF to the extent that movMF handles many issues that vMF does not take into account. vMF can generate random vectors more quickly from the von Mises-Fisher distribution. We show in some examples below that vMF  can be useful for directional statistical simulation questions.

How to install vMF

vMF is still a package we are testing and is not yet available on CRAN. You can proceed with offline installation by performing these steps:

1. Install R version 3.5.1 available on CRAN.

2. Install Rcpp package that vMF depends on.  install.packages("Rcpp")

3. Download vMF version you need: the package source for developers*, the Windows binary for Windows users and the OS X binary for Linux and Mac users.​​
* At step 2 developers need  BH and Rcpp packages as dependencies.

4. Install vFM: Use the code below depending of the version you downloaded.

In examples below, we show how to use vMF and compare its performance with that of the package movMF.

Example 1

library(vMF)
library(movMF)
library(microbenchmark)
#For comparing elapsed time

TIME1 <- microbenchmark("vMF1" = rvMF(1,c(1,0,0)), "movMF1" = rmovMF(1,c(1,0,0)) ,"vMF2" = rvMF(100,c(1,0,0)), "movMF2" = rmovMF(100,c(1,0,0)), "vMF3" = rvMF(1000,c(1,0,0)), "movMF3" = rmovMF(1000,c(1,0,0)))

print(TIME1)

Example 2

library(vMF)

library(movMF)

library(microbenchmark) #For comparing elapsed time

# Fonction based on vMF to simulate theta

SamplevMF<-function(n,initial){
output<-matrix(NaN,n+1,length(initial))
output[1,]<-t(initial)
for (i in 1:n) {
output[i+1,]<-rvMF(1,output[i,])
}
return(output)
}

# Fonction based on movMF to simulate theta

SamplemovMF<-function(n,initial){
output<-matrix(NaN,n+1,length(initial))
output[1,]<-initial
for (i in 1:n) {
output[i+1,]<-rmovMF(1,output[i,])
}
return(output)
}

TIME2 <-  microbenchmark("vMF" = SamplevMF(1000,c(0,0,0,0)), "movMF" = SamplemovMF(1000,c(0,0,0,0)))

print(TIME2)

Unit: milliseconds

expr            min           lq               mean        median          uq            max     neval    cld

vMF          9.55       10.01          12.20       10.19         12.19        35.80     100       a

movMF 298.74     324.37    367.40    336.02      362.93    879.16    100       b

This site was designed with the
.com
website builder. Create your website today.