Statistical Inference
Statistical inference: population and sample, standard error, Central Limit Theorem, confidence intervals, hypothesis tests, p-values and effect size.
https://morrisonkuhlsen.com/en/statistical-inference/
Statistical Inference
Statistical inference is the part of statistics that lets us draw conclusions about a population from a sample. We use it when we cannot observe every individual of interest but want to estimate quantities, test hypotheses and make decisions based on data, while also saying how much uncertainty those conclusions carry.
What Is Statistical Inference?
In Descriptive Statistics, we organize and summarize the observed data.
In Probability, we study uncertainty mathematically.
In Statistical Inference, we combine these two ideas to answer one central question:
What can we conclude about a population using only a sample?
This kind of reasoning appears in election polls, medical studies, quality control, market research, scientific experiments, economic models and many other settings.
Pages in this section
The topics below go into each part of this page in detail, with worked examples and Julia code:
- Sampling: how to choose the sample (simple random, stratified, cluster, systematic) and how large it should be.
- Hypothesis Testing: hypotheses, test statistic, p-value, Type I and Type II errors, and power.
- Confidence Intervals: how to build and interpret intervals for means and proportions.
- Estimators: bias, variance, mean squared error and maximum likelihood.
- Analysis of Variance (ANOVA): comparing the means of several groups with the F test, and Tukey’s test.
Population and Sample
Two concepts are fundamental to inference: the population and the sample.
Population
The complete set of elements we want to study. It can be made up of people, companies, service calls, measurements, products, municipalities or any unit of interest.
Sample
A part of the population selected for analysis. From it, we try to estimate characteristics of the whole population.
Parameter
A true measure of the population, usually unknown, such as the population mean, the population proportion or the population variance.
Statistic
A measure computed from the sample, such as the sample mean, the sample proportion or the sample standard deviation.
Parameter versus Statistic
The difference between a parameter and a statistic is one of the most important ideas in statistical inference. Greek letters usually denote parameters; Latin letters, statistics.
| Concept | Represents | Examples |
|---|---|---|
| Parameter | A characteristic of the population (a fixed number, usually unknown). | $\mu$ (mean), $\sigma^2$ (variance), $p$ (proportion) |
| Statistic | A characteristic computed from the sample (changes from sample to sample). | $\bar{x}$ (mean), $s^2$ (variance), $\hat{p}$ (proportion) |
For example, if we want to know the mean income of all residents of a city, that true mean, $\mu$, is a parameter. If we interview 500 randomly chosen residents and compute the mean of that sample, we get a statistic, $\bar{x}$.
Why Do We Need Inference?
In many real problems, observing the whole population is impossible, expensive or slow.
Imagine, for example:
- interviewing every voter in a country;
- testing the durability of every product made (the test destroys the product);
- measuring every inhabitant of a city;
- following every patient in a population;
- checking every service call in a system over several years.
That is why we use samples.
The big issue is that samples vary.
If we draw two different samples from the same population, we will hardly ever get exactly the same mean, proportion or standard deviation.
Point Estimation
Point estimation means using a single value computed from the sample to estimate a population parameter.
For example, we use the sample mean to estimate the population mean, and the sample proportion to estimate the population proportion:
| Population parameter | Sample estimator |
|---|---|
| Population mean: $\mu$ | Sample mean: $\bar{x}$ |
| Population proportion: $p$ | Sample proportion: $\hat{p}$ |
| Population variance: $\sigma^2$ | Sample variance: $s^2$ (with divisor $n - 1$) |
How to judge whether an estimator is good (bias, variance, mean squared error) is covered in Estimators.
Sampling Error
Since the sample is only part of the population, there is a natural difference between the sample value and the population value.
That difference is called sampling error. For the mean:
In practice, we do not know $\mu$, so we cannot know the sampling error of a specific sample. What we can do is measure how large it tends to be from sample to sample. This idea leads to the concept of standard error.
Sampling error is different from errors that do not come from the random draw (badly worded questions, people who do not respond, a miscalibrated instrument). Those do not shrink with a larger sample.
Standard Error of the Mean
The standard error of a statistic is the standard deviation of its sampling distribution: it measures how much the statistic varies from one sample to another.
If the $n$ observations are independent and come from a population with standard deviation $\sigma$, the standard error of the mean is:
When $\sigma$ is unknown (the most common case), it is estimated by replacing $\sigma$ with the sample standard deviation $s$:
Where:
- $SE(\bar{x})$ is the standard error of the mean;
- $\sigma$ is the population standard deviation, and $s$, the sample one;
- $n$ is the sample size.
Sampling Distribution
The sampling distribution is the distribution of a statistic computed over all possible samples of the same size.
For example, if we drew many samples of size $n$ from the same population and computed the mean of each one, we would have many sample means:
The distribution of these values is called the sampling distribution of the mean. In practice we have only one sample; the sampling distribution is what theory tells us about all the samples we could have drawn.
This idea is the basis of confidence intervals and hypothesis tests.
Central Limit Theorem
The Central Limit Theorem (CLT) is one of the most important results in statistics.
For independent observations from the same distribution, with mean $\mu$ and finite variance $\sigma^2$, the following always hold, for any $n$:
- the mean of the sampling distribution of $\bar{X}$ is exactly $\mu$: $E[\bar{X}] = \mu$;
- the variance of $\bar{X}$ is $\sigma^2 / n$, which decreases as $n$ grows.
The CLT adds the shape: as $n$ grows, the distribution of $\bar{X}$ approaches a normal distribution, even if the population is not normal:
How large $n$ needs to be depends on the population: for symmetric populations, the approximation is already good with small samples; for very skewed populations, it may take many more. The well-known “$n \geq 30$” is a rule of thumb, not a theorem.
Confidence Interval
A point estimate gives a single value, which is almost never exactly equal to the parameter.
So it is usually better to give a range of plausible values for the parameter, built with a margin of error.
That range is called a confidence interval.
When $\sigma$ is known, a confidence interval for the mean is:
When $\sigma$ is unknown and we use $s$, the critical value comes from Student’s t distribution with $n - 1$ degrees of freedom:
Where:
- $\bar{x}$ is the sample mean;
- $1 - \alpha$ is the confidence level (for example, $\alpha = 0.05$ for 95%);
- $z_{\alpha/2}$ is the critical value of the standard normal distribution (1.96 for 95%);
- $t_{\alpha/2,\ n-1}$ is the critical value of the t distribution;
- $s$ is the sample standard deviation;
- $n$ is the sample size.
Both formulas assume independent observations and either a normal population or $n$ large enough for the CLT to apply. Details and examples in Confidence Intervals.
How to Interpret a Confidence Interval
A 95% confidence interval does not mean there is a 95% chance that the parameter lies in that specific interval, once it has been computed. The parameter is a fixed number: either it is inside or it is not.
The correct (frequentist) interpretation is about the method:
If we repeated the sampling process many times and built a confidence interval from each sample, about 95% of those intervals would contain the true population parameter.
Example
Suppose (illustrative numbers) that a survey estimates the mean service time with the 95% interval $CI_{95\%} = [8.4,\ 10.2]$ minutes.
This means the interval was built by a method that captures the true mean in 95% of samples, and that the values from 8.4 to 10.2 minutes are the ones compatible with the data by that criterion. It does not mean that 95% of service calls last between 8.4 and 10.2 minutes: the interval is about the mean, not about each call.
Hypothesis Tests
Hypothesis tests are used to assess claims about population parameters.
They help answer questions such as:
- Is the mean of a population different from a certain value?
- Are two means statistically different?
- Has a proportion changed over time?
- Is there an association between two categorical variables?
- Did a treatment have a measurable effect?
Every hypothesis test starts with two hypotheses:
| Hypothesis | Meaning |
|---|---|
| $H_0$ | Null hypothesis. Usually represents no effect, no difference or a reference value. |
| $H_1$ or $H_a$ | Alternative hypothesis. Represents what we want to look for evidence of. |
The test starts from $H_0$ and asks whether the data are too unusual for it. Details in Hypothesis Testing.
Example of Hypotheses
Suppose a company claims that the mean service time is 10 minutes.
We want to check whether the data indicate that the mean time is different from 10 minutes.
The hypotheses would be:
This is a two-sided test, because we are interested in differences both upward and downward.
Test Statistic
The test statistic turns the sample data into a standardized value that can be compared with a known distribution.
To test a mean with a known population standard deviation, we use the Z statistic, which under $H_0$ follows the standard normal distribution:
When the population standard deviation is unknown, we use the t statistic, which under $H_0$ follows Student’s t distribution with $n - 1$ degrees of freedom (assuming a normal population or large $n$):
Where:
- $\bar{x}$ is the sample mean;
- $\mu_0$ is the value of the mean under the null hypothesis;
- $\sigma$ is the population standard deviation, and $s$, the sample one;
- $n$ is the sample size.
p-Value
The p-value is the probability of getting a result as extreme as or more extreme than the one observed, assuming the null hypothesis is true.
If the p-value is very small, the data would be rare if $H_0$ were true, and that is evidence against $H_0$.
A common reading, which is only a convention (not a rule of mathematics), is:
| p-value | Common reading |
|---|---|
| $p \leq 0.01$ | Strong evidence against $H_0$. |
| $0.01 < p \leq 0.05$ | Moderate evidence against $H_0$. |
| $p > 0.05$ | Not enough evidence to reject $H_0$ at the 5% level. |
Significance Level
The significance level is denoted by $\alpha$. It is chosen before looking at the data and sets the threshold used to decide whether or not to reject the null hypothesis.
The most common value is $\alpha = 0.05$, but it is a convention; different fields use different values.
The decision rule is:
| Condition | Decision |
|---|---|
| $p \leq \alpha$ | We reject $H_0$. |
| $p > \alpha$ | We do not reject $H_0$. |
Type I and Type II Errors
Since tests are based on samples, statistical decisions can be wrong.
| Type of error | What happens? | Probability |
|---|---|---|
| Type I error | Rejecting $H_0$ when $H_0$ is true (false positive). | $\alpha$ |
| Type II error | Not rejecting $H_0$ when $H_0$ is false (false negative). | $\beta$ (depends on how far the true value is from $H_0$) |
The statistical power of a test is the probability of correctly rejecting $H_0$ when it is false:
For the same $\alpha$, power increases with the sample size and with the effect size.
One-Sided and Two-Sided Tests
The alternative hypothesis can take different forms. The choice is made before seeing the data, based on the question.
| Type of test | Alternative hypothesis | When to use it? |
|---|---|---|
| Two-sided | $H_1: \mu \neq \mu_0$ | When we want to know whether there is a difference in either direction. |
| Right-tailed | $H_1: \mu > \mu_0$ | When we only care whether the mean is greater than the reference value. |
| Left-tailed | $H_1: \mu < \mu_0$ | When we only care whether the mean is less than the reference value. |
Main Statistical Tests
| Test | Main use |
|---|---|
| Z-test | Testing a mean when the population standard deviation is known, or a proportion with a large sample. |
| Student's t-test | Testing means (one sample, two samples or paired data) when the population standard deviation is unknown. |
| Chi-square test | Testing association between categorical variables or goodness of fit to a distribution. |
| ANOVA | Comparing the means of two or more groups (used mostly with three or more). See Analysis of Variance. |
| Pearson correlation | Assessing the linear association between two quantitative variables. |
| Linear regression | Modeling the relationship between a response variable and one or more explanatory variables. |
Worked Example: Test for a Mean
Suppose (illustrative numbers) that a random sample of 36 service calls gave:
- sample size: $n = 36$;
- sample mean: $\bar{x} = 12$ minutes;
- sample standard deviation: $s = 6$ minutes;
- reference value (the company’s claim): $\mu_0 = 10$ minutes;
- significance level: $\alpha = 0.05$.
Hypotheses:
Conditions. The calls were randomly selected (independence). The population standard deviation is unknown, so we use the t statistic. With $n = 36$, the t distribution works even if the times are not exactly normal, as long as they are not very skewed.
Formula and substitution:
Arithmetic, one step per line:
Degrees of freedom:
Decision using the critical value. For a two-sided test at 5%, the critical value is the 97.5% quantile of the t distribution with 35 degrees of freedom: $t_{0.025;\,35} = 2.030$ (t table; in Julia, quantile(TDist(35), 0.975) gives 2.0301). Since $\lvert t \rvert = 2 < 2.030$, we do not reject $H_0$.
Decision using the p-value. $p = 2 \times P(T_{35} \geq 2) = 0.0533$ (in Julia, 2 * ccdf(TDist(35), 2)). Since $0.0533 > 0.05$, the decision is the same: do not reject $H_0$.
Check with the interval. The 95% interval is $12 \pm 2.0301 \times 1 = [9.97,\ 14.03]$ minutes. It contains 10, which agrees with not rejecting $H_0$.
Interpretation. The sample mean is 2 minutes above the advertised value, but with this sample size and this much variation, such a difference is not rare enough to rule out a true mean of 10 minutes. This does not prove that the mean is 10: the interval shows that values from about 10 up to 14 minutes are compatible with the data.
Effect Size
Not every statistically significant result matters in practice, and a non-significant result can hide a relevant effect measured with little precision.
So, besides the p-value, it is important to look at the effect size.
For a mean, a common measure is Cohen’s d, the difference measured in standard deviations:
In the previous example:
Interpretation: the sample mean is one third of a standard deviation above the advertised value. By the benchmarks Cohen (1988) proposed for the behavioral sciences (0.2 small, 0.5 medium, 0.8 large), this is an effect between small and medium. Cohen himself warned that these benchmarks are relative to the field; for service times, what matters is whether 2 extra minutes make a difference to the service.
Frequentist and Bayesian Inference
There are different ways of thinking about inference.
| Approach | Main idea |
|---|---|
| Frequentist | Treats parameters as fixed, unknown numbers; probability describes what would happen over many repetitions of the sampling. Uses p-values, confidence intervals and hypothesis tests. |
| Bayesian | Represents uncertainty about the parameters with probability distributions and updates them with data, through Bayes' Theorem. |
In Bayesian inference, the update can be summarized as follows (the symbol $\propto$ means “proportional to”):
In other words, we combine initial information (the prior) with the evidence brought by the data (the likelihood). This section of the site uses the frequentist approach.
Pitfalls in Statistical Inference
Statistical inference is powerful, but it must be used with care.
Some common mistakes are:
- concluding causation from correlation alone;
- treating a sample that was not randomly drawn (volunteers, whoever answered) as if it were random;
- ignoring the sample size;
- reading the p-value as the probability that the null hypothesis is true;
- choosing the test, or the hypotheses, after looking at the results;
- running many tests and reporting only the significant ones;
- ignoring the model’s assumptions;
- removing data without justification;
- confusing statistical significance with practical importance.
Overall Summary
| Concept | Main idea |
|---|---|
| Population | The complete set we want to study. |
| Sample | The part of the population used for analysis, ideally drawn at random. |
| Parameter | A fixed and usually unknown measure of the population. |
| Statistic | A measure computed from the sample; it varies from sample to sample. |
| Standard error | The standard deviation of the sampling distribution of a statistic. |
| Confidence interval | A range of plausible values for a parameter, produced by a method that succeeds in a known proportion of samples. |
| Hypothesis test | A procedure for assessing the evidence against a null hypothesis. |
| p-value | The probability of a result as extreme as or more extreme than the one observed, if $H_0$ is true. |
| Statistical power | The probability of detecting an effect when it really exists. |
Statistical inference is the bridge between the sample and the population. It lets us estimate parameters, test hypotheses and make decisions under uncertainty. More than applying formulas, doing inference requires interpreting results carefully, understanding the assumptions and recognizing the limits of the available data.
“All models are wrong but some are useful.”
— George E. P. Box, title of a section of “Robustness in the Strategy of Scientific Model Building” (1979), p. 202
References
- Box, G. E. P. (1979). Robustness in the Strategy of Scientific Model Building. In: Launer, R. L.; Wilkinson, G. N. (Eds.). Robustness in Statistics. Academic Press, pp. 201–236.
- Bussab, W. O.; Morettin, P. A. (2023). Estatística Básica. 10th ed. Saraiva Uni. (in Portuguese)
- Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences. 2nd ed. Lawrence Erlbaum Associates.
- Wasserstein, R. L.; Lazar, N. A. (2016). The ASA’s Statement on p-Values: Context, Process, and Purpose. The American Statistician, 70(2), 129–133. DOI: 10.1080/00031305.2016.1154108.