Probability and Statistics

Chapter 8 · Think Data Science & Management

Probability Models

8.1 · Think Data Science & Management

Today's goals

  • Write a probability model: outcomes and their probabilities
  • Find the probability of an event and its complement
  • Compute and interpret an expected value
  • Use simulation to connect a model to data
  • Separate population from sample, variable from observation

A probability model for one shipment

shipping = pd.DataFrame({
    'outcome': ['on time', '1 day late', '3+ days late'],
    'probability': [0.80, 0.15, 0.05],
})
shipping
        outcome  probability
0       on time         0.80
1    1 day late         0.15
2  3+ days late         0.05
  • Outcomes together form the sample space

Two rules every model follows

  1. Each probability is between 0 (impossible) and 1 (certain)
  2. The probabilities of all outcomes add up to 1
print(shipping['probability'].sum())
1.0

Is this a valid probability model?

On time 0.80 · 1 day late 0.15 · 3+ days late 0.10

  1. Yes: every probability is between 0 and 1
  2. No: the probabilities add up to 1.05
  3. Yes: late shipments are rarer than on-time ones
  4. No: a model needs at least four outcomes

Events and complements

late = shipping['outcome'] != 'on time'
p_late = shipping.loc[late, 'probability'].sum()
print(p_late, 1 - p_late)
0.2 0.8
  • An event is a set of outcomes: "late" = 1 day late or 3+ days late
  • Complement: P(not A) = 1 − P(A)

Expected value: the long-run average

shipping['credit'] = [0, 5, 20]     # $ credit per outcome
print((shipping['credit'] * shipping['probability']).sum())
1.75

What $1.75 means

  • No shipment costs $1.75: each costs $0, $5, or $20
  • It is the average over many shipments
  • 10,000 shipments a month → budget about $17,500

Expected value is for planning across many cases, not predicting one.

The expected credit is $1.75. Which statement is right?

  1. A typical shipment costs $1.75 in credits
  2. Over many shipments, credits average about $1.75 each
  3. Every shipment has a 1.75% chance of a credit
  4. The store should give every customer $1.75

From model to data: simulation

rng = np.random.default_rng(8)
simulated = pd.Series(rng.choice(shipping['outcome'], size=10000,
                                 p=shipping['probability']))
simulated.value_counts(normalize=True)
on time         0.8016
1 day late      0.1525
3+ days late    0.0459
Name: proportion, dtype: float64

Model vs. simulated

Bars comparing model probabilities with simulated proportions for each outcome; they nearly match

  • Simulated average credit: $1.68, close to the expected $1.75
  • More shipments → closer (law of large numbers, 8.2)

Population vs. sample

  • Population: the full group we care about
    • all lunch and dinner bills at the restaurant this year
  • Sample: the part we actually measured
    • the 244 bills in the tips data

We see the sample; we want to learn about the population.

Variables and observations

   total_bill   tip     sex  day    time  size
0       16.99  1.01  Female  Sun  Dinner     2
1       10.34  1.66    Male  Sun  Dinner     3
2       21.01  3.50    Male  Sun  Dinner     3
  • Each row is an observation (one bill)
  • Each column is a variable
  • Quantitative: total_bill, tip · Categorical: sex, day, time

A distribution shows how often values occur

  • Numeric: are most bills around $10? $20? Any very large ones?
  • Categorical: how common is Dinner vs. Lunch?
  • A probability model gives a distribution of chances
  • An empirical distribution gives the observed proportions

Which is the complement of "a support ticket is solved the same day"?

  1. Solved the next day
  2. Not solved the same day
  3. Solved within two days
  4. Never solved

Your turn: a bakery's daily demand

demand = [0, 1, 2, 3]                       # cakes ordered in a day
probabilities = [0.10, 0.30, 0.40, 0.20]
observed = [2, 1, 0, 3, 2, 2, 1, 0, 2, 3, 1, 2, 2, 1, 3, 2, 0, 2, 1, 2]
  1. Check that the probabilities add up to 1
  2. Find P(at least one order) using the complement
  3. Compute the expected number of orders per day
  4. Compare with 20 observed days: share with an order, average orders

