Lawfare Academy

CS 230 — Mathematics, Statistics and Data for AI · Weeks 9–11

Sampling, uncertainty and causal limits

Full teaching sequence and cumulative subject work

Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Study the statistical estimation material in Dive into Deep Learning and scikit-learn model evaluation. Review sampling assumptions and selection mechanisms before interpreting uncertainty.

Derive and verify a two-parameter least-squares fit — primary material, constructed-response tasks, complete worked model and changed-case examination →

Sampling units, dependence and causal questions

A sample size is a count of observational units, not merely rows. Repeated observations from the same customer can share causes and outcomes. Treating them as independent customers can understate uncertainty. Define the target population, sampling unit, assignment mechanism and estimand before applying a standard error formula.

A narrow confidence interval does not repair a biased selection process. Nor does a precise association automatically estimate a causal effect. A before/after comparison may mix the intervention with seasonality or changes in customer composition.

Worked problem

A service receives 100 ratings from five customers, each rating 20 visits. A report claims a sample of 100 independent customers. Diagnose the inference.

Trace the complete reasoning
  1. The row count is 100 but there are five customer clusters. Ratings within a customer may be correlated.

  2. If the target is customer experience, first define how visits and customers are weighted. Equal visits and equal customers need not yield the same estimand.

  3. Use an analysis that reflects the sampling/dependence structure, or gather more independently sampled customers. A simple independent-row standard error is not justified by row count.

  4. Generalization also depends on who supplied ratings. Five self-selected customers may not represent the customer population even with many visits.

Independent transfer problem

Ratings improve after a new scheduling system launches in a quiet season. What evidence would strengthen a causal interpretation?

Compare the transfer solution

Use a credible comparison that separates the system from season and composition changes, such as randomized rollout when appropriate, or a justified comparison design with baseline trends and explicit assumptions. Measure the same outcome consistently. More rows can improve precision conditional on a design, but cannot by themselves identify the system’s causal effect.

Learning objectives

  • Explain and trace the mechanisms in sampling, uncertainty and causal limits.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Study the mechanism

A dataset is a sample produced by a collection process. Ask who or what could enter, what was excluded and which outcomes are missing. A survey of satisfied repeat customers cannot estimate satisfaction for all customers without strong additional assumptions. More rows reduce some sampling variation but do not automatically remove selection bias.

A sample mean summarizes observed values. Standard deviation describes dispersion of observations, while standard error describes uncertainty in an estimator under assumptions. They answer different questions. Confidence intervals depend on a sampling or model procedure; they do not guarantee that bias, measurement error or distribution shift has been addressed. Reporting many decimal places does not increase the information in the data.

Association is not causation. If trained staff have fewer errors, experience, job assignment and selection into training may explain part of the difference. A randomized intervention can strengthen causal identification, but still needs appropriate measurement, adherence and analysis. For observational data, state plausible confounders and avoid claiming that a prediction coefficient establishes the effect of changing that feature. A variable can be highly predictive yet unsuitable for intervention.

Worked example

import statistics
values = [8, 9, 10, 11, 12]
mean = statistics.mean(values)
sd = statistics.stdev(values)
se = sd / len(values) ** 0.5
assert mean == 10
assert round(sd, 4) == 1.5811
assert round(se, 4) == 0.7071

The standard deviation summarizes the spread of five observations. Dividing by square root of five gives the usual independent-sample standard-error estimate for the mean. If these values are five closely related measurements from one customer, treating them as independent customers understates uncertainty. The arithmetic can be correct while the sampling interpretation is wrong.

Check your understanding

What does adding more biased observations guarantee?

  1. No guarantee that selection bias disappears
  2. A representative sample automatically
  3. A causal estimate from any correlation
Answer and reasoning for every option

Correct: No guarantee that selection bias disappears Sample size and representativeness are separate issues.

Reconsider: A representative sample automatically A larger selected sample can preserve systematic distortion.

Reconsider: A causal estimate from any correlation Correlation does not identify an intervention effect.

Transfer laboratory: Repeated measures and an overstated sample size

Ten customers each provide fifty measurements. A report calculates uncertainty as if 500 customers were sampled independently. Explain the correction needed before interpreting a narrow interval.

Work through the full solution

Within-customer observations may be correlated. Define the inference target and sampling units, then use a suitable clustered, hierarchical or customer-level analysis. There is no universal correction obtained by replacing n with 10 without examining the design; the key is to model dependence. Evaluate new-customer predictions with customer-disjoint partitions where that matches deployment.

Evidence of understanding

Identify dependence and target population; do not promise a universal effective sample size.

Complete on-site teaching readings

These are full attributed source sections, not previews. Read them alongside the original Academy explanation and code.

  1. 22.10. Statistics Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  2. 22.7. Maximum Likelihood Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola

Open in My Learning to record progress →