Book contents

STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 3

Describing Data

Once data have been collected, the first step in analysis is to describe and visualise them. Descriptive statistics provide summaries of the central tendency, variation and distribution shape of the data. Effective graphics help detect outliers, skewness and patterns that suggest relationships between variables.

Measures of Central Tendency

Measures of Variability

Visualising Data

Graphs reveal information that summary statistics cannot. Common plots include:

Example: Heights of Students

Imagine a dataset of heights (in centimetres) for a sample of 30 students:

168, 172, 165, 175, 169, 170, 166, 173, 171, 174, 167, 169, 170, 175, 172, 168, 169, 171, 170, 173, 174, 168, 169, 166, 172, 170, 168, 171, 175, 169.

Worked example

Descriptive statistics in R:

heights <- c(168,172,165,175,169,170,166,173,171,174,
             167,169,170,175,172,168,169,171,170,173,
             174,168,169,166,172,170,168,171,175,169)
mean_height <- mean(heights)
median_height <- median(heights)
sd_height <- sd(heights)
summary(heights)

Descriptive statistics in Python:

import numpy as np
heights = np.array([168,172,165,175,169,170,166,173,171,174,
                    167,169,170,175,172,168,169,171,170,173,
                    174,168,169,166,172,170,168,171,175,169])
mean_height = np.mean(heights)
median_height = np.median(heights)
sd_height = np.std(heights, ddof=1)
quartiles = np.percentile(heights, [25, 50, 75])

Descriptive statistics in Julia:

using Statistics
heights = [168,172,165,175,169,170,166,173,171,174,
           167,169,170,175,172,168,169,171,170,173,
           174,168,169,166,172,170,168,171,175,169]
mean_height = mean(heights)
median_height = median(heights)
sd_height = std(heights)
q1, med, q3 = quantile(heights, [0.25, 0.5, 0.75])

These commands compute measures of central tendency and spread. Histograms and boxplots can be produced using functions such as ‘hist‘ in R, ‘matplotlib.pyplot.hist‘ in Python and ‘StatsPlots‘ in Julia.

Exercises

Practice

  1. For the student heights data above, draw a histogram and boxplot in your preferred language. Comment on the symmetry or skewness.

  2. Create a small dataset of 10 values with a large outlier. Compute the mean and median. Discuss which measure better reflects the central tendency.

  3. Explain why the variance is computed with n−1n-1 in the denominator rather than nn. What effect would using nn have on the estimate?

  4. Find a dataset online (e.g. from a government statistics portal) and compute descriptive statistics for a quantitative variable. Produce a scatterplot of two variables if available.

References