We will be using data from the kingdom of Equestria (yes, from My Little Pony).
Categorical variable
A qualitative or categorical variable classifies an observation into one of two or more groups or categories.
Nominal: purely qualitative and unordered
Ordinal: data can be ranked, but intervals between ranks may not be equivalent
Continuous variable
A quantitative or continuous variable takes numerical values for which arithmetic operations such as adding and averaging make sense; typically has a unit of measure.
Interval: meaningful differences between values, but no true zero point
Ratio: meaningful differences and a true zero point
Mean
The mean is the average of a set of values and describes the center of the data distribution.
\bar{y} = \frac{\sum_{i=1}^n y_i}{n}
\bar{y} = \frac{\sum_{i=1}^n y_i}{n} = \frac{10 + 20 + 30 + 40 + 100}{5} = 40
Median
The median is the middle value in an ordered dataset and describes the center of the data distribution.
Variance
The variance is the average of squared differences from the mean and describes the spread of the data distribution.
s_y^2 = \frac{\sum_iy_i^2 - (\sum_iy_i)^2/n}{n-1}
Standard deviation
The standard deviation is the average distance from the mean and describes the spread of the data distribution.
s_y = \sqrt{s_y^2}
\begin{align*} s_y^2 &= \frac{\sum_iy_i^2 - (\sum_iy_i)^2/n}{n-1} \\ &= \frac{(10^2+...+100^2)-(10+...+100)^2/5}{4} \\ &= 1250 \end{align*}
Find the variance and standard deviation for the flying speeds (km/hr) of 5 ponies: {10, 20, 30, 40, 100}
The variance is 1250 (km/hr)2
s_y = \sqrt{s^2_y} = \sqrt{1250} \approx 35.36
Range
The range is the difference between the maximum and minimum values.
\text{range} = \text{max}(y) - \text{min}(y)
\begin{align*} \text{range} = \text{max}(y) - \text{min}(y) = 100 - 10 = 90 \end{align*}
Interquartile Range
The interquartile range (IQR) is the difference between 25th percentile and the 75th percentile and describes the spread of the middle 50% of the data.
\text{IQR} = \text{P}_{75} − \text{P}_{25}
\begin{align*} \text{IQR} = \text{P}_{75} − \text{P}_{25} = 70 - 15 = 55 \end{align*}
Proportion
The proportion is a type of mean for categorical data
\hat{p} = \frac{\sum_{i=1}^n y_i}{n},
y_i = \begin{cases} 1 & \text{if in category }i \\ 0 & \text{otherwise} \end{cases}
Find the proportion of ponies that have wings in the following sample: {Y, N, Y, Y, N, Y}
Count the number of “Y” responses and divide by total:
\hat{p} = \frac{\sum_{i=1}^n y_i}{n} = \frac{4}{6} \approx 0.67
Frequency table
A frequency table is a table showing how often each value appears in a dataset.
Contingency table
A contingency table is a frequency table that simultaneously summarizes two qualitative variables.
We will not concern ourselves with the derivation, but will rely on R.
Consider this data,
ggplot() uses 1.75 \times IQR.Histograms show the distribution (or shape) of a continuous variable.
Values are grouped into intervals (“bins”), then the bin height demonstrates how many values fall into that interval.
This allows us to quickly see if there are any oddities.
Increased proportion of a specific value/bin.
Any values that are “out in the tail”?
We have now reviewed two “bar style” graphs that we see regularly: histograms and bar graphs.
We use histograms to see the distribution of continuous variables.
We use bar graphs to see the distribution of categorical variables.
STA4173 - Biostatistics - Fall 2026