Chapter 4: Transformations and Z-scores

STAT117: Introduction to Statistics

Why transform a variable?

There are several common reasons to transform data:

  • convert from one unit to another, such as inches to centimeters or Celsius to Fahrenheit;
  • reverse the direction of a variable coding, such as changing (1 = Agree and 5 = Disagree) to (1 = Disagree and 5 = Agree);
  • standardize data so scores measured on different scales or unit can be compared.

The central question is: How does a transformation affect the distribution of a variable?

Specifically, we want to consider what happens to:

  • location: mode, median, and mean
  • spread: range, IQR, and standard deviation
  • shape: skewness ratio

Linear transformations

A linear transformation has the form

\[ \text{new data} = K*(\text{old data}) + C, \]

where K and C are constants.

  • K represents a scale factor
  • C represents a location shift

Examples:

  • new = 2(old) + 3 (scale everything up by 2; shift everything to the right by 3)

  • new = -1.5(old) - 10 (scale factor = -1.5; shift everything to the left by 10)

  • new = (old)/10 (scale factor = 1/10, no location shift)

Effect on location

Location statistics mimic the transformation:

\[ \text{new statistic} = K*(\text{old statistic}) + C \]

This rule applies to the mode, median, and mean.

For example, if the original mean is 20 and new = 3*(old) + 4, then

\[ \text{new mean} = 3*(20) + 4 = 64. \]

If the original median is 15 and new = -2*(old) + 5, then \[ \text{new median} = -2*(15) + 5 = -25. \]

Effect on spread

Spread statistics are affected by the magnitude of K, but not by C:

\[ \text{new spread} = |K|*(\text{old spread}) \]

This rule applies to the range, IQR, and standard deviation.

Note 1: These statistics are always positive, hence the absolute value in the formula.

Intution: the spread of a distribution is a measure of distance, which is always positive: the distance from my house to Drew is 2 miles, and the distance from Drew to my house is also 2 miles. You would never say that the distance from my house to Drew is “-2 miles.”

Note 2: The location shift C does not affect the spread of the distribution.

Intuition: if you move the entire distribution to the right or left, the distance between the values does not change (neither does the shape, so C also does not affect the skewness ratio).

For example, if the original data has a min of 0 and max of 4, then the range is 4. If new = 2*(old) + 3, then the new min is 3 and the new max is 11, so the new range is 8, or simply |2|(4) = 8. If new = -3*(old) + 4, then the new min is 4 and the new max is -8, so the new range is 12, or simply |-3|(4) = 12.

If the original standard deviation is 5 and new = -3*(old) + 4, then

\[ \text{new SD} = |-3|(5) = 15. \]

Effect on skewness

The skewness ratio is affected only by the sign of K:

\[ \text{new skewness ratio} = \begin{cases} \text{old skewness ratio}, & K > 0 \\ -\text{old skewness ratio}, & K < 0 \end{cases} \]

In other words, multiplying by a positive number does not change the skewness ratio. Multiplying by a negative number reverses the sign of the skewness ratio.

Intuition: imagine a distribution with a range of 0 to 10. If you multiply by 2, the range becomes 0 to 20, but the shape is the same. If you multiply by -2, the range becomes -20 to 0. The old minimum becomes the new maximum, and the shape is reversed: left skewed becomes right skewed, and right skewed becomes left skewed.

Example 1: Celsius to Fahrenheit

The conversion from Celsius to Fahrenheit is

\[ F = \frac{9}{5}C + 32. \]

Suppose a set of Celsius temperatures has mean 14.6, standard deviation 5, IQR 7, range 20, and skewness ratio 0.8. Calculate the corresponding Fahrenheit statistics.

Statistic Celsius Fahrenheit
Mean 14.6
Standard deviation 5
IQR 7
Range 20
Skewness ratio 0.8

In addition, as a review, what does the skewness ratio tell us about the shape of the distribution?

Show solution
Statistic Celsius Fahrenheit
Mean 14.6 58.28
Standard deviation 5 9
IQR 7 12.6
Range 20 36
Skewness ratio 0.8 0.8
The Fahrenheit distribution has the same shape, but a different center and spread because K = 9/5 is positive. The skewness ratio of 0.8 indicates that the distribution is roughly symmetric.

Example 2: reversing a scale

\[ \text{new data} = -2*(\text{old data}) + 5. \]

If the old mean is 3, the old standard deviation is 1.5, the old IQR is 2, and the old skewness ratio is 2.4, calculate the new statistics.

