# I was greatly inspired by StatsWithJuliaBook
# https://statisticswithjulia.org/index.html
using Pkg
Pkg.activate("MAA204")
using StatsPlots, LaTeXStrings, Distributions, Random
Activating environment at `C:\Users\david\Nextcloud\cours\MAA_204_Statistics\notebook_julia\MAA204\Project.toml`
a = 10 # true value (unkown)
N = 400
X = 10*rand(N) # Samples
# Various estimaros
a_1(X) = maximum(X)
a_2(X) = 2*mean(X)
a_3(X) = 2*median(X)
a_4(X) = sqrt(12*var(X))
a_4 (generic function with 1 method)
plot([n -> a_1(X[1:n]), n-> a_2(X[1:n]), n-> a_3(X[1:n]), n-> a_4(X[1:n])],1:N, xlabel = "Number of sample n",legend=:bottom, label = ["Max(X)" "mean(X)" "median(X)" "sqrt(12 σ^2)"])
n = 10^6
λ = 10
data = rand(Exponential(1 / λ), n) # Julia convention is $\theta = 1/\lambda$
averages = accumulate(+, data) ./ collect(1:n)
plot(1:n, averages,
legend = :none,
xscale = :log10, xlims = (1, n), xlabel = "n", ylabel = "Running average")
hline!([1 / λ], c = :black, s = :dot)