Back to homeMathematics · 2nd Bach. Social Sciences · Change subject
Start for free
BAC2 ss · Mathematics
Statistics · Inference

Confidence intervals

No study asks the whole population: a survey, a quality check or a poll always works with a sample. Statistical inference is the bridge that goes from that sample data to a statement about the whole population, with an explicit margin of error and a confidence level that tells you how far you can trust that margin.

Before you start, make sure you know: The normal distribution (1st Bachillerato)
Before you start, make sure you know: Approximating the binomial distribution with the normal (1st Bachillerato)

The sample mean as a random variable

Comparison between the normal curve of the general population and the narrower, more concentrated curve of the sample mean. X (population, n=1) X̄ (large sample): narrower
Practice★☆☆Not started
A social media analyst wants to study the daily time that Spanish teenagers aged between 15 and 18 spend on TikTok*. To do so, they randomly select 400 users in this age…

A social media analyst wants to study the daily time that Spanish teenagers aged between 15 and 18 spend on TikTok. To do so, they randomly select 400 users in this age group across the country and record their connection times.

Clearly identify the following elements of the statistical study:

  1. a) The population under study.
  1. b) The sample selected.
  1. c) The sample size.
  1. d) The statistic that would be calculated to summarise the information from the sample.
Solve
Practice★☆☆Not started
It is known that the waiting time in the queue of a popular theme park ride follows a normal distribution with a mean of $\mu = 45$ minutes and a standard deviation of…

It is known that the waiting time in the queue of a popular theme park ride follows a normal distribution with a mean of $\mu = 45$ minutes and a standard deviation of $\sigma = 12$ minutes.

If we choose a random sample of $n = 36$ visitors who have been on the ride:

  1. What distribution does the sample mean $\bar{X}$ follow? State its mean and standard deviation (standard error).

  2. Calculate the probability that the mean waiting time of this sample is greater than $48$ minutes.

Solve

Confidence interval for a mean

Diagram of the confidence interval for the mean centred on the sample mean x̄, with the maximum error E on both sides and the endpoints x̄ − E and x̄ + E. confidence interval x̄ E E x̄ − E x̄ + E
Practice★☆☆Not started
In statistical inference, the critical value $z_{\alpha/2}$ is essential for determining the width of a confidence interval. It is the value of the standard normal…

In statistical inference, the critical value $z_{\alpha/2}$ is essential for determining the width of a confidence interval. It is the value of the standard normal distribution $N(0, 1)$ that leaves an area $\alpha/2$ to its right, where $1-\alpha$ is the confidence level (in the figure, the central area is $1-\alpha$ and each tail is $\alpha/2$).

Using the standard normal distribution table $N(0, 1)$, find the critical values $z_{\alpha/2}$ corresponding to the following confidence levels:

  1. a) A confidence level of $90\,\%$.
  1. b) A confidence level of $95\,\%$.
  1. c) A confidence level of $99\,\%$.
Gaussian bell curve N(0, 1) with central area 1 − α between −z α/2 and z α/2 and two tails of area α/2z−zα/2zα/201 − αα/2α/2N(0, 1)
Solve
Practice★☆☆Not started
A courier company is studying the weight of packages it delivers in a city. The population is assumed to follow a normal distribution with a standard deviation of…

A courier company is studying the weight of packages it delivers in a city. The population is assumed to follow a normal distribution with a standard deviation of $\sigma = 0,8$ kg. A random sample of $n = 64$ packages is taken, obtaining a sample mean of $\bar{x} = 4,2$ kg.

Calculate a confidence interval for the mean weight of all packages delivered by the company, using a confidence level of $95\%$.

Solve
Practice★★★Not started
A well-known content creator is analysing how long his followers stay connected during his live e-sports streams. The connection time is known to follow a normal…

A well-known content creator is analysing how long his followers stay connected during his live e-sports streams. The connection time is known to follow a normal distribution with a standard deviation of $12$ minutes. After analysing a random sample of $144$ users, a confidence interval for the population mean of $(32,35; 36,25)$ has been obtained.

  1. a) Determine the value of the sample mean obtained and the confidence level used to construct this interval.
  1. b) If the streamer wants to reduce the width of this interval to one quarter while keeping the same confidence level, what should the minimum sample size be?
  1. c) Explain, without carrying out any additional calculations, what would happen to the precision of the estimate if we increased the sample size but also wanted to work with a confidence level higher than the one calculated in part a).