Recap

  • A model lists outcomes and probabilities; they add up to 1
  • Complement: P(not A) = 1 − P(A)
  • Expected value = Σ value × probability: a long-run average
  • Simulation turns a model into data
  • Sample → learn about the population

Descriptive Distributions

8.2 · Think Data Science & Management

Today's goals

  • Summarize a variable with mean, median, SD, and IQR
  • Use percentiles and the 1.5 × IQR rule to flag outliers
  • Describe center, spread, shape, and outliers from a plot
  • Recognize normal, binomial, and uniform distributions
  • Explain the Central Limit Theorem and the law of large numbers

describe(): a summary in one call

tips[['total_bill', 'tip', 'size']].describe().round(2)
       total_bill     tip    size
count      244.00  244.00  244.00
mean        19.79    3.00    2.57
std          8.90    1.38    0.95
min          3.07    1.00    1.00
25%         13.35    2.00    2.00
50%         17.80    2.90    2.00
75%         24.13    3.56    3.00
max         50.81   10.00    6.00

Center and spread for total_bill

Statistic Value Meaning
Mean $19.79 the average
Median $17.80 the middle bill
SD $8.90 typical distance from the mean
IQR $10.78 range of the middle 50%

Mean > median: a few large bills pull the mean up.

Spread: variance, SD, and percentiles

col = tips['total_bill']
print(round(col.var(), 2), round(col.std(), 2), round(np.std(col), 2))
np.percentile(col, [25, 50, 75, 90])
79.25 8.9 8.88
array([13.3475, 17.795 , 24.1275, 32.235 ])
  • Variance = SD², in dollars², so we report the SD
  • pandas .std() divides by n − 1; np.std() divides by n
  • 90th percentile $32.24: 90% of bills are at or below it

Outliers: the 1.5 × IQR rule

  • Q1 = $13.35 · Q3 = $24.13 · IQR = Q3 − Q1 = $10.78
  • Upper fence = Q3 + 1.5 × IQR = $40.30
  • Lower fence = Q1 − 1.5 × IQR = −$2.82 (no bill is that low)
  • 9 bills are above $40.30
upper = q75 + 1.5 * (q75 - q25)
(col > upper).sum()          # 9

Look at the shape

Left: a right-skewed histogram of total bill with the mean line to the right of the median line. Right: a box plot with several high outliers

Center · spread · shape · outliers

Salaries: most employees earn $50K–$80K, a few executives over $1M. Which describes a typical employee best?

  1. The mean salary
  2. The median salary
  3. The maximum salary
  4. The standard deviation

The normal distribution

  • Symmetric, bell-shaped, centered on the mean
  • Defined by its mean and standard deviation
  • About 68% within 1 SD, 95% within 2 SD, 99.7% within 3 SD
rng = np.random.default_rng(42)
values = rng.normal(loc=50, scale=5, size=1000)   # mean 50, SD 5

68% and 95%, checked

Histogram of 1,000 normal draws with dashed lines at 1 and 2 standard deviations from the mean

  • Within 1 SD: 68.8% · within 2 SD: 95.7% of these 1,000 draws

The binomial distribution

  • Number of successes in n independent yes/no trials
  • Each trial has the same probability p
  • rng.binomial(n=100, p=0.5): heads in 100 coin flips

Two histograms: binomial with n=100, p=0.5, and normal with mean 50 and SD 5; both bell-shaped around 50

More trials, more bell-shaped

Three histograms of binomial counts with p = 0.2 for 5, 30, and 300 trials, each with a matching normal curve; skewed at 5 trials, bell-shaped at 300

  • Same 5,000 draws in every panel; only the number of trials n changes
  • Central Limit Theorem: sums and averages of many independent values tend toward a normal shape

The uniform distribution: every value equally likely

Four histograms of die rolls for 60, 600, 6,000, and 60,000 rolls; the bars flatten toward one sixth

  • One fair die: each face has probability 1/6
  • Few rolls: bumpy · many rolls: flat

100 customers are each offered an upgrade; each accepts with probability 0.3, independently. The number who accept is:

  1. Normal with mean 0.3
  2. Uniform from 0 to 100
  3. Binomial with n = 100, p = 0.3
  4. Always exactly 30

The law of large numbers

