DESCRIPTIVE STATISTICS IN MATLAB
A. Preparing Data
Consider the hypothetical data below:
1. Manual
Input: >>A=[2.27 0.75 1 0.43 3.6; 27 21 36 34 69; 4920 4113 6072 4024 3562]
Output:
A=
2.27 0.75 1 0.43 3.6
27 21 36 34 69
4920 4113 6072 4024 3562
Note: Values appear in horizontal (row) form with “space” as delimiter and “;” as row
identifier. Use “ ‘ “ to create 3 columns (that is, transpose).
Input: >>A=[2.27 0.75 1 0.43 3.6; 27 21 36 34 69; 4920 4113 6072 4024 3562]’
Output:
A=
2.27 27 4920
0.75 21 4113
1 36 6072
0.43 34 4024
3.6 69 3562
2. Importing data file:
Input: >>A=readtable(file_name.xlsx) %make sure that the file is in the current directory
Output:
A=
Acres Age Taxes
2.27 27 4920
0.75 21 4113
1 36 6072
0.43 34 4024
3.6 69 3562
3. Common Descriptive statistics:
Tables:
>>tabulate(A) %creates a frequency table of data A. The default format has 3 column: 1st
column — the unique values of x; 2nd column — the number of instances
of each value; 3rd column — the percentage of each value
For grouped data, you need to install the Statistics Toolbox to be able to set-up the FDT:
Graphs:
>>bar(A) %creates the bar chart of the data defined as A
(applies if A is a single column)
>>bar(A(1:25,1)) %creates the bar chart for the first 25 data points of column 1
>>bar(A(:,1)) % creates the bar chart of the 1st column of data A
>>histogram(A)%creates the histogram with a default of 10 bins/intervals
>>histogram(A,nbins)%creates the histogram with specified number of bins/intervals
>>pie(A)%creates a pie chart for data A
>>boxplot(A) %draws the boxplot of data A
Central Values
>>mean(A) %calculates the mean
>>median(A) %calculates the median
>>mode(A) %finds the mode
>>geomean(A) %calculates the geometric mean
>>harmmean(A) % calculates the harmonic mean
>>trimmean(A,10) % calculates the 10% trimmed mean
Percentiles
>>prctile(A,84) %calculates the 84th percentile of data A. This can also be used to find
other quantiles, like “>>prctile(A,75)” will calculate the third quartile
while “>>prctile(A,40)” will calculate the 4th decile.
Variations/Dispersion
>>std(A) % calculates the standard deviation
>>var(A) % calculates the variance
>>range(A) % calculates the range
>>mad(A) % calculates the mean absolute deviation
>>iqr(A) % calculates the Interquartile Range
Shapes
>>skewness(A)
>>kurtosis(A)