Statistical distributions in julia

This is a quick note on how to generate random variables in Julia and sample from them.

We first needs to load the package Distributions. If it is not already installed, you can do so with:

using Distributions

All standard distributions are implemented and well documented. I will create a normally distributed random variable with mean 5 and standard deviation 10.
nd = Normal(5, 10)
We apply various functions, e.g. to get the probability density function (pdf)
pdf(nd, 1:5)
cdf(nd, 5)

Finally we would like to take a random sample of size 10
rand(nd, 10)
or fill an Array, a, with a random sample from this distribution
a = Array(Float64, 10^5, 2);
rand!(nd, a);


This entry was posted in julia and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s