Function Repository Resource:

# ConditionalProductDistribution (1.0.0)current version: 1.1.0 »

Represent a product of distributions where some distributions can depend on others

Contributed by: Sjoerd Smit
 ResourceFunction["ConditionalProductDistribution"][Distributed[var1,dist1],Distributed[var2,dist2],…] represents the multivariate distribution of {var1,var2, …} where each disti may depend on varj for all i

## Details and Options

ResourceFunction["ConditionalProductDistribution"] is used to define a multivariate distribution in terms of conditional probabilities using the conditional product rule (where f𝒟 denotes the PDF of a distribution 𝒟).
ResourceFunction["ConditionalProductDistribution"] is like a hybrid between ProductDistribution (which allows you to draw from multiple independent distributions at once) and ParameterMixtureDistribution (which allows you to define new distributions in terms of existing ones).
ResourceFunction["ConditionalProductDistribution"] works with RandomVariate, PDF, Likelihood and LogLikelihood. It does not necessarily work in all Wolfram Language functions for distributions.
Graph can be used to create a dependency graph of the variables vari.
ResourceFunction["ConditionalProductDistribution"] will return \$Failed if one of the disti depends on some varj for ij.

## Examples

### Basic Examples (2)

Define a BinomialDistribution where the probability of success is drawn from a BetaDistribution:

 In[1]:=
 Out[1]=

Compute the PDF:

 In[2]:=
 Out[2]=

You can use RandomVariate to draw random samples from a ConditionalProductDistribution. Each sample returns the values of k and p:

 In[3]:=
 Out[4]=

Generate multiple samples:

 In[5]:=
 Out[5]=

Calculate the LogLikelihood of the samples:

 In[6]:=
 Out[6]=

Samples with lower values of k are generally produced by samples with lower values of p:

 In[7]:=
 Out[7]=

### Scope (2)

Graph can be used to generate a dependency graph of the individual random variables. Each edge xy should be read as "x influences y":

 In[8]:=
 Out[9]=

The graph is acyclic:

 In[10]:=
 Out[10]=

When a ConditionalProductDistribution is defined using unprotected symbols for the bound variables, they will be replaced with symbols of the form x[i]:

 In[11]:=
 Out[11]=

### Applications (3)

Define a Normal-inverse-Wishart distribution, which is the conjugate prior to a multivariate normal distribution of unknown mean and covariance:

 In[12]:=

Draw samples from it:

 In[13]:=
 Out[13]=

Draw samples from the posterior predictive distribution:

 In[14]:=
 Out[15]=

### Properties and Relations (3)

A ParameterMixtureDistribution is the marginal distribution of a ConditionalProductDistribution:

 In[16]:=
 Out[16]=

Compute the marginal over k by integrating out p from the PDF of the corresponding ConditionalProductDistribution:

 In[17]:=
 Out[17]=

The result is the same:

 In[18]:=
 Out[18]=

### Possible Issues (3)

The distributions need to be ordered correctly and cannot be circular:

 In[19]:=
 Out[19]=
 In[20]:=
 Out[20]=

In some cases PDF cannot distinguish between evaluating a single coordinate or threading over multiple coordinates. In the following example, the second argument will be interpreted as a pair of coordinates rather than a single 2×2 coordinate:

 In[21]:=
 Out[21]=

In this case, wrap the second argument in a list to remove the ambiguity:

 In[22]:=
 Out[22]=

Bound variables should not have definitions at the time of defining a ConditionalProductDistribution, since this can have unexpected results:

 In[23]:=
 Out[24]=
 In[25]:=
 Out[25]=

Use Clear or Block to make sure p has no value at the moment of definition. After that, the variable will have been localized so that p can be used again:

 In[26]:=
 Out[26]=
 In[27]:=
 Out[28]=

Sjoerd Smit

## Version History

• 1.1.0 – 10 February 2023
• 1.0.0 – 14 August 2020