Running proportion of heads over 1,000 coin flips: it swings widely at first and settles near 0.5

  • After 10 flips: 0.40 · 100: 0.52 · 1,000: 0.509
  • More observations → the average settles near the true value

How the running proportion is computed

rng = np.random.default_rng(42)
flips = rng.integers(0, 2, size=1000)          # 0 = tails, 1 = heads
running = flips.cumsum() / (np.arange(1000) + 1)
  • cumsum(): heads so far · np.arange(1000) + 1: flips so far

Your turn: website visits

visits = np.array([410, 395, 430, 420, 405, 1250, 415,
                   400, 425, 390, 435, 410, 1180, 420])
  1. Compute the mean, median, and SD (np.std)
  2. Is the distribution skewed? Compare mean and median
  3. Which would you report as a typical day?
  4. Find Q1, Q3, the IQR, and the upper fence; how many outlier days?

Recap

  • Center: mean and median · Spread: SD, percentiles, IQR
  • Outliers: beyond 1.5 × IQR from the quartiles
  • Mean > median → right skew; report the median for "typical"
  • Normal: 68-95-99.7 · Binomial: successes in n trials · Uniform: all equal
  • CLT: sums of many independent values → bell shape
  • Law of large numbers: averages settle as n grows

Sampling Variability

8.3 · Think Data Science & Management

Today's goals

  • Tell a parameter from a statistic
  • Explain why repeated samples give different results
  • Simulate a sampling distribution
  • Compute the standard error of a proportion and of a mean
  • Predict how sample size changes the standard error

Parameter vs. statistic

  • Treat the 244 bills as the whole population
  • Parameter: the population mean, = $19.79
  • Statistic: the mean of one random sample of 20 bills
rng = np.random.default_rng(42)
for i in range(3):
    print(rng.choice(bills, size=20).mean().round(2))
22.45
17.54
20.98

5,000 samples of 20 bills

Left: histogram of the 244 bills, skewed right. Right: histogram of 5,000 sample means on the same axis, narrow and bell-shaped around 19.79

  • Centered on μ · SD of the means $1.99 vs $8.88 for single bills
  • Bell-shaped even though the bills are skewed: the CLT again

One survey, one number

  • True share of customers who would renew: p = 0.6 (unknown in practice)
  • We survey n = 40 customers and get a sample proportion,
  • A second survey of 40 different customers gives a different

How much do those numbers bounce around?

Simulate 5,000 surveys

rng = np.random.default_rng(seed=0)
p_true, n, n_sims = 0.6, 40, 5000

samples = rng.binomial(n=n, p=p_true, size=n_sims)
sample_props = samples / n
np.percentile(sample_props, [2.5, 97.5])
array([0.45, 0.75])

The sampling distribution

Histogram of 5,000 sample proportions from samples of 40, centered on the true 0.6

  • Centered on the true p = 0.6
  • The spread is the sampling variability

Two levels: the data and the samples

One survey's data

  • 40 answers: renew or not
  • Summarized by one
  • What a company actually has

The sampling distribution

  • 5,000 surveys' values
  • Shows how varies
  • Imagined, or simulated

The histogram on the sampling distribution slide shows...

  1. The 40 answers in one survey
  2. The sample proportions from 5,000 surveys
  3. The true proportion of all customers
  4. The customers who did not renew

Standard error: the typical miss

print(round(np.sqrt(0.6 * 0.4 / 40), 4),
      round(sample_props.std(ddof=1), 4))
0.0775 0.0781
  • Formula and simulation agree
  • In practice, plug in for the unknown

Margin of error: about 2 standard errors

  • About 95% of sample proportions land within 2 SE of p
  • 0.6 ± 2 × 0.0775 → 0.445 to 0.755
  • Matches the simulated middle 95%: 0.45 to 0.75

A survey's "margin of error" is usually 2 SE.

Worked example: plug in

A survey of 40 customers finds 26 would renew.

  • 2 SE ≈ 0.15: the true share is plausibly about 0.50 to 0.80
  • Too wide to tell a manager "most customers will renew" with confidence

Standard error of a sample mean

  • Matches the SD of the 5,000 simulated means: $1.99
  • Single bills vary by about $8.88; means of 20 vary by about $2
  • In practice, plug in the sample SD : SE ≈

