“Theory is a well-established principle or set of general principles to explain a broad range of observations.”
Theory = Explanation = Generalisation
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.
A sample is a subset of the population that’s actually observed or measured in the study.
Samples have statistics
“Elements in the study that are measured or manipulated.”
Independent variable
Dependent variable
“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.
[1] 4201.754
[1] 4050
na.rm = TRUE is essential here — without it, mean() returns NA if even one value is missingMean: 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.
Source: Wikipedia
[1] 801.9545
[1] 643131.1
[1] 1200
0% 25% 50% 75% 100%
2700 3550 4050 4750 6300
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.”
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().
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?
cor() gives a single number (-1 to 1) summarising the strength and direction of a linear relationship.
