{"id":340,"date":"2012-10-19T14:30:53","date_gmt":"2012-10-19T13:30:53","guid":{"rendered":"http:\/\/numbercrunch.de\/blog\/?p=340"},"modified":"2023-01-18T23:45:32","modified_gmt":"2023-01-18T22:45:32","slug":"point-and-interval-estimation-in-python","status":"publish","type":"post","link":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/","title":{"rendered":"Point and interval estimation in Python"},"content":{"rendered":"<p style=\"text-align: justify;\">Let us consider a random sample $x_1,x_2,\\dots,x_N$ drawn from a normal distribution with unknown mean $\\mu$ and unknown variance $\\sigma^2$. The best point estimates for the mean and the variance are given by the sample mean\\begin{equation}<br \/>\n\\hat\\mu = \\frac{1}{N}\\sum_{i=1}^{N} x_i<br \/>\n\\end{equation}<br \/>\nand the sample variance<br \/>\n\\begin{equation}<br \/>\n\\hat\\sigma^2 = \\frac{1}{N-1}\\sum_{i=1}^{N} (x_i-\\hat\\mu)^2\\,,<br \/>\n\\end{equation}<br \/>\nrespectively. The sample mean and the sample variance and interval estimates for the mean and the variance may be computed easily using Python.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\n\nfrom pylab import *\nimport scipy.stats \n\nN=1000.      # sample size\ngamma=0.95  # confidence level\n\nmu=10.      # true mean\nsigma=2.    # true standard diviation\nx=randn(N)*sigma+mu  # surrogate data\n\nmu_hat=mean(x)           # sample mean\nsigma_hat=std(x, ddof=1) # sample standard deviation\n\nprint('sample mean mu_hat                  : %f' % mu_hat)\nprint('sample standard deviation sigma_hat : %f' % sigma_hat)\nl=scipy.stats.t.ppf( (1-gamma)\/2, N-1)    # lower percentile\nu=scipy.stats.t.ppf( 1-(1-gamma)\/2, N-1)  # upper percentile\nprint('confidence interval mu_hat          : (%f, %f)' % \n      (mu_hat+l*sigma_hat\/sqrt(N), mu_hat+u*sigma_hat\/sqrt(N)))\nl=scipy.stats.chi2.ppf( (1-gamma)\/2, N-1)    # lower percentile\nu=scipy.stats.chi2.ppf( 1-(1-gamma)\/2, N-1)  # upper percentile\nprint('confidence interval sigma_hat       : (%f, %f)' % \n      ( sqrt((N-1)\/u)*sigma_hat, sqrt((N-1)\/l)*sigma_hat))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let us consider a random sample $x_1,x_2,\\dots,x_N$ drawn from a normal distribution with unknown mean $\\mu$ and unknown variance $\\sigma^2$. The best point estimates for the mean and the variance are given by the sample mean\\begin{equation} \\hat\\mu = \\frac{1}{N}\\sum_{i=1}^{N} x_i \\end{equation} and the sample variance \\begin{equation} \\hat\\sigma^2 = \\frac{1}{N-1}\\sum_{i=1}^{N} (x_i-\\hat\\mu)^2\\,, \\end{equation} respectively. The sample mean&hellip; <a href=\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Point and interval estimation in Python<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Point and interval estimation in Python - Number Crunch<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Point and interval estimation in Python - Number Crunch\" \/>\n<meta property=\"og:description\" content=\"Let us consider a random sample $x_1,x_2,dots,x_N$ drawn from a normal distribution with unknown mean $mu$ and unknown variance $sigma^2$. The best point estimates for the mean and the variance are given by the sample meanbegin{equation} hatmu = frac{1}{N}sum_{i=1}^{N} x_i end{equation} and the sample variance begin{equation} hatsigma^2 = frac{1}{N-1}sum_{i=1}^{N} (x_i-hatmu)^2,, end{equation} respectively. The sample mean&hellip; Continue reading Point and interval estimation in Python\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Number Crunch\" \/>\n<meta property=\"article:published_time\" content=\"2012-10-19T13:30:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-18T22:45:32+00:00\" \/>\n<meta name=\"author\" content=\"Heiko Bauke\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Heiko Bauke\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\"},\"author\":{\"name\":\"Heiko Bauke\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"headline\":\"Point and interval estimation in Python\",\"datePublished\":\"2012-10-19T13:30:53+00:00\",\"dateModified\":\"2023-01-18T22:45:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\"},\"wordCount\":101,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\",\"url\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\",\"name\":\"Point and interval estimation in Python - Number Crunch\",\"isPartOf\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#website\"},\"datePublished\":\"2012-10-19T13:30:53+00:00\",\"dateModified\":\"2023-01-18T22:45:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.numbercrunch.de\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Point and interval estimation in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#website\",\"url\":\"https:\/\/www.numbercrunch.de\/blog\/\",\"name\":\"Number Crunch\",\"description\":\"A computational science blog.\",\"publisher\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.numbercrunch.de\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413\",\"name\":\"Heiko Bauke\",\"logo\":{\"@id\":\"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Point and interval estimation in Python - Number Crunch","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Point and interval estimation in Python - Number Crunch","og_description":"Let us consider a random sample $x_1,x_2,dots,x_N$ drawn from a normal distribution with unknown mean $mu$ and unknown variance $sigma^2$. The best point estimates for the mean and the variance are given by the sample meanbegin{equation} hatmu = frac{1}{N}sum_{i=1}^{N} x_i end{equation} and the sample variance begin{equation} hatsigma^2 = frac{1}{N-1}sum_{i=1}^{N} (x_i-hatmu)^2,, end{equation} respectively. The sample mean&hellip; Continue reading Point and interval estimation in Python","og_url":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/","og_site_name":"Number Crunch","article_published_time":"2012-10-19T13:30:53+00:00","article_modified_time":"2023-01-18T22:45:32+00:00","author":"Heiko Bauke","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Heiko Bauke","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#article","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/"},"author":{"name":"Heiko Bauke","@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"headline":"Point and interval estimation in Python","datePublished":"2012-10-19T13:30:53+00:00","dateModified":"2023-01-18T22:45:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/"},"wordCount":101,"commentCount":0,"publisher":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/","url":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/","name":"Point and interval estimation in Python - Number Crunch","isPartOf":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#website"},"datePublished":"2012-10-19T13:30:53+00:00","dateModified":"2023-01-18T22:45:32+00:00","breadcrumb":{"@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.numbercrunch.de\/blog\/2012\/10\/point-and-interval-estimation-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.numbercrunch.de\/blog\/"},{"@type":"ListItem","position":2,"name":"Point and interval estimation in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.numbercrunch.de\/blog\/#website","url":"https:\/\/www.numbercrunch.de\/blog\/","name":"Number Crunch","description":"A computational science blog.","publisher":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.numbercrunch.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/e73eab65b1721dd0c3d408edb887e413","name":"Heiko Bauke","logo":{"@id":"https:\/\/www.numbercrunch.de\/blog\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/340"}],"collection":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":20,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":999,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions\/999"}],"wp:attachment":[{"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.numbercrunch.de\/blog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}