Bigger samples, smaller standard error

Three histograms of sample proportions for n = 10, 40, and 200; the spread shrinks as n grows

n 10 40 200
SE (formula) 0.155 0.077 0.035

The square-root rule

  • SE shrinks with , not with
  • 4× the sample → ½ the standard error
  • 40 → 160 customers: SE 0.077 → about 0.039

Precision costs more and more: halving the error needs four times the data.

A manager surveys 400 customers instead of 100. The standard error...

  1. Stays the same
  2. Is cut in half
  3. Is cut to one quarter
  4. Doubles

Your turn: planning a bank survey

About 30% of a bank's customers use mobile check deposit.

  1. Compute the SE for samples of 100 and 900 customers
  2. How many times smaller is the SE with 900?
  3. Is 900 worth nine times the cost?
  4. A survey of 100 finds 27%: parameter or statistic?
  5. Deposits have SD $400: SE of the mean deposit for n = 100 and 400

Recap

  • A statistic estimates a parameter; repeated samples vary
  • The sampling distribution shows how much
  • Standard error = SD of the sampling distribution
  • SE of a proportion: · of a mean:
  • 4× the sample → ½ the SE

This deck holds the slides for all of Chapter 8, one part per class meeting: - 8.1 Probability Models (slide 2) - 8.2 Descriptive Distributions (slide 19) - 8.3 Sampling Variability (slide 37) Each part opens with its own title slide and runs about 50 minutes, with its own goals, quick checks, "Your turn" exercise, and recap. To start a class, jump to that part's slide number: in the HTML deck, type the number and press Enter, or add #number to the URL.

Welcome to Chapter 8. Up to now we have described data we already have. This chapter adds the other side: models of chance that describe how data could come out. Managers use them every day, whether or not they call them probability: delivery promises, return rates, budget reserves. Today: what a probability model is, events and complements, expected value, simulation, and the vocabulary of populations, samples, variables, and observations. Timing: about 50 minutes, three quick checks, one practice exercise.

Read the goals. They support chapter objectives 1 (describe a probability model and compute event probabilities, complements, and expected values) and 3 (interpret empirical distributions).

Our running case: an online store ships orders, and the operations team uses this model for one shipment. The table lists every possible outcome and its probability. The list of all outcomes is the sample space. The model does not say what will happen to the next shipment; it says how likely each outcome is. Ask: "Where do numbers like 0.80 come from?" Usually from past data: 80% of past shipments arrived on time.

These two rules are how you check any probability model. Exactly one outcome must happen, so the probabilities must add up to 1. Quick sanity habit for students: whenever you build a model in code, sum the probability column.

Give students 20 seconds. Answer: B. 0.80 + 0.15 + 0.10 = 1.05. Both rules must hold, and the second one fails. Why the others are wrong: A checks only the first rule. C is about the order of the probabilities, which is not a rule. D is not a rule; any number of outcomes works. This exact case is homework question 1.

An event groups outcomes we care about. "Late" contains two outcomes, so its probability is the sum: 0.15 + 0.05 = 0.20. The complement is "the event does not happen". Because everything adds up to 1, P(not late) = 1 - 0.20 = 0.80. The complement is often the shortcut: "at least one day late" is everything except "on time".

The store gives a $5 credit for a 1-day delay and $20 for 3 or more days. The credit is a random variable: a number that depends on chance. The expected value multiplies each value by its probability and adds them up: $1.75 per shipment.

This is the most commonly misunderstood idea in the section. Expected value is not the typical outcome. Most shipments cost $0. It is the long-run average, which is exactly what a manager needs for a budget.

Give students 20 seconds. Answer: B. Expected value is a long-run average. Why the others are wrong: A, a typical shipment costs $0. C confuses a dollar amount with a probability; P(any credit) is 0.20. D is a policy idea, not what the number means. This is homework question 2.

A model describes the process; data are what we observe. Simulation connects them: rng.choice draws 10,000 outcomes with the model's probabilities. The proportions in the simulated data, the empirical distribution, are close to the model's 0.80, 0.15, 0.05, but not exactly equal. A different seed gives slightly different numbers.

