turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: Dirichlet distributions in JMP (for Bayes prio...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

May 24, 2018 1:52 AM
(624 views)

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 );
```

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

May 25, 2018 10:03 AM
(1073 views)

Solution

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

May 24, 2018 3:56 AM
(610 views)

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

May 25, 2018 10:03 AM
(1074 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

May 28, 2018 6:10 AM
(519 views)