SimpleCountingStatistics.nb – A Mathematica notebook for basic counting statistics

Coded in Mathematica 11 by Vince Cronin

Created August 25, 2017;  last modified August 26, 2017

Purpose of this Code

The purpose of this Mathematica notebook is to compute some simple counting statistics for a dataset that has been saved in one row of an Excel spreadsheet.  It is also intended to provide a modest explanation of the code.

Make the Input Data File in Excel

This code is written to accept input from an Excel .xlsx spreadsheet file in which the data are written in a single horizontal row or a single vertical column.  Screen images of valid spreadsheets are shown below.

In this example, the Excel file testData.xlsx is located on the desktop of Vince’s computer, as is the SimpleCountingStatistics.nb file.

Import the Data File

To modify this code so that it can be used for your dataset, do the following.

1.  Enter the following as an input line (under the black box, below):

inDataRaw = Import[];

2. Put your cursor between the square brackets in the Import[] statement and click to establish the insertion point we will need in the next step.

3. Go to the Insert menu, select File Path, navigate to the correct input data file and choose it, and the correct file path will be inserted at the cursor.  In this example, the Excel file is located on the desktop of Vince’s computer, and so Mathematica will insert the path “/Users/vince/Desktop/testData.xlsx” between the brackets.  The path will be different for every different file, and on every different computer.

inDataRaw = Import[“/Users/vince/Desktop/testData.xlsx”];

4.  The imported dataset will have to be modified so that it has the correct dimensions for this analysis, which is accomplished with the following code.

inData = Flatten[inRawData, 2];

Add an input line below this line.  Type  inDataRaw = Import[];  and follow the rest of the instructions above.  You can make sure it is an input line by clicking on that line’s bracket on the far right edge of this window, going to the Format menu, selecting the Style submenu, and then choosing Input

This won' t work unless you follow directions and add the appropriate input line above this line.  Your input line should look something like the example:
inDataRaw = Import[“/Users/vince/Desktop/testData.xlsx”];

Evaluate the Notebook (Run the Program)

Select the Evaluation drop-down menu from the horizontal menu bar at the top of the window/screen, and choose Evaluate Notebook.

Computation

Adjust the input dataset so that it has the proper dimensions

inData = Flatten[inDataRaw, 2];

Examine the contents of the dataset

The example dataset derived from the Excel spreadsheet testData.xlsx (described above) should look like this:   {14., 32., 6., 9., 24., 16., 10., 18., 10., 38., 27.}

inData

Number of Values in a Dataset — n

Given a set of values, the variable n is used to indicate the number of values in the dataset.

n=Dimensions[inData]

Sort

A sorted input data set is reordered in order of magnitude, starting with the smallest value and ending with the largest value.  The Mathematica built-in symbol Sort is used to sort a dataset.

sortedData=Sort[inData]

Max

The Mathematica built-in symbol Max is used to identify the largest value in a dataset.

maximumOfData=Max[inData]

Min

The Mathematica built-in symbol Min is used to identify the smallest value in a dataset.

miximumOfData=Min[inData]

Median

A median value of a dataset is the middle value in a dataset that has been sorted by magnitude.  The median value of a dataset that has been sorted and that has an odd number of values is the middle value — for example, the third value in the sorted list of 5 values.  The median of a dataset with an even number of values is the average of the two values closest to the middle of the dataset — for example, the average of the third and fourth values in a sorted list of 6 values.  The Mathematica built-in symbol Median is used to find the median of a sorted dataset.

medianOfData=Median[inData]

Mode

The mode (or modes) of a dataset is (are) the value(s) that occur most commonly in a dataset.  The Mathematica built-in symbol Commonest is used to identify the values that recur most commonly in a dataset.

modeOfData=Commonest[inData]

Sample Mean or Average

The mean or average of a sample — a limited dataset — is the sum of the values divided by the number of values.  The mean value of a dataset x = {(Subscript[x, 1]), (Subscript[x, 2]), ..., (Subscript[x, n])} is usually identified with a bar over the name of the dataset, as in (OverBar[x]).
mean of dataset  x ⟹ (OverBar[x]) = (((∑_(i=1)^n)(Subscript[x, i]))/n) 
The Mathematica built-in symbol Mean is used to determine the mean of a dataset.

meanOfData=Mean[inData]

N[meanOfData]

Sample Variance

The sample variance ((s^2)) is “essentially the average of the squares of distances from the mean...” (Crow et al., 1960) and is a measure of the distribution of a sample — a limited dataset — around the mean of that sample.  
sample variance of a dataset x ⟹  (s^2) = (((∑_(i=1)^n)((((Subscript[x, i]) –(OverBar[ x])))^2))/(n–1))
The Mathematica built-in symbol Variance is used to determine the sample variance of a dataset.

medianOfData=Variance[inData]

N[medianOfData]

Sample Standard Deviation

The sample standard deviation (s) is the square root of the variance and is another measure of the distribution of a sample — a limited dataset — around the mean of that sample.  
sample standard deviation of a dataset x ⟹  s = (Sqrt[(((∑_(i=1)^n)((((Subscript[x, i]) –(OverBar[ x])))^2))/(n–1))])
The Mathematica built-in symbol StandardDeviation is used to determine the sample standard deviation of a dataset.

standardDeviationOfData=StandardDeviation[inData]

N[standardDeviationOfData]

References

Caers, J., 2011, Modeling uncertainty in the Earth sciences:  Wiley-Blackwell, 229 p., ISBN 978-1-119-99262-2.

Crow, E.L., Davis, F.A., and Maxfield, M.W., 1960, Statistics manual:  New York, Dover Publications, 320 p., ISBN-10: 048660599X, ISBN-13: 978-0486605999.

Davis, J.C., 1973, Statistics and data analysis in geology :  New York, John Wiley & Sons, 550 p.,

Fanchi, J.R., 2000, Math refresher for scientists and engineers [2nd edition]:  New York, John Wiley & Sons, 308 p., ISBN 0-471-38457-7.

Lyons, L., 1991, A practical guide to data analysis for physical science students:  Cambridge, UK, Cambridge University Press, 95 p., ISBN 0-521-42463-1.

McKillup, S., and Dyar, M.D., 2010, Geostatistics explained, an introductory guide for Earth scientists:  Cambridge, UK, Cambridge University Press, 396 p., ISBN 978-0-521-74656-4.

Till, R., 1974, Statistical methods for the Earth scientist, an introduction:  New York, John Wiley & Sons, 154 p., ISBN 0 470-26340-7

Waltham, D., Oxford, 2000, Mathematics, a simple tool for geologists [2nd edition]:  UK, Blackwell Science, 201 p., ISBN 0-632-05345-3.