Created
October 19, 2022 07:37
-
-
Save agila5/c1c0927e45ecfe758b51145c2fc6f7cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sia X1, ..., Xn un campione casuale estratto da X ~ N(0, 1). Dalla teoria | |
# dell'inferenza statistica, sappiamo che lo stimatore | |
# | |
# (n - 1) S^2 / sigma ^ 2= 1 / sigma ^ 2 * sommatoria di (x_i - x_medio) ^ 2 | |
# | |
# ha distribuzione Chi-quadrato con n - 1 gradi di liberta. Proviamo a | |
# verificare empiricamente questa affermazione. | |
m <- 1e4 # numero di simulazioni usate per approssimare la distribuzione | |
n <- 100 # numero di elementi nel campione | |
sigma2 <- 1 | |
out <- vector(mode = "numeric", length = m) | |
for (i in seq_along(out)) { | |
x <- rnorm(n, sd = sqrt(sigma2)) | |
out[i] <- (n - 1) * var(x) / sigma2 | |
} | |
hist(out, probability = TRUE) | |
curve(dchisq(x, df = n - 1), add = TRUE, col = "darkred", lty = 2, lwd = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment