<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Intro to Statistical Inference - Medium]]></title>
        <description><![CDATA[Topics in Statistical Inference, Sample Statistic, Sampling Variablity, Hypothesis Tesing and Confidence Intervals - Medium]]></description>
        <link>https://medium.com/intro-to-statistical-inference?source=rss----f4be3135713---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Intro to Statistical Inference - Medium</title>
            <link>https://medium.com/intro-to-statistical-inference?source=rss----f4be3135713---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:21:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/intro-to-statistical-inference" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Intro to Statistical Inference — Part 3: Confidence Interval for Proportion]]></title>
            <link>https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-3-confidence-interval-for-proportion-e45d4776a7b7?source=rss----f4be3135713---4</link>
            <guid isPermaLink="false">https://medium.com/p/e45d4776a7b7</guid>
            <category><![CDATA[confidence-interval]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[inferential-statistics]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Hussain Anwaar]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 22:40:37 GMT</pubDate>
            <atom:updated>2023-09-09T22:40:37.553Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro to Statistical Inference — Part 3: Confidence Interval for Proportion</h3><p>By now we know a thing or two about the word “confidence interval” and it’s significance in the world of statistical inference. Last time we discussed how to build a confidence interval if the variable of interest is a continuous variable (<strong>revenue per user</strong> in the grocery store analysis example we worked on previously). We also discussed why do we even need the confidence interval for reporting different stats in the grocery store example for decision making.</p><p>If you need a quick recap on C.I for Means, i highly recommend reading the last article.</p><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-2-confidence-interval-for-mean-and-proportion-2e9befbd191c">Intro to Statistical Inference — Part 2: Confidence Interval for Mean and Proportion</a></p><p>Today we’ll discuss cases where the parameter of interest is not continuous rather it is binary — meaning it takes only two values either a “0” or a “1”. Now if your variable looks something like this, how would you report it?</p><p>Let’s follow the example of grocery store from our last blog where you are working as a data analyst at a local grocery store and you record some data regarding sales daily. Here’s the data you have collected today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*LyUcCVzZnuNOc-bd9-syhg.png" /></figure><p>Revenue is simply “sales per customer”, and the buy flag is whether the customer bought at least one product. So, it would be zero if the customer did not buy anything. Let’s say your manager asked you to report an important metric of “Proportion of people who buy at-least one product during their visit” — It could help you analyze the health of the business where if you track this metric every day and look at it over weeks or months, you would want to see it increasing, if the business is growing and the % of shoppers with at-least one product bought is increasing. This relates directly to revenue growth aswell.</p><p>Here is an example plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sD672nlHIxWhUN9RhqCr2w.png" /></figure><p>Let’s say you gathered the data and calculated the proportion of people who atleast bought one product and it comes out to be 60%, which we know is the point estimate. By this time we know that the point estimate is not enough to make an informed decision, we have to define the variability around the point estimate using confidence interval. And this is what we would learn next.</p><p>Before moving to C.I, i want to introduce an important concept of <strong>Bernoulli Distribution, Bernoulli Trials and The Binomial Distribution.</strong></p><p>Let’s start with the estimate of the metric we have got from data, which is 60%. You see this metric can also be explained as “There is 60% chance that a shopper will buy at least one product”, so we can think of this metric as the probability of buying at least one product. There are two things at play here.</p><ol><li>A binary variable is needed to explain whether a shopper will buy or not</li><li>There is a fixed probability of buying at least one product for every shopper</li></ol><p>Think of it like this, let’s say a new shopper enters your grocery store. If you had to guess whether they would buy a product or not, how would you do it? You would say there is a 60% chance they would buy a single product. In statistics we call this a <strong>Bernoulli trial</strong>, where there are only two outcomes of a trial, and is modeled using the <strong>Bernoulli Distribution</strong> with probability of success as P(Success) &amp; P(Failure) = 1 — P(Success), which in our case is P(Buy ≥ 1 Product) = 0.6 &amp; P(Buy nothing) = 1–0.6 = 0.4. Now imagine imagine you run the analysis one day later, where you have 50 new shoppers who came to the store today and now you have to report the metric. Here, you want to calculate out of 50 people how many successes you will have (meaning how many will buy ≥ 1 product). This is the case of <strong>Binomial Distribution — </strong>It’s a probability distribution used to model the <strong>“Number of Successes from N Bernoulli Trials”.</strong></p><p>In our case we have:</p><ol><li>50 people thus N = 50</li><li>Each can either buy or not buy anything (Hence Bernoulli Trial)</li><li>With some fixed probability of success — which we estimated from our analysis as P = 0.60</li></ol><p>Now you might be asking why this is important. Why did i take this detour of explaining some boring probability concepts. If you have been paying attention, We want to define the confidence interval around this metric P (Proportion of people buying ≥ 1 product = Probability of buying ≥ 1 Product). Above i explained that this “P” models the variable that follows Binomial Distribution. Now remember this as we do the proof of C.I for proportion.</p><p>If you went through the first article, where i explained that to build a confidence interval we need these things:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*Az3N2oOPZ3lS70AU-8O2DA.png" /></figure><p>Where I introduced the concept of sampling distribution and it’s importance. I also mentioned that:</p><p>Point Estimate is the Mean of sampling distribution, whereas the Standard Error is the variance of sampling distribution. If your knowledge on sampling distribution is a bit rusty, please go through this quick article which explains these concepts in detail.</p><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-1-what-is-statistical-inference-43a006c9a71">Intro to Statistical Inference — Part 1: What is Statistical Inference?</a></p><h4><strong>A little recap on how to build Confidence Interval</strong></h4><p>To build the confidence interval we need to build the sampling distribution, which in this case would be achieve by:</p><ul><li>Repeat N times:<br>- Take a sample of let’s say size n = 30, calculate the metric</li></ul><p>Now,</p><p><strong>Point Estimate</strong> = Mean (Metric of all N times we repeated the above experiment)</p><p><strong>Standard Error</strong> = Standard Deviation (Metric of all N times we repeated the above experiment)</p><p>It’s literally as simple as that. But since we made it a point in the first article that we don’t have luxury to draw samples “N” times. We usually only have one sample to draw our inference (Which is the whole point of statistical inference). Now follow this proof to see how we derive the quick and easy mathematical equations for C.I for proportions.</p><h4>Proof</h4><p>Let’s assume a random variable “X” which is used to model <strong>“Number of successes in n Bernoulli trials” —</strong> In simple words X can model situations like: If you toss your coin 10 times, how many time it would come up as heads <strong>OR</strong> If 100 customers visit your grocery stores how many of them buy atleast one thing from the store!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*Am5cwYz-BcAwDAN4Z7HVuA.png" /><figcaption>Proof of C.I for Proportion</figcaption></figure><p>The above proof was to show how we came up with the equations and formulas, i hope it all makes sense to you. Now, the final piece of the puzzle is, how do we calculate the alpha. We are going to use the help of Central Limit Theorem here. We saw in the first blog that if sample size if large enough (N ≥ 30) then sampling distribution of the mean of any random variable follows the normal distribution. There is a proof that shows how the mean of large number of random variables that follow binomial distribution can be estimated using normal distribution (Here’s the link for people who are interested). Thus, we can say that alpha can be estimated through standard normal distribution with given confidence level.</p><p>Here is the code snippet to calculate C.I of our proportion based metric from the data:</p><pre>from scipy.stats import norm<br>alpha = 0.95<br>p_hat = df.buy_flag.mean() # Sample Statistic<br>standard_error = np.sqrt(p_hat * (1-p_hat)/df.shape[0]) # Standard Error<br>critical_value = abs(norm.ppf((1-alpha)/2,0,1)) # Critical Value<br>C_I = [p_hat - critical_value*standard_error, p_hat + critical_value*standard_error]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*r2iV7tZRcjXgRtGueBbSBQ.png" /></figure><p>This means that we are 95% confident that on average the shopper conversion would be between 78% and 83%.</p><h4>Conclusion</h4><p>In this blog, we discussed the confidence intervals for ratio/proportion based metrics and we solved a real time example from a grocery store. We also looked at the significance of reporting confidence interval for these metrics.</p><p>In the next few articles i’ll dive into the realm of hypothesis testing and then finally in models like regression, anova and their significance.</p><p>Stay Tuned for next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e45d4776a7b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-3-confidence-interval-for-proportion-e45d4776a7b7">Intro to Statistical Inference — Part 3: Confidence Interval for Proportion</a> was originally published in <a href="https://medium.com/intro-to-statistical-inference">Intro to Statistical Inference</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to Statistical Inference — Part 2: Confidence Interval for Mean and Proportion]]></title>
            <link>https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-2-confidence-interval-for-mean-and-proportion-2e9befbd191c?source=rss----f4be3135713---4</link>
            <guid isPermaLink="false">https://medium.com/p/2e9befbd191c</guid>
            <category><![CDATA[hypothesis-testing]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[confidence-interval]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[statistical-inference]]></category>
            <dc:creator><![CDATA[Hussain Anwaar]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 21:28:44 GMT</pubDate>
            <atom:updated>2024-02-16T21:02:52.764Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro to Statistical Inference — Part 2: Confidence Interval for Mean</h3><p>In the last article we discussed what a confidence interval is and the intuition behind it. If you need to refresh your knowledge on “Confidence Interval and Central Limit Theorem” — please review this first blog i wrote in the series.</p><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-1-what-is-statistical-inference-43a006c9a71">Intro to Statistical Inference — Part 1: What is Statistical Inference?</a></p><p>Today, we’ll dive a bit more into:<br><strong>1. General details around confidence interval<br>2. Confidence Interval for Mean — Derivation &amp; Examples</strong></p><p>I’ll provide some practical examples and code snippets to run quick simulations to develop a strong understanding of the concept.</p><p>Let’s dive right into it!</p><h4>A few general details on Confidence Interval</h4><p>In the last article we explained that confidence interval is “a plausible range of values that contains true population parameter with some confidence”. Simply put, C.I quantifies the uncertainty (variability) around the sample statistic.</p><p>But why do we need C.I, why can’t we just report a single metric like average revenue per customer, avg. time spent reading on medium etc. I discussed this topic in detail in previous blog.</p><p>Now let’s focus on how to build the confidence interval. We need three things to build C.I for any metric.</p><ol><li>Point Estimate (Metric of Interest — avg. revenue etc)</li><li>Standard Error (Variance of Sampling Distribution) — Quantifies the variability around the point estimate (metric of interest)</li><li>Confidence (1 — alpha) — Shows how confident we are in the range we provided</li></ol><p>Thus, the complete equation look something like this:<br><strong>Point Estimate ± Confidence × Standard Error</strong></p><p><strong>Point estimate —</strong> relates to some metric you are trying to report/measure. It could be avg. revenue, avg. spend or even a proportion based metric like CVR (conversion rate — based on a binary metric).</p><p><strong>Standard Error —</strong> as explained in the last article is the variability around the metric.</p><p><strong>Confidence </strong>— quantifies the confidence you have in the range you produced using point estimate and standard error. Intuitively, this means that for a higher confidence value, the range of C.I would be larger and you would have a higher confidence — Meaning you’d be more confident in saying that the range you calculated (using C.I) would contain the true population parameter, whereas for a lower confidence, the range of C.I would be smaller (As suggested by the formula above). Now let’s look at this picture below from last article —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QH-FTWrn6rf6OYPKAUSeqQ.png" /></figure><p>Range of 1-sigma (one standard deviation) around the mean captures ~68% of variability, while as you increase the limit and move to 2-sigma, the percentage of variability captured increases. Thus, finding this 1, 2 or 3 in sigma, is where the significance of your confidence lies. If you want to be ~68% confident in your C.I, you can use “1”. If you want to be ~95% confident, you can use “2”.</p><p>I used confidence for simplicity here. In reality we use critical value which is defined by the confidence percentage. As in above example, 95% confidence relates to 2 for Standard Normal Distribution.</p><p>Enough with the theory already, let’s talk about some practical example. Usually there is a metric you always want to calculate the confidence interval for. Suppose you are the analyst at a grocery store — You could have different important metrics that you are tracking, E.g <strong>spend per customer</strong> (revenue per customer), <strong>customer conversion</strong> (% of total customer that at-least buy one product in a visit). The first metric is a continuous metric, meaning more of an average of some numbers, whereas the second metric is a percentage of a binary metric (Metric that take 1 or 0 value — whether the customer bought any item or not). Your analytics lead might have asked you to report these metrics in a meeting to analyze the store’s growth. Now you have already been following this series and know that it is always important to report the variability around the metric, so you want to make sure you report the Confidence Intervals for both metrics. Let’s see how we can do that!</p><h4>Confidence Interval for Means</h4><p>Whenever the point estimate is a continuous quantity, we’ll use confidence interval for means to report the metric and variability around it. The data you have is of each customer’s spend per visit and looks something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*wxtr3CPfKRKXutAiZITnDQ.png" /></figure><p>Since it is a continuous metric and the easiest way we can aggregate the Revenue/Spend is by taking it’s average and report it. Thus, you’d follow this process below:</p><ol><li>Calculate the average of the metric of interest, which in our case is revenue per customer:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*sVYfrWQuGiEVfUmSSP6__w.png" /></figure><p>2. Calculate the Standard Error for that metric:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*mFRckCZw1BQ6X2MuPbTXKQ.png" /></figure><p>3. Decide on Confidence Level to report on and calculate the critical value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*XZNHahpPxmvbYC9GX9QS_A.png" /></figure><p>Plug all the above into the formula below and you have the C.I for the metric:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*ZrGa3dDC_ZTzXSuuBiWmLA.png" /></figure><p>Now, there is a caveat in the above equation. If you see the formulation for standard error, it contains “sigma”. Which is the population standard deviation and not the sample one. However, in most cases we only have access to the sample only as in the case above. So, the question is how can we use sample standard deviation to estimate the standard error and what changes we need to make?</p><p>The good news is that we can use sample standard deviation and there not a whole lot we need to change. With the new formulation here is complete process (Don’t worry i’ll explain it all in a bit)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*kN54GROyOiwf7TcV8gYbYg.png" /></figure><p>If you take a deeper look at the formulation, not a whole lot changed. Except now we are talking about t-Distribution instead of the standard normal distribution to calculate the critical value. Why?</p><p>Here is a simple answer, because now we are estimating the standard error (variance of sampling distribution) using sample standard deviation. Thus, samples usually have more variability compared to population from which they are sampled from. Simply because we take a small chunk from a population and variability would be higher. To cater to that we use student t-distribution to simulate the sampling distribution instead of the standard normal distribution as we did in CLT proof in the last article. One of the major differences between a normal and t-distribution is that the latter has fatter tails so that it can be used to model some extra variance (which comes from the fact that we are using a sample standard deviation to estimate the sampling distribution’s variability (i.e Standard Error). From the POV of computation, not a whole lot changes. Previously we use the critical value table from standard normal distribution, now we’ll use the critical value from t-distribution. I’ll do a deeper dive on the differences between t-distribution and standard normal distribution. But for now just remember that they both are:</p><ol><li>Very similar to each other in shape</li><li>Both are centered around zero</li><li>larger the df (degrees of freedom — due to larger sample size), the more similar two distributions become</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*gHMat2fLs23ndIMPUfWP2g.png" /></figure><p>Now let’s look at some data and run some code to calculate the C.I for the Revenue per user.</p><p>I created a dummy dataset which has user_id’s and their spend from last day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*CB3rgSvv4PCwo96lqWKFeg.png" /></figure><p>Here is the code snippet to calculate the C.I from the data:</p><pre>from scipy.stats import t<br>alpha = 0.95<br>n = df.shape[0]<br>x_bar = df[&#39;revenue&#39;].mean()<br>s = df[&#39;revenue&#39;].std()<br>critical_value = t.ppf(alpha ,df = n - 1)<br>C_I = [x_bar - critical_value*(s/np.sqrt(n)), x_bar + critical_value*(s/np.sqrt(n))]</pre><p>Here’s the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*D_h53kLkbrwbpujPwuIlUA.png" /></figure><p>This means that we are 95% confident that the true avg. spend per customer would lie somewhere between $49.51 and $50.54. You can track this over days or weeks and analyze the growth of the store.</p><h4>Conclusion</h4><p>In this blog, we discussed the important facets of confidence intervals and how to calculate confidence intervals for means. We looked at a practical example of the user spend data and how to report avg. revenue per user like a pro using the confidence intervals.</p><p>In the next article we’ll look into the second metric of conversion meaning what % of users convert on their visit. This kind of metric can help us analyze why certain users are not buying anything from the store, which can later be used to find causes of why certain users do not buy anything from the store.</p><p>Stay Tuned for next one!</p><h4>Resources</h4><p><a href="https://github.com/mitu246/blogs/blob/main/CI%20for%20Mean.ipynb">Github code</a></p><h4>Connect with me</h4><p>I just started rewriting the blog series and share my knowledge along the way. My interests are Statistics, Causal Inference, Traditional Machine Learning, Reinforcement Learning</p><p>If any of the above topics interests you, i’d love to chat more and connect!</p><p>My LinkedIn: <a href="https://www.linkedin.com/in/hussainanwaar246/">hussain_anwaar</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9befbd191c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-2-confidence-interval-for-mean-and-proportion-2e9befbd191c">Intro to Statistical Inference — Part 2: Confidence Interval for Mean and Proportion</a> was originally published in <a href="https://medium.com/intro-to-statistical-inference">Intro to Statistical Inference</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to Statistical Inference — Part 1: What is Statistical Inference?]]></title>
            <link>https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-1-what-is-statistical-inference-43a006c9a71?source=rss----f4be3135713---4</link>
            <guid isPermaLink="false">https://medium.com/p/43a006c9a71</guid>
            <category><![CDATA[confidence-interval]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[statistical-inference]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hypothesis-testing]]></category>
            <dc:creator><![CDATA[Hussain Anwaar]]></dc:creator>
            <pubDate>Thu, 21 Oct 2021 21:56:17 GMT</pubDate>
            <atom:updated>2023-08-13T21:39:42.539Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro to Statistical Inference — Part 1: What is Statistical Inference?</h3><p>In this blog series, I will talk about the basics of Statistical Inference. I’ll start with what Statistical Inference is and what we mean when we say “Infer something about the population from the data we observe”, and in later parts I’ll talk about different Statistical Tests to decide the significance of effects we observe through the data (i.e. if these effects are true effects or just random noise). I’ll dive into the explanations of different types Statistical Tests used for different types of data (or should I say the type of population parameter in question). Most of the time I’ll try to keep things simple and basic, however I’ll be posting examples designed in R and Python to help understand the concept.</p><h3>What is Statistical Inference?</h3><p>By definition, it is the study of theory and methods used to form judgements regarding a “population” from the sample (data) that we observe, and measure the reliability of those judgements made from the sample data. In simple words, we can say that Inference is about generalizing something with a “certain degree of certainty” about a population by looking at a sample from that population.</p><p>For example, you may want to how many glasses of water people of your age usually drink everyday. Now, the easiest way to check that is by observing yourself and asking your friends (assuming they are your age) about the glasses of water they drink everyday. After asking two of your friends and observing yourself, you came up to a conclusion that “People of your age drink on average “X” many glass of water”. We’ll discuss the process of reaching this conclusion shortly, but the above statement is where you are inferring about the population (i.e. people of your age) that they drink a certain amount of water everyday.</p><p>Now you might ask — Why do we need to Infer something about the population, why can’t we exactly know how the population looks like and what is the value of it’s parameter of interest (Population Parameter). The answer is that in real time scenarios, population parameter of interest is unknown, because the complete population is mostly unobserved, e.g You can never ask every person of your age on earth, how many glasses of water they drink as it’s practically impossible. We can only make some inferences about population by observing a sample from the same population</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*9O_-82J62STps3IjMivzCA.png" /></figure><h3>Basic Terminologies</h3><p>Before diving deep into the example above I wanted to talk about the basic terminologies I’ll be using throughout this blog series.</p><h4>Population</h4><p>Complete set of Individuals/Objects under study is population. From the example above population is the all the people your age in this world.</p><h4>Parameter of Interest</h4><p>Parameter of Interest is the attribute you want to infer in regards to the population under study. Amount of water is the parameter of interest as you are inferring how much water people your age drink.</p><h4>Measuring the Parameter of Interest</h4><p>After deciding about the Parameter of Interest you need to decide on how would you quantify/measure the parameter of interest. In our case it is the number of glasses a person drink everyday.</p><h4>Population Parameter &amp; Sample Statistic</h4><p>The measure for Parameter we talked about in the previous section can be measured w.r.t both the population and sample. When it is measured w.r.t population, it is called Population Parameter and when measured for a sample, it’s called Sample Statistic. For example — Average glass of water that a person of your age drinks (Population) is a population parameter, while the average glass of water you and the sample of your two friends drink is the sample statistic. Population parameter is what is unknown mostly all the time, while sample statistic is what we can measure from our sample and use it to make an inference about population parameter.</p><p>From our example we discussed above — Let’s say you drink 5 glasses, your first friend drinks 3 and your second friend drinks 7 glasses of water everyday. The average of these numbers comes out as 5 which is the sample statistic in this case. You might be wondering, Well — I can infer each person of my age on average drinks 5 glasses of water, right? — Wrong! Because you did not account for the variability that would occur in terms of sample statistic if you were to take a different sample from what you just took. For example, you had asked two people from your neighborhood other than your two friends that you just asked, they might have answered that they drink 9 and 13 glasses of water everyday. Now if you average your 5 glasses of water, 9 and 13 from the above two people, you now have a sample statistic of average of 9 glasses per day. Now if you notice how different your sample statistic would be if you had chosen this sample instead of the last one.</p><p>This Variability in sample statistic due to difference in samples we collect is called Sampling Variability. We can use this variability and sample statistic to define the plausible range of values from which we can say the population parameter can lie with a certain degree of confidence.</p><h4>Sampling Distribution and Central Limit Theorem (CLT)</h4><p>It is the distribution of different (yet identical) values of sample statistic that can come from different samples of same size from a population. In our example above, your sample is of size n=3. Let’s say you decided to take 15 samples (each of size n=3, i.e three people — You decided to ask 15 groups of 3 people each) and you recorded the “Average Number of glasses for each sample. Here are the numbers Sn = 8,7,9,8,7,9,6,10,8,8,7,6,9,5,11 — Avg. Number of glasses per sample. Let’s plot them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_8s8VULSjQ0OCezsklyrw.jpeg" /></figure><p>If we assume that the underlying population is normal in our case, and you had kept on sampling and were able to sample the entire population, the curve shown above would start approaching a normal distribution with mean “mu — μ” and standard deviation (Sampling Variability or sometimes called Standard Error) as “σ/√n” (where “μ” population mean (population parameter) and “σ” is the standard deviation of the population). This essentially means that the sampling distribution of sample mean (<strong>x̄</strong>) ~ N(μ,σ²/n), given that the underlying population is normal. Even if the underlying population is not normal (i.e Binomial, Uniform Distribution etc), the sampling distribution will still be normal given the sample size is large enough. The description above most accurately describes what Central Limit Theorem is. Here is a short proof for all the things I have mentioned. This will form the basis for most types of Statistical Tests we’ll talk about in the next blogs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*mQTxiDUmOvle3e_4iiSgKw.png" /><figcaption>Please read the left page first and then move towards right</figcaption></figure><p>Here’s a simulation I ran in R that would help understand the CLT better. I took a uniform distribution with mean 0.5, and ran a simulation to show the sampling distribution based on different sample sizes. We can visualize that as the sample size increases, the sampling distribution appears to be more like normal distribution. As sample size approaches infinity the sampling distribution becomes exactly normal. Here’s how it looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAe1qofd4KrBHYqRNii1WQ.png" /></figure><p>Here’s the code snippet to do it:</p><pre># CLT Proof:<br>x &lt;- runif(1000000,0,1)</pre><pre># We&#39;ll take a total of 100 samples of different sizes to show <br># how the sampling distribution looks like</pre><pre># Sample Sizes<br>n &lt;- c(10,50,100,150,200,1000)</pre><pre># Final Data Table:<br>final_dt &lt;- data.table()<br>for(n_ in n){<br>  x_bar_list &lt;- c()<br>  dt_ &lt;- data.table()<br>  for(i in 1:100){<br>    x_i &lt;- sample(x,n_,replace=T)<br>    x_bar &lt;- mean(x_i)<br>    <br>    x_bar_list &lt;- c(x_bar_list,x_bar)<br>  }<br>  dt_[,`:=`(sample_size=rep(n_,length(x_bar_list)),<br>            x_bar=x_bar_list)] <br>  final_dt &lt;- rbind(final_dt,dt_)<br>}<br># Plot the sampling distributions for different sample sizes:<br>final_dt$sample_size = as.character(final_dt$sample_size)<br>ggplot(final_dt)+geom_density(aes(x=x_bar,col=sample_size))</pre><h4>Confidence Interval</h4><p>Unfortunately, we don’t have the luxury or resources to sample a population completely and generate the whole sampling distribution. We mostly just have one sample from the population on the basis of which we have to infer something about the population. Now we would agree on the fact that due to sampling variability we cannot infer by only using sample statistic, we need to cater for the sampling variability, and we do that by generating a plausible range of values in which the true population parameter would lie with a certain degree of confidence. Why, we say with certain degree of confidence, let’s dive into it after we build some intuition using the normal probability curve. Let’s say we have a normal distribution following ~ N(μ,σ²).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSUqv2yB94q9B3aDp37Ovw.jpeg" /></figure><p>From the above picture we see that 68% of the data lies within +/-1σ of mean, while 95% of the data lies within <strong>+/-2</strong>σ of mean, and the percentage increases as we increase the range around the mean. Now, think of it in terms of sample statistic mean and it’s standard deviation (Sampling Variability or Standard Error).</p><p>Following this analogy we can say that p% confidence interval can be built using this formula:<br><strong>x̄ +/- [critical_value(given p% confidence) * S.E]</strong></p><p>Now, if sample mean (sample statistic) follows a normal distribution then we can get the critical value for respective confidence percentage from the normal distribution defined above. For example, for 95% confidence we would use the critical value of 2. Sample mean can follow either normal distribution or T-Distribution depending upon how we estimate standard error. We’ll dive into the explanation for this in the next article.</p><p>Finally, I’d want to build some intuition behind Confidence Interval. Let’s assume we generated a p% C.I. This means that if we were to generate “x” number of these intervals from x different samples (coming from same population) then x*p% of these intervals would contain the true population parameter. For example, let’s say you generate x=10 different (yet identical) 95% Confidence Intervals by taking 10 samples from population, then about 9.5 (~ round down to 9) of these 10 C.I’s would contain the true unknown population parameter or 9.5 out of 10 times your Confidence Interval is solid!</p><p>In this article, I tried to explain the baseline idea behind statistical inference and the tools we use to infer something about a population by using a single sample from that population. In the next few articles, I’ll discuss how to build Confidence Intervals for different type of measurements (e.g mean and proportion) and we’ll discuss other concepts like Hypothesis Testing, Regression and Analysis of Variance in detail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43a006c9a71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intro-to-statistical-inference/intro-to-statistical-inference-part-1-what-is-statistical-inference-43a006c9a71">Intro to Statistical Inference — Part 1: What is Statistical Inference?</a> was originally published in <a href="https://medium.com/intro-to-statistical-inference">Intro to Statistical Inference</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>