Side by side, the model and the simulation almost match. The simulated average credit is $1.68, close to the $1.75 expected value. With more shipments, the average tends to get closer; that is the law of large numbers, coming up in 8.2.

In practice we work the other way around: we observe a sample and want to learn about the population. That gap is what the rest of the course is about: how much can a sample tell us? Business examples: a customer survey (sample) and all customers (population); last month's orders and all future orders.

This connects back to tidy data in Chapter 7. One row per observation, one column per variable. The type of variable decides the summary: quantitative variables get means and spreads; categorical variables get counts and proportions. Party size is numeric but takes few values, a useful edge case to discuss.

Distribution is the word that ties this section together. A model's distribution says what should happen; an empirical distribution says what did happen in data. Comparing the two is the heart of statistics, and Chapter 9 does exactly that with hypothesis tests.

Give students 20 seconds. Answer: B. The complement is everything except the event. It includes next day, 2+ days, and never. Why the others are wrong: A and C are only parts of the complement. D is one possible outcome, not the whole complement.

This is the section 8.1 exercise. Give students 5 minutes. Answers: total probability 1.0; P(at least one) = 1 - 0.10 = 0.90; expected orders = 0*0.1 + 1*0.3 + 2*0.4 + 3*0.2 = 1.7. Observed days: 17 of 20 had an order (0.85) and the average was 1.6. Close to the model, not equal: 20 days is a small sample, so the empirical distribution varies by chance. Common mistakes: computing P(at least one) by adding only 0.30 + 0.40 and forgetting 3 cakes; reading the expected value 1.7 as "the bakery sells 1.7 cakes on a typical day"; floating-point output such as 0.8999999999999999, which round(…, 2) fixes.

Ask students to supply each line. Next time, 8.2: describing distributions of data with center, spread, and shape, and three distributions that come up again and again: normal, binomial, and uniform.

Last time we built models of chance. Today we describe what data actually look like: center, spread, and shape, plus three common distributions and the law of large numbers. Timing: about 50 minutes, three quick checks, one practice exercise.

Read the goals. They support chapter objectives 2 (summarize a distribution by its center, spread, and shape) and 3 (interpret empirical distributions).

describe gives count, mean, standard deviation, min, the three quartiles, and max for every numeric column. The 50% row is the median. Ask: "What do you notice about total_bill's mean and median?" The mean, $19.79, is above the median, $17.80. That gap is a clue about shape, next slide.

Two measures of center and two of spread. The mean is pulled toward large values; the median is not. When the mean is noticeably above the median, the data are skewed to the right: a long tail of large values. For a typical bill, report the median. The SD and IQR both measure spread. The IQR, like the median, resists outliers. Rule of thumb used in the exercises: if the mean is more than 20% above the median, treat the data as right-skewed and report the median. It is a practice convention, not a formal test. For tips the mean is about 11% above the median, so the skew is moderate.

Variance is the SD squared. Its units are squared dollars, which nobody can picture, so we report the SD. Two standard deviations: pandas .std() divides by n minus 1 (the sample SD, ddof=1) and np.std() divides by n (ddof=0). With 244 bills they differ by two cents, 8.90 vs 8.88, but on a dataset of 10 values the gap is noticeable. Lab question 4 asks for np.std, so use the function a question names. The p-th percentile is the value below which p percent of the values fall. The 25th, 50th, and 75th are the quartiles; the 50th is the median. Ask: "What does the 90th percentile tell a manager?" Nine bills in ten are $32.24 or less.

The 1.5 times IQR rule is the usual way to flag outliers, and it is exactly what a box plot uses: anything past the fences is drawn as a separate dot. All nine flagged bills are on the high side, which matches the right skew. Flagged does not mean wrong: these are real, large bills. A manager would look at them, not delete them.

The histogram shows the right skew: a peak around $15 to $20 and a long tail toward $50. The mean (dashed red) sits to the right of the median (dotted black). The box plot shows the same thing compactly: the box is the IQR, the line is the median, and the dots on the right are the nine bills above the $40.30 fence from the previous slide. Use the four-word checklist every time you describe a distribution.

Give students 20 seconds. Answer: B. The few very large salaries pull the mean up; the median is the middle value and is not affected by how large the top salaries are. Why the others are wrong: the maximum describes one person; the SD measures spread, not center. This is homework question 3.

