Quantitative
Analysis

Theory

“Theory is a well-established principle or set of general principles to explain a broad range of observations.”

Theory = Explanation = Generalisation

Population

  • The population is the complete set of all individuals, items, or observations that share a common characteristic and are of interest to the researcher.

  • It has unknown parameters which we estimate.

Sample

  • A sample is a subset of the population that’s actually observed or measured in the study.

  • Samples have statistics

Statistical Inference

  • The goal of most research is statistical inference: using sample statistics to make educated guesses about population parameters.

Variables

“Elements in the study that are measured or manipulated.”

  • Independent variable

  • Dependent variable

Statistical Learning

“Statistical Learning refers to a vast set of tools for understanding data.”

  • Summarizes and organizes data to describe its main features.

  • Limited to the observed data.

  • Makes predictions or inferences about a population from a sample.

  • Goes beyond the observed data to infer population characteristics.

Central Tendency & Spread

R Packages

library(palmerpenguins)
library(tidyverse)

Measures of central tendency

mean(penguins$body_mass_g, na.rm = TRUE)
[1] 4201.754
median(penguins$body_mass_g, na.rm = TRUE)
[1] 4050
  • na.rm = TRUE is essential here — without it, mean() returns NA if even one value is missing
  • Mean vs. median: mean is pulled by outliers/skew; median is more robust. Always check both, especially with real-world (messy) data

Key Insights

  • Mean: Best for symmetric datasets but affected by outliers.

  • Median: Robust to outliers, useful for skewed data.

  • Mode: Describes the most common value, useful for categorical data.

Skewness


Measures of spread

sd(penguins$body_mass_g, na.rm = TRUE)
[1] 801.9545
var(penguins$body_mass_g, na.rm = TRUE)
[1] 643131.1
IQR(penguins$body_mass_g, na.rm = TRUE)
[1] 1200
quantile(penguins$body_mass_g, na.rm = TRUE)
  0%  25%  50%  75% 100% 
2700 3550 4050 4750 6300 
  • SD: average distance from the mean, same units as the variable
  • Variance: SD squared — used more in formulas than in reporting
  • IQR: range of the middle 50% — robust to outliers, pairs naturally with the median

Grouped Summaries

group_by() + summarise()

penguins |>
  group_by(species) |>
  summarise(
    mean_mass = mean(body_mass_g, na.rm = TRUE),
    sd_mass   = sd(body_mass_g, na.rm = TRUE),
    n         = n()
  )
# A tibble: 3 × 4
  species   mean_mass sd_mass     n
  <fct>         <dbl>   <dbl> <int>
1 Adelie        3701.    459.   152
2 Chinstrap     3733.    384.    68
3 Gentoo        5076.    504.   124

This is the single most-used pattern in applied quantitative work: “give me this statistic, for each level of this category.”

Grouping by more than one variable

penguins |>
  group_by(species, sex) |>
  summarise(mean_mass = mean(body_mass_g, na.rm = TRUE), .groups = "drop")
# A tibble: 8 × 3
  species   sex    mean_mass
  <fct>     <fct>      <dbl>
1 Adelie    female     3369.
2 Adelie    male       4043.
3 Adelie    <NA>       3540 
4 Chinstrap female     3527.
5 Chinstrap male       3939.
6 Gentoo    female     4680.
7 Gentoo    male       5485.
8 Gentoo    <NA>       4588.

.groups = "drop" avoids a message and returns a plain (ungrouped) tibble — good habit once you start chaining more steps after summarise().

Standard Error

penguins |>
  filter(!is.na(body_mass_g)) |>
  group_by(species) |>
  summarise(
    mean_mass = mean(body_mass_g),
    se_mass   = sd(body_mass_g) / sqrt(n())
  )
# A tibble: 3 × 3
  species   mean_mass se_mass
  <fct>         <dbl>   <dbl>
1 Adelie        3701.    37.3
2 Chinstrap     3733.    46.6
3 Gentoo        5076.    45.5

SD describes spread of individual penguins. Standard error (SE) describes uncertainty in the mean itself — how much would this mean likely shift if we resampled?

Visual Exploration

Why visualise before testing

  • Numbers alone can hide skew, outliers, or multi-modal distributions
  • A quick plot often prevents a wrong statistical choice later (e.g. running a t-test on badly skewed data)

Histogram — shape of one variable

ggplot(penguins, aes(x = body_mass_g)) +
  geom_histogram(binwidth = 250, fill = "steelblue", color = "white") +
  labs(title = "Distribution of Body Mass", x = "Body mass (g)", y = "Count")

Boxplot — spread across groups

ggplot(penguins, aes(x = species, y = body_mass_g, fill = species)) +
  geom_boxplot(alpha = 0.7) +
  labs(title = "Body Mass by Species", x = "Species", y = "Body mass (g)")

Scatterplot

ggplot(penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
  geom_point(alpha = 0.6) +
  labs(title = "Flipper Length vs Body Mass")

Correlation (descriptive, not yet a test)

cor(penguins$flipper_length_mm, penguins$body_mass_g, use = "complete.obs")
[1] 0.8712018

cor() gives a single number (-1 to 1) summarising the strength and direction of a linear relationship.