Beginning Mathematica Statistics

C.T.J. Dodson

University of Toronto

This Notebook gives a brief introduction to some commonly 
occuring statistical operations that may be performed using 
Mathematica. Click on the side bars to open interactive cells.
Shift-Enter inputs the command in an input cell

PLOTTING HISTOGRAMS AND PIECHARTS

<<Graphics`Graphics`

bin[p_,n_][r_]:=((n!)/(r!(n-r)!)) p^r (1-p)^(n-r)

binb=Table[{bin[.5,10][r],r},{r,0,10}];

BarChart[binb];

PieChart[{0.5,0.2,0.2,.1}];

DISCRETE DISTRIBUTIONS

<<Statistics`DiscreteDistributions`

?PoissonDistribution

poiss = PoissonDistribution[a]

Mean[poiss]

Variance[poiss]

PDF[PoissonDistribution[a], x]

ps=Table[{PDF[PoissonDistribution[2],r],r},{r,0,10,1}]

BarChart[ps];

CONTINUOUS DISTRIBUTIONS

<<Statistics`ContinuousDistributions`

?NormalDistribution

normal[a_,b_]:=NormalDistribution[a,b]

PDF[normal[a,b],x]

Plot[PDF[normal[20,2],x],{x,10,30}];

Plot[{CDF[normal[20,2],x],PDF[normal[2,0.4],x]},
{x,0.9,3.1}];

CDF[normal[a,b],x]

Plot[CDF[normal[20,2],x],{x,10,30}];

?LogNormalDistribution

lognormal[a_,b_]:=LogNormalDistribution[a,b]

Mean[lognormal[a,b]]

Variance[lognormal[a,b]]

PDF[lognormal[a,b],x]

Plot[PDF[lognormal[4,1.5],x],{x,0.0001,100}];

CDF[lognormal[a,b],x]

Plot[CDF[lognormal[4,1.5],x],{x,0.0001,400}];

?CharacteristicFunction

REGRESSION ANALYSIS

<<Statistics`LinearRegression`

t={ {72,.7439},{41,2.09},{48,1.7411},{65,1.2307},{88,1.0581},{109,1.287},{86,.3767},
    {50,.8687},{101,.7874},{81,1.5158},{109,.6891},{90,.7508},{52,.237},{90,1.1913},
    {49,1.7653},{102,1.213},{143,.9155},{82,1.1899},{91,.6078},{52,2.8804},{89,.9365},
    {95,.8054},{134,-.2804},{109,.9581},{88,0.7752},{115,.8433},{102,1.3047},{72,1.5769},
    {116,.571},{136,0.8353},{78,.719},{85,1.0035},{127,.845},{142,.9627},{91,.9706},
    {96,.7922},{107,.7764},{97,.979},{71,1.2802},{82,1.2972},{83,1.0682},{71,1.9469},
    {106,.2534},{109,.4051},{105,.0714},{106,.9486},{74,1.1435},{78,.8672},{86,1.3471} };

l = ListPlot[t, PlotRange->{{20,160},{-1,3}}];

Regress[t, {1,x,x^2},x]

f = Plot[3.0894 - 0.0358 x + 0.00013 x^2,{x,20,160}];

Show[l,f];