Module 8 · Statistics for Data Analysis
Confidence intervals
Turn a sample's answer into an honest range with a 95% confidence interval for a mean (CONFIDENCE.T) or a percentage, interpret it correctly, and use it to say when a difference might just be noise.
About 25 minutes
The problem
Ashgrove Chambers is negotiating an overdraft with its bank, sized to cover the gap between issuing invoices and getting paid. The finance partner asks:
"How long do clients take to pay? The bank wants a number we can stand behind."
The average across the 327 paid invoices so far is 45.4 days. But those invoices are a sample of the firm's billing, and next year's clients won't behave identically. "45.4 days" sounds more precise than it is. A confidence interval says how precise it really is: "between about 43 and 48 days, with 95% confidence". That's a number the firm can stand behind, and it tells the bank how much buffer to allow.
The concept
What a confidence interval is
A 95% confidence interval is a range built from a sample so that, if you repeated the sampling many times, 95% of the ranges built this way would contain the true value. In practice: it's the range of values the true number plausibly lies in, given the sample.
It's built from the standard error (lesson 7):
estimate ± margin of error, where for a mean the margin ≈ 1.96 × SE
The 1.96 comes from the normal distribution: 95% of values lie within 1.96 SDs of the mean.
For a mean, in Excel
Excel formula
=CONFIDENCE.T(0.05, STDEV.S(range), COUNT(range))returns the margin of error for a 95% interval (0.05 = 5% left over). The interval is AVERAGE(range) ± margin. CONFIDENCE.T uses the t-distribution, which makes the interval slightly wider for small samples. With more than about 30 values it's almost the same as 1.96 × SE.
For a percentage (a proportion)
For a share p (as a decimal) from n observations:
margin = 1.96 × √( p × (1 − p) ÷ n )
In Excel: =1.96 * SQRT(p * (1 - p) / n). This works well when there are at least 10 "yes" and 10 "no" answers; for rarer events, use a bigger sample.
Reading intervals correctly
- Wider interval = less certain. Smaller samples and noisier data give wider intervals.
- Overlapping intervals for two groups mean the difference might be chance; the formal check is a test (next lesson). Intervals that don't overlap at all mean the difference is very unlikely to be chance.
- An interval only covers sampling error. It says nothing about a biased sample, bad data, or a change in the future.
- Don't say "there's a 95% chance the true value is in this interval". Say "we're 95% confident the true value is between X and Y". (The true value is fixed; it's the interval that varies.)
Choosing the confidence level
95% is the convention. 90% gives a narrower interval with less confidence; 99% a wider one with more. Use CONFIDENCE.T(0.10, …) for 90% or CONFIDENCE.T(0.01, …) for 99%. Pick one before you look at the results, and say which you used.
Example
Ashgrove's days to pay, for the 327 paid invoices:
Excel formula
=AVERAGE(days) 45.4
=STDEV.S(days) 25.6
=CONFIDENCE.T(0.05, STDEV.S(days), COUNT(days)) 2.8The 95% confidence interval is 45.4 ± 2.8: about 42.6 to 48.2 days.
For the bank: "Clients pay in 45 days on average; we're 95% confident the true average is between 43 and 48 days. Individual invoices vary much more (some take 90 days), so the overdraft should cover the slow payers, not just the average." The last sentence matters: the interval is about the average, not about any one invoice.
A percentage, from the HR data: 103 of 1,518 June attendance records were Late, 6.8%.
Excel formula
=1.96 * SQRT(0.0679 * (1 - 0.0679) / 1518) 0.0127, or 1.3 percentage pointsSo the lateness rate is 6.8% ± 1.3 pp: between about 5.5% and 8.1%. One month of data pins it down fairly well.
Walkthrough
- Open the legal
invoices.csvand adddays_to_pay(blank for unpaid invoices), as in lesson 2. - Calculate the mean,
STDEV.S,COUNTand the margin withCONFIDENCE.T(0.05, …). Write the 95% interval. - Recalculate with 0.10 and 0.01 to get the 90% and 99% intervals. Which is widest?
- Open the HR
attendance.csv. Calculate the share of records that are Late and its 95% margin with the proportion formula. - In the logistics data, calculate the on-time rate for delivered Air shipments and its 95% interval.
- Write the sentence you'd give the bank, including what the interval does not cover.
Practice
Practice
What is the 95% margin of error (CONFIDENCE.T(0.05, …)) for the mean days to pay, across the paid invoices? Two decimal places.
Practice
What is the lower end of the 95% confidence interval for mean days to pay? One decimal place.
Practice
Air freight on-time delivery is 75.3% across 275 delivered shipments. What is the 95% margin of error, in percentage points? One decimal place.
Challenge
Challenge · optional
A customer survey finds that 60% of 50 customers are satisfied. How many customers would you need for a 95% margin of error of about ±5 percentage points (assuming the share stays near 60%)? Round up to a whole customer.
Check your understanding
Answer every question to check.