Bell curve with the confidence interval (32,35; 36,25) shaded, centered at the sample mean and with the margin of error E indicated E 1 − α 32,35 x̄ 36,25 n = 144 σ = 12
Solve

Confidence interval for a proportion

Diagram of the confidence interval for a proportion centred on the sample estimate with its margin of error on both sides. confidence interval p̂ E E p̂ − E p̂ + E
Practice★☆☆Not started
In a secondary school, it is suspected that $15\%$ of the students are left-handed. A random sample of $n = 100$ students is selected to check this. 1. What distribution…

In a secondary school, it is suspected that $15\%$ of the students are left-handed. A random sample of $n = 100$ students is selected to check this.

  1. What distribution does the sample proportion $\hat{p}$ of left-handed students follow? State its mean and standard deviation.

  2. Calculate the probability that the proportion of left-handed students in the selected sample is less than $18\%$.

Solve
Practice★☆☆Not started
We wish to estimate the proportion of households in a city that separate organic waste for recycling. To do so, a random sample of $n = 400$ households is surveyed, of…

We wish to estimate the proportion of households in a city that separate organic waste for recycling. To do so, a random sample of $n = 400$ households is surveyed, of which $160$ state that they separate this waste.

Determine the confidence interval for the proportion of households that recycle organic waste across the whole city, using a confidence level of $90\%$.

Solve
Practice★★☆Not started
In a survey carried out on $400$ students at a secondary school about the use of streaming platforms, $260$ said that they prefer watching TV series rather than films.…

In a survey carried out on $400$ students at a secondary school about the use of streaming platforms, $260$ said that they prefer watching TV series rather than films.

  1. a) Find the point estimate of the proportion of students who prefer series.
  1. b) Obtain a $97\,\%$ confidence interval for the true proportion of students who prefer series at that school.
Solve

Sample size and margin of error

Practice★★☆Not started
An estimate is to be made of the proportion of citizens who would be willing to use public transport if it were free. In a prior study the expected proportion is…

An estimate is to be made of the proportion of citizens who would be willing to use public transport if it were free. In a prior study the expected proportion is unknown, so maximum variance ($p = q = 0,5$) is assumed.

Determine the minimum sample size required to estimate this proportion with a maximum margin of error of $4 \%$ and a confidence level of $95,44 \%$ (which corresponds to a critical value of $z_{\alpha/2} = 2$).

Solve
Practice★★★Not started
A mobile phone company wants to estimate the proportion of teenagers who use "dark mode" on their devices at night. In an initial sample of $100$ users, $60\%$ confirmed…

A mobile phone company wants to estimate the proportion of teenagers who use "dark mode" on their devices at night. In an initial sample of $100$ users, $60\%$ confirmed using it.

  1. a) Calculate the $98\%$ confidence interval for the population proportion of users of this mode.
  1. b) Suppose that no prior information about the proportion is available (maximum uncertainty scenario). Determine the sample size needed for the maximum margin of error to be $0,02$ with a confidence level of $95\%$.
  1. c) If the proportion obtained in the initial sample ($0,6$) is used to calculate the sample size under the same conditions as in part b) (margin of error $0,02$ and confidence level $95\%$), how many fewer users would need to be surveyed compared to the maximum uncertainty scenario?
Solve

Relationship between confidence, error and sample size

The margin of error, the confidence level and the sample size are tied together: you cannot improve one without affecting another. Raising the confidence (more certainty) increases $z_{\alpha/2}$ and, all else being equal, widens the interval; the only way to gain precision without losing confidence is to increase $n$.

Visual comparison of confidence intervals showing how the width of the interval varies with the chosen confidence level and the sample size. large n: narrower high confidence: wider
Practice★★☆Not started
Two secondary schools, A and B, measure the mean time that their 2nd year Baccalaureate students spend studying mathematics per week. In both schools, it is known that…

