9.5: Z-scores

Statistical Thinking for the 21st Century · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    9.5: Z-scores

    A Z-score is obtained by first subtracting the mean and then dividing by the standard deviation of a distribution. Let’s do this for the height_sample data.

    mean_height <- mean(height_sample)
    sd_height <- sd(height_sample)
    
    z_height <- (height_sample - mean_height)/sd_height

    Now let’s plot the histogram of Z-scores alongside the histogram for the original values. We will use the plot_grid() function from the cowplot library to plot the two figures alongside one another. First we need to put the values into a data frame, since ggplot() requires the data to be contained in a data frame.

    height_df <- data.frame(orig_height=height_sample, 
                            z_height=z_height)
    
    # create individual plots
    plot_orig <- ggplot(height_df, aes(orig_height)) + 
      geom_histogram()
    plot_z <- ggplot(height_df, aes(z_height)) + 
      geom_histogram()
    
    # combine into a single figure
    plot_grid(plot_orig, plot_z)

    file61.png

    You will notice that the shapes of the histograms are similar but not exactly the same. This occurs because the binning is slightly different between the two sets of values. However, if we plot them against one another in a scatterplot, we will see that there is a direct linear relation between the two sets of values:

    ggplot(height_df, aes(orig_height, z_height)) + 
      geom_point()

    file62.png


    This page titled 9.5: Z-scores was last modified on Mon, 11 Jan 2021 05:13:40 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.