Skip to content
Permalink
aa114e22fe
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
61 lines (61 sloc) 1.75 KB
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conjugate Normal Distributions (known variance)\n",
"\n",
"We are trying to learn about the unknown mean of a normal distribution with known variance. \n",
"We choose a prior distribution is normal with mean $\\mu_{0}$ and variance $\\tau_{0}^2$. \n",
"We draw $n$ values $y_1,\\ldots, y_n$ from the distribution with known variance $\\sigma^2$. The posterior distribution\n",
"$p(\\mu|y_1,\\ldots,y_n)=p(y_1,\\ldots,y_n|\\mu)p(\\mu)$ is again normal. Let \n",
"$$\n",
"\\overline{y}=\\frac{1}{n}\\sum_{i=1}^{n} y_i\n",
"$$\n",
"be the sample mean. \n",
"\n",
"The posterior variance\n",
"is\n",
"$$\\frac{1}{\\tau_1^2}=\\frac{1}{\\tau_0^2}+\\frac{n}{\\sigma^2}$$\n",
"and the posterior mean is\n",
"$$\n",
"\\mu_1=\\frac{\\frac{\\mu_0}{\\tau_0^2}+\\frac{n\\overline{y}}{\\sigma^2}}{\\frac{1}{\\tau_{1}^2}}\n",
"$$\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def posterior(prior_mean,prior_variance,sample_mean,pop_variance,n):\n",
" post_var=1/((1/prior_variance) + n/pop_variance)\n",
" post_mean=(prior_mean/prior_variance+sample_mean*n/pop_variance)/(1/post_var)\n",
" return post_mean, post_var"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}