Created
November 21, 2020 21:30
-
-
Save daxinniu/faa2002a85b0f67849153e0c5800f25b to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using Distributions, Random" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Suppose we have a distribution $\\nu = \\mathrm{Unif}([0,1])$. We want to find out the standard error of the sample mean of 10 observations from this distribution with 1/10 mass on each of the observations." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"10-element Array{Float64,1}:\n", | |
" 0.7684476751965699\n", | |
" 0.940515000715187\n", | |
" 0.6739586945680673\n", | |
" 0.3954531123351086\n", | |
" 0.3132439558075186\n", | |
" 0.6625548164736534\n", | |
" 0.5860221243068029\n", | |
" 0.05213316316865657\n", | |
" 0.26863956854495097\n", | |
" 0.10887074134844155" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"Random.seed!(123)\n", | |
"observations = rand(10)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Using our knowledge of standard error of sample mean above, we can calculate the standard error of the sample mean. We have $\\sqrt{\\frac{10(1/12)}{10^2}} = \\sqrt{1/120}$ " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.09128709291752768" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"true_std = sqrt(1/120)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.08818705818316087" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"bootstrapping_std = std([mean(sample(observations, 10)) for i in 1:2000000])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Notice that in this case, the standard error of the sample mean we get is far from the true standard error. This is because we are estimation $T(\\hat{\\nu})$ instead of $T(\\nu)$. These two values might not be close to each other." | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 1.5.1", | |
"language": "julia", | |
"name": "julia-1.5" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "1.5.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment