How to | Work with Statistical Distributions

Statistical distributions have applications in many fields, including the biological, social, and physical sciences. Mathematica represents statistical distributions as symbolic objects. You can obtain properties, results, and random numbers for hundreds of built-in or custom distributions by applying built-in functions to the objects.

Statistical distributions are simply Mathematica objects:

In[1]:=
Click for copyable input
Out[1]=

You can use the PDF function to get the probability density function for the distribution:

In[2]:=
Click for copyable input
Out[2]=

You can get numeric results by inserting numbers for , , and .

Compute the density for numeric values of , , and :

In[3]:=
Click for copyable input
Out[3]=

Symbolic results can be used in other functions as well.

Here the density function is plotted for specified values of and :

In[4]:=
Click for copyable input
Out[4]=

You can directly obtain common properties such as the mean, variance, cumulative distribution function (CDF), and characteristic function using built-in functions.

This is the mean for a binomial distribution for 100 trials with success probability .3:

In[5]:=
Click for copyable input
Out[5]=

Like a PDF, a characteristic function uniquely defines a distribution.

Obtain the general formula for the characteristic function of a Cauchy distribution:

In[6]:=
Click for copyable input
Out[6]=

You can also compute more general expected values, which give the value expected for a given function applied to a random variable from a given distribution. The ^(th) raw moment is the expected value of raised to the ^(th) power.

Obtain the ^(th) raw moment for a Poisson-distributed random variable :

In[7]:=
Click for copyable input
Out[7]=

You can generate random numbers from distributions using RandomVariate.

These are 10 numbers simulated from a distribution with 15 degrees of freedom:

In[8]:=
Click for copyable input
Out[8]=

A geometric distribution describes the number of trials before a failure when there is a probability of success in each trial.

Simulate 20 numbers from a geometric distribution with success probability parameter :

In[9]:=
Click for copyable input
Out[9]=

You could even visualize a sample against a theoretical distribution because plots of data and functions can be combined.

Here gamma-distributed numbers are generated and stored to the symbol data:

In[10]:=
Click for copyable input

You can use Histogram to generate a histogram of these values on a probability density scale:

In[11]:=
Click for copyable input
Out[11]=

You can visualize the theoretical density function using Plot:

In[12]:=
Click for copyable input
Out[12]=

You can then use Show to display the two graphics together:

In[13]:=
Click for copyable input
Out[13]=

You might also want to estimate parameter values assuming a dataset follows a particular distribution. For instance, you could find the maximum likelihood estimate for parameters by using FindDistributionParameters:

In[14]:=
Click for copyable input
Out[14]=

The results can be packaged up into a distribution object using EstimatedDistribution:

In[15]:=
Click for copyable input
Out[15]=

The log-likelihood could also be computed using LogLikelihood with the estimated distribution:

In[16]:=
Click for copyable input
Out[16]=

The log-likelihood value is mostly relevant compared to log-likelihood values for other parameters. Creating a ContourPlot near the obtained values can provide a qualitative comparison. Points on a given contour have the same log-likelihood.

Here a white point is placed at the optimal point:

In[17]:=
Click for copyable input
Out[17]=
New to Mathematica? Find your learning path »
Have a question? Ask support »