Docsity

Statistical Indicators: Means, Medians, Modes, and Standard Deviations - Prof. Kay Robbins, Study notes of Computer Science

Toggle sidebar
bg1
CS1173:Statisticalindicators(11/2/08)
A=[2,4,2,3,5,1,4,3]andB=[1,2,2,1,5,4,1,3]andC=[NaN,2,NaN,3]arethreeMATLAB
variablesrepresentingsetsofmeasurementsusedintheexamplesbelow.LetDbeaMATLABmatrix
thathas4rowsand3columns.Let
[
]
n
x,...,x,x,xx 321
=representageneralsetofnmeasurements
thatwewilluseinourformulas.
1.Theaverageormeanmeasuresthecentraltendencyofasetofnumbers.Tocalculatetheaverage,
addthevaluesanddividebythenumberofvalues.Theaverageofxis∑
=
=
n
1k
k
x
n
1
x.
Example1:TheaverageofAis(2+4+2+3+5+1+4+3)/8=3

TheMATLABfunctionforaverageiscalledmean.
Example2:mean(D,1)ormean(D)isthecolumnmeanofD.Itisasinglerowof3values.
Example3:mean(D,2)istherowmeanofD.Itisasinglecolumnof4values.
Example4:mean(A)isthemeanofA.(Forvectors,youneverneedthesecondparameterandthe
resultisalwaysasinglenumber.)
Example5:ThemeanoftheentirearrayDismean(D(:)).Hereweusethelinearrepresentationof
Dtoextractasinglevalue.
Example6:mean(C)isNaN.TheMATLABreturnsNaNresultsifanyofthevaluesinthevectorare
NaN.
TheMATLABfunctionnanmeancomputestheaveragebycompletelyignoringtheNaNs.
2.Themedianisanothermeasureofcentraltendency.Incontrasttotheaverage,themedianisnot
heavilyinfluencedbyoutliers.Whentheaverageandthemedianarefarapartinvalue,youcansurmise
thattheremustbesomeoutliersinthedata.Tocalculatethemedian,sortthevaluesandtakethe
middleone.Ifthenumberofitemsiseven,averagethemiddletwovalues.
Example7:sort(A)is[1,2,2,2,3,3,4,5].Theaverageofthemiddletwovaluesis(2+3)/2=2.5
TheMATLABfunctionforcomputingthemedianiscalledmedian.Themedianfunctionfollowsthe
samerulesasthemeanfunction.
TheMATLABfunctionnanmediancomputesthemedianbycompletelyignoringtheNaNs.
3.Themodeisthevaluemostfrequentlyappearinginthedata.Thisvaluemaynotbeunique.
Example8:ThemodeofBis1,whilethemodeofAhastwomostfrequentvalues:2and4
pf2

Partial preview of the text

Download Statistical Indicators: Means, Medians, Modes, and Standard Deviations - Prof. Kay Robbins and more Study notes Computer Science in PDF only on Docsity!

CS 1173: Statistical indicators (11/2/08)

A = [ 2, 4, 2, 3, 5, 1, 4, 3] and B = [1, 2, 2, 1, 5, 4, 1, 3] and C = [NaN, 2, NaN, 3] are three MATLAB variables representing sets of measurements used in the examples below. Let D be a MATLAB matrix

that has 4 rows and 3 columns. Let x = [x 1 ,x 2 ,x 3 ,...,xn]represent a general set of n measurements

that we will use in our formulas.

1. The average or mean measures the central tendency of a set of numbers. To calculate the average,

add the values and divide by the number of values. The average of x is ∑

=

n k 1

xk

n

x.

Example 1: The average of A is (2 + 4 + 2 + 3 + 5 + 1 + 4 + 3)/8 = 3 The MATLAB function for average is called mean. Example 2: mean(D, 1) or mean(D) is the column mean of D. It is a single row of 3 values. Example 3: mean(D, 2) is the row mean of D. It is a single column of 4 values. Example 4: mean(A) is the mean of A. (For vectors, you never need the second parameter and the result is always a single number.) Example 5: The mean of the entire array D is mean(D(:)). Here we use the linear representation of D to extract a single value. Example 6: mean(C) is NaN. The MATLAB returns NaN results if any of the values in the vector are NaN. The MATLAB function nanmean computes the average by completely ignoring the NaNs.

2. The median is another measure of central tendency. In contrast to the average, the median is not heavily influenced by outliers. When the average and the median are far apart in value, you can surmise that there must be some outliers in the data. To calculate the median, sort the values and take the middle one. If the number of items is even, average the middle two values. Example 7: sort(A) is [ 1, 2, 2, 2, 3, 3, 4, 5]. The average of the middle two values is (2 + 3)/2 = 2. The MATLAB function for computing the median is called median. The median function follows the same rules as the mean function. The MATLAB function nanmedian computes the median by completely ignoring the NaNs. 3. The mode is the value most frequently appearing in the data. This value may not be unique. Example 8: The mode of B is 1, while the mode of A has two most frequent values: 2 and 4

4. The standard deviation measures the spread or dispersion of values from the mean. The standard deviation is calculated as the square root of the average of the squares of the distance of each value

from the mean. The standard deviation of x is ( )

n^2 k 1

xk x

n

s ∑

=

= − where x is the mean of x.

Example 9: Calculate the standard deviation of A: a) First compute the sum of the squares of the differences with the mean (2 ‐ 3)^2 + (4 ‐ 3)^2 + (2 ‐ 3)^2 + (3 ‐ 3) 2 + (5 ‐ 3)^2 + (1 ‐ 3)^2 + (4 ‐ 3) 2 + (3 ‐ 3)^2 = 1 + 1 + 1 + 0 + 4 + 4 + 1 + 0 = 12

b) Divide by n and take the square root = 12 / 8 = 1.

The MATLAB function for computing the standard deviation is called std. Example 10: std(D, 1, 1) is the standard deviation of the columns of D. It is a row vector of size 1 x

Example 11: std(D) contains a row vector with an unbiased estimator of the population standard deviation. This could also be written as std(D, 0, 1). (The populations and samples handout.) Example 12: std(D, 1, 2) is the standard deviation of the rows of D. It is a column vector of size 4 x

The MATLAB function nanstd computes the standard deviation by completely ignoring the NaNs. The nanstd function follows the same rules as the std.

5. The pth^ percentile is the data value such that p% of the data fall below that value. The 50% percentile is the median. The 25 th^ percentile is sometimes called the first quartile. Example 13: MATLAB statement [a, b] = prctile(x, [25, 75]); has the 25 th^ percentile value in a and the 75 th^ percentile value in b. 6. Boxplots use the 75th percentile for the top of the box and the 25th percentile for the bottom of the box. The horizontal line across the box corresponds to the median value. Example 14: The MATLAB statement boxplot(x) produces a boxplot showing the distribution of values in the vector x. 7. The interquartile range (IQR) is the 75 th^ percentile minus the 25 th^ percentile.