diff --git a/Lecture 6/Interval estimation.ipynb b/Lecture 6/Interval estimation.ipynb new file mode 100644 index 0000000..6d2670a --- /dev/null +++ b/Lecture 6/Interval estimation.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "## Confidence intervals\n", + "\n", + "n=10\n", + "mu = 12\n", + "sigma = 2\n", + "alpha = 0.05\n", + "\n", + "data <- rnorm(n,mu,sigma)\n", + "\n", + "plot(data,rep(0,n),col=\"blue\")\n", + "abline(v=mu,col=\"red\")\n", + "abline(v=mean(data),col=\"blue\")\n", + "\n", + "lb=mean(data)-sigma/sqrt(n)*qnorm(1-alpha/2) # This is the lower bound of the confidence interval\n", + "ub=mean(data)+sigma/sqrt(n)*qnorm(1-alpha/2) # Upper bound.\n", + "\n", + "rect(lb,-0.5,ub,0.5)\n", + "\n", + "text(mean(data)-0.4,1,labels = \"mean\",col=\"blue\")\n", + "text(mu+0.3,-1,labels = \"mu\",col=\"red\")\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "R", + "language": "R", + "name": "ir" + }, + "language_info": { + "codemirror_mode": "r", + "file_extension": ".r", + "mimetype": "text/x-r-source", + "name": "R", + "pygments_lexer": "r", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}