Statistic Old data New data
Mean 3
Standard deviation 1.5
IQR 2
Skewness ratio 2.4

In addition, what does the skewness ratio tell us about the shape of the distribution?

Show solution
Statistic Old data New data
Mean 3 -2(3) + 5 = -1
Standard deviation 1.5 |-2|(1.5) = 3
IQR 2 |-2|(2) = 4
Skewness ratio 2.4 -2.4
The negative value of K reverses the direction of the distribution. The skewness ratio of the old distribution, 2.4, indicates that the distribution is severely right-skewed. The new skewness ratio of -2.4 indicates that the distribution is severely left-skewed. The shape is reversed because we multiplied by a negative number.

Example 3: transform SES in NELS

Use the NELS variable ses, Socio-Economic Status, and define

\[ \text{SESNEW} = -2*(\text{SES}) + 5. \]

As practice, open the NELS dataset in Jamovi and verify the listed summary statistics for ses. Then, use the transformation rules to calculate the summary statistics for SESNEW.

Statistic ses SESNEW = -2*(ses) + 5
Mean 18.434
Median 19
Standard deviation 6.924
IQR 10.25
Range 35
Skewness ratio -1.03
Show solution
Statistic ses SESNEW = -2*(ses) + 5
Mean 18.434 -31.868
Median 19 -33
Standard deviation 6.924 13.849
IQR 10.25 20.5
Range 35 70
Skewness ratio -1.03 1.03

Example 4: reverse a Likert scale

Suppose a Likert scale variable measures agreement with the statement “I like statistics”:

  • 1 = Strongly Agree
  • 2 = Agree
  • 3 = Neither agree nor disagree
  • 4 = Disagree
  • 5 = Strongly Disagree

Its summary statistics are mean = 2.56, median = 2, IQR = 2, and skewness ratio = 2.11.

We want to recode the variable so that high scores correspond to more interest in statistics:

  • 1 = Strongly Disagree
  • 2 = Disagree
  • 3 = Neither agree nor disagree
  • 4 = Agree
  • 5 = Strongly Agree
  1. Write down the linear transformation to do so.

  2. What are the mean, median, IQR, and skewness ratio of the transformed variable?

Statistic Original scale Reversed scale
Mean 2.56
Median 2
IQR 2
Skewness ratio 2.11
Show solution

The linear transformation is

\[ \text{new} = -1*(\text{old}) + 6. \]

Statistic Original scale Reversed scale
Mean 2.56 -1(2.56) + 6 = 3.44
Median 2 -1(2) + 6 = 4
IQR 2 |-1|(2) = 2
Skewness ratio 2.11 -2.11

Z-scores

Why calculate z-scores?

We want to standardize data so that we can compare scores regardless of their original unit or scale.

  • Motivating example 1: Tom has an SAT score of 1400. Jerry has an ACT score of 28. Who has the better score relative to the other students who took the same test?
Test Raw score Mean SD
SAT 1400 1100 150
ACT 28 25 2
Show solution Tom’s SAT z-score is (1400 - 1100) / 150 = 2. Jerry’s ACT z-score is (28 - 25) / 2 = 1.5. Tom scored higher relative to test-takers on his exam.


  • Motivating example 2: In the NELS dataset, the SES score of student ID 1 is 23. How do we make sense of this value? What about for student with ID 2?
Show solution In NELS, student 1 has SES = 23 and student 2 has SES = 20. Using the SES mean of 18.434 and standard deviation of 6.924, their z-scores are approximately (23 - 18.434) / 6.924 = 0.66 and (20 - 18.434) / 6.924 = 0.23. Both are above the mean; student 1 is farther above it.

Z-score: definition

The formula for calculating a z-score is:

\[ \textit{z-score} = \frac{\textit{raw score} - \textit{mean}}{\textit{sd}} \]

To convert a z-score back to the raw score: \[ \textit{raw score} = \textit{z-score} \times \textit{sd} + \textit{mean} \]

For example, the z-score for SES is calculated as

\[ z_{SES} = \frac{\text{SES} - 18.4}{6.92} \]

  • Why is this a linear transformation?


  • What is the mean of \(z_{SES}\)?


  • What is the standard deviation of \(z_{SES}\)?


  • What is the skewness ratio of \(z_{SES}\)?


Show solution

The z-score is a linear transformation because it can be written as z_SES = (1/6.92)*SES - 18.4/6.92, which has the form K*(old data) + C.

  • The mean is 0.
  • The standard deviation is 1.
  • The skewness ratio is unchanged because the scale factor 1/6.92 is positive; for SES, it is approximately -1.03.

