Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Represent a MarginalDistribution permitting negative numbers as indices
ResourceFunction["NegativeCoordinateMarginalDistribution"][dist,k] represents a univariate marginal distribution of the kth coordinate from the multivariate distribution dist, where k is allowed to be a negative index. | |
ResourceFunction["NegativeCoordinateMarginalDistribution"][dist,{k1,k2,… }] represents a multivariate marginal distribution of the {k1,k2,…} coordinates, but extending the coordinate values to permit negative indices. | |
ResourceFunction["NegativeCoordinateMarginalDistribution"][dist] represents the last marginal distribution of the distribution dist. |
Get the marginal distribution of a CategoricalDistribution for its last coordinate:
In[1]:= |
|
Out[1]= |
|
Get the marginal distribution of a symbolic multivariate normal distribution for its penultimate coordinate:
In[2]:= |
|
In[3]:= |
|
Out[3]= |
|
Positive and negative indices can be used together:
In[4]:= |
|
Out[4]= |
|
If no index is specified, the last index is used:
In[5]:= |
|
Out[5]= |
|
A causal graph between anxiety, peer pressure and smoking:
In[6]:= |
|
Out[6]= |
|
Determine the effect of changing the probability of peer pressure on the probability of smoking as follows. First, generate categorical distributions for peer pressure and anxiety:
In[7]:= |
|
In[8]:= |
|
Assume the two are independent and so one can find their joint distribution using the resource function MixtureCategoricalDistribution as follows:
In[9]:= |
|
Out[9]= |
|
To use a CategoricalDistribution as input to another MixtureCategoricalDistribution, it must be univariate:
In[10]:= |
|
Out[10]= |
|
Now form the distribution of smoking as a function of whether the person is anxious and subject to peer pressure:
In[11]:= |
|
Out[11]= |
|
Use NegativeCoordinateMarginalDistribution to get the probability of smoking as a function of the prevalence of peer pressure:
In[12]:= |
|
Out[12]= |
|
Plot the relationship between the prevalence of peer pressure and the probability of smoking:
In[13]:= |
|
Out[13]= |
|
NegativeCoordinateMarginalDistribution works the same as MarginalDistribution if a positive number is used for the index:
In[14]:= |
|
Out[14]= |
|
In[15]:= |
|
Out[15]= |
|
NegativeCoordinateMarginalDistribution[dist] is equivalent to NegativeCoordinateMarginalDistribution[dist,-1]:
In[16]:= |
|
Out[16]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License