0% found this document useful (0 votes)
6 views31 pages

Chapter 03 Statistics Using R

The document discusses measures of location, spread, and skewness in statistics, covering central tendency (mode, median, mean), dispersion (range, interquartile range, variance, standard deviation), and shape (skewness). It provides definitions, examples, and commands for calculating these measures using the NELS dataset. Additionally, it highlights the impact of distribution shape on the mean and median, and the importance of choosing the appropriate measure of central tendency based on data characteristics.

Uploaded by

Alexis Montalvo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views31 pages

Chapter 03 Statistics Using R

The document discusses measures of location, spread, and skewness in statistics, covering central tendency (mode, median, mean), dispersion (range, interquartile range, variance, standard deviation), and shape (skewness). It provides definitions, examples, and commands for calculating these measures using the NELS dataset. Additionally, it highlights the impact of distribution shape on the mean and median, and the importance of choosing the appropriate measure of central tendency based on data characteristics.

Uploaded by

Alexis Montalvo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MEASURES OF

LOCATION,
SPREAD, AND
SKEWNESS

CHAPTER 3
OVERVIEW

• Measures of Central Tendency (Level)


• Mode
• Median
• Mean
• Measures of Dispersion (Spread)
• Range
• Interquartile Range
• Variance
• Standard Deviation
• Measure of Shape
• Skewness and Skewness Ratio
MEASURES OF LOCATION: MODE

Definition: The mode is the score that occurs most often.


It is useful when data are nominal or ordinal with only a
limited number of categories.

To find the mode of home language background from the NELS


dataset, for example, we may type the following command in the
console and hit Enter:
[Link](NELS$region)
MEASURES OF LOCATION: MODE

Example: home language background (homelang) from NELS.


What is this variable’s mode?

Using the [Link] command, we obtain that the mode =


English Only (which has a value of 4). To verify, we use the
command: table(NELS$homelang)

Non-English Only Non-English Dominant English Dominant English Only


15 35 47 403
MEASURES OF LOCATION: MODE

Example: Although the mode is technically South, North Central is close enough
that this distribution may be considered bimodal.
barplot(table(NELS$region), ylab = "Frequency")
MEASURES OF LOCATION: MODE
MEASURES OF LOCATION: MODE

• Definition: A bimodal distribution is one


with two modes, usually at some distance
apart from each other.
• Definition: trimodal is one with three modes
• Definition: A uniform distribution is one in
which all values occur with the same
frequency.
MEASURES OF LOCATION: MODE

Uniform or rectangular distributions are not well


characterized by the mode
MEASURES OF LOCATION: MODE

The effectiveness of a mode as a measure of a distribution’s


location depends on the shape. On Symmetric and unimodal, the
mode is usuful in characterizing location.
MEASURES OF LOCATION: MEDIAN

Definition: The median is the middle point in a distribution.


It is particularly useful when ordinal or scale data are severely
skewed.

To find the median, or 50th percentile, of the NELS variable, ses, we


may use either of the following commands:

• median(NELS$ses)
• quantile(NELS$ses, c(0.5))

• From the quantile command we know the median of ses is 19.


Both the median and quantile commands refer to the median as
the 50th percentile or, in shortened form as p50. The median of ses
is 19, which is the same value as the mode of ses.
MEASURES OF LOCATION: MEDIAN
MEASURES OF LOCATION: MEAN

Definition: The mean is the sum of all of the data points divided
by the number of data points.
It is useful when data are scale and not severely skewed.

To find the mean of the NELS variable, seswe may use the
following command: mean(NELS$ses), and the answer we
obtain is 18.434.
MEASURES OF LOCATION: MEAN

In the case where a variable is dichotomous and coded as 0 and 1, the


mean is interpreted as the proportion of 1’s in the distribution. (Example:
gender)
Because gender is a string (not a numeric) variable in the NELS dataset, coded 1
(for females) and 2 (for males), we first need to re-code the values as 0 and 1 and
consider the variable as numeric, not string. We use the following commands to
do so, and then find the mean of this new numeric variable, numeric_gender.
NELS$numeric_gender = [Link](NELS$gender) - 1
mean(NELS$numeric_gender)
The mean value we obtain is: 0.546, which suggests that 54.6% of the sample of 500
is female. We verify this with the following command:
[Link](NELS$gender)
And obtain these results, which confirm our interpretation of the mean:
Male Female
45.4 54.6
MEASURES OF LOCATION:
COMPARING THE MEAN AND THE MEDIAN

We compare the mean and median for the following NELS variables that have
different degrees and direction of skewness:
ses (reasonably symmetric)
expinc30 (highly positively skewed)
schattrt (somewhat negatively skewed)
Note: By calculating the mean of these variables, we are treating them as at
least interval-leveled. [Link]=T omits missing data in calculating the values.
mean(NELS$ses, [Link] = T) 18.43
mean(NELS$expinc30, [Link] = T) 51574.73
mean(NELS$schattrt, [Link] = T) 93.65

median(NELS$ses, [Link] = T) 19
median(NELS$expinc30, [Link] = T) 40000
median(NELS$schattrt, [Link] = T) 95
MEASURES OF LOCATION:
COMPARING THE MEAN AND THE MEDIAN

symmetric bimodal -> mean = median symmetric unimodal -> mean = median = mode

if mean = median, the distribution


