# [R] Von Mises mixtures: mu and kappa?

Peter Mills peter.mills at strath.ac.uk
Tue Feb 28 16:39:20 CET 2017

```Thank you Bert for the references. I have found mix.vmf as a possible alternative to movMF but am stuck with applying either to my application.

Does anyone know why mix.vmf requires to 2 columns for x?

For example when I use:
gWD <- c(0.1, 1, 0.9, 0.7,0.3)
> mix.vmf(gWD, 2)

I get the error:
‘Error in matrix(nrow = n, ncol = g) : non-numeric matrix extent’

The following code works but I'm not sure how to adapt this to the application I require. What I need is to calculate the mixture parameters for a vector of directional data not a matrix. Could anyone suggest how I can do this?

k <- c(1, 2)
prob <- c(0.3, 0.4, 0.3)
mu <- matrix(rnorm(4), ncol = 2)
mu <- mu / sqrt( rowSums(mu^2) )
x <- rmixvmf(10, prob, mu, k)\$x
mix.vmf(x, 3)

With regards to my original post and using movMF I'm stuck with this also. I found the following from [1], I thought this was the answer however it seems to need some adjustment as it is not giving me the theta and kappa values I started with:
kappa2 <- row_norms(y2\$theta)
mu2<-y2\$theta/row_norms(y2\$theta)

[1] On lines 94 and 107 of “v58i10.R: R example code from the paper “ available from https://www.jstatsoft.org/article/view/v058i10

Any suggestion would be greatly appreciated as after a further week of researching this and trying code I still don't seem to have working code.

Here is some code I am using as a testing example:
################################################
## Generate and fit a "small-mix" data set a la Banerjee et al.
mu1 <- rbind(c(-0.251, -0.968),
c(0.399, 0.917))
kappa1 <- c(4, 4)
theta <- kappa1 * mu1
alpha <- c(0.48, 0.52)
## Generate a sample of size n = 50 from the von Mises-Fisher mixture ## with the above parameters.
set.seed(123)
x <- rmovMF(50, theta, alpha)
## Fit a von Mises-Fisher mixture with the "right" number of components, ## using 10 EM runs.
y2 <- movMF(x, 2, nruns = 10)

kappa2 <- row_norms(y2\$theta)
mu2<-y2\$theta/row_norms(y2\$theta)

mu3c <- lapply(y2, function(x) y2\$theta / row_norms(y2\$theta)) ################################################

I don't understand why this doesn't give me the values of mu and kappa I started with. I have tried to adapted this code to have the same number of mu and kappa values but it doesn't work then as mu is know longer a matrix.

I don't understand why both movMF and mix.vmf give both mu1 and mu2 values per kappa value. In other words for a Von Mises mixture with 3 mixtures (clusters) the code gives 6 mu values and 3 kappa values. I was expecting to get 3 preferred directions (mu).

For example:
mix.vmf(x, 3) gives

\$param
mu1        	mu2     	kappa     probs
Cluster 1 0.4985047 -0.8668870 12.281773 0.3571429
Cluster 2 0.9490725  0.3150578 34.028465 0.2857143
Cluster 3 0.1017800  0.9948069  4.182367 0.3571429

Many thanks
Peter

-----Original Message-----
From: Bert Gunter [mailto:bgunter.4567 at gmail.com]
Sent: 14 February 2017 17:49
To: Peter Mills
Cc: r-help at r-project.org
Subject: Re: [R] Von Mises mixtures: mu and kappa?

Searching "von mises mixture distributions" on rseek.org brought up what appeared to be several relevant hits. If none of these meet your needs, you should probably explain why not in a follow up post.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Tue, Feb 14, 2017 at 8:55 AM, Peter Mills <peter.mills at strath.ac.uk> wrote:
> Hello
>
> I am trying to calculate the values of the concentration parameters (kappa) and preferred direction (mu) for a Von Mises mixture model. I currently have some R code that gives me optimised values for the product of kappa and mu, but I'm not sure how to calculate them when both are unknown? How could I calculate mu and kappa from y2 if I didn't know either in the 1st place? I what to use movMF to give me values of kappa from some directional data where I don't know either kappa or mu.
>
>
> ## Generate and fit a "small-mix" data set a la Banerjee et al.
> mu <- rbind(c(-0.251, -0.968),
>             c(0.399, 0.917))
> kappa <- c(4, 4)
>
> theta <- kappa * mu
> theta
> alpha <- c(0.48, 0.52)
>
> ## Generate a sample of size n = 50 from the von Mises-Fisher mixture
> ## with the above parameters.
> set.seed(123)
> x <- rmovMF(50, theta, alpha)
> ## Fit a von Mises-Fisher mixture with the "right" number of
> components, ## using 10 EM runs.
> y2 <- movMF(x, 2, nruns = 10)
>
> Y2 gives
>> y2
> theta:
>        [,1]      [,2]
> 1  2.443225  5.259337
> 2 -1.851384 -4.291278
> alpha:
> [1] 0.4823648 0.5176352
> L:
> [1] 24.98124
>
> How could I calculate kappa and mu if I didn't know either in the 1st place?
>
> Thanks
> Peter
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help