Community Trekker

Joined:

Oct 6, 2014

## Dirichlet distributions in JMP (for Bayes prior)

Hi,

I am trying some Bayesian bootstrapping and would like to do it in JMP Pro. One of the prior distibutions I would like to use is Dirichlet. I was thinking of using the column data type Expression to hold vectors of the weights and using the Compress to Label Addin to index the unique values in the column so I know which row/column of the vector contains the correct weight to apply.

I can generate Dirichlet vectors using the R connector (below) but would like to do it in a formula column so I can take advantage of the Bootstrap feature in Pro. Any suggestions?

``````Names Default To Here( 1 );
R Init();

//input list, outputlist, Rcode
rc = R Execute(
{nSamples,pollResult},
{x},
"
library (DirichletReg)

x <- rdirichlet(nSamples, c(728,584,138))"
);
Wait( 3 );
//get dataframe from R
resultMatrix = R Get(x);

//close connection
R Term();

//export results
dt = As Table( resultMatrix );``````
1 ACCEPTED SOLUTION

Accepted Solutions

Staff

Joined:

Nov 10, 2016

Solution

## Re: Dirichlet distributions in JMP (for Bayes prior)

Hi Stephen,

You can paste the code below into a column formula, and it should sample from a Dirichlet. I'd recommend that you convince yourself that it's accurate before using it, since I didn't test it. I wrote it based off of https://en.wikipedia.org/wiki/Dirichlet_distribution#Random_number_generation

``````alpha = [1 2 3 4 5];
gams = Random Gamma(alpha)`;
gams/sum(gams); // values sampled from dirichlet with concentration parameters alpha ``````

Milo

3 REPLIES
Highlighted

Staff

Joined:

Jun 23, 2011

## Re: Dirichlet distributions in JMP (for Bayes prior)

The Dirichlet distribution is not available directly in JMP but you do not need to call R in this case. You can make a column formula in which you use the functions that are available in JMP. See, for example, "What is an intuitive explanation of the Dirichlet distribution?" for more information.

Learn it once, use it forever!

Staff

Joined:

Nov 10, 2016

Solution

## Re: Dirichlet distributions in JMP (for Bayes prior)

Hi Stephen,

You can paste the code below into a column formula, and it should sample from a Dirichlet. I'd recommend that you convince yourself that it's accurate before using it, since I didn't test it. I wrote it based off of https://en.wikipedia.org/wiki/Dirichlet_distribution#Random_number_generation

``````alpha = [1 2 3 4 5];
gams = Random Gamma(alpha)`;
gams/sum(gams); // values sampled from dirichlet with concentration parameters alpha ``````

Milo

Community Trekker

Joined:

Oct 6, 2014

## Re: Dirichlet distributions in JMP (for Bayes prior)

Combining this infomation with Expand Vector Column Add-in has given me just what I needed. Thanks.