Lawfare Group → Knowledge Institute → Lawfare Academy
← CS 230 — Mathematics, Statistics and Data for AI
Weeks 9–11
Sampling, uncertainty and causal limits
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.
Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.
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 reasoning 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.
Extended teaching and laboratory
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.
Step-by-step reasoning 1. The row count is 100 but there are five customer clusters. Ratings within a customer may be correlated.
- 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.
- 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.
- Generalization also depends on who supplied ratings. Five self-selected customers may not represent the customer population even with many visits.
Fit a probability model without confusing it with evidence about the world
A parameter belongs to a specified model; an estimator is a rule that maps a sample into a parameter estimate. An estimate is the value that rule produces on one observed sample. These are different objects. For independent Bernoulli observations, a model uses a common probability p for each binary outcome. If a fictional sample has eight successes and twelve failures, the likelihood of its particular ordered sequence is p⁸(1−p)¹². The count likelihood includes a binomial coefficient, but that coefficient does not depend on p and therefore leaves its maximizing value unchanged.
Likelihood treats the observations as fixed and varies the parameter. It is not a probability distribution over the parameter and need not integrate to one over parameter space. A posterior distribution additionally requires a prior and Bayes' rule; maximum a posteriori estimation and maximum likelihood are different procedures. A constant prior in one coordinate need not remain constant after reparameterization. Calling a prior flat therefore does not eliminate assumptions.
Using natural logarithms, the negative log-likelihood is ℓ(p)=−8 ln p−12 ln(1−p). On 0<p<1, its derivative is −8/p+12/(1−p). Setting it to zero gives 20p=8, hence p̂=.4. The second derivative 8/p²+12/(1−p)² is positive, so this is the unique minimum in the interior; endpoints assign zero probability to this mixed sample. For an all-success sample the constrained maximum is at p=1 instead. An unconstrained numerical update can leave [0,1], so domain handling is part of an implementation, not a cosmetic check.
Independent observations let products become sums of log probabilities. This avoids direct multiplication of many tiny numbers and makes derivatives easier to accumulate. Differentiating a negative log term retains its leading minus sign: d[−ln q(p)]/dp=−q′(p)/q(p). Specify the logarithm base: natural logarithms measure information in nats; base two measures bits. Changing base rescales the objective but does not change its unpenalized maximizer. Continuous likelihood uses densities at the observed values; a density's value is not the probability of observing that exact point. Its units and coordinate transformation matter.
Conditioning, smoothing and a naive Bayes model
For a class C and observed features x, Bayes' rule is P(C|x)=P(x|C)P(C)/P(x), provided P(x)>0. A naive Bayes model assumes features are independent
conditional on the class
, giving score s(C)=P(C)∏j P(xⱼ|C). It does not assert that features are independent in the pooled population. Include the class prior once. Comparing scores selects a class; normalizing by their sum produces this model's posterior probabilities. Neither result establishes real-world calibration.
Use fictional urgent and routine cases with priors .2 and .8. Two binary indicators are present. Their conditional presence probabilities are [.8,.6] for urgent and [.1,.2] for routine. The unnormalized scores are .2×.8×.6=.096 and .8×.1×.2=.016; normalization gives urgent probability 6/7. This uses the declared conditional-independence assumption. If the second indicator merely copies the first, multiplying them as independent evidence double-counts information. A well-formed probability output can then be overconfident. Duplicating a field must not manufacture an independent observation.
A zero estimated probability makes a product zero, even if the unseen value was simply absent from a small training sample. For a Bernoulli feature, adding a positive pseudocount a to each of its two outcomes gives (k+a)/(n+2a) for presence and (n−k+a)/(n+2a) for absence. With k=0,n=8,a=1, these become .1 and .9. This is a deliberate estimation rule, not proof that the presence rate is actually .1. Fit counts and any smoothing choice in development data. In a log implementation, sum log priors and log conditional probabilities, and use stable normalization; distinguish an impossible event under the chosen model from arithmetic underflow.
Compare estimators under an explicit repeated-sampling target
For a fixed true parameter θ, bias is E[θ̂]−θ, variance is E[(θ̂−Eθ̂)²], and mean squared error is E[(θ̂−θ)²]. Expanding the square gives MSE=variance+bias². There is no additional random-parameter noise term in this fixed-parameter identity. Predicting a new noisy outcome is a different problem and can include irreducible outcome variance. The standard deviation of an estimator's sampling distribution is its standard error; it differs from the standard deviation of individual observations.
A constructed comparison makes the tradeoff visible. Estimator A has bias zero and variance nine, so MSE is nine. Estimator B has bias one and variance four, so MSE is five. Under squared-error loss B is preferable despite being biased. This does not establish that B is preferable under every loss or that either estimator repairs selection bias in a real sample. More rows cannot turn a systematically selected population into a representative one by arithmetic alone.
Intervals and tests describe procedures under assumptions
For independent, identically normally distributed observations with a common unknown mean and variance, the sample mean has estimated standard error s/√n, where s²=Σ(xᵢ−x̄)²/(n−1). The statistic (x̄−μ)/(s/√n) has a Student t distribution with n−1 degrees of freedom. A two-sided 95% confidence procedure uses x̄±t*.975,n−1 s/√n. The normal critical value 1.96 is a large-sample approximation, not an exact finite-sample replacement. Dependence, selection, heavy tails and model changes require examination before applying the formula.
For an explicitly constructed normal-sampling record with n=25,x̄=12,s=5, the standard error is one. Using the supplied t critical value 2.064 for 24 degrees of freedom gives [9.936,14.064]. A 95% confidence claim refers to coverage of the procedure over repeated samples under the model. It does not assign a 95% posterior probability to the fixed mean after seeing this one interval. It does not mean 95% of individual observations lie inside the interval, and it does not account for an unmodeled selection mechanism.
A hypothesis test declares a null, alternative, statistic and rejection rule. The significance level α controls the probability of a Type I error under the null according to the test's assumptions; it is not the probability that the null is true. A p-value is a tail probability of results at least as extreme under the specified null. The tail depends on the prespecified one- or two-sided alternative. Failing to reject does not prove equivalence. Power is the probability of rejecting at a specified alternative effect and depends on sample size, variability and the rule. Plan it for meaningful effect sizes; it is not a universal property of a dataset.
Report estimated effects, denominators and uncertainty alongside decisions. Repeatedly trying endpoints, subgroups or stopping times and reporting only a small p-value changes the selection procedure. A nominal .05 threshold alone does not address that search. Random assignment can support a causal comparison; random sampling addresses population representation. Neither makes two observed groups numerically identical or removes measurement error by declaration.
Optional changed record and complete reasoning
A new independent Bernoulli sample contains twelve successes and eight failures. Fit p by maximum likelihood. In the two-indicator model, keep priors and first-indicator rates, but change the second-indicator rates to .3 for urgent and .4 for routine. Recompute the normalized urgent probability. Finally a normal-sampling record has n=16,x̄=10,s=4; use the supplied 15-degree-of-freedom 95% t critical value 2.131.
The negative log-likelihood derivative is −12/p+8/(1−p); the interior minimum is p̂=.6. It estimates a model probability from this sample and does not establish a causal improvement over the earlier .4 sample. The new class scores are .2×.8×.3=.048 and .8×.1×.4=.032. Their sum is .08, giving urgent probability .6. The changed conditional evidence changes the result despite unchanged priors. If the indicators are dependent within a class, these numbers remain only the fitted naive model's calculation.
The new standard error is 4/√16=1, so the confidence interval is [7.869,12.131]. Comparing these endpoints with the earlier record does not by itself supply a test of the difference between population means. The two sampling designs, dependence and a difference-estimator standard error must be specified. A narrow interval or a larger point estimate cannot substitute for that design.
Optional criteria: distinguish likelihood from posterior; derive the Bernoulli estimate with its domain; compute and normalize class scores while stating conditional independence; calculate the interval and explain coverage and causal limits. Award one point for each fully explained criterion.
Apply the idea
A service receives 100 ratings from five customers, each rating 20 visits. A report claims a sample of 100 independent customers. Diagnose the inference.
Ratings improve after a new scheduling system launches in a quiet season. What evidence would strengthen a causal interpretation?
Read the worked reasoning
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.
Check understanding
What does adding more biased observations guarantee?
- No guarantee that selection bias disappears
Feedback
Sample size and representativeness are separate issues.
- A representative sample automatically
Feedback
A larger selected sample can preserve systematic distortion.
- A causal estimate from any correlation
Feedback
Correlation does not identify an intervention effect.
Further reading
Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.
Read the original on-site preparation chapter and preserved investigation. Work the changed record before opening its full model. Earlier source assignment directions remain in immutable edition4.