Statistics

with Mathematica at UMBC


Contents

  1. Summary Statistics
  2. Graphs & Exploratory Analysis
  3. Multivariate: Correlation & Regression
  4. Generating Random Numbers

[Prev] [Mathematica Intro] [Next]

The Mathematica programming language has basic commands and subroutines which implement all basic statistics (and many other things). A general introduction to Mathematica use and how Mathematica can be accessed at UMBC can be found in a separate document.

The most natural way to represent a statistical data set is as a list, for example mydata = {1.2, 2.1, 1.1, 2.3, 0.2, 1.2}.

Summary Statistics

The Mean, Median, StandardDeviation, Variance and Quantile commands implement basic summary statistics.

Examples:

Note that if the data is all integers, the results will be a fraction, not a floating point number. Thus Mean[{1,2,3,4}] returns 5/2, while Mean[{1.0,2,3,4}] and N[Mean[{1,2,3,4}]] both return 2.5.

The use of Mathematica for Basic Statistics is well documented on the Wolfram.com website at [http://reference.wolfram.com/mathematica/tutorial/BasicStatistics.html].

Graphs & Exploratory Analysis

Mathematica and its various standard packages implement a variety of graphs useful for exploratory data analysis.

Multivariate: Correlation & Regression

Generating Random Numbers

Statistics`NormalDistribution` - NormalDistribution[mu, sigma] Statistics`ContinuousDistributions` - Statistics`DiscreteDistributions` - BinomialDistribution[n,p], BernoulliDistribution[p], etc (* Flip a fair coin 50 times - BernoulliDistribution[1/2] *) flip50 = RandomArray[BernoulliDistribution[1/2],50] (* Plot the NormalDistribution *) Plot[PDF[NormalDistribution[],x],{x,-3,3}] (* Compare to binomial distribution, either directly or via Binomial *) mu=5; Show[{Plot[PDF[NormalDistribution[mu,Sqrt[mu]],x],{x,0,2*mu}], Histogram[Map[(Binomial[2*mu,#]/2^(2*mu))&, Range[2*mu]],FrequencyData->True]}] mu=5; Show[{Plot[PDF[NormalDistribution[mu,Sqrt[mu]],x],{x,0,2*mu}], BarChart[Map[BinomialDistribution[2*mu,1/2],#]&,Range[2*mu]],FrequencyData->True]}] n=10; Show[{Plot[PDF[NormalDistribution[n/2,Sqrt[n/4]],x],{x,0,n}], BarChart[Map[PDF[BinomialDistribution[n,1/2],#]&,Range[n]]]},PlotRange->{0,1.2*Binomial[n,n/2]/2^n}]
[Prev] [Mathematica Intro] [Next]
Robert Campbell
28 August, 2008