---
title: "Multivariate trials"
canonical: "https://modelassist.epixanalytics.com/space/EA/26575636/Multivariate%20trials"
format: markdown
---
We sometimes need to recognize the inter-relationship between probabilities of values for two or more distributions.

In other words, these distributions are not independent of each other.

In some simulation software packages, specific features, such as [Rank Order Correlation](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575456/) in Crystal Ball, and other [modeling methods](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575455/) allow us to crudely model correlations between several distributions. However, there are certain situations where specific multinomial distributions are needed.

  


The following three common multivariate distributions are described here:

- Multinomial
- Dirichlet
- and Multivariate Hypergeometric

  


**Multinomial distribution**

  


For a set of n trials, each of which could take one of k different outcomes (like different colours of balls in a huge urn) with probabilities p<sub>1</sub>..p<sub>k</sub>, the distribution of the outcomes is known as multinomial, which is just an extension of the [binomial distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575204/). The only difference is the number of possible outcomes: only two for the binomial and multiple for the multinomial. The Multinomial distribution has the following probability mass function:

![image](media://dcc0b4be-0379-42e5-944f-d25f8e56b20f)


> Macro (mathblock)

> Macro (anchor)



![image](media://ae67d864-dc06-4563-8e59-13a52425ec47)


> Macro (mathblock)

  


 

![image](media://547ae9e7-2e2d-4fa6-9fbd-18ff65c8d0d6)

> Macro (mathinline)

                    is sometimes known as Multinomial coefficient.

  


Let's consider the following problem: The cars in a city are divided into 9 different categories. We know the proportion of the city's cars that are in each category. If we were to monitor 1000 cars that enter a particular motorway, how many cars of each category would we see?

  


This is clearly a problem of multinomial trials since every car that enters the motorway can be any one of 9 types.

To sample from a multinomial distribution we need to proceed as follows:

We know p<sub>1</sub>, p<sub>2</sub>,…,p<sub>k</sub> (proportions of each type) and n (our sample size - 1000).

First we simulate from binomial(n, p<sub>1</sub>) – this gives us s1.

For each remaining category, we simulate s<sub>2</sub>, s<sub>3</sub>, …,, s<sub>k</sub> in order with s<sub>j</sub> = binomial(n-SUM(s<sub>1</sub>…s<sub>j-1</sub>),p<sub>j</sub>/SUM(p<sub>j</sub>…p<sub>k</sub>))

Note that the marginal distribution (the distribution of the parameter looked at in isolation, i.e. with the uncertainty of all the other parameters integrated out) for s<sub>j</sub> (i.e. the distribution of generated values for sj when looked at by itself) is simply a binomial(n,p<sub>j</sub>).

  


An example of a multinomial distribution can be found in the Multinomial model below.

> Macro (anchor)



The links to the Multinomial software specific models are provided here:

<details>
<summary>Crystal Ball</summary>

> Macro (inline-media-image)

 [Multinomial](/wiki/download/attachments/26579343/Multinomial-CB.xlsx?version=1&modificationDate=1506113497000&cacheVersion=1&api=v2)

Here is a screenshot of the model:

![image118.jpg](media://6b3b24be-14b5-486f-9341-2c2eb894d59a)

   


Our first category is simulated in cell C14, which is just a binomial distribution : Binomial(5%, 1000)

As the second category now needs to take into account the result from the first type, the formula in cell D14 becomes as shown above - number of trials is decreased by the number of successes from the first category (see D13), and the probability of success becomes the probability of category two divided by the sum of the probabilities of the remaining 8 categories (see D12). This logic is consistent throughout the "Successes" row (cells D15: K15).
</details>

  


<details>
<summary>@Risk</summary>

> Macro (inline-media-image)

 [Multinomial](/wiki/download/attachments/26581760/Multinomial-AtRISK.xlsx?version=1&modificationDate=1506097517000&cacheVersion=1&api=v2)

 Here is a screenshot of the model:


![image65.gif](media://873ceb07-f64e-4a1b-bd75-c8d5c5c99645)

   


Our first category is simulated in cell C11, which is just a binomial distribution : RiskBinomial(1000, 5%)

As the second category now needs to take into account the result from the first type, the formula in cell D11 becomes as shown above - number of trials is decreased by the number of successes from the first category, and the probability of success becomes the probability of category two divided by the sum of the probabilities of the remaining 8 categories.

This logic is consistent throughout the "Successes" row (cells D11: K11), and the row "Outputs" shows a nice way of naming the output cells.
</details>

  
  


**Dirichlet distribution**

  


The conjugate to the multinomial distribution is the Dirichlet distribution, much like the [beta distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575217/) is the conjugate to the [binomial distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575204/). The Dirichlet distribution is used for modeling the uncertainty around probabilities of successes in multinomial trials.

The Dirichlet distribution has the following probability density function:

![image](media://8fd290f8-7cf1-41a3-9299-54941b8f656a)


> Macro (mathblock)

  


For example, if you've observed s<sub>1</sub>, s<sub>2</sub>, … s<sub>k</sub> of different types of outcomes from n trials, the Dirichlet distribution provides the confidence distribution about the correct values for the probability that a random trial will produce each type of outcome by setting *a*<sub>1</sub> = s<sub>1</sub>+1,. Obviously these probabilities have to sum to 1, so their uncertainty distributions are inter-related.

  


Let's take the same problem that we used in the previous example: All cars in a city are divided into 9 different types. But now we have monitored 100 cars that were entering a particular motorway, and counted the number of cars of each type. What is the uncertainty distribution for the proportions of each type in the total population of cars?

  


In order to solve this problem we need to go through the following steps:

  


- Simulate p<sub>1</sub> = Beta(*a*<sub>1</sub>, SUM(*a*<sub>2</sub>..*a*<sub>k</sub>),1)
- For each remaining probability (except pk), simulate p<sub>2</sub>, p<sub>3</sub>, …,, p<sub>k-1</sub> in order with  
pj = (1-SUM(p<sub>1</sub>..p<sub>j-1</sub>))*Beta(*a*<sub>j</sub>, SUM(*a*<sub>j+1</sub>..*a*<sub>k</sub>),1)
- Finally set p<sub>k</sub> = 1-SUM(p<sub>1</sub>..p<sub>k-1</sub>)

Note that the marginal distribution of p<sub>j</sub> is  Beta(s<sub>j</sub>+1, n+k-s<sub>j</sub>-1, 1), which means that if we have no information (i.e. n = 0, s<sub>j</sub> = 0), the prior is Beta(1,k-1,1) which has a mean of 1/k. This is not a Uniform distribution. That makes sense because the probabilities must add up to 1, so the means of their uncertainties must add up to 1.

An example of a Dirichlet distribution can be found in the Dirichlet model below. 

> Macro (anchor)



The links to the Dirichlet software specific models are provided here:

<details>
<summary>Crystal Ball</summary>

> Macro (inline-media-image)

 [Dirichlet](/wiki/download/attachments/26579343/Dirichlet-CB.xlsx?version=1&modificationDate=1506113490000&cacheVersion=1&api=v2)

Putting the above logic into a spreadsheet model looks like this:

  


![CBMultivariatetrials.JPG](media://50d1ffb0-077b-4097-abe0-ba20813465c2)

   


Row "Alphas" (Cells C10:K10) is calculating the values for *a*j , which are just sj+1

Cell C12 is calculating the confidence distribution for the proportion of category 1 cars using Crystal Ball's Beta distribution with the first parameter equal to *a*1 and the second parameter equal to the summation of *a*2 to *a*9*.*

The second part of the equation in cells D13 to J13 follow similar logic as C13, which is then multiplied by the (1 - sum of the previous cells in the same row). The last Cell K13 calculates the implied probability for the last category as 1-sum(C13:J13).
</details>

  


<details>
<summary>@Risk</summary>

> Macro (inline-media-image)

 [Dirichlet](/wiki/download/attachments/26581760/Dirichlet-AtRISK.xlsx?version=1&modificationDate=1506097508000&cacheVersion=1&api=v2)

Putting the above logic into a spreadsheet model looks like this:


![image67.gif](media://d4fcdd4c-0de6-47a9-b8cd-db89057dbdb6)

   


Row "Alphas" (Cells C9:K9) is calculating the values for *a*j , which are just sj+1

Cell C10 is calculating the confidence distribution for the proportion of category 1 cars using a RiskBeta function with the first parameter equal to *a*1 and the second parameter equal to the summation of *a*2 to *a*9*.*

The second part of the equation in cells D10 to J10 follow similar logic as C10, which is then multiplied by the (1 - sum of the previous cells in the same row). The last Cell K10 calculates the implied probability for the last category as 1-sum(C10:J10).
</details>

  


The Dirichlet distribution is not as intuitive as the Multinomial distribution, but it is a very handy tool when modeling multinomial trials.

  


  


**Multivariate hypergeometric**

  


Sometimes we need to model sampling from a population without replacement with multiple outcomes and when the population is small so the process cannot be approximated to a multinomial where the probabilities of success remain constant. In this case we use the multivariate hypergeometric distribution, which is similar to the [hypergeometric distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575208/), with the difference in the number of possible outcomes from a trial (two - in the hypergeometric and many - in the multivariate hypergeometric).

  


The figure below shows the graphical representation of the multivariate hypergeometric process. D<sub>1</sub>, D<sub>2</sub>, D<sub>3</sub> and so on are the number of individuals of different types in a population, and x<sub>1</sub>, x<sub>2</sub>, x<sub>3</sub>, ... are the number of successes (the number of individuals in our random sample (circled) belonging to each category).

  


![image](media://876be545-cc47-41c5-921f-24acc839bb96)

  


The Multivariate hypergeometric distribution has the following probability mass function:

  


![image](media://1b7d7068-01ef-4233-b28a-e4f6464eb385)

> Macro (mathblock)

, where 

![image](media://1fb63a2c-e97e-4cde-b9e0-e007c0d17b7a)

 > Macro (mathinline)



  


Let's imagine a problem where we have 100 colored balls in a bag, from which 10 are red, 15 purple, 20 blue, 25 green and 30 yellow. Without looking into the bag, you take 30 balls out. How many balls of each color will you take from the bag?

  


We cannot model this problem using the multivariate distribution, because when we take the first ball out, the proportions of the different color balls in the bag change. The same happens when we take the second ball out and so on.

  


Thus, we must proceed as follows:

  


- Model the first color (red for example) as x<sub>1</sub>= Hypergeometric(s<sub>1</sub> ,N, M) , where s<sub>1</sub> is the the type 1 population = 10, N is the sample size = 30, and M is the population size = 100
- Model the rest as: x<sub>i</sub> = Hypergeometric (s<sub>i</sub>, N - SUM(x<sub>1</sub>: x<sub>i-1</sub>), SUM(D<sub>i</sub> : D<sub>n</sub>)) , where s<sub>i</sub> is the the type i population, x<sub>i</sub> is the number of successes of the type i in a sample, x<sub>i-1</sub> is the number of successes of the type i-1 in a sample, D<sub>i</sub> is the number of successes of type i in the total population, D<sub>n</sub> is the number of successes of the last type in the total population.

  


An example of a Multivariate Hypergeometric distribution can be found in the Multivariate Hypergeometric model below. 

> Macro (anchor)



The links to the Multivariate Hypergeometric software specific models are provided here:

<details>
<summary>Crystal Ball</summary>

> Macro (inline-media-image)

 [Multivariate_hypergeometric](/wiki/download/attachments/26579343/Multivariate_hypergeometric-CB.xlsx?version=1&modificationDate=1506113497000&cacheVersion=1&api=v2)
</details>

  


<details>
<summary>@Risk</summary>

> Macro (inline-media-image)

 [Multivariate_hypergeometric](/wiki/download/attachments/26581760/Multivariate_hypergeometric-AtRISK.xlsx?version=1&modificationDate=1506097517000&cacheVersion=1&api=v2)
</details>

  


  


---