Chapter 7: Confidence Intervals
Learning Objectives
- Explain why a point estimate on its own isn't enough to support a business decision.
- Build a confidence interval for a mean as estimate ± critical value × standard error, and explain why it uses the t distribution.
- Compute a 95% confidence interval for a mean in Excel cells, and check it with
CONFIDENCE.T. - Interpret a confidence level correctly, and recognize the common wrong interpretations.
- Compute and check a confidence interval for a proportion, and state its conditions.
- Explain how sample size and confidence level affect the margin of error, and plan the sample size needed for a target margin.
- Ask an AI for confidence intervals in R for Excel, read the output, and explain small differences between R and Excel.
7.1 How Much Does a Customer Spend?
Dana Whitfield is planning next year's budget. Two numbers drive most of it. The first is how much a customer spends on a typical visit. The second is how many customers would recommend Ridgeline to a friend, because word of mouth is how a small chain grows. She asks you for both.
You already know the survey answers. In Chapter 4. Describing Data, you found that the 600 surveyed customers spent an average of $8.48 per visit. In Chapter 1. Statistics, Data, and AI in Business, you saw that 407 of them (67.8%) would recommend Ridgeline. But Dana isn't budgeting for 600 people. She's budgeting for every customer who walks in next year. So her real question is: what do all Ridgeline customers spend on average, and what share of all of them would recommend us?
Nobody knows those population values exactly. In Chapter 6. Sampling and the Central Limit Theorem, you saw that a different sample of 600 customers would have given a slightly different average. This chapter turns that idea into a tool you'll use constantly: a range of plausible values for a population parameter, with a stated level of confidence. By the end, you'll be able to tell Dana something like "the average spend is between $8.27 and $8.68, with 95% confidence," and explain exactly what that sentence means.
7.2 The Point Estimate and Why It Isn't Enough
The simplest answer to Dana's question is the sample mean: $8.48. It's the best single guess you have for the population mean. A single number used this way is called a point estimate.
Point estimate — A single number, calculated from a sample, used as the best guess for a population parameter. The sample mean is the point estimate of the population mean, and the sample proportion is the point estimate of the population proportion.
A point estimate is useful, but on its own it hides something important: how far off it might be. Consider two analysts who both report "average spend is $8.48."
- The first surveyed 600 customers.
- The second surveyed 5.
Both reports look identical. You'd trust the first far more, because you know from Chapter 6. Sampling and the Central Limit Theorem that averages from small samples bounce around much more than averages from large ones. A point estimate says nothing about that. It doesn't tell Dana whether the true average could plausibly be $8.00 or $9.00, and that difference matters. With about 1.56 million transactions a year, a 50-cent error in average spend is a budget error of roughly three-quarters of a million dollars.
What Dana needs is the point estimate plus a statement of its precision. That's what a confidence interval gives her.
7.3 From Standard Error to an Interval
You already have the key ingredient. In Chapter 6. Sampling and the Central Limit Theorem, you met the standard error: the standard deviation of the sampling distribution of a statistic. For a sample mean, it measures how far a typical sample mean lands from the population mean. You also learned that, thanks to the central limit theorem, sample means from reasonably large samples follow a sampling distribution that is close to normal and centered on the population mean.
Put those two facts together with the empirical rule from Chapter 5. Probability and Distributions. About 95% of the values in a normal distribution fall within about 2 standard deviations of its center. Here the "values" are possible sample means, the center is the population mean μ, and the standard deviation is the standard error. So:
In about 95% of all possible samples, the sample mean lands within about 2 standard errors of the population mean.
Now flip that sentence around. If the sample mean is usually within 2 standard errors of μ, then μ is usually within 2 standard errors of the sample mean. So if you start at your sample mean and reach out 2 standard errors in each direction, the range you mark off will contain μ for about 95% of all samples. That range is a confidence interval.
A diagram in two rows. Top row: a normal curve labelled "sampling distribution of the sample mean," centered on a vertical line labelled μ, with the middle 95% shaded and the edges marked "μ − 2 SE" and "μ + 2 SE." Several dots on the axis mark sample means, most inside the shaded area. Bottom row: the same dots, each with a horizontal bar of width ± 2 SE drawn around it. The bars from dots inside the shaded area cross the μ line; the bars from the one or two dots outside it miss. Caption: "If the sample mean is within 2 SE of μ, the interval around it reaches μ."
Every confidence interval in this book has the same shape:
estimate ± critical value × standard error
- The estimate is the point estimate: a sample mean or a sample proportion.
- The standard error measures how much that estimate varies from sample to sample.
- The critical value sets how many standard errors to reach out. It comes from a distribution (normal or t) and depends on how confident you want to be. For 95% with a normal distribution, it's 1.96, the precise version of "about 2."
The part after the ± is called the margin of error.
Confidence interval — A range of values, calculated from a sample, that gives plausible values for a population parameter. It's built as estimate ± margin of error, using a method that captures the true parameter in a known share of samples.
Margin of error — The distance from the point estimate to either end of a confidence interval: critical value × standard error. A smaller margin of error means a more precise estimate.
Confidence level — The share of all possible samples for which the interval-building method captures the true parameter, such as 90%, 95% or 99%. It describes the method, not any one interval.
In symbols, for a mean:
x̄ ± t* × s / √n
where x̄ is the sample mean, s is the sample standard deviation, n is the sample size, s / √n is the standard error, and t* is the critical value. The next section explains why the critical value comes from a t distribution rather than the normal distribution.
7.4 Why t Instead of z
The standard error of a mean is σ / √n, where σ is the population standard deviation. There's a catch: you almost never know σ. If you knew everything about the population, you wouldn't need a sample. So you use the sample standard deviation s in its place.
That substitution adds a second source of uncertainty. The sample mean varies from sample to sample, and so does s. In a small sample, s can easily come out too small, by chance. When it does, the standard error looks smaller than it really is, and an interval built with 1.96 standard errors would be too narrow. It would miss μ more often than 5% of the time.
The fix, worked out by William Gosset at the Guinness brewery in 1908, is to use a slightly wider multiplier taken from a different distribution: the t distribution. It looks like the standard normal distribution (bell-shaped, centered on 0, symmetric), but it has heavier tails, which means more of its area is far from the center. Heavier tails mean larger critical values, which mean wider intervals. That extra width pays for not knowing σ.
t distribution — A bell-shaped, symmetric distribution centered on 0, with heavier tails than the standard normal distribution. It's used in place of the normal distribution when the standard error is calculated from the sample standard deviation. Its exact shape depends on its degrees of freedom.
How much heavier the tails are depends on how much information you have about spread, which is measured by the degrees of freedom. For a single mean, the degrees of freedom are n − 1.
Why n − 1 and not n? To calculate s, you first calculate the sample mean, and then you measure how far each value is from it. Those distances always add up to zero. So once you know n − 1 of them, the last one is fixed: it has to be whatever makes the total zero. Only n − 1 of the distances are free to vary, so only n − 1 pieces of information go into estimating spread. With three numbers whose mean is 5, if two of them are 4 and 7, the third must be 4. You had three numbers but only two free choices.
Degrees of freedom — The number of independent pieces of information available to estimate variability. For a confidence interval or test about one mean, it's n − 1. The t distribution's shape depends on it: more degrees of freedom means lighter tails and a shape closer to the standard normal.
The table below shows the 95% critical value for several degrees of freedom. You can reproduce every number in it with =T.INV.2T(0.05, df), and the last row with =NORM.S.INV(0.975).
| Sample size n | Degrees of freedom | 95% critical value t* |
|---|---|---|
| 5 | 4 | 2.776 |
| 10 | 9 | 2.262 |
| 25 | 24 | 2.064 |
| 100 | 99 | 1.984 |
| 600 | 599 | 1.964 |
| (σ known) | z* = 1.960 |
With 5 observations, you reach out 2.78 standard errors instead of 1.96. That's a big penalty for having so little information. By 100 observations, the difference is small, and at 600 it's almost gone: 1.964 versus 1.960. With large samples, t and z give practically the same interval. Statistical software uses t for means anyway, because it's correct at every sample size, and this book does the same.
What
T.INV.2Tdoes.T.INV.2T(0.05, df)returns the t value that leaves 2.5% in each tail and 95% in the middle, which is the critical value a 95% interval needs. The "2T" means "two-tailed."
7.5 Prepare the Data in Excel
Open the Ridgeline workbook. You'll work with the Survey Table, which has one row per survey response. Two columns matter in this chapter:
spend: dollars spent on the visit, a continuous numeric variable.would_recommend: Yes or No, a categorical variable with two values.
Before building any interval, check the data. Confirm that spend has no blanks and no text: =COUNT(Survey[spend]) should return 600, the same as =ROWS(Survey[spend]). Confirm that would_recommend holds only "Yes" and "No": =COUNTIF(Survey[would_recommend],"Yes")+COUNTIF(Survey[would_recommend],"No") should also return 600. A quick histogram of spend (Insert > Insert Statistic Chart > Histogram) shows a roughly symmetric, single-peaked shape, which matches the skewness of −0.03 you found earlier. That shape matters later, when you check the interval's assumptions.
Now make a working sheet. Right-click the Survey sheet tab, choose Insert… > Worksheet, and rename the new sheet CI (double-click its tab and type). You'll build both intervals on this sheet.
7.6 How the Interval Works: Mean Spend
This is the core of the chapter. You'll build a 95% confidence interval for the mean spend of all Ridgeline customers, one cell at a time, so you can see every piece.
7.6.1 The worked example, cell by cell
On the CI sheet, type the labels in column A and the formulas in column B:
| Cell | Label (column A) | Formula (column B) | Result |
|---|---|---|---|
| B1 | Sample mean | =AVERAGE(Survey[spend]) |
8.475 |
| B2 | Sample SD | =STDEV.S(Survey[spend]) |
2.584 |
| B3 | n | =COUNT(Survey[spend]) |
600 |
| B4 | Standard error | =B2/SQRT(B3) |
0.1055 |
| B5 | Confidence level | 0.95 (typed in) |
0.95 |
| B6 | Critical value t* | =T.INV.2T(1-B5,B3-1) |
1.9639 |
| B7 | Margin of error | =B6*B4 |
0.207 |
| B8 | Lower limit | =B1-B7 |
8.268 |
| B9 | Upper limit | =B1+B7 |
8.682 |
Read the cells as a story:
- B1 to B3 summarize the sample: the average customer in the survey spent $8.475, individual spends typically varied by about $2.58 from that average, and there are 600 responses.
- B4 is the standard error. Individual customers vary by $2.58, but an average of 600 customers varies much less: by about $0.11 from sample to sample. Dividing by √600 (about 24.5) is what shrinks it.
- B6 is the critical value for 95% confidence with 599 degrees of freedom.
1-B5turns the confidence level into the 0.05 thatT.INV.2Texpects. Using a cell for the level, instead of typing 0.05 into the formula, lets you change the level later and watch everything update. - B7 is the margin of error: 1.964 standard errors, or about 21 cents.
- B8 and B9 are the interval: $8.27 to $8.68.
The CI sheet in Excel with labels in A1:A9 and formulas in B1:B9 as in the table above. Cell B6 is selected, so the formula bar shows =T.INV.2T(1-B5,B3-1). Number formats show 3 decimals for B1, B7, B8 and B9, and 4 decimals for B4 and B6.
Give the cells names. Select B1, click in the Name Box (left of the formula bar), type
xbarand press Enter. Do the same fors,nandse. Then the standard error formula can read=s/SQRT(n), which is much easier to check. Named ranges were introduced in Chapter 2. Working with AI and R for Excel.
7.6.2 Check it with CONFIDENCE.T
Excel has a function that computes the margin of error in one step. In B10, type the label "Margin (CONFIDENCE.T)" in A10 and this formula in B10:
=CONFIDENCE.T(1-B5,B2,B3)
It takes the significance (0.05), the sample standard deviation and the sample size, and returns 0.2072, the same margin as B7. This is the book's "two tools, one answer" habit at small scale: you computed the margin from its parts, and Excel's built-in function agrees.
CONFIDENCE.Treturns only the margin of error, not the interval. You still add it to and subtract it from the mean. Also watch its first argument: it wants 0.05 for a 95% interval, not 0.95. Typing 0.95 gives a tiny margin for a 5% interval, which is a silent and serious error. Its older cousinCONFIDENCE.NORMuses z instead of t; for a mean with unknown σ, useCONFIDENCE.T.
7.6.3 Changing the confidence level
Change B5 to 0.90, then to 0.99, and watch the interval change. Here is what you'll see:
| Confidence level | Critical value t* | Margin of error | Interval |
|---|---|---|---|
| 90% | 1.647 | $0.174 | $8.30 to $8.65 |
| 95% | 1.964 | $0.207 | $8.27 to $8.68 |
| 99% | 2.584 | $0.273 | $8.20 to $8.75 |
Higher confidence means a wider interval. That's the basic trade-off. To be more sure your net catches the true mean, you need a bigger net. A 100% confidence interval would have to run from the smallest possible spend to the largest, which is useless. Nobody can be completely sure and precise from a sample.
95% is the business and scientific convention. It's a sensible balance, but it isn't a law of nature. A manager deciding on something cheap and reversible might be happy with 90%. A decision that is expensive or hard to undo might call for 99%.
A coincidence worth noticing. At 99%, the critical value
T.INV.2T(0.01,599)is 2.584, and the sample standard deviation of spend is also 2.584. That's pure chance. They're different quantities that happen to share three decimals. If you ever see the same number in two places on your sheet, check that each formula points where you think it does.
7.6.4 What "95% confident" actually means
This is the most misunderstood idea in introductory statistics, so take it slowly.
The population mean μ is a fixed number. It isn't random. You don't know it, but it doesn't change from sample to sample. What changes is your interval. Each possible sample of 600 customers gives a different mean, a different standard deviation, and so a different interval. Some of those intervals contain μ, and some miss it.
The 95% describes that whole collection of possible intervals. If you repeated the survey over and over, drawing a new random sample each time and building a 95% interval each time, about 95% of those intervals would contain μ. The 95% is the method's long-run hit rate.
Your one interval, $8.27 to $8.68, either contains μ or it doesn't. You can't know which. But you used a method that works 95% of the time, and that's why you can say you're "95% confident" in it. It's like trusting a forecaster who is right 95% of the time: you never know whether today is one of the misses, but you have good reason to trust the forecast.
Common wrong interpretations of a 95% confidence interval. Each of these sounds reasonable and is wrong:
- "There's a 95% probability that μ is between $8.27 and $8.68." After you've computed the interval, μ is either in it or not. The 95% belongs to the method, not to this particular interval.
- "95% of customers spend between $8.27 and $8.68." The interval is about the average, not about individuals. Individual spends range from $2.25 to $16.54, and most customers spend outside this narrow interval.
- "95% of sample means fall between $8.27 and $8.68." Sample means cluster around μ, not around your sample mean.
- "If we repeated the survey, there's a 95% chance the new mean would fall in this interval." Again, this treats your interval as the center of things. It isn't.
A safe sentence to use: "We are 95% confident that the average spend of all Ridgeline customers is between $8.27 and $8.68." If someone asks what "95% confident" means, say: "The method we used captures the true average in 95% of samples."
7.6.5 See the 95% for yourself
You can watch the long-run hit rate happen with a simulation like the ones in Chapter 6. Sampling and the Central Limit Theorem. Treat the 600 survey spends as if they were the whole population, so the "true" mean is known: μ = 8.475. Then draw many small samples from it, build an interval from each, and count how many contain 8.475.
Insert a new sheet named
Coverage.In A1 type
Lower, in B1Upper, in C1Hit?.In A2, enter this formula, which draws 25 random spends, computes their mean and margin, and returns the lower and upper limits side by side:
=LET(x,INDEX(Survey[spend],RANDARRAY(25,1,1,600,TRUE)),m,AVERAGE(x),e,CONFIDENCE.T(0.05,STDEV.S(x),25),HSTACK(m-e,m+e))In C2, enter
=AND(A2<=8.475,B2>=8.475). It shows TRUE if the interval contains the true mean.Select A2:C2 and drag the fill handle down to row 101, giving 100 intervals.
In E1, count the hits:
=COUNTIF(C2:C101,TRUE).
Press F9 to draw 100 new samples. The count changes every time, but it usually lands somewhere in the low-to-high 90s, centered near 95. A few intervals miss, through no fault of the method. That's the 5%.
The Coverage sheet: columns A and B show 100 rows of lower and upper limits, column C shows TRUE/FALSE, with conditional formatting that highlights the FALSE rows in light red. E1 shows a hit count such as 94. Beside it, an error-bar style chart of the first 30 intervals as horizontal lines, with a vertical line at 8.475; the one or two misses are drawn in red.
7.6.6 Assumptions behind the t interval
A t interval for a mean gives honest 95% coverage when these conditions hold:
- The sample is random, or close to it. The interval accounts for random sampling error only. It does nothing about bias. If Ridgeline had surveyed only its happiest customers, the interval would be precise and wrong.
- Observations are independent. One customer's spend doesn't affect another's. That's reasonable for a survey of different customers on different days.
- The sampling distribution of the mean is close to normal. This holds if the data themselves are roughly normal, or if the sample is large enough for the central limit theorem to do its work. A common rule of thumb is that n of 30 or more is enough unless the data are strongly skewed or have extreme outliers. With 600 roughly symmetric spends, this condition is easily met.
With small samples (say, under 30), look at a histogram first. If it's strongly skewed or has an extreme outlier, the t interval may not be trustworthy, and you should say so.
7.7 A Confidence Interval for a Proportion
Dana's second question is about a Yes/No variable: what share of all Ridgeline customers would recommend it? The parameter here is a population proportion, usually written p. The point estimate is the sample proportion, p̂ ("p-hat"): 407 Yes answers out of 600, or 0.678.
The interval has the same shape as before: estimate ± critical value × standard error. Two pieces change.
- The standard error of a proportion is √(p̂(1 − p̂) / n). You met this formula in Chapter 6. Sampling and the Central Limit Theorem, where the standard error of the recommend proportion for n = 600 came out to 0.019. Notice that it doesn't need a separate standard deviation: for a Yes/No variable, the spread is determined by the proportion itself.
- The critical value comes from the normal distribution, not the t distribution. There's no separately estimated standard deviation here, so the reason for using t doesn't apply. For 95%, the critical value is z* =
NORM.S.INV(0.975)= 1.960. The 0.975 leaves 2.5% in the upper tail, and by symmetry another 2.5% in the lower tail.
7.7.1 The worked example, cell by cell
On the CI sheet, starting in D1 (labels) and E1 (formulas):
| Cell | Label (column D) | Formula (column E) | Result |
|---|---|---|---|
| E1 | Yes count | =COUNTIF(Survey[would_recommend],"Yes") |
407 |
| E2 | n | =COUNTA(Survey[would_recommend]) |
600 |
| E3 | Sample proportion p̂ | =E1/E2 |
0.678 |
| E4 | Standard error | =SQRT(E3*(1-E3)/E2) |
0.0191 |
| E5 | Critical value z* | =NORM.S.INV(0.975) |
1.960 |
| E6 | Margin of error | =E5*E4 |
0.0374 |
| E7 | Lower limit | =E3-E6 |
0.641 |
| E8 | Upper limit | =E3+E6 |
0.716 |
The 95% confidence interval for the share of all customers who would recommend Ridgeline runs from 0.641 to 0.716, or about 64% to 72%. That's the inferential statement you saw previewed in Chapter 1. Statistics, Data, and AI in Business. Now you know where it came from.
To check the margin, use CONFIDENCE.NORM. It's built for means with a known σ, but for a proportion the "σ" is √(p̂(1 − p̂)), so you can feed it that:
=CONFIDENCE.NORM(0.05,SQRT(E3*(1-E3)),E2)
It returns 0.0374, matching E6.
Margins of error for proportions are often reported in percentage points. A margin of 0.0374 is 3.7 percentage points. News reports of polls ("52% support, margin of error ±3 points") are confidence intervals for proportions, almost always at 95%.
7.7.2 Conditions for the proportion interval
This formula (often called the Wald or normal-approximation interval) relies on the sampling distribution of p̂ being close to normal. That's true when:
- The sample is random and the observations are independent, as for the mean.
- There are enough of each answer. A common rule is at least 10 "successes" and at least 10 "failures" in the sample. Here there are 407 Yes and 193 No, far more than enough.
When either count is small, for example if you're estimating the share of customers who complain and only 4 of 80 did, the simple formula can give poor intervals, sometimes even below 0. Software offers better methods for those cases, which you'll meet when you run this in R.
7.8 Sample Size and Precision
7.8.1 Why 600 responses beat 25
Suppose the survey had stopped after the first 25 responses (R0001 through R0025). You can build that interval yourself. In a spare area of the CI sheet, use TAKE to grab the first 25 spends:
- Mean:
=AVERAGE(TAKE(Survey[spend],25))→ 9.506 - SD:
=STDEV.S(TAKE(Survey[spend],25))→ 3.022 - Margin:
=CONFIDENCE.T(0.05,STDEV.S(TAKE(Survey[spend],25)),25)→ 1.247
The 95% interval from 25 responses runs from $8.26 to $10.75. From all 600, it runs from $8.27 to $8.68.
Three things stand out.
- The small-sample interval is about six times wider. It spans about $2.50, which is too vague to budget with.
- Its point estimate is noticeably off. The first 25 customers happened to spend more, averaging $9.51. That's exactly the sampling variability you studied in Chapter 6. Sampling and the Central Limit Theorem.
- Its interval still contains the larger sample's estimate. The wide interval was honest about its own uncertainty. It didn't claim more precision than 25 responses could give.
The margin of error shrinks with √n, not with n. To cut the margin in half, you need four times as many observations. Going from 600 to 2,400 responses would shrink the spend margin from about $0.21 to about $0.10. Each extra bit of precision costs more than the last, which is why surveys rarely go beyond a few thousand responses.
7.8.2 Planning a sample size
Often you know the precision you need before you collect any data. Suppose Dana says: "Next year, I want to know average spend to within 25 cents, with 95% confidence." How many customers should you survey?
Start from the margin of error, E = z* × σ / √n, and solve it for n:
n = (z* × σ / E)²
Then round up, because rounding down would give a margin slightly bigger than the target. Two practical points:
- Use z*, not t*. The t critical value depends on n, which is the thing you're solving for. With samples in the hundreds, the difference between t* and z* is negligible.
- You need a guess for σ. Use the standard deviation from a previous survey or a small pilot. This year's survey gives 2.584.
In Excel:
=ROUNDUP((NORM.S.INV(0.975)*STDEV.S(Survey[spend])/0.25)^2,0)
returns 411. A survey of 411 customers should give a margin of error of about $0.25. This year's 600 gave a margin of $0.21, which is consistent: more responses than needed, so a slightly smaller margin.
For a proportion, the formula is the same with √(p(1 − p)) in place of σ:
n = (z* / E)² × p(1 − p)
Suppose Marcus wants next year's recommend share to within ±3 percentage points (E = 0.03). If you have no idea what p will be, use p = 0.5, which gives the largest possible p(1 − p) and so the safest (largest) sample size:
=ROUNDUP((NORM.S.INV(0.975)/0.03)^2*0.5*(1-0.5),0) → 1,068
If you trust this year's 0.678 as a guide, use it instead (here, from cell E3):
=ROUNDUP((NORM.S.INV(0.975)/0.03)^2*E3*(1-E3),0) → 932
The 1,068 is why national polls so often survey "about 1,000 people": it's the sample size that guarantees ±3 points at 95% whatever the true proportion is.
The population size barely matters. Notice that neither formula mentions how many customers Ridgeline has in total. As long as the sample is a small fraction of the population, precision depends on the sample size, not the population size. A random sample of 1,068 measures a city of 100,000 or a country of 300 million with about the same precision.
7.9 Intervals by Region
Marcus wants to know whether average spend differs by region. Confidence intervals give you a useful first look. The survey doesn't record region, so you'll look it up from the Stores Table.
Add a region column to the Survey Table.
- Go to the
Surveysheet and click the first empty cell to the right of the Table's header row (the cell right ofwould_recommend). - Type
regionand press Enter. Excel extends the Table to include the new column. - In the first data cell of the new column, type
=XLOOKUP([@store_id],Stores[store_id],Stores[region])and press Enter. The Table fills the formula down all 600 rows.
Build the region summary. On the CI sheet, starting in G1, type the headers Region, n, Mean, SD, Margin, Lower, Upper. In G2:G4, type Metro, Mountain and Suburban. Then in row 2:
| Column | Formula in row 2 |
|---|---|
| n (H) | =COUNTIFS(Survey[region],G2) |
| Mean (I) | =AVERAGEIFS(Survey[spend],Survey[region],G2) |
| SD (J) | =STDEV.S(FILTER(Survey[spend],Survey[region]=G2)) |
| Margin (K) | =CONFIDENCE.T(0.05,J2,H2) |
| Lower (L) | =I2-K2 |
| Upper (M) | =I2+K2 |
Copy row 2 down to rows 3 and 4. FILTER returns only the spends for that row's region, and STDEV.S measures their spread. Excel has no STDEV.SIFS function, so FILTER fills that gap.
| Region | n | Mean spend | 95% CI |
|---|---|---|---|
| Metro | 217 | $8.33 | $7.97 to $8.69 |
| Mountain | 190 | $8.40 | $8.03 to $8.76 |
| Suburban | 193 | $8.72 | $8.36 to $9.08 |
Each region's interval is wider than the overall one (about ±$0.36 versus ±$0.21), because each is based on about a third of the data.
Chart it. Select G1:G4 and I1:I4 (hold Ctrl to select the second range), then choose Insert > Insert Column or Bar Chart > Clustered Column. Click the chart, then Chart Design > Add Chart Element > Error Bars > More Error Bar Options. Under Error Amount, choose Custom, click Specify Value, and set both the positive and negative error values to =CI!$K$2:$K$4. Each bar now shows its 95% interval.
A clustered column chart of mean spend for Metro, Mountain and Suburban, with custom error bars showing each 95% confidence interval. The vertical axis starts at 7.50 so the differences are visible, and the axis title says "Mean spend per visit (dollars)". The Format Error Bars pane is open on the right, with Custom selected.
What does the chart say? Suburban customers spent the most in the sample, $8.72 versus about $8.33 to $8.40 elsewhere. But all three intervals overlap substantially. Metro's interval reaches up to $8.69, and Suburban's reaches down to $8.36. The data are consistent with all three regions having the same average spend, or with real differences of a few tens of cents. This sample can't tell those apart.
Overlapping intervals are a rough guide, not a test. Two intervals that overlap a little can still come from groups whose means differ significantly. Intervals that don't overlap do point to a real difference, but checking overlaps one pair at a time gets unreliable with several groups. The right tool for comparing several group means at once is analysis of variance, in Chapter 10. Comparing Many Groups: ANOVA.
7.10 Describe the Data to AI
Now do the same analysis with R for Excel, so you can compare it with your hand-built version. Open the app in JOLT. In 1. Data, click Add a table… and choose Survey. The app lists the columns and their types. If you added the region column, it appears too; that's fine.
In 2. Ask your AI, type your data description. The app already tells the AI each column's name, type and range. Your job is to say what the columns mean and what you want:
Each row of Survey is one customer's response to Ridgeline Coffee's 2025 survey
(600 responses, one per customer visit). spend is the dollars the customer spent
on that visit. would_recommend is Yes or No: whether the customer would recommend
Ridgeline to a friend.
Question: What is the average spend per visit for ALL Ridgeline customers, and what
share of ALL customers would recommend us? I want a range of plausible values for
each, not just the sample numbers.
I'm in an intro business statistics course and have learned descriptive statistics,
the normal distribution, standard error, and confidence intervals for a mean (using t)
and for a proportion.
Please compute a 95% confidence interval for the mean of spend and a 95% confidence
interval for the proportion who answered Yes to would_recommend, send the key results
to Excel with excel_out(), and explain how to read them.
Click Copy prompt, paste it into your AI assistant, and send it.
The R for Excel task pane in JOLT. Under 1. Data, the Survey table is listed with its columns and types. Under 2. Ask your AI, the question box contains the data description above, and the Copy prompt button is highlighted.
Needs: a reply with a short R script that uses t.test(Survey$spend) (or its conf.int) for the mean and prop.test or binom.test on 407 of 600 for the proportion, sends both to Excel with excel_out(), and explains how to read the confidence limits. Ideally it mentions that the t.test output also includes a test against 0 that can be ignored here. The text after this block compares the AI's script with the example below and notes whether it used prop.test (Wilson with continuity correction), binom.test (exact) or the hand formula.
7.11 Read the Script
Before you run anything, read what the AI sent. You're checking three things: which data it uses, which method it runs, and where the results go. A script for this usually looks like the one below.
# 95% confidence interval for the average spend (uses the t distribution)
spend_ci <- t.test(Survey$spend, conf.level = 0.95)
excel_out(spend_ci, "95% CI for mean spend")
# Count the Yes answers and the total number of answers
yes <- sum(Survey$would_recommend == "Yes")
n <- nrow(Survey)
# 95% confidence interval for the share who would recommend
rec_ci <- prop.test(yes, n, conf.level = 0.95)
excel_out(rec_ci, "95% CI for share who would recommend")
In plain language:
- The first block runs
t.teston thespendcolumn of theSurveydata frame.t.testis R's function for t procedures, and it reports a confidence interval for the mean along with other results.conf.level = 0.95asks for 95%. Thenexcel_outsends the whole result to an output card titled "95% CI for mean spend." - The second block counts how many rows have
would_recommendequal to "Yes" (407) and how many rows there are in total (600). Check that the script compares with"Yes"spelled exactly as it is in the data. A script that tested for"yes"would count zero and still run. - The third block runs
prop.teston 407 out of 600, which reports a confidence interval for a proportion, and sends it to a second card.
In the AI's version, check that it uses spend, counts "Yes," asks for 95% and ends with excel_out. If it used binom.test instead of prop.test, that's fine too; you'll see below why the choice matters a little.
7.12 Run It in R for Excel
- Paste the AI's whole reply into 3. Run R code. The app keeps just the code.
- Click Run.
- Two output cards appear under the results. On the first, click New sheet. Do the same for the second.
If you get an error instead, click Copy a prompt to fix it, paste that prompt back into your AI, and run the corrected code. The fix prompt already contains the code, the error message and your data.
The R for Excel task pane after running the script: two output cards titled "95% CI for mean spend" and "95% CI for share who would recommend," each with a preview and the New sheet and At selected cell buttons. Behind the pane, a new worksheet shows the first card's block, headed "One Sample t-test."
7.13 Interpret and Verify
7.13.1 Reading the mean output
The first sheet has a two-column block headed "One Sample t-test." The rows you need are:
- mean of x: 8.475, the point estimate.
- Lower 95% and Upper 95%: 8.268 and 8.682, the confidence interval.
These match cells B8 and B9 on your CI sheet to every decimal shown. Two tools, one answer.
The block also contains rows you can ignore for now: "Hypothesized mean" (0), "t" (about 80), "df" (599), "P-value" (a tiny number) and "Alternative." t.test always tests something, and with no target given it tests whether the mean spend could be $0. Nobody thinks it could, so that test tells you nothing. You'll learn to read those rows in Chapter 8. Hypothesis Testing, where the hypothesized value is chosen to answer a real question.
7.13.2 Reading the proportion output, and why it differs slightly
The second sheet's block is headed something like "1-sample proportions test with continuity correction." The estimate row, p, shows 0.678. But look at the limits:
| Method | Lower | Upper |
|---|---|---|
| Your Excel formula (Wald) | 0.641 | 0.716 |
R prop.test (Wilson, with continuity correction) |
0.639 | 0.715 |
R binom.test (exact, Clopper–Pearson) |
0.639 | 0.716 |
The R interval differs from yours in the third decimal. Neither tool made a mistake. They used different formulas for the same idea.
- Your Excel formula is the simplest one: p̂ ± z* × √(p̂(1 − p̂)/n). It treats the sampling distribution of p̂ as exactly normal and centered on p̂.
prop.testuses the Wilson method, with a small continuity correction that allows for the fact that counts are whole numbers. It's more accurate than the simple formula, especially when n is small or p̂ is near 0 or 1, and its interval isn't exactly centered on p̂.binom.testcomputes an exact interval directly from the binomial distribution in Chapter 5. Probability and Distributions.
With 600 responses and a proportion near the middle, all three agree to about two decimals: 64% to 72%. In a business report, that's the same answer. With a sample of 40 and a proportion of 0.95, they would disagree noticeably, and the simple formula would be the one to distrust.
This is a general lesson about AI-written analysis. When an AI's R output and your Excel check differ slightly, the usual reason is a different method or a different default setting, not an error. When they differ a lot, something is wrong: a different column, a filter, a typo in "Yes." Either way, find out why before you report.
If you want R to match your Excel formula exactly, for instance so a reviewer can trace every number, ask for that method by name.
Needs: a reply that explains prop.test uses the Wilson score interval with a continuity correction (and that binom.test would give an exact Clopper-Pearson interval), says the Wald formula is simpler and less accurate in small samples but fine here, and gives a short base R script computing p-hat, the standard error, qnorm(0.975), and the lower and upper limits, sent with excel_out(). The text after this block points out whether the reply's explanation is accurate.
Check the AI's explanation against the table above. If it says one of the two answers is "wrong," push back: both are legitimate methods, and they agree closely here.
7.13.3 The conclusion, in business language
Numbers on a sheet aren't the end. Dana needs sentences she can act on:
Average spend. Surveyed customers spent $8.48 per visit on average. We are 95% confident that the average for all Ridgeline customers is between $8.27 and $8.68. For budgeting, a planning figure of about $8.50 per visit is well supported. A conservative budget could use $8.27.
Recommendation. 67.8% of surveyed customers said they would recommend Ridgeline. We are 95% confident that between about 64% and 72% of all customers would. Roughly two in three customers are likely promoters, and about one in three is not.
By region. Suburban customers spent the most in the survey ($8.72 versus about $8.35 elsewhere), but the regions' intervals overlap a lot, so the survey doesn't show a clear difference in spend by region.
Each statement gives the estimate, the interval and what it means for a decision, and each talks about all customers, not just the 600 surveyed. The region sentence says what the data can't show, which is just as useful to a manager as what it can. Notice the rounding, too: two decimals for dollars and whole percentages for proportions.
7.14 Summary
A point estimate, such as the sample mean of $8.48, is the best single guess for a population parameter, but it says nothing about how far off it might be. A confidence interval adds that information. Every interval in this book has the form estimate ± critical value × standard error, and the part after the ± is the margin of error. For a mean, the critical value comes from the t distribution with n − 1 degrees of freedom, because the standard error uses the sample standard deviation in place of the unknown σ. For a proportion, the critical value comes from the standard normal distribution. In Excel, T.INV.2T, NORM.S.INV, CONFIDENCE.T and CONFIDENCE.NORM let you build and check both kinds of interval cell by cell.
The confidence level describes the method, not any single interval: a 95% method captures the true parameter in 95% of samples. Higher confidence gives wider intervals, and larger samples give narrower ones, with the margin shrinking with √n. You can plan the sample size needed for a target margin before collecting data. Ridgeline's 600 responses estimate average spend at $8.27 to $8.68 and the share who would recommend at about 64% to 72%. When R and Excel give slightly different intervals, the usual reason is a different method, such as prop.test's Wilson interval. Find out why before you report, and then say what the interval means in a sentence a manager can use.