Two secondary schools, A and B, measure the mean time that their 2nd year Baccalaureate students spend studying mathematics per week. In both schools, it is known that the population standard deviation is $1,5$ hours.

A sample of $100$ students is taken in each school. In school A, the confidence interval obtained for the mean has a width of $0,588$ hours. In school B, the confidence interval obtained for the mean is $(6,2; 7,2)$.

  1. a) Determine the confidence level used in school A.
  2. b) Determine the confidence level used in school B.
  3. c) Which of the two schools has made a more precise estimate? Justify your answer.
Solve
Practice★★☆Not started
An "eco-friendly" clothing brand claims that $30\,\%$ of its customers are under $20$ years old. To check this, a random sample of $500$ customers is taken and it is…

An "eco-friendly" clothing brand claims that $30\,\%$ of its customers are under $20$ years old. To check this, a random sample of $500$ customers is taken and it is observed that $135$ of them are under $20$ years old.

  1. a) Construct a $99\,\%$ confidence interval for the proportion of customers under $20$ years old based on the sample data.
  1. b) In view of the result, can we consider the brand's claim to be consistent with the data obtained at a $99\,\%$ confidence level? Explain why.
Solve
Practice★★★Not started
The reaction time of pilots using a state-of-the-art flight simulator follows a normal distribution with unknown mean and standard deviation of $0,05$ seconds. On taking…

The reaction time of pilots using a state-of-the-art flight simulator follows a normal distribution with unknown mean and standard deviation of $0,05$ seconds. On taking a sample of $64$ pilots, a mean of $0,42$ seconds is observed.

  1. a) Obtain the confidence interval for the population mean at a confidence level of $97\%$.
  1. b) The simulator manufacturer claims that the mean reaction time is $0,40$ seconds. Is this claim compatible with the interval obtained in the previous part? Justify your answer based on the relationship between confidence intervals and population parameters.
  1. c) If it is decided to double the sample size and reduce the confidence level to $90\%$, how will this affect the width of the interval? Calculate the factor by which the width is reduced or increased.
Solve

Lab: intervals, simulation and decision-making

A fictitious survey randomly selects 400 households from a large population; 160 say they separate organic waste. Assume independent observations. Design the record sheet beforehand: population, sampling frame, selection, non-response, variable and confidence. A voluntary selection through a social network is not validated by calculating a narrow interval.

from math import sqrt, ceil, comb

from statistics import NormalDist

from random import Random

normal = NormalDist()

n, exitos, confianza = 400, 160, 0.90

p = exitos/n

z = normal.inv_cdf((1+confianza)/2)

E = z*sqrt(p*(1-p)/n)

print('IC proporción:', p-E, p+E)

print('n para error 0.04 al 95%:', ceil(normal.inv_cdf(.975)**2*.25/.04**2))

print('Binomial: exactamente 6 de 10, p=.4:', comb(10,6)*.4**6*.6**4)

print('Normal: P(X<=4.4), mu=4.2, sigma=.8:', NormalDist(4.2,.8).cdf(4.4))

# Simulación del IC de una media con sigma conocida:

rng = Random(2026)

mu, sigma, tamano, repeticiones = 50, 10, 25, 1000

margen = normal.inv_cdf(.975)*sigma/sqrt(tamano)

cubren = 0

for _ in range(repeticiones):

    media = sum(rng.gauss(mu,sigma) for _ in range(tamano))/tamano

    cubren += media-margen <= mu <= media+margen

print('Fracción de intervalos que cubren mu:', cubren/repeticiones)

Intervals change from sample to sample; the model parameter stays fixed:

Simulation diagram comparing three different sample intervals with the fixed value of the population mean, where two capture it and one misses it.μ fixedTwo intervals cover μ; the third does not (diagram)

Change $n$ and the confidence level, keeping the same observed proportion, and compare widths. Distinguish standard error from margin. For quantitative data, also calculate the mean and the sample standard deviation (with divisor $n-1$) using a spreadsheet: the latter estimates $\sigma$, but it does not automatically turn a normal interval into an exact one if $\sigma$ is unknown. Hand in the data, the procedure, the checks and the limits of the decision.

Summary

See all the exercises in this section