Created
December 9, 2019 18:49
-
-
Save homedirectory/9d54ba0b8b2d1eb769f48fe60468ad01 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
(4) Another (and a more universal approach) to get rid of the dependence on $\theta$ in (2) is to estimate $s$ via the sample | |
standard error and use approximation of $\bar{X}$ via Student t-distribution; see details in Ross textbook on statistics or in the lecture notes | |
```{r} | |
for (n in c(100, 1000, 10000)) { | |
cat("FOR SAMPLE SIZE = ", n, ":\n") | |
sample_exp = rexp(n*m, lambda) # creating a single sample of exponential distribution | |
sample_means = colMeans(matrix(sample_exp, nrow=n)) # creating a sample of sample means | |
for (a in c(0.1, 0.05, 0.01)) { # iterating for each alpha | |
cat("for alpha = ", a, ":\n") | |
beta = 1 - a/2 | |
St = qt(beta, n-1) | |
prob = mean(abs(1 - sample_means / theta) <= St / sqrt(n)) # divided both sides of equation by theta | |
cat("probability of theta being in the confidence interval = ", prob, "\n") | |
interval_length = mean(sqrt(n)*sample_means*2*St / (n - St*St)) # long equation transformations that result into this | |
cat("interval length = ", interval_length, "\n\n") | |
} | |
cat("\n") | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment