QML - Week 5

Intro to statistical modelling

Stefano Coretta

Statistical modelling

Gaussian models

\[y \sim Gaussian(\mu, \sigma)\]

Simulate Gaussian data

rnorm(n, mean, sd)

  • n: number of observations to generate
  • mean: mean of the Gaussian distribution
  • sd: SD of the Gaussian distribution

Simulate fundamental frequency f0.

set.seed(812)
f0 <- rnorm(200, 125, 25) |> round()

f0[1:10]
 [1]  79 146 111 114 112 147 167  98 143 102

f0 density

Simulation vs estimation



SIMULATION

You have \(\mu, \sigma\) and you generate \(y\).

ESTIMATION

You have \(y\) and you estimate \(\mu\) and \(\sigma\).

Gaussian model of f0

\[\begin{align} f0 & \sim Gaussian(\mu, \sigma)\\ \mu & = ...\\ \sigma & = ... \end{align}\]

Gaussian model of f0

\[\begin{align} f0 & \sim Gaussian(\mu, \sigma)\\ \mu & = P_\mu\\ \sigma & = P_\sigma \end{align}\]

\(P\) is a generic posterior probability distribution.

Gaussian model of f0: brms

f0_tib <- tibble(f0 = f0)

library(brms)

f0_bm <- brm(
  f0 ~ 1,
  family = gaussian,
  data = f0_tib,
  file = "cache/f0_bm"
)

Gaussian model of height: posteriors

Posterior summary

posterior_summary(f0_bm, probs = c(0.1, 0.9))[1:2,] |> round()
            Estimate Est.Error Q10 Q90
b_Intercept      126         2 124 129
sigma             27         1  25  28

Sample size and uncertainty




the lower the sample size

the higher the uncertainty

A bit harder: N = 5

set.seed(4256)
f0_tib <- tibble(f0 = sample(f0, 5))

f0_bm_small <- brm(
  f0 ~ 1,
  family = gaussian,
  data = f0_tib,
  file = "cache/f0_bm_small"
)

A bit harder: N = 5

A bit harder: N = 5

posterior_summary(f0_bm_small, probs = c(0.1, 0.9))[1:2,] |> round()
            Estimate Est.Error Q10 Q90
b_Intercept      122         7 114 130
sigma             22         7  15  31

Statistical modelling