Histogramming
and Statistics

This laboratory will expand your repetoire of analytical skills and introduce the notion of a frequency distribution.

1. Basic Commands.

In this laboratory you will take a set of data and plot the frequency of different results. You will then extract simple statistical information from the histogram. The first step is to load the packages below into Mathematica. This should be done first and only once during the session.

Needs["BarCharts`"];
Needs["Histograms`"];
Needs["PieCharts`"]

Next, enter some data. The command below shows how to enter an array of data in Mathematica.

data ={0.0789609,-0.471797,-0.698464,-0.158695,0.0848231,2.39845,1.36031,1.07166,1.06801,0.954635,-1.47636,-1.03402,-0.172193,-0.0546502,-1.40035,1.89033,-0.164824,1.31812,0.477657,1.37246,0.713923,1.05531,-0.961621,-0.541414,-0.789451,0.751251,0.692603,0.206209,0.785431,0.886077,1.02105,-0.405319,1.97813,0.230765,-0.796516,1.21065,-1.89966,0.367685,1.57743,-0.0878903,0.240861,0.737706,0.0976328,-0.340478,1.5002,0.430084,0.315298,1.32552,-0.389734,-0.66366,0.48413,0.839891,-1.63951,-0.32257,0.326307,2.23439,-2.09491,-0.164018,0.595124,-0.529316,0.288771,0.0797093,1.0018,-0.795769,0.966422,-1.45939,0.95543,0.682462,0.122714,-0.388816,1.59474,-1.39029,1.24754,1.38261,-0.233177,-1.18613,-0.307277,-0.229948,-1.34569,0.0661231,0.533871,0.337921,-0.690251,-0.55572,0.519533,0.157858,-0.374646,-1.6623,0.266872,0.894534,-0.588928,-0.525838,-0.661636,0.448432,-0.120686,-0.961073,-0.150906,1.08303,1.96417,0.136119};

Make a histogram of the data array.

Histogram[data]

2. Choosing Your Own Bins.

Sometimes you will want to have more control over how the frequency data are binned. Notice how the bins are different sizes in the next command. Compare this plot with the one in Section 1.

Histogram[data,
HistogramCategories->{-3.6,-2.4,-1.4,-.6,0,.6,1.4,2.4,3.6}]

If you have a lot of categories and you have equal size bins, make a table to create the categories quickly and with less misery. Compare this plot with the other two.

bins = Table[x,{x,-5,5,1}]
Histogram[data, HistogramCategories->bins]

3. Calculating Statistics.

Use the commands here to get basic statistics of the data.

Mean[data]
Variance[data]
StandardDeviation[data]

Use the following commands to calculate the uncertainty on the mean.

StandardDeviation[data]/Sqrt[Length[data]]

4. Manipulating the Data.

If you want to make a repetitive calculation for each data point (i.e., multiply each data point by, say, 5.2), use the Table command demonstrated below.

data2 = Table[5.2*data[[i]],{i,1,Length[data]}]

You can also act on a subset  of the array by indexing things properly. In the example below, we multiply every third point by 0.52.

data3 = Table[0.52*data[[i]],{i,1,Length[data],3}]

If you want to merge two sets of data, use the Join command.

MergedData = Join[data,data2]