The normal distribution appears whenever many small independent effects add up: measurement errors, heights, daily demand for a stable product. loc is the mean and scale is the standard deviation. The 68-95-99.7 rule is worth memorizing; we use it constantly in Chapters 9 to 11.

In these 1,000 simulated values, 68.8% are within 1 SD of the mean (45 to 55) and 95.7% are within 2 SD (40 to 60), close to the 68% and 95% the rule predicts. Simulation lets us check a rule instead of memorizing it.

Business examples of binomial: how many of 100 customers renew, how many of 50 parts are defective, how many emails get opened. With n = 100 and p = 0.5 the binomial looks almost exactly like a normal with mean 50 and SD 5. It is discrete, whole numbers only, but the shape is a bell. That is the Central Limit Theorem at work: totals of many independent trials tend toward normal.

A binomial count is a sum of n yes/no trials. With p = 0.2 and only 5 trials, most counts are 0 or 1 and the distribution is skewed right; the red normal curve with the same mean and SD fits poorly. At 30 trials it is close to a bell; at 300 the histogram follows the curve almost exactly. Stress what changes: not the number of draws, which is 5,000 everywhere, but n, the number of trials added up in each count. That is the Central Limit Theorem. In 8.3 we see the same thing for sample means.

A fair die is uniform: each face has a one-in-six chance. With 60 rolls the bars are uneven by chance. By 60,000 rolls they are nearly flat at the red line, 1/6. That pattern, noisy with little data, close to the model with a lot, is exactly the next idea.

Give students 30 seconds. Answer: C. A fixed number of independent yes/no trials with the same success probability is binomial. Why the others are wrong: A has the wrong mean; the expected count is 100 x 0.3 = 30. B would make 0 and 100 as likely as 30. D ignores chance: 30 is the expected value, not a guarantee.

Each flip is 0 or 1. The line shows the proportion of heads so far. Early on it swings widely; after 1,000 flips it is 0.509, close to the true 0.5. The law of large numbers says the sample average gets closer to the true average as the sample grows. It is why a casino can plan its revenue and why the shipping budget from 8.1 works across 10,000 shipments. Common misconception: it does not say a head is "due" after a run of tails. Each flip is still 50-50.

cumsum adds up the heads as we go; dividing by the number of flips so far gives the running proportion. This two-line pattern works for any running average.

This is the section 8.2 exercise. Give students 5 minutes. Answers: mean 527.5, median 417.5, SD 281.3. Two promotion days pull the mean far above the median, so the data are skewed to the right and the median describes a typical day better. Q1 = 406.25, Q3 = 428.75, IQR = 22.5, upper fence = 462.5, and 2 days (the promotion days) are outliers. Common mistake: reporting the mean because it is "the average". Ask what the 1,250 and 1,180 days were; a manager would want them explained separately.

Ask students to supply each line. Next time, 8.3: if we took another sample, how different would our numbers be? That is sampling variability, measured by the standard error.

Last time: averages settle down as samples grow. Today we measure how much a sample result would change if we drew a different sample. That amount, the standard error, is behind every margin of error in a survey and every confidence interval in Chapter 11. Timing: about 50 minutes, three quick checks, one practice exercise.

Read the goals. They support chapter objectives 4 (explain why samples vary, and use simulation to show it) and 5 (use the standard error to describe how sample size affects precision).

In real work we never see the population. Here we flip it around: pretend the 244 bills are every bill there is, so we know the true mean, 19.79. That number is a parameter. Each random sample of 20 bills gives its own mean, a statistic. Three samples, three different answers, none exactly 19.79. That is sampling variability, and it is the subject of today. rng.choice samples with replacement by default, as if each bill came from the restaurant's steady stream of customers.

Repeat the sampling 5,000 times and plot every sample mean on the same axis as the bills. Three things to point out: the means are centered on the population mean (the red line); they vary far less than individual bills, about $2 instead of about $9; and they form a bell even though the bills themselves are skewed right. That last point is the Central Limit Theorem from 8.2, now for sample means. The SD of the sample means has a name, the standard error. We come back to it after looking at proportions.