need not to be symmetric
MEASURES OF LOCATION:
COMPARING THE MEAN AND THE MEDIAN
highly negatively skewed unimodal continuous: highly positively skewed unimodal continuous:
mean < median (in general) mean > median (in general)

Discrete or multimodal continuous


distributions counter-examples exist

if the mean and the median are


different from each other, the
distribution need not be skewed
HOW THE SHAPE OF THE DISTRIBUTION
AFFECTS THE MEAN AND MEDIAN

• For a severely positively skewed distribution, in general, the


mean is greater than the median.
• For a severely negatively skewed distribution, in general, the
mean is less than the median.
• For a symmetric distribution, the mean equals the median.

reasonably highly highly reasonably


symmetric positively negatively symmetric
skewed skewed
MEASURES OF SPREAD

Key words to indicate that a question relates to spread:


spread
variability
dispersion
heterogeneity
inconsistency
unpredictability
MEASURES OF SPREAD VISUALLY

When traveling to these two cities, would the same clothing be suitable for
both cities at any time during the year from the point of view of warmth
(Temperature)? boxplot(Temp$Temperature~Temp$City)
MEASURES OF SPREAD

How can we quantify the obvious difference in temperature


variability across the year between these two cities?
By using the range or interquartile range (IQR),
or by using the variance or standard deviation.
The range is the difference between the highest and lowest
values in the distribution.
The interquartile range (IQR) is the range of the middle half of
the data, or the difference between the 75th and 25th
percentiles. It is useful when data are ordinal or scale and
severely skewed.
The variance is the average of the squared deviations
from the mean. The standard deviation is the square
root of the variance. These are explained more fully in a later
size.
THE RANGE AND INTERQUARTILE RANGE

To obtain the IQRs for distributions of a single variable for


different sub-groups, defined, for example, by the variable City,
we type:
IQR(Temp$Temperature[Temp$City == "Springfield"])
IQR(Temp$Temperature[Temp$City == "SanFrancisco"])

IQR is said to be a resistant statistic: not sensitive to extreme


values (as the median)
THE VARIANCE AND STANDARD DEVIATION

We may think of the standard deviation as the distance we have


to travel in both directions from the mean to capture the
majority of values in a distribution. The farther out we need to
travel, the more spread out are the values of the distribution
from the mean. These are useful when data are at least
interval and not severely skewed.

var(Temp$Temperature[Temp$City == "Springfield"])
var(Temp$Temperature[Temp$City == "SanFrancisco"])

To find the sdev, substitute sd for var in the above commands.


MEASURES OF DISPERSION

Be executing the commands on the two previous slide, we


obtain the following indicators of spread for temperature for
the two cities.
sdev variance iqr range
Springfield 16.82 282.99 28.0 46
San Francisco 2.90 29.06 8.5 15

Consistent with the earlier boxplots, all quantitative measures


show that Springfield has a greater temperature spread than
San Francisco.
MEASURES OF SHAPE

The skewness statistic is a measure of the shape of a


distribution.

It is negative when the distribution is negatively skewed.


It is zero when the distribution is not skewed.
It is positive when the distribution is positively skewed.

skew(Temp$Temperature[Temp$City == "SanFrancisco"])
EXAMPLES OF DISTRIBUTIONS WITH DIFFERENT
SHAPES

skew(NELS$ses) -0.1120025

skew(NELS$schattrt) -6.212213

skew(NELS$expinc30) 10.89864
MEASURES OF SHAPE

To compare the skewness of two distributions of relatively equal size, one may
use the skewness values themselves.

To compare the skewness of two distributions that are quite unequal in size,
or to evaluate the severity of skewness for a particular distribution when that
distribution is small or moderate in size, one should compute a skewness ratio.

By convention, when the skewness ratio exceeds 2.00 for small- and
moderate-sized samples, one should consider the distribution to be highly skewed
Can we reduce skewness? Yes, by transforming the data in an alternative
form
MEASURES OF SHAPE
WHICH MEASURE OF CENTRAL TENDENCY
SHOULD ONE USE

• An article in the Wall Street Journal online


([Link]
from
August 24, 2007 reported the following:
• The average cost of a wedding is between $27,400 and
$28,800.
• The median is approximately $15,000.

How can we justify this apparent contradiction in the cost of a


wedding?
APPLYING WHAT WE HAVE LEARNED

• What is the extent to which eighth-grade males


expect larger incomes at age 30 than eighth-grade
females (variable is expinc30)?

• To what extent is there lack of consensus among


males in their income expectations as compared
to females (variable is expinc30)?

• How are the answers to these questions


influenced by the outliers and general shape of
these distributions as shown in the boxplots in the
last slide?
DESCRIPTIVE STATISTICS FOR MALES & FEMALES

summary(NELS$expinc30[NELS$gender == "Female"], [Link] = T)


summary(NELS$expinc30[NELS$gender == "Male"], [Link] = T)
sd(NELS$expinc30[NELS$gender == "Female"], [Link] = T)
sd(NELS$expinc30[NELS$gender == ”Male"], [Link] = T)

Gender Min. 1st Qu. Median Mean 3rd Qu. SDev Max. NA’s

Female 0 30000 40000 43516 50000 26965 250000 29


Male. 1 35000 45000 60721 60000 79259 1000000 12

NOTE: NA’s are the number of expinc30 missing values for females &
males. We may find the IQR by subtracting the 1st Qu. from the 3rd Qu.
BOXPLOTS FOR MALES AND FEMALES

boxplot(NELS$expinc30~NELS$gender)

You might also like