Lawfare Group → Knowledge Institute → Lawfare Academy
← CS 230 — Mathematics, Statistics and Data for AI
Weeks 6–8
Probability, conditional reasoning and base rates
Learning objectives
- Explain and trace the mechanisms in probability, conditional reasoning and base rates.
- 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 probability describes uncertainty within a model or repeated sampling process. Conditional probability changes the reference group: P(alert given defect) is not P(defect given alert). Confusing them can produce badly overstated confidence when defects are rare. Begin with counts in a hypothetical population so every denominator is visible.
Suppose 100 of 10000 orders are defective. A detector flags 90 of those and also flags 495 of the 9900 nondefective orders. Sensitivity is 90/100 = 90 percent, while positive predictive value is 90/585, approximately 15.38 percent. Both statements can be true. The base rate and false-positive rate explain why most alerts are false despite high sensitivity.
Independence is an assumption about joint behavior, not a synonym for distinct events. Repeated alerts from closely related measurements may add less information than independent evidence. Expected value combines outcomes weighted by probabilities, but does not describe the full distribution or justify ignoring rare severe failures. When a model produces probabilities, assess calibration as well as ranking: among items assigned about 0.8 probability, the observed event rate should be near 0.8 under an appropriate evaluation setting.
Worked reasoning The denominator contains every flagged order, not every truly defective order. Calling 90 percent the chance that an alert is correct swaps the conditioning direction. If the deployment defect rate changes, predictive value can change even if conditional detection rates remain stable. That is why a laboratory result cannot be moved unchanged into any population.
Extended teaching and laboratory
Conditional probabilities reverse only with additional information. Sensitivity P(alert|defect) differs from predictive value P(defect|alert). A natural-frequency table makes the denominator visible. Count true alerts and false alerts in the same population before computing what an alert means.
Changing prevalence changes predictive value even if sensitivity and false-positive rate stay fixed. That is a mathematical consequence, not evidence that the test’s internal mechanism necessarily changed. Separate population shift from a changed conditional performance rate.
Worked problem Among 10,000 jobs, 1% are defective. A screen detects 90% of defects and alerts on 5% of nondefective jobs. Calculate the probability that an alert is a defect.
Step-by-step reasoning 1. There are 100 defective and 9900 nondefective jobs. The screen yields 90 true alerts and 495 false alerts.
- All alerts total 585. The predictive value is 90/585≈15.38%, not 90%.
- The 90% figure uses defective jobs as its denominator; the requested probability uses alerts.
- A negative result is another conditional question with a different denominator. Do not obtain it by subtracting the positive predictive value from one.
Probability models, distributions and dependence
A sample space lists possible outcomes; an event is a set of outcomes. A probability measure is nonnegative, assigns one to the whole space, and adds probabilities over disjoint events. Consequently P(not A)=1−P(A) and P(A or B)=P(A)+P(B)−P(A and B). A random variable maps outcomes into numerical values. The same outcome can determine several variables, so different columns do not imply independent information.
A joint table assigns probabilities to combinations. Sum over unwanted categories to obtain a marginal. Conditioning restricts the reference group: P(A|B)=P(A and B)/P(B) when P(B)>0. Bayes' rule reverses the direction using P(A|B)=P(B|A)P(A)/P(B). The denominator can be computed by summing P(B|a)P(a) over mutually exclusive, exhaustive categories a. The native rare-defect examples show why sensitivity and alert precision have different denominators; their substantial original worked reasoning remains part of this course.
Independence means joint probabilities factor into marginals for all relevant events. Conditional independence given C means P(A,B|C)=P(A|C)P(B|C), a different assertion. For two independent fair binary variables X and Y, conditioning on X+Y=1 makes them dependent: knowing X=1 forces Y=0. Selecting a subgroup can therefore create associations. Repeating a measurement is not automatically independent confirmation; shared errors or copied fields require a joint model. A chain with the assumption that C is independent of A given B factors as P(A,B,C)=P(A)P(B|A)P(C|B); the factorization follows that stated assumption, not the variable names.
Mass, density, expectation and covariance
A discrete probability mass function sums to one. A probability density f is nonnegative and integrates to one; interval probability is ∫aᵇf(x)dx. A density may exceed one. For a uniform duration on [0,.25] hours, density is four per hour, while probability of a duration in [0,.1] is .4. An exact point has probability zero under this density. A cumulative distribution F(t)=P(X≤t) is nondecreasing, right-continuous and tends to zero and one at the respective infinities. Discrete CDFs jump by point masses. A continuous-density CDF has no jumps, but general distributions can mix discrete and continuous parts.
Expectation is a probability-weighted sum or integral, when it exists. For outcomes 0,2,6 with probabilities .5,.25,.25, E[X]=2 and E[X²]=10, so variance is 10−4=6 and standard deviation is √6. The expected value need not be a likely outcome. A nonlinear decision utility requires E[u(X)], which generally differs from u(E[X]). For u(x)=x², this example gives 10 versus four. Expected values and variance alone do not characterize tail risk.
Linearity gives E[aX+bY]=aE[X]+bE[Y] without independence when expectations exist. Variance needs dependence information: Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y), where Cov(X,Y)=E[XY]−E[X]E[Y]. Correlation divides covariance by both positive standard deviations. Scaling one variable by a negative constant reverses correlation's sign; translating it does not change correlation. Zero covariance does not imply independence. If X is equally likely to be −1,0,1 and Y=X², covariance is zero although Y is completely determined by X.
For a vector, its covariance matrix Σ has variances on the diagonal and pairwise covariances off diagonal. A weighted sum aᵀX has variance aᵀΣa. With Σ=[[4,1],[1,9]] and equal weights [.5,.5], variance is .25×4+.5×1+.25×9=3.75. Dropping the covariance term would give 3.25 and answer a different model.
Moment formulas require finite moments. The standard Cauchy density is 1/[π(1+x²)], not 1/(1+x²); the normalization matters. Its ordinary mean and variance are undefined. Symmetric cancellation can give a principal value zero without creating a finite expectation. For any finite-variance distribution with positive standard deviation, Chebyshev bounds P(|X−μ|≥kσ)≤1/k². At k=2 this bounds the outside probability by .25; it does not assert that exactly 75% are inside or that the distribution is normal.
Select a distribution by its experiment
A Bernoulli(p) variable records one binary outcome, with mean p and variance p(1−p). A binomial(n,p) count sums n independent Bernoulli trials with the same p: P(K=k)=choose(n,k)pᵏ(1−p)ⁿ⁻ᵏ, mean np and variance np(1−p). For n=4,p=.25, probability of exactly one success is 4×.25×.75³=.421875, with mean one and variance .75. A finite count with changing probabilities or dependent trials need not be binomial.
A discrete uniform variable on integers 1 through m has mass 1/m, mean (m+1)/2 and variance (m²−1)/12. A library's exclusive upper bound requires m+1 to include m. A continuous uniform variable on [a,b], a<b, has density 1/(b−a), mean (a+b)/2 and variance (b−a)²/12. Equal density means probabilities scale with interval length; it does not assign positive equal mass to every real point.
A Poisson(λ) count has P(K=k)=exp(−λ)λᵏ/k!, mean and variance λ. λ is the expected count over the declared exposure, not automatically a per-hour rate. A rate of two arrivals/hour over three hours gives λ=6 under a homogeneous Poisson-process model. Independent increments and a suitable event mechanism must be justified; clustering can defeat the model. Its CDF sums masses from zero through floor(t); a finite plotting grid does not make the remaining tail vanish.
A normal distribution N(μ,σ²), σ>0, has density exp[−(x−μ)²/(2σ²)]/(σ√(2π)). Standardization Z=(X−μ)/σ expresses values in standard-deviation units. For independent identically distributed observations with finite mean and finite nonzero variance, the classical central limit theorem describes the standardized sum approaching a standard normal distribution. It does not make the original observations normal or supply a universal sample-size cutoff. The law of large numbers concerns convergence of averages under suitable assumptions; neither law removes selection bias or dependence by increasing row count.
An exponential-family representation has form h(x)exp[η·T(x)−A(η)] with A normalizing the distribution. For Bernoulli p in (0,1), η=ln[p/(1−p)], T(x)=x, h(x)=1 and A(η)=ln(1+exp η). Substituting x=0 or 1 recovers 1−p and p. For independent observations the summed successes and sample count retain the parameter-dependent likelihood information in this model. Sufficient statistics are model-relative, not a claim that discarded data contain nothing relevant to any other question. A uniform distribution whose support itself depends on an unknown parameter needs additional qualifications before applying regular exponential-family results.
Optional changed record and reasoning
Change the three-outcome probabilities to [.25,.5,.25]. Calculate mean and variance. For the binomial example change p to .5, keeping n=4. Finally change the covariance matrix's off-diagonal entries from one to −one, retaining equal weights.
The mean becomes .25×0+.5×2+.25×6=2.5, and second moment is .5×4+.25×36=11. Variance is 11−2.5²=4.75. For the binomial, probability of exactly one success is 4(.5)⁴=.25, mean is two and variance is one. Equal-weight variance becomes one−.5+2.25=2.75. The same marginal variances can therefore yield a different aggregate risk because covariance changed. None of these constructed calculations establishes real arrival independence, a causal mechanism or population representativeness.
Optional criteria: state a sample space and conditioning denominator; distinguish mass from density; calculate moments and dependence terms; justify distribution assumptions and limitations. Award one point per fully explained criterion.
Apply the idea
Among 10,000 jobs, 1% are defective. A screen detects 90% of defects and alerts on 5% of nondefective jobs. Calculate the probability that an alert is a defect.
Prevalence rises to 10% in another 10,000-job population while both conditional alert rates stay the same. Recompute positive predictive value.
Read the worked reasoning
There are 1000 defective jobs, giving 900 true alerts, and 9000 nondefective jobs, giving 450 false alerts. Predictive value is 900/1350=66.67%. The alert becomes more informative in this population despite unchanged sensitivity and false-positive rate. Transporting the earlier 15.38% without checking prevalence would answer the wrong setting.
Check understanding
Why can high sensitivity coexist with low alert precision?
- Sensitivity and precision are always equal
Feedback
The metrics measure different properties.
- The number of negative cases never matters
Feedback
The large negative group can dominate alert counts.
- Rare events plus many false alerts among the large negative group
Feedback
Conditioning and prevalence determine different denominators.
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.
- Original on-site preparation — Probability models, distributions and dependence
- 2.6. Probability and Statistics Open the notebook in SageMaker Studio Lab
- 22.6. Random Variables Open the notebook in SageMaker Studio Lab
- 22.8. Distributions Open the notebook in SageMaker Studio Lab
- 22.9. Naive Bayes Open the notebook in SageMaker Studio Lab