Exemple

L’estadístic \((n-1) \cdot \frac{\hat S^2}{\sigma^2}\), on \(\hat S^2\) és la variància corregida, segueix una distribució \(\chi^2_{n-1}\) com diu el material de l’assignatura:

Alguns exemples:

mu <- 80
sigma <- 15
N <- 1e6

n <- 4
mu <- 10
sigma <- 2
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")

n <- 9
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")

n <- 12
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")

Però…

Però si fem una simulació amb poques mostres i un histograma amb pocs intervals pot semblar que no ajusten bé, perquè els efectes aleatoris són cada cop més importants. Els mateixos exemples traient menys mostres:

N <- 100

n <- 4
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")

set.seed(321)
n <- 9
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")

n <- 12
vars <- replicate(N,
                  var(rnorm(n, mu, sigma)))
ests <- vars/sigma^2*(n-1)
hist(ests, breaks="scott", freq=FALSE)
curve(dchisq(x, n-1), add=TRUE, col="red")