Interpretation examples:

If z-score is 0.7: The raw score is 0.7 standard deviations ABOVE the mean.

If z-score is -1.2: The raw score is 1.2 standard deviations BELOW the mean.

Example: achievement scores (NELS)

  1. A tenth-grade student scored 53 on both the math achievement test (achmat10) and the reading achievement test (achrdg10). The mean and standard deviation values for each variable can be found using Jamovi - Analyses - Exploration - Descriptives.
Test Student score Mean SD
Math (achmat10) 53 57 7.84
Reading (achrdg10) 53 56.1 8.30
  1. What is the z-score for her math achievement?


  1. What is the z-score for her reading achievement?


  1. Based on z-scores, on which test did she do better relative to her peers?


  1. Based on cumulative percentage, on which test did she do better relative to her peers?


  1. Another 10th grade student from the NELS dataset has a z-score of 2.1 for the math achievement test (achmat10). Is this a good score? What is the student’s raw score?


Show solution
  1. Math: (53 - 57) / 7.84 = -0.51.

  2. Reading: (53 - 56.1) / 8.30 = -0.37.

  3. She did better relative to peers on reading: its z-score is higher (less below the mean).

  4. The empirical cumulative percentages in NELS are 28.6% for math and 32.0% for reading, so reading is also higher by cumulative percentage.

For the second student, a z-score of 2.1 is unusually high. The raw score is 2.1*7.84 + 57 = 73.464, or about 73.5.

Example: NBA

The following information are given in the NBAPlayers2024 data from Statistics: Unlocking the Power of Data.

LeBron James

Statistic Raw score Mean SD z-score
Rebounds per game 7.30 5.11 2.41
Field-goal percentage 0.540 0.478 0.062
Three-point percentage 0.410 0.350 0.075

Stephen Curry

Statistic Raw score Mean SD z-score
Rebounds per game 4.46 5.11 2.41
Field-goal percentage 0.450 0.478 0.062
Three-point percentage 0.408 0.350 0.075
  1. Calculate each z-score.


  1. Which skill set is LeBron James better at relative to his peers? What about Stephen Curry?


  1. If you only consider the three skill sets listed above, who is a better player, overall, Lebron James or Stephen Curry?
Show solution
Player Rebounds z-score Field-goal z-score Three-point z-score
LeBron James (7.30 - 5.11) / 2.41 = 0.91 (0.540 - 0.478) / 0.062 = 1.00 (0.410 - 0.350) / 0.075 = 0.80
Stephen Curry (4.46 - 5.11) / 2.41 = -0.27 (0.450 - 0.478) / 0.062 = -0.45 (0.408 - 0.350) / 0.075 = 0.77
LeBron is above average in all three skills; Curry is above average in three-point shooting and below average in the other two. If the three skills are weighted equally, LeBron’s average z-score is about 0.90, compared with about 0.02 for Curry, so LeBron is better overall on this limited comparison.

Z-scores and outliers

What kind of z-score values would be considered unusual?

Exercise: pick a numeric variable from the NELS dataset and calculate the raw scores for the following z-scores.

z-score raw-score
0
-0.5
1.5
-4.5
12.5
Show solution

For an example, use SES, with mean 18.4 and standard deviation 6.92. Convert each z-score with raw score = z-score*6.92 + 18.4:

z-score Example SES raw score
0 18.40
-0.5 14.94
1.5 28.78
-4.5 -12.74
12.5 104.90
The last two are mathematical extrapolations and would be far outside the plausible SES range; the exercise can use any numeric variable, so answers vary with the selected variable.
  • For many numerical variables, it is unlikely to be more than 2 SD’s away from the mean (4.5% chance if the distribution is normal – more on this later).

  • As a result, if a z-score is greater than 2 or less than -2, we could consider the corresponding raw score as an outlier.

Summary

  • Z-score (also called “standard score”) is defined via the linear transformation formula.


  • The distribution of z-scores for any variable would have a mean of 0 and a standard deviation of 1 (by definition).

  • Because the definition of a z-score involves the mean and standard deviation, it only really makes sense to talk about z-scores with numeric variables.

  • We can use z-scores to determine outliers. For instance, we can call a raw score an outlier if its z-score is greater than 2 or less than -2.

  • We can standardize a variable using:

      - z-score
    
      - cumulative percentage (i.e., percentile rank)