Created
September 16, 2018 05:25
-
-
Save EvanMu96/96aefd154c5b28858f07dfe752b94a09 to your computer and use it in GitHub Desktop.
homework4.2
This file contains 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
# Author: Sen Mu | |
# to install Distributions.jl, please julia>Pkg.add("Distributions") | |
using Compat, Random, Distributions | |
# Generate seed of random numbers | |
Random.seed!(241) | |
# create a uniform distribution (0,1) | |
d = Uniform(0, 1) | |
function f(sample_size) | |
deviates = [] | |
for i=1:11 | |
# generate deviates | |
x = rand(d, sample_size) | |
x_mean = mean(x) | |
push!(deviates, x_mean) | |
end | |
E_x = mean(deviates) | |
Var_x = var(deviates) | |
sigma = sqrt(Var_x) | |
Ur = 2.23*(sigma/sqrt(11)) | |
lower_bound = E_x-Ur | |
upper_bound = E_x+Ur | |
println("Sample size = $(sample_size)") | |
println("Mean:$(E_x), Deviation$(sigma)") | |
println("Confidence Interval 95%:($(lower_bound), $(upper_bound))\n") | |
end | |
# different sample sizes | |
sample_size = [10, 100, 1000, 10000, 100000, 1000000] | |
# experiment with 6 different sample_sizes | |
for n in sample_size | |
f(n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment