From observations to fitted predictions
George Mason University
The secretary problem: also called the matching or marriage problem.
Say I have a budget to consider candidates, and they have the following scores (which I do not know)
1 7 4 5 3 8 10 3 0 11
I decide to screen 3 candidates before making a decision.
What’s your best strategy?
The peak is near and height (Monte Carlo, so the top wiggles).
You live in a house that is somewhat prone to mud slides.
Should you build the wall? Should you use the Geologist’s Test and Bayes Rule?
Let’s formally solve this as follows:
There’s also the possibility of a further test to see if the wall will hold.
Let’s include the testing option
If you choose the test, then should you build the wall?
Bayes Rule is as follows:
We’ll use this to find our optimal course of action.
The Bayes probability given a positive test is
The Bayes probability given a negative test is
Compare this to the initial base rate of a % chance of having a mud slide.
You build the wall without testing, what’s the probability that you lose everything?
With the given situation, there is one path (or sequence of events and decisions) that leads to losing everything:
You choose the test, what’s the probability that you’ll lose everything?
There are two paths that lead to losing everything:
For the first path
For the second path
Hence putting it all together
Risk-Return Trade-off
| Choice | Expected Cost | Risk | P |
|---|---|---|---|
| Don’t Build | $10,000 | 0.01 | 1 in 100 |
| Build w/o testing | $40,500 | 0.0005 | 1 in 2000 |
| Test | $10,760 | 0.00146 | 1 in 700 |
Expected Cost: Fee + Build + Loss
Expected cost: or $10,760
What do you choose?
Probability is a property of what you know.
Litowitz, Fortune, 15 September 2026. Opening of The Adaptability Quotient.
Coherence forces the same rules Kolmogorov wrote down.
The complement rule is 2 and 3 together. Violate any of them and someone can lock in a loss.
As grows, settles near .
Albert Solomon (1913)
Challenges
Pattern recognition
Impact
Chess Analogy
“Let’s say a chess game. And you don’t know the rules… you try to figure out what the rules are… You might discover that when there’s only one bishop around on the board, that the bishop maintains its color. Later on you might discover the law for the bishop is that it moves on a diagonal…”
Feynman on AI
“When we make a bird, the airplanes don’t fly like a bird… It’s different, right? So, there’s no question that the later machines are not going to think like people think… they’re not going to do arithmetic the same way as we do arithmetic, but they’ll do it better.”
Evolution in Chess:
Correlation coefficient: measures strength of linear relationship
Range:
Applications:
2012 Obama Election Prediction
| state | R.pct | O.pct | EV |
|---|---|---|---|
| Alabama | 61 | 38 | 9 |
| Alaska | 55 | 42 | 3 |
| Arizona | 54 | 44 | 11 |
| Arkansas | 61 | 37 | 6 |
| California | 38 | 59 | 55 |
| Colorado | 47 | 51 | 9 |
| Connecticut | 40 | 58 | 7 |
| D.C. | 7 | 91 | 3 |
| Delaware | 40 | 59 | 3 |
| Florida | 49 | 50 | 29 |
| Georgia | 53 | 45 | 16 |
| Hawaii | 28 | 71 | 4 |
| Idaho | 65 | 33 | 4 |
| Illinois | 41 | 57 | 20 |
| Indiana | 54 | 44 | 11 |
| Iowa | 47 | 52 | 6 |
| Kansas | 60 | 38 | 6 |
| Kentucky | 61 | 38 | 8 |
| Louisiana | 58 | 41 | 8 |
| Maine | 41 | 56 | 4 |
| Maryland | 37 | 62 | 10 |
| Massachusetts | 38 | 61 | 11 |
| Michigan | 45 | 54 | 16 |
| Minnesota | 45 | 53 | 10 |
| Mississippi | 56 | 44 | 6 |
| state | R.pct | O.pct | EV | |
|---|---|---|---|---|
| 26 | Missouri | 54 | 44 | 10 |
| 27 | Montana | 55 | 41 | 3 |
| 28 | Nebraska | 61 | 38 | 5 |
| 29 | Nevada | 46 | 52 | 6 |
| 30 | New Hampshire | 46 | 52 | 4 |
| 31 | New Jersey | 41 | 58 | 14 |
| 32 | New Mexico | 43 | 53 | 5 |
| 33 | New York | 36 | 63 | 29 |
| 34 | North Carolina | 51 | 48 | 15 |
| 35 | North Dakota | 59 | 39 | 3 |
| 36 | Ohio | 48 | 50 | 18 |
| 37 | Oklahoma | 67 | 33 | 7 |
| 38 | Oregon | 43 | 54 | 7 |
| 39 | Pennsylvania | 47 | 52 | 20 |
| 40 | Rhode Island | 36 | 63 | 4 |
| 41 | South Carolina | 55 | 44 | 9 |
| 42 | South Dakota | 58 | 40 | 3 |
| 43 | Tennessee | 60 | 39 | 11 |
| 44 | Texas | 57 | 41 | 38 |
| 45 | Utah | 73 | 25 | 6 |
| 46 | Vermont | 31 | 67 | 3 |
| 47 | Virginia | 48 | 51 | 13 |
| 48 | Washington | 42 | 56 | 12 |
| 49 | West Virginia | 62 | 36 | 5 |
| 50 | Wisconsin | 46 | 53 | 10 |
| 51 | Wyoming | 69 | 28 | 3 |
Calculate the probability of Obama having 270 EV or more
[1] 0.9631
Application in Election Forecasting:
Why Use Dirichlet for Polling?
Results of recent state polls in the 2008 United States Presidential Election between Barack Obama and John McCain.
n Observed Expected
1 1 18 12.2
2 3 28 27.0
3 4 56 56.5
4 5 105 94.9
5 6 126 132.7
6 7 146 159.1
[1] 0.8354598
To fit a Poisson distribution, we need to estimate its single parameter, λ.
A natural choice for the estimate, , is the sample mean of the observed counts.
We will explore the rationale for this choice and how to assess its reliability.
Let’s plot the observed and expected frequencies.
The density of normal is
The mean and variance of the normal distribution are:
Now Plot the histogram and the fitted normal curve.
We will look at two general methods for creating estimates: 1. The Method of Moments 2. The Method of Maximum Likelihood
This method equates sample moments with the theoretical moments of the distribution, which are functions of the parameters.
Procedure:
For a Poisson distribution, the first theoretical moment is the mean:
The first sample moment is the sample mean:
Equating them gives the method of moments estimate for λ:
This is precisely what was done in the alpha particle example.
For a Normal distribution, the first two theoretical moments are: Solving for the parameters gives: The method of moments estimates are found by replacing theoretical moments with sample moments:
Let’s fit a normal distribution to human body temperature data. We’ll use the method of moments to estimate μ and σ and visualize the fit.
[1] "Estimated mu: 98.25"
[1] "Estimated sigma: 0.73"
An estimate is wrong for two reasons.
Internet-scale makes the blue line vanish.
Eight calls took (in seconds)
The timeout is 2 seconds.
What share finished in time?
This is an empirical CDF!
For the eight times, is the share at most 2 seconds. For the next call, is a probability, and the eight counts are one estimate of it.
A later time cannot have a smaller accumulated probability: if , then .
For a fair die, what are and ? What event has probability ?
The blue step is the sample. The orange ramp is the model . At 2 seconds the sample says and the model says . Under the model, and , because a single instant has no length.
Which number would you trust for the next call?
0.75 0.5
Each face has probability , so jumps at .
, , and is the event .
Does that interval include a 2? The jump at 2 is in , not in the difference.
For uniform distribution on with PDF:
The CDF is:
1. Probability Calculations:
1. Probability Calculations:
2. Confidence Intervals:
3. Quality Control:
SAT scores are approximately . The green band is one standard deviation around the mean, . The red tail is .
Key Properties of :
The next call has seconds, so on .
The quantile is seconds, the smallest time that keeps 90% of the calls.
In general, .
That same quantile is a draw. Write as , the inverse of . Take and set . Then has CDF .
For the call model, . The draw returns the seconds already computed.
The same step works for any distribution whose quantile you can compute, and it returns an exact sample from .
R function: qnorm() for the normal distribution (and q* for other distributions)
[1] 1.959964
[1] 1328.971
The next block uses a sample to choose a model.
Sir Isaac Newton’s Role (1696):
The Process:
Example: 1 million coins minted, sample
One sample of 100 coins, then the same draw repeated 2000 times. The histogram is the sampling distribution of the mean.
Sample mean: 4.9951 grams
The red curve is a normal density with the mean and standard deviation of these 2000 sample means.
A CDF reads a probability from a known model. Now the tosses are known and is not.
Eight heads and two tails give
[[0.5 0.14551915]
[0.8 1. ]
[0.95 0.24714337]]
At the maximum, , giving .
The logarithm preserves the ordering of positive likelihoods.
10 minutes. Estimation notebook, notebooks/p1-estimation.ipynb.
Open the notebook. Plot both likelihoods, then multiply both counts by another factor.
The larger sample distinguishes nearby parameter values more strongly.
Imagine a machine whose true success probability is 0.6.
We observe 25 trials and calculate . Another team repeats the experiment independently.
Must the two estimates agree?
35 minutes. Notebook B. Switch the keyboard operator halfway through.
Explain which uncertainty the histogram measures.
The formula has two standard deviations. They answer different questions.
| Question, at | Standard deviation |
|---|---|
| Will the next click happen? | |
| How far is from 100 clicks? |
25 0.601392 0.09798603133100146
100 0.600142 0.048667852181907514
400 0.6002105000000001 0.024467364789653993
The spread matches . Four times the sample size, about half the spread.
Galton Board: Physical demonstration of the CLT
The central limit theorem is not wrong here. Its main assumption, independence, is broken.
Each ball’s randomness has two parts:
As grows, the part dominates. does not settle at . It settles at that ball’s own coin, or . The limit of the standardized is a two-point distribution, not . The picture is two bells, because the theorem still works inside each coin, at a location chosen by one coin draw.
Every pair of bounces from the same ball is correlated through the shared coin: . That correlation does not shrink with the distance between the rows, so
Averaging removes noise that is independent from one observation to the next. It cannot remove a factor every observation shares, and with a shared coin that factor sets the shape.
Standard Error decreases with :
This means: To halve uncertainty, you need to quadruple sample size!
The Math:
Practical Implications:
Key Insight: The relationship is logarithmic - each doubling of sample size reduces uncertainty by
Scenario: Quality control for coin weights
Required sample sizes:
Required sample size: 385
This gives CI width: 0.02 grams
CI widths for different sample sizes:
n = 100 → CI width = 0.0392 grams
n = 400 → CI width = 0.0196 grams
n = 1600 → CI width = 0.0098 grams
n = 6400 → CI width = 0.0049 grams
The Cost of Precision: - To get 4x more precise (0.08 → 0.02 grams), need 16× more data! - This is why large-scale experiments are expensive but necessary
The Challenge:
The Solution:
The Math: where = number of phones With massive , standard error becomes incredibly small!
Search requests are assigned at random to the current algorithm or a new one. Success is a click on a result. 2500 requests each.
| Algo 1 | Algo 2 | |
|---|---|---|
| Success | 1755 | 1818 |
| Failure | 745 | 682 |
| Total | 2500 | 2500 |
The same standard error, , for each click rate and for their difference.
0.702 0.7272
(0.6840707239008375, 0.7199292760991625)
(0.7097403640054438, 0.7446596359945561)
(-0.05022594314910829, -0.00017405685089171008)
You just watched an interval miss zero by . That gap was earned by random assignment.
A narrow interval means the sample agreed with itself. It does not mean the sample was the population.
Independent observations, one unknown mean, variance held fixed:
The log-likelihood is the sum of the log densities:
Differentiate the sum of squares. The constant terms drop out.
Set that to zero. , so
Dataset: SAT score for 1000 students
| Parameter | Value |
|---|---|
| μ (mean) | 103.33 |
| σ² (variance) | 203.92 |
| σ (std dev) | 14.28 |
| n (sample size) | 1000.00 |
# Define negative log-likelihood function
neg_log_likelihood <- function(params, data) {
mu <- params[1]
sigma <- params[2]
# Ensure sigma is positive
if (sigma <= 0) return(Inf)
# Calculate negative log-likelihood
n <- length(data)
-sum(dnorm(data, mean = mu, sd = sigma, log = TRUE))
}
# Optimize using built-in optimizer
result <- optim(c(50, 10), neg_log_likelihood, data = sat$sat_sum)
mu_optim <- result$par[1]
sigma_optim <- result$par[2]
# Create results table for optimization
optim_table <- data.frame(
Parameter = c("μ", "σ"),
Analytical = c(round(mu_mle, 2), round(sigma_mle, 2)),
Optimized = c(round(mu_optim, 2), round(sigma_optim, 2)),
Difference = c(round(abs(mu_mle - mu_optim), 6), round(abs(sigma_mle - sigma_optim), 6))
)
kable(optim_table, caption = "Comparison of Analytical vs Numerical Optimization Results")| Parameter | Analytical | Optimized | Difference |
|---|---|---|---|
| μ | 103.33 | 103.33 | 0.000542 |
| σ | 14.28 | 14.28 | 0.002433 |
95% Confidence Interval for μ:
Lower bound: 102.44
Upper bound: 104.21
Margin of error: 0.89
For an i.i.d. sample from a Poisson(λ) distribution, the log-likelihood is:
To find the maximum, we take the derivative with respect to λ and set it to zero:
For the Poisson distribution, the Method of Moments and the Maximum Likelihood estimates are the same.
A law for a positive number: a waiting time, a rainfall amount, a claim size.
Same scale, three shapes. Shape 1 piles up at zero. Larger shape moves the mass to the right and makes a hump.
dgamma(..., rate = ) is that form. The curve does not change.For the Gamma distribution, the log-likelihood is: The MLEs for α and λ don’t have a simple closed-form solution and must be found numerically by maximizing this function.
Let’s fit a Gamma distribution to the inter-arrival times of gamma-rays.
[1] "MLE for alpha: 1.0263"
[1] "MLE for lambda: 0.0128"
A law for a count, like the Poisson, with one extra fact: the variance is larger than the mean.
Mean fixed at 4. The Poisson is the narrowest. Small puts more mass at zero and a longer right tail.
Potato beetles per plant. The count is the negative binomial from the last slides.
[1] "MLE for r (size): 2.24"
[1] "MLE for mean (mu): 4.7"
| Output Type | Problem Type | Example |
|---|---|---|
| Binary | Classification | Spam detection |
| Categorical | Classification | Content categorization |
| Quantitative | Regression | House prices |
| Ordinal | Ranking | Customer satisfaction |
A quarter of the houses are small, and their average price is 2. The other three quarters are large, and their average price is 6. Prices are in the same thousands of dollars as the next slide.
Saratoga house prices
What does the slope say at 2,200 square feet?
[ 13.439394 113.12254185] 262.30898606787036
For Saratoga use the revised 1,728-row fit. Its intercept is extrapolation, not an identified land value.
R Code Explanation:
lm(): Fits linear model using least squaresprice ~ livingArea: Formula notation (dependent ~ independent)abline(): Adds regression line to plotFor Saratoga use the revised 1,728-row fit. Its intercept is extrapolation, not an identified land value.
(Intercept) livingArea
13.43939 113.12254
Interpretation:
Example: Predict price for 2,200 sq ft house
For Saratoga use the revised 1,728-row fit. Its intercept is extrapolation, not an identified land value.
| mle | mle_optim | ||
|---|---|---|---|
| (Intercept) | 13.44 | 13.44 | 13.40 |
| livingArea | 113.12 | 113.12 | 113.14 |
A curve through every point is easy. Would you trust it at ?
Would a negative residual sit above or below the line?
Squaring prevents positive and negative errors from canceling.
The factor simplifies the gradient. It does not change the minimizing line.
A new outcome at a chosen is the fitted line plus a fresh error. The line is estimated from the sample, so both pieces vary. Here is the residual standard deviation.
[1. 2. 3.]
X.shape == (3, 2) and theta.shape == (2,):| NumPy expression | Meaning | Shape |
|---|---|---|
X @ theta |
Three dot products | (3,) |
X * theta |
Elementwise scaling of columns | (3, 2) |
X.T |
Transpose | (2, 3) |
theta[:, None] |
Explicit column | (2, 1) |
.T does not make it a column.If two columns of are identical, only the sum of their coefficients affects .
Adding 1 to one coefficient and subtracting 1 from the other leaves every prediction unchanged.
Linear dependence can make the coefficients non-unique. We can still ask about predictions and the loss.
A partial derivative changes one parameter while holding the others fixed.
Compare an analytic derivative with central finite differences:
Which feature of the residual plot would you investigate?
We know the mechanism because we generated these observations.
The straight line cannot represent the whole conditional mean.
Which feature of your residual plot supports your explanation?
Notah Begay III
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Dave Pelz: From Rocket Scientist to Golf Analytics Pioneer
Data-Driven Golf Insight: Short game matters most for overall scoring
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Dataset: 195 professional golfers, 2000 PGA Tour season
Variables:
money: Official dollar winningsnevents: Number of official PGA eventsdrivedist: Average driving distance (yards)gir: Greens in regulation (percentage)avgputts: Average putts per roundGoal: Determine which factors most influence tour earnings
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 14856637.77 | 4206466.17 | 3.53 | 0.00 |
| nevents | -30066.53 | 11183.31 | -2.69 | 0.01 |
| drivedist | 21309.72 | 6912.98 | 3.08 | 0.00 |
| gir | 120855.16 | 17429.37 | 6.93 | 0.00 |
| avgputts | -15203044.72 | 2000904.79 | -7.60 | 0.00 |
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Problem: Extreme outlier suggests need for transformation
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 36.15 | 3.58 | 10.10 | 0.00 |
| nevents | -0.01 | 0.01 | -0.94 | 0.35 |
| drivedist | 0.01 | 0.01 | 2.40 | 0.02 |
| gir | 0.17 | 0.01 | 11.18 | 0.00 |
| avgputts | -21.13 | 1.70 | -12.42 | 0.00 |
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Remove nevents (t-statistic < 1.5, not significant)
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 36.17 | 3.58 | 10.11 | 0.00 |
| drivedist | 0.01 | 0.01 | 2.50 | 0.01 |
| gir | 0.17 | 0.01 | 11.19 | 0.00 |
| avgputts | -21.37 | 1.68 | -12.70 | 0.00 |
Key Insights:
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Over-performers (earning more than predicted):
Under-performers (earning less than predicted):
Practical Application: Model identifies players exceeding/falling short of statistical expectations
Use the verified 2000 PGA data. Raw coefficient sizes across different units do not rank causal importance. These fits are in-sample diagnostics.
Modern relevance: Analytics-driven approach now standard in professional golf training and strategy
2.1832796605662286 0.7431983221963678 1.673882572282309
Brain/body residuals do not rank intelligence. Exponentiating a log fit does not automatically estimate the arithmetic conditional mean.
Dataset: 62 mammal species (Jerison, 1973) - Brain weight (grams) - Body weight (kilograms)
| Mammal | Brain | Body |
|---|---|---|
| African_elephant | 5712.0 | 6654.000 |
| African_giant_pouched_rat | 6.6 | 1.000 |
| Arctic_Fox | 44.5 | 3.385 |
| Arctic_ground_squirrel | 5.7 | 0.920 |
| Asian_elephant | 4603.0 | 2547.000 |
| Baboon | 179.5 | 10.550 |
Question: How does brain size relate to body size across species?
Problems: Outliers, non-constant variance, poor fit
Diagnosis: Need transformation to fix model assumptions
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 2.183 | 0.107 | 20.439 | 0 |
| log(Body) | 0.743 | 0.032 | 23.477 | 0 |
Model:
Interpretation: - 10% increase in body weight → 7.4% increase in brain weight - Brain weight scales as Body0.74 (allometric scaling)
Diagnostic question: Does the transformed residual plot support a linear mean and roughly constant spread?
Brain/body residuals do not rank intelligence. Exponentiating a log fit does not automatically estimate the arithmetic conditional mean.
| Mammal | Brain | Body | Std.Res | Residual | Fit | |
|---|---|---|---|---|---|---|
| 11 | Chinchilla | 64.0 | 0.42 | 3.41 | 2.61 | 4.70 |
| 34 | Man | 1320.0 | 62.00 | 2.53 | 1.93 | 190.67 |
| 50 | Rhesus_monkey | 179.0 | 6.80 | 2.06 | 1.58 | 36.89 |
| 6 | Baboon | 179.5 | 10.55 | 1.64 | 1.26 | 51.13 |
| 42 | Owl_monkey | 15.5 | 0.48 | 1.44 | 1.10 | 5.14 |
Key Finding: Humans and some small mammals have disproportionately large brains!
A 1/0 column standing in for a yes/no feature. The intercept is the mean when that column is 0. The coefficient is how the mean shifts when it is 1. “Has a garage” is this: one column.
A factor with more than two levels is the same idea, repeated.
Neighborhood is A, B, or C. You cannot put into a sum. You make two columns and omit A as the reference:
| House | ||
|---|---|---|
| A | 0 | 0 |
| B | 1 | 0 |
| C | 0 | 1 |
The intercept is the mean for A. The coefficient on is how B differs from A. Four neighborhoods would be three columns.
R’s lm drops the first level of a factor. factor(nbhd, levels = c("A","B","C")) makes A the reference. That is a modeling decision, not a default to ignore.
If you want “typical house” as the baseline, put that level first. If you change the reference, every coefficient changes and the fitted values do not.
Mean Rule:
Binary Classification (Thresholding):
Nearest Neighbor Rule:
Trade-off: Mean rule (high bias, low variance) vs NN rule (low bias, high variance)
Problem: Not all relationships are linear!
Examples: Stock prices, population growth, brain-body relationships
Apple Stock (2000-2024): Exponential growth pattern
[1] "AAPL"
Observation: Linear model would be poor fit for exponential growth
Problem: Straight line cannot capture curved relationship
Compounding Formula:
Example: $1,000 investment at 10% annual rate - Annual compounding: - Monthly compounding:
Extreme example: 0.1% daily compounding for 4 years
Key Limit: as
Exponential Growth Model:
Log Transformation:
Power Law Model:
Examples:
Log-Log Transformation:
Interpretation: is the elasticity (% change in per % change in )
Remember: Coefficients in log models represent percentage effects!
Business Examples:
Scientific Examples:
Key Insight: Transform to reveal hidden linear structure
Practice small calculations and explanations:
Conditional means and the assumptions behind a prediction.
CDFs, likelihood, and sampling variability.
Fitted values, residuals, loss, and one gradient update.
Compare a numerical prediction with a predicted class probability.
Work individually.
What does a slope of 2 mean in the units of and ?
What does a curved residual pattern suggest?
Why does a small training loss leave a question about future predictions unanswered?
AII 600