Loading and Using the NormalDistribution Package

Ken Levasseur
Mathematical Sciences
UMass Lowell
Kenneth_Levasseur@uml.edu

Loading the package

To load the NormalDistribution package, all you need to do is evaluate the following expression.   The accent mark you see at two points between the quotes is the key below the "escape" key  on the top left of most keyboards.

Needs["Statistics`NormalDistribution`"]

You may also substitute the nearly equivalent expression  <<Statistics`NormalDistribution` to load the package.  Using Needs is better because it will avoid loading the package if it is already loaded.

What's in the package

You can use the Help Browser to see what capabilities are contained in the package.  Also you can get a list of functions defined by the package by evaluating the following.

? Statistics`NormalDistribution`*

Statistics`NormalDistribution`
ChiSquareDistribution NormalDistribution StudentTDistribution
FRatioDistribution PercentagePoint

Using the Package

To see how to use a function, you can use the Help Browser or do the following.

? NormalDistribution

NormalDistribution[mu, sigma] represents the normal (Gaussian) distribution with mean mu and standard deviation sigma. More…

Most of these examples speak for themselves.

f = NormalDistribution[100, 20]

NormalDistribution(100, 20)

PDF[NormalDistribution[μ, σ], x]

^(-(x - μ)^2/(2 σ^2))/((2 π)^(1/2) σ)

PDF[f, x]

^(-1/800 (x - 100)^2)/(20 (2 π)^(1/2))

Plot[PDF[f, x], {x, 40, 160}]

[Graphics:HTMLFiles/NormalDemo_16.gif]

-Graphics -

Plot[CDF[f, x], {x, 40, 160}]

[Graphics:HTMLFiles/NormalDemo_19.gif]

-Graphics -

CDF[f, 110.]

0.691462

Integrate[PDF[f, x], {x, 0, 110.}]

0.691462

You can generate pseudorandom numbers with specific normal distributions either individually, as we do ten times here in a table,

Table[Random[NormalDistribution[0, 1]], {10}]

{1.81724, -1.58102, -1.6343, -0.522284, 0.94227, -0.774528, 0.441353, -1.81744, -0.438504, 0.333013}

or you can generate arrays of pseudorandom numbers.  Here is a two dimensional array.

RandomArray[NormalDistribution[0, 1], {5, 5}]

And here is a three dimensional array.

RandomArray[NormalDistribution[0, 1], {5, 5, 2}]

Pitfalls

This applies it all packages, not just the NormalDistribution package.

A common error once you've gotten accustomed to using a specific package is to forget to load it before using one of its functions.  Here is what happens

PDF[NormalDistribution[100, 20]]

PDF[NormalDistribution[100, 20]]

Notice how the output is identical to the input, instead of the density function we got above.   This kind of thing happens mostly when you've forgotten to load a package.   Now if we load the package, look at what happens.

Needs["Statistics`NormalDistribution`"]

The names PDF and NormalDistribution that you used are actually different from the ones in the package.  Mathematica puts names that are defined in packages into "contexts"  and the names PDF and NormalDistribution that you had entered earlier are in a different context.  The easiest thing to do at this point is to select "Quit Kernel" from the Kernel menu and start over again, making sure to load the package first.


Created by Mathematica  (April 6, 2006) Valid XHTML 1.1!