This is the core question. p is a fact about the population; we never see it directly. p-hat is what our survey gives. Every new random sample gives a new p-hat. Two surveys showing 72% and 68% satisfied does not mean anything changed; it may just be sampling variability. That is homework question 4.

We pretend we know p = 0.6 and run 5,000 surveys of 40 customers each. rng.binomial gives the number of renewals in each survey; dividing by 40 gives each p-hat. The middle 95% of the 5,000 p-hats run from 0.45 to 0.75. So one survey of 40 people could easily say 45% or 75% even though the truth is 60%.

This histogram is the sampling distribution: the distribution of p-hat across many repeated samples. It is centered on the truth, so the survey method is unbiased, but individual surveys land anywhere from about 0.45 to 0.75. Stress the difference: the distribution of the data (40 yes/no answers) is not the sampling distribution (5,000 p-hats).

Students often mix these up. Inside one survey there are 40 yes/no answers, summarized by one number, p-hat. The sampling distribution is one level up: the p-hats from many surveys. A company only ever runs one survey; the sampling distribution tells it how far that one number could be from the truth.

Give students 20 seconds. Answer: B. Each value in the histogram is one survey's p-hat. Why the others are wrong: A would be 40 zeros and ones. C is a single number, 0.6, the red line. D is not shown. If students pick A, redraw the two levels on the board: answers inside a survey, and surveys inside the simulation.

The standard error is the standard deviation of the sampling distribution: how far a typical p-hat lands from p. The formula gives 0.0775; the SD of the 5,000 simulated p-hats is 0.0781. They agree, which is the point: the formula summarizes what the simulation shows. In real work we do not know p, so we plug in the sample's p-hat. That approximation works well for reasonably large samples.

Combine the 68-95 rule from 8.2 with the standard error. About 95% of p-hats fall within 2 SE of the truth. Two SE here is 0.155, so 0.445 to 0.755, which matches the 2.5th and 97.5th percentiles of our 5,000 simulated surveys. When a news report says "plus or minus 3 points", that is about 2 standard errors. Chapter 11 turns this into confidence intervals.

In practice we do not know p, so we plug in p-hat. 26 of 40 is 0.65; the SE is about 0.075; two SE is about 0.15. So the truth could plausibly be anywhere from 0.50 to 0.80. Business reading: a survey of 40 cannot distinguish "half our customers" from "four out of five". If the decision depends on that difference, survey more people; the next slides show how many.

Back to the tips bills. The same square-root idea works for means: the standard error of a sample mean is the population SD divided by the square root of n. With sigma = 8.88 (np.std of the 244 bills, since they are the whole population) and n = 20, the formula gives 1.99, exactly what the simulation showed. As with proportions, we rarely know sigma, so we plug in the sample SD. This is homework question 10.

Same true p, three sample sizes. With 10 customers the p-hats are all over the place; with 200 they cluster tightly around 0.6. The table gives the formula SE for each n; the panel titles give the SD of the simulated p-hats, which match to within 0.001.

Because n is under a square root, doubling the sample does not halve the error. Quadrupling it does. Management angle: a survey vendor quotes a price per response. Cutting the margin of error in half costs four times as much. Often a moderate sample is the better business decision.

Give students 20 seconds. Answer: B. Four times the sample size, so the SE is divided by the square root of 4, which is 2. Why the others are wrong: C would require 16 times the sample. A and D ignore the formula. This is homework question 5.

This is the section 8.3 exercise. Give students 5 minutes. Answers: SE with n = 100 is sqrt(0.3 x 0.7 / 100) = 0.046; with n = 900 it is 0.015; the ratio is 3.0. Nine times the sample gives an SE three times smaller. The 27% is a statistic: it comes from a sample, and the parameter is the true share, about 30%. SE of the mean deposit: 400 / sqrt(100) = 40 and 400 / sqrt(400) = 20. Lab question 5 asks students to check the mean version by simulation. Question 3 has no single right answer; discuss what decision the survey supports and whether plus or minus 4.6 points is precise enough.

Ask students to supply each line. That completes Chapter 8. Before next class: the section exercises, then the Chapter 8 lab and homework. Next chapter: hypothesis testing. We will compare an observed result with what a chance model predicts, using exactly the simulation ideas from today.