AI Foundations: AII 600

Introduction: AI Today and in the Past. Probability and Bayes Rule

Vadim Sokolov

George Mason University

Fall 2026

Course Page, Slides

References

Bayes, AI and Deep Learning

Polson and Sokolov

  • Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, 2007.
  • Kevin Murphy, Machine Learning: A Probabilistic Perspective, MIT Press, 2013.
  • Trevor Hastie, Robert Tibshirani, and Jerome Friedman, The Elements of Statistical Learning: Data Mining, Inference, and Prediction, 2nd ed., Springer, 2009.

Logistics

Syllabus. Submit on Canvas.

  • Wednesdays 7:20–10:00, Enterprise 276. Weeks 1–7 lecture. Week 8 midterm. Weeks 9–14 studio and the project. Week 15 is the defense. Lecture is optional.

  • Labs 10, midterm 40, studio 10, defense 40. A correct number is not enough. You have to say what it means and what would change the choice.

  • Nothing is due tonight. Lab 1 is due before next class. On-time submission is the 10%. Not graded.

  • Laptops stay closed between stops. Open them on the orange slide. Use whatever AI you want at the stop, and disclose it. You are responsible for work you did not write. Midterm: pen and paper, one cheat sheet, no laptop, phone, or watch.

  • Set up the tutor this week, about ten minutes. R or Python; use the language you will defend.

  • I suggest cursor as your AI agent. $20 (16 if you pay for a year) subscription should be enough for the course.

Random facts

On this Day (August 26):

  • 1682: Edmond Halley observes the comet later named after him. He will show it is the same body seen in 1531 and 1607, returning on a 76-year orbit.
  • 1789: France’s National Constituent Assembly adopts the Declaration of the Rights of Man and of the Citizen.
  • 1883: Krakatoa enters the climactic phase of its eruption. The explosions the next morning are the loudest sound in recorded history.
  • 1920: The 19th Amendment is certified. American women have the right to vote.
  • 1957: The Soviet Union announces it has tested an intercontinental ballistic missile, the rocket technology that leads to Sputnik two months later.

How tonight works

  • Four blocks. In each one I lecture for 20 to 30 minutes, then we stop. Lids down while I talk.

  • You work the problem on your own first. Then compare with a neighbor. Laptop and AI are allowed at the stop. Then we reveal and start the next block.

  • The orange slides are the stop. Stay there until we discuss. The green slides are the solution. Do not skip ahead.

  • The take-home lab is separate. These in-class problems are not submitted.

Brief History of AI

The first thoughts about artificial intelligence

The wish is old: Talos, Galatea, clay, a golem.

Albertus Magnus, 13th century, spends years on a brass head that answers questions.

  • Thomas Aquinas, his student, smashes it.
  • The legend: it would not stop talking, or speech without a soul was intolerable.
  • The question is already Turing’s. Speech is not understanding.

Mechanical machines

Robots and Automatic Machines Were Generally Very Inventive: Al-Jazari (XII Century)

Hesdin Castle (Robert II of Artois), Leonardo’s robot…

Mechanical machines

Jaquet-Droz automata (XVIII century):

Mechanical machines

  • But this is in mechanics, in mathematics/logic AI it was quite rudimentary for a long time

Logic machine of Ramon Llull (XIII-XIV centuries)

  • Starting with Dr. Frankenstein, further AI in the literature appears constantly …

Turing Test

  • AI as a science begins with a Turing test (1950).
  • The idea of the Turing test is to check if a machine can imitate a human in a conversation.
  • The original formulation was more nuanced.

Shannon’s Theseus

  • YouTube Video
  • Early 1950s, Claude Shannon (The father of Information Theory) demonstrates Theseus
  • A life-sized magnetic mouse controlled by relay circuits, learns its way around a maze.

Stanford Cart

  • YouTube Video
  • Takes 2.6-second for signal to travel from earth to the moon
  • Latest iterations is automated with 3D vision capabilities
  • Pause after each meter of movement and take 10-15 minutes to reassess its surroundings and reevaluate its decided path.
  • In 1979, this cautious version of the cart successfully made its way 20 meters through a chair-strewn room in five hours without human intervention.

What an AI system needs

Dartmouth workshop

  • AI as a science appeared in 1956 at the Dartmouth workshop.
  • It was organized by John McCarthy, Marvin Minsky, Claude Shannon and Nathaniel Rochester.
  • It was probably the most ambitious grant proposal in the history of computer science.

Dartmouth workshop

From the proposal:

  • A 2-month, 10-man study of artificial intelligence, summer 1956, Dartmouth College.
  • The conjecture: every aspect of learning or any other feature of intelligence can in principle be so precisely described that a machine can be made to simulate it.
  • The agenda: make machines use language, form abstractions and concepts, solve problems now reserved for humans, and improve themselves.
  • The bet: a significant advance if a carefully selected group of scientists work on it together for a summer.

1956-1960: Great hopes

  • Optimistic time. It seemed a that we were almost there…
  • Allen Newell, Herbert A. Simon, and Cliff Shaw: Logic Theorist.
  • Automated reasoning.
  • It was able to prove most of the Principia Mathematica, in some places even more elegant than Russell and Whitehead.

1956-1960: Big Hopes

  • General Problem Solver (Newell and Simon): means-ends analysis. Look at the goal, look at where you are, apply an operator that shrinks the gap. Search, not learning.
  • Arthur Samuel’s checkers (1959): the program played itself and got better. No grandmaster wrote the evaluation. AlphaGo is this idea with a neural net.
  • McCarthy’s Lisp (1958): the language these programs were written in. Lists as data and as code.
  • Microworlds, a few years later: Evans’s Analogy (IQ items), Bobrow’s Student (algebra word problems), Winograd’s Blocks World (stack the red cube). Each worked in a box small enough that “understand” meant a few dozen objects.

1970s: Knowledge Based Systems

  • The bottom line: to accumulate a fairly large set of rules and knowledge about the subject area, then draw conclusions.
  • First success: MYCIN - Diagnosis of blood infections:
    • about 450 rules
    • The results are like an experienced doctor and significantly better than beginner doctors.

1980-2010: Commercial applications Industry AI

  • The first AI department was at DEC (Digital Equipment Corporation). It is argued that by 1986 it saved DEC about $10 million per year.
  • The boom ended by the end of the 80s, when many companies could not live up to high expectations.

1990-2010: DATA MINING, MACHINE LEARNING

  • In recent decades, the main emphasis has shifted to machine learning and search for patterns in the data.
  • Especially - with the development of the Internet.
  • Not too many people remember the original AI ideas, but Machine Learning is now everywhere.
  • Robotics flourishes (Physical AI) and uses Machine Learning at every step.

Rule-Based System vs Bayes

  • Since 1956, the field of artificial intelligence (AI) has undergone significant transformations
  • traditional AI was mostly focused on rule-based systems and boolean logic programming, with limited learning capabilities. It lead to them being brittle in changing environments.
  • On the other hand, emerging AI is focused on modeling uncertainties, pattern matching, and deep learning.
  • All of those are data-driven approaches.
  • These approaches are more adaptable and can handle complex and unstructured data. They are also more data-dependent and lack interpretability.

Rule-Based System vs Bayes

Old AI


If rain outside, then take umbrella

This rule cannot be learned from data. It does not allow inference. Cannot say anything about rain outside if I see an umbrella.


 

New AI

Probability of taking umbrella, given there is rain

Conditional probability rule can be learned from data. Allows for inference. We can calculate the probability of rain outside if we see an umbrella.

  • Bayesian approach is a powerful statistical framework based on the work of Thomas Bayes and later Laplace.
  • It provides a probabilistic approach to reasoning and learning
  • Allowing us to update our beliefs about the world as we gather new data.
  • This makes it a natural fit for artificial intelligence, where we often need to deal with uncertainty and incomplete information.

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

A hospital currently uses 400 if-then rules, written by doctors, to recommend antibiotics. Write two sentences.

  • One failure mode of this rule system that a probabilistic model, trained on outcomes, would not have.
  • One failure mode of that data-driven model that the rule system would not have.

Self-check: solution

Count it right if sentence 1 names brittleness or the absence of a degree of belief, and sentence 2 names inheriting whatever the history rewarded. The paragraphs below are one way to say that.

  • The rules do not learn from new cases, and they have no degree of belief: a missing symptom or a slightly different presentation can make the system silent or wrong, with no probability attached. A probabilistic model can put weight on incomplete evidence and update as outcomes arrive.
  • The data-driven model will recommend whatever the historical data rewarded, including outdated practice, coding artifacts, and groups that were never treated. The rule system can encode a constraint the hospital actually wants, even if it has never appeared in the data.

DEFINITION

  • How to determine “learning”?

Definition:

The computer program learns as the data is accumulating relative to a certain problem class \(T\) and the target function of \(P\) if the quality of solving these problems (relative to \(P\)) improves with gaining new experience.

  • The definition is very (too?) General.
  • What specific examples can be given?

Tasks and concepts of ML

Tasks and concepts of ML: Supervised Learning

  • training sample – a set of examples, each of which consists of input features (attributes) and the correct “answers” - the response variable
  • Learn a rule that maps input features to the response variable
  • Then this rule is applied to new examples (deployment)
  • The main thing is to train a model that explains not only examples from the training set, but also new examples (generalizes)
  • Otherwise - overfitting

Tasks and concepts of ML: unsupervised learning

There are no correct answers, only data, e.g. clustering:

  • We need to divide the data into pre -unknown classes to some extent similar:
    • highlight the family of genes from the sequences of nucleotides
    • cluster users and personalize the application for them
    • cluster the mass spectrometric image to parts with different composition

Tasks and concepts of ML: unsupervised learning

  • Dimensionality reduction: a pathologist has 10,000 gene measurements per tumor and 200 tumors. Nobody can look at 10,000 axes. PCA (or a similar map) finds two or three directions that still separate the subtypes. The plot is the product; the 10,000 numbers were the raw material.
  • Matrix completion: Netflix is a users-by-movies table that is almost empty. The prize was to fill the holes: what would this person have rated this film? Same job as a sensor that failed for an hour: what would it have read?
  • Anomaly detection: a card that usually spends $40 at grocery stores charges $1,200 at 3am in another country. You did not train on a labeled “fraud” class. You trained on what usual looks like, and this is not that.
  • Semi-supervised: 10,000 product photos, 200 with labels. Use the unlabeled pile to learn what “looks like the same thing,” then the 200 names to tag the groups. Most of the data never had an answer.

Tasks and concepts of ML: reinforcement learning

  • Multi-armed bandits: three headlines for the same landing page. Each visitor is a pull: they click or they do not. You do not know which headline converts. The job is to show ads this week so the total clicks are as high as possible, not to write a report on which headline is best in the limit.
  • Exploration vs. exploitation: the headline that is winning so far vs. a fourth headline you have barely tried. Netflix is the same trade: keep recommending the show they already click, or risk a new one that might be the one they actually want.
  • Credit assignment: AlphaGo wins 200 moves later. The reward is one bit at the end. Which of those 200 moves deserved it? Same problem as a robot that only hears “the tower stood” after the last block.

Tasks and concepts of ML: active learning

The three paradigms say what you are given. These are decisions you make while you learn. They are not a fourth paradigm.

  • Active learning: labels cost money or time. Do not label at random. Query the point where the current model is most unsure, or where an answer would change the decision. A test you have not chosen yet is an expensive experiment.
  • Boosting: one weak rule is a coin flip. Many weak rules, each trained on the mistakes of the last, can be a strong classifier. Gradient boosting is this idea with the volume turned up.
  • Model selection: a model with more parameters will fit last week’s data. The question is next week’s. Weeks 10 and 11 are this problem: cross-validation, then ridge and lasso as a way to choose the size rather than guess it.
  • Ranking: the output is an order, not a class. Search, recommendations, “which patient first.” A good ranking can have a terrible accuracy and still be the right model for the decision.

Tasks and concepts of AI

Tasks and concepts of AI: Reasoning

Reasoning is computing what else follows from what you already believe. Old AI used logic. New AI uses probability. A Bayes net is the clean version. An LLM chain is the messy one. This course is the clean one, so you can check the messy one.

  • Bayesian networks: write \(P(\text{child} \mid \text{parents})\). Inference is \(P(\text{query} \mid \text{evidence})\). This is the rest of Module 1.
  • Modern loops: ReAct is thought → tool → observation, then again. Tree-of-thought branches and scores paths. Reflexion writes what went wrong and retries. o1-style models hide a search like that inside the model.
  • Agents: the same loop is allowed to act (call a function, write a file). The reasoning is in the loop, not in a larger weight matrix.

If you cannot say what was conditioned on, you did not reason. You generated.

Tasks and concepts of AI: Representation

Reasoning needs something to reason over. Generation needs something to generate from. That object is a representation. Old AI wrote it by hand. New AI learns it from data. Same job.

  • Knowledge graphs: Paris — capital_of — France. You can query and compose facts. Brittle when the edge was never entered.
  • Embeddings: each object is a point. Nearby means similar. “King − man + woman” lands near “queen”. No edge had to be typed.
  • Transformers: “Bank” next to “river” is not “bank” next to “loan”. Self-attention builds that context.

A representation is a bet about which distinctions matter. A bad one makes every later model look worse than it is.

Generation: a Bayesian poem

In shadows of data, uncertainty reigns,
Bayesian whispers, where knowledge remains.
With prior beliefs, we start our quest,
Updating with evidence, we strive for the best.

A dance of the models, predictions unfold,
Inferences drawn, from the new and the old.
Through probabilities, we find our way,
In the world of AI, it’s the Bayesian sway.

So gather your data, let prior thoughts flow,
In the realm of the unknown, let your insights grow.
For in this approach, with each little clue,
We weave understanding, both rich and true.

Music

Generation: a DALL-E call

from openai import OpenAI
client = OpenAI(api_key="your-api-key")
response = client.images.generate(
    model="dall-e-3",
    prompt="a hockey player trying to understand the Bayes rule",
    size="1024x1024",
    quality="standard",
    n=1,
)

print(response.data[0].url)

Generation: hockey player

A humorous and illustrative scene of a hockey player sitting on a bench in full gear, holding a hockey stick in one hand and a whiteboard marker in th

Generation: where this actually runs

Where this actually runs. Not a demo.

  • Text: email, support replies, code, search answers. ChatGPT, Claude, Gemini, Copilot. A large share of the prose at work this year was proposed by a model.
  • Images: product shots, storyboards, the hockey player on the last slide. Midjourney, Flux, Imagen.
  • Video ads: Higgsfield takes a product URL and emits UGC-style spots with a consistent spokesperson, native audio, and dozens of variants for Meta and TikTok. Runway, Kling, and Veo do the film-like version of the same job.
  • Voice and music: ElevenLabs for speech; Suno for the song two slides back.
  • The industrial use in marketing is not one perfect ad. It is a hundred variants, then a test. Generation made the variants cheap. It did not decide which one to run.

Sampling from \(P(\text{output} \mid \text{prompt})\) is the mechanism. Selecting the sample is still a decision.

Chess and AI

Old AI: Deep Blue (1997) vs. Garry Kasparov.

  • Search plus a hand-written evaluation. Grandmasters wrote the rules for what a position is worth. The machine did not learn from games.
  • About 200 million positions a second. Kasparov lost the match 3.5-2.5. That is brute force, not probability.

Kasparov vs IBM’s DeepBlue in 1997

AlphaGo Zero

  • Remove all human knowledge from training process - only uses self play,
  • Takes raw board as input and neural network predicts the next move.
  • Monte Carlo tree search: from this position, play out many games to the end and count who wins. The move that wins more often is the one you play. That is sampling, not Deep Blue’s 200 million-position brute force.
  • The algorithm was able to beat AlphaGo 100-0. The algorithm was then used to play chess and shogi and was able to beat the best human players in those games as well.

Alpha GO vs Lee Sedol: Move 37 by AlphaGo in Game Two

Probability in machine learning

A model that only emits a point answer is unfinished. How confident is this? How well does it describe the data we have? If we ran the experiment again, how much would the number move? Classification, generation, and AlphaGo all produce those questions. A rule that fires or does not cannot.

  • Supervised: \(P(y \mid x)\), not only \(\hat{y}\).
  • Unsupervised: a distribution over structure we did not label.
  • Reinforcement: random rewards; exploration is a bet about what we do not know yet.
  • Generation: sampling from \(P(\text{output} \mid \text{prompt})\).
  • Old AI: if rain, take umbrella. New AI: \(P(\text{umbrella} \mid \text{rain})\), which you can invert.

The rest of tonight, and the next six weeks, is the machinery behind those statements.

Bayes Approach

Review of Basic Probability Concepts

Probability lets us talk efficiently about things that we are uncertain about.

  • What will Amazon’s sales be next quarter?
  • What will the return be on my stocks next year?
  • How often will users click on a particular Google ad?

All these involve estimating or predicting unknowns!!

Random Variables

Random Variables are numbers that we are not sure about. There’s a list of potential outcomes. We assign probabilities to each outcome.

Example: Two fair coins. Four equally likely outcomes:

\[\{TT,\; TH,\; HT,\; HH\}\]

Let \(X\) be the number of heads. \(X\) is not the coins. \(X\) is a function from those four outcomes to a number.

Random Variables

\[ \begin{array}{c|c} \text{outcome} & X \\ \hline TT & 0 \\ TH & 1 \\ HT & 1 \\ HH & 2 \end{array} \]

So \(X\) can be \(0\), \(1\), or \(2\). We do not yet know which. The next slide is the list of probabilities for those three numbers. That list is the distribution of \(X\).

Probability

Probability is a language designed to help us communicate about uncertainty. We assign a number between \(0\) and \(1\) measuring how likely that event is to occur. It’s immensely useful, and there’s only a few basic rules.

  1. If an event \(A\) is certain to occur, it has probability \(1\), denoted \(P(A)=1\)
  2. Either an event \(A\) occurs or it does not. \[P(A) = 1 - P(\text{not }A)\]
  3. If two events are mutually exclusive (both cannot occur simultaneously) then \[P(A \text{ or } B) = P(A) + P(B)\] In general, when they can overlap, \[P(A \text{ or } B) = P(A) + P(B) - P(A \text{ and } B)\]
  4. Joint probability, when events are independent \[P(A \text{ and } B) = P( A) P(B)\]

Probability Distribution

We describe the behavior of random variables with a Probability Distribution

Example: Suppose we are about to toss two coins. Let \(X\) denote the number of heads.

\[X = \left\{ \begin{array}{ll} 0 \text{ with prob. } 1/4\\ 1 \text{ with prob. } 1/2\\ 2 \text{ with prob. } 1/4 \end{array} \right.\]

\(X\) is called a Discrete Random Variable

Question: What is \(P(X=0)\)? How about \(P(X \geq 1)\)?

Pete Rose Hitting Streak

Pete Rose of the Cincinnati Reds set a National League record of hitting safely in \(44\) consecutive games …

  • Rose was a \(300\) hitter. Assume he comes to bat \(4\) times each game.
  • Each at bat is assumed to be independent, i.e., the current at bat doesn’t affect the outcome of the next.

What probability might reasonably be associated with that hitting streak?

Joe DiMaggio’s record is \(56\)! His batting average was \(.325\)

Pete Rose Hitting Streak (Solution)

Let \(A_i\) be the event that Rose hits safely in game \(i\). Independence across games gives

\[P(A_1 \cap \cdots \cap A_{44}) = P(A_1)\cdots P(A_{44}) = \bigl(P(A_1)\bigr)^{44}\]

One game, four independent at-bats, batting average \(0.300\):

\[\begin{align*} P(A_1) &= 1 - P(\text{four outs}) \\ &= 1 - (0.7)^4 \\ &= 0.7599 \end{align*}\]

So \[P(\text{44-game hitting streak}) = (0.7599)^{44} \approx 5.67 \times 10^{-6}\]

Pete Rose Hitting Streak (Inference)

There are three basic inferences:

  • The odds for a particular player as good as Pete Rose starting a hitting streak today are about 176,500 to 1
  • That does not mean the run of \(44\) will never be beaten by some player at some time: the Law of Very Large Numbers
  • Joe DiMaggio’s record is \(56\). Batting average \(0.325\), so \(P(A_i)=1-(0.675)^4=0.7924\), and \((0.7924)^{56} \approx 2.19 \times 10^{-6}\), or about 456,000 to 1. Hard to beat.

Conditional, Joint and Marginal Distributions

Use probability to describe outcomes involving more than one variable at a time. Need to be able to measure what we think will happen to one variable relative to another

In general the notation is ...

  • \(P(X=x, Y=y )\) is the joint probability that \(X =x\) and \(Y=y\)
  • \(P(X=x \mid Y=y )\) is the conditional probability that \(X\) equals \(x\) given \(Y=y\)
  • \(P(X=x)\) is the marginal probability of \(X=x\)

Conditional, Joint and Marginal Distributions

Relationship between the joint and conditional ...

\[\begin{align*} P(x,y) & = P(x) P(y \mid x) \\ & = P(y) P(x \mid y) \end{align*}\]

Relationship between the joint and marginal ...

\[\begin{align*} P(x) & = \sum_y P(x,y) \\ P(y) & = \sum_x P(x,y) \end{align*}\]

Example: Happiness Index

“happiness index” as a function of salary.

Salary (\(X\)) Happiness (\(Y\)): 0 (low) 1 (medium) 2 (high)
low 0 0.03 0.12 0.07
medium 1 0.02 0.13 0.11
high 2 0.01 0.13 0.14
very high 3 0.01 0.09 0.14

Is \(P(Y=2 \mid X=3) > P(Y=2)\)?

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

A wealth-management team wants to pitch a “wellbeing” product only to top-salary clients. The table is last year’s book.

Salary \(X\) / Happiness \(Y\) 0 1 2
0 0.03 0.12 0.07
1 0.02 0.13 0.11
2 0.01 0.13 0.14
3 0.01 0.09 0.14
  • What share of the book is both top-salary and high-happiness? That is who the pitch is even talking to.
  • What share of the whole book is high-happiness? What share is top-salary?
  • Among top-salary clients, what share is high-happiness? Among high-happiness clients, what share is top-salary?
  • The deck says “our highest earners are the happy ones.” Restrict the product to the top band, or did they mix up a slice with the whole book?

Self-check: solution

  • One cell: \(P(X=3,Y=2)=0.14\). Fourteen percent of the book.
  • High-happiness is the last column: \(P(Y=2)=0.07+0.11+0.14+0.14=0.46\). Top-salary is the last row: \(P(X=3)=0.01+0.09+0.14=0.24\).
  • Among top-salary: \(0.14/0.24\approx 0.583\). Among high-happiness: \(0.14/0.46\approx 0.304\). Same cell, two different denominators. Those are not the same claim.
  • \(0.583>0.46\), so high happiness is more common in the top band than in the book. That supports a slice story, not “high earners are the happy ones”: most high-happiness clients (\(1-0.304\)) are not in the top band. Restricting the product to \(X=3\) walks past most of the people who are already happy. 42% of the top band is not high-happiness.

Bayes Rule: from joint and prior

The computation of \(P(x \mid y)\) from \(P(x)\) and \(P(y \mid x)\) is called Bayes theorem ... \[ P(x \mid y) = \frac{P(y,x)}{P(y)} = \frac{P(y,x)}{\sum_x P(y,x)} = \frac{P(y \mid x)P(x)}{\sum_x P(y \mid x)P(x)} \]

This shows now the conditional distribution is related to the joint and marginal distributions.

You’ll be given all the quantities on the r.h.s.

Bayes Rule: \(P(x \mid y)\) is not \(P(y \mid x)\)

Key fact: \(P(x \mid y)\) is generally different from \(P(y \mid x)\)!

Example: Most people would agree

\[\begin{align*} Pr & \left ( Practice \; hard \mid Play \; in \; NBA \right ) \approx 1\\ Pr & \left ( Play \; in \; NBA \mid Practice \; hard \right ) \approx 0 \end{align*}\]

The main reason for the difference is that \(P( Play \; in \; NBA ) \approx 0\).

Independence

Two random variable \(X\) and \(Y\) are independent if \[ P(Y = y \mid X = x) = P (Y = y) \] for all possible \(x\) and \(y\) values. Knowing \(X=x\) tells you nothing about \(Y\)!

Example: Tossing a coin twice. What’s the probability of getting \(H\) in the second toss given we saw a \(T\) in the first one?

Sally Clark Case: Independence or Bayes?

Sally Clark was accused and convicted of killing her two children

They could have both died of SIDS.

  • The chance of a family which are non-smokers and over 25 having a SIDS death is around 1 in 8,500.

  • The chance of a family which has already had a SIDS death having a second is around 1 in 100.

  • The chance of a mother killing her two children is around 1 in 1,000,000.

Bayes or Independence

  1. Under Bayes \[\begin{align*} P \left( \mathrm{both} \; \; \mathrm{SIDS} \right) & = P \left( \mathrm{first} \; \mathrm{SIDS} \right) P \left( \mathrm{Second} \; \; \mathrm{SIDS} | \mathrm{first} \; \mathrm{SIDS} \right) \\ & = \frac{1}{8500} \cdot \frac{1}{100} = \frac{1}{850,000} \end{align*}\]

The \(\frac{1}{100}\) comes from taking into account genetics.

  1. Independence, as the court did, gets you

\[ P \left( \mathrm{both} \; \; \mathrm{SIDS} \right) = (1/8500) (1/8500) = (1/73,000,000) \]

  1. By Bayes rule

\[ \frac{p(I|E)}{p(G|E)} = \frac{P( E \cap I)}{P( E \cap G)} \] \(P( E \cap I) = P(E|I )P(I)\) needs discussion of \(p(I)\).

Comparison

  • Hence putting these two together gives the odds of innocence as

\[ \frac{p(I|E)}{p(G|E)} = \frac{1/850,000}{1/1,000,000} = 1.18 \] This step treats the two stories as the only hypotheses and gives them equal prior odds. That is a modeling choice; \(p(I)\) still needs a real discussion.

In terms of posterior probabilities

\[ p( G|E) = \frac{1}{1 + 1.18} \approx 0.46 \]

  • If you use independence

\[ \frac{p(I|E)}{p(G|E)} = \frac{1}{73} \; \text{and} \; p( G|E) \approx 0.99 \] The suspect looks guilty.

Random Variables: Expectation \(E(X)\)

The expected value of a random variable is simply a weighted average of the possible values X can assume.

The weights are the probabilities of occurrence of those values.

\[E(X) = \sum_x xP(X=x)\]

With \(n\) equally likely outcomes with values \(x_1, \ldots, x_n\), \(P(X = x_i) = 1/n\)

\[E(X) = \frac{x_1+x_2+\ldots+x_n}{n}\]

Roulette Expectation

  • European Odds: 36 numbers (red/black) + zero
  • You bet $1 on 11 Black (pays 35 to 1)
  • \(X\) is the return on this bet

\[E(X) = \frac{1}{37}\times 36 + \frac{36}{37}\times 0 = 0.97\]

  • If you bet $1 on Black (pays 1 to 1)

\[E(X) = \frac{18}{37}\times 2 + \frac{19}{37}\times 0 = 0.97\]

Casino is guaranteed to make money in the long run!

Standard Deviation \(sd(X)\) and Variance \(Var(X)\)

The variance is calculated as

\[Var(X) = E\left((X - E(X))^2\right)\]

A simpler calculation is \(Var(X) = E(X^2) - E(X)^2\).

The standard deviation is the square-root of variance.

\[sd(X) = \sqrt{Var(X)}\]

Roulette Variance

  • European Odds: 36 numbers (red/black) + zero
  • You bet $1 on 11 Black (pays 35 to 1)
  • \(X\) is the return on this bet

\[Var(X) = \frac{1}{37}\times (36 - 0.97)^2 + \frac{36}{37}\times (0 - 0.97)^2 = 34\]

  • If you bet $1 on Black (pays 1 to 1)

\[Var(X) = \frac{18}{37}\times (2 - 0.97)^2+ \frac{19}{37}\times (0- 0.97)^2 = 1\]

If your goal is to spend as much time as possible in the casino (free drinks): place small bets on black/red

Example: \(E(X)\) and \(Var(X)\)

Tortoise and Hare are selling cars. Probability distributions, means and variances for \(X\), the number of cars sold

0 1 2 3 Mean Variance sd
cars sold \(X\) \(E(X)\) \(Var(X)\) \(\sqrt{Var(X)}\)
Tortoise 0 0.5 0.5 0 1.5 0.25 0.5
Hare 0.5 0 0 0.5 1.5 2.25 1.5

Expectation and Variance Calculations

Let’s do Tortoise expectations and variances

  • The Tortoise \[\begin{align*} E(T) &= (1/2)(1) + (1/2)(2) = 1.5 \\ Var(T) &= E(T^2) - E(T)^2 \\ &= (1/2)(1)^2 + (1/2)(2)^2 - (1.5)^2 = 0.25 \end{align*}\]

  • Now the Hare’s \[\begin{align*} E(H) &= (1/2)(0) + (1/2)(3) = 1.5 \\ Var(H) &= (1/2)(0)^2 + (1/2)(3)^2- (1.5)^2 = 2.25 \end{align*}\]

Expectation and Variance Interpretation

What do these tell us above the long run behavior?

  • Tortoise and Hare have the same expected number of cars sold.
  • Tortoise is more predictable than Hare. He has a smaller variance The standard deviations \(\sqrt{Var(X)}\) are \(0.5\) and \(1.5\), respectively
  • Given two equal means, you always want to pick the lower variance.

Odds: Oddschecker

We can express probabilities in terms of Odds via \[ O(A) = \frac{ 1- P(A) }{ P(A) } \; \; \text{or} \; \; P(A) = \frac{ 1 }{ 1 + O(A) } \]

  • For example if \(O(A) = 1\) then for ever $1 bet you will payout $1. An event with probability \(\frac{1}{2}\).
  • If \(O(A) = 2\) or \(2:1\), then for a $1 bet you’ll payback $3.

In terms of probability \(P = \frac{1}{3}\).

Bookies vs Betters: The Battle of Probabilistic Models

Source: The Secret Betting Strategy That Beats Online Bookmakers

Bookies vs Betters: The Battle of Probabilistic Models

  • Bookies set odds that reflect their best guess on probabilities of a win, draw, or loss. Plus their own margin
  • Bookies have risk aversion bias. When many people bet for an underdog (more popular team)
  • Bookies hedge their bets by offering more favorable odds to the opposed team
  • Simple algorithm: calculate average odds across many bookies and find outliers with large deviation from the mean

Covariance

Suppose that we have two random variables \(X\) and \(Y\)

We need to measure whether they move together or in opposite directions The Covariance is defined by

\[Cov(X,Y) = E\left((X- E(X))(Y- E(Y))\right)\]

In terms of probability distributions, we need to calculate

\[Cov(X,Y) = \sum_{x,y} (x - E(X))(y - E(Y))P(x,y)\]

Let’s look at Covariance on Markets

VIX vs S&P vs AAPL

Correlation

The Correlation is defined by

\[Corr(X,Y) = \frac{Cov(X,Y)}{sd(X) sd(Y)}\]

  • What are the units of \(Corr(X,Y)\)? They don’t depend on the units of \(X\) or \(Y\)!
  • \(-1 \leq Corr(X,Y) \leq 1\)

If \(Cov(\text{Apple Sales, Economy}) = 5\), \(sd(\text{Apple Sales}) = 2\) and \(sd(\text{Economy}) = 3.5\), then there’s a \(71.4\)% correlation

\[Corr(\text{Apple Sales, Economy}) = \frac{5}{2 \times 3.5} = \frac{5}{7} = 0.714\]

Linear Combinations of Random Variables

Two key properties:

Let \(a, b\) be given constants

  • Expectations and Variances \[\begin{align*} E(aX + bY) &= a E(X) + b E(Y) \\ Var(aX + bY) &= a^2 Var(X) + b^2 Var(Y) + 2 ab Cov(X,Y) \end{align*}\]

where \(Cov(X,Y)\) is the covariance between random variables.

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

  • You split Saturday’s leads: half to Tortoise, half to Hare. \(P=\tfrac12 T+\tfrac12 H\) is the average per rep, not the floor total.
  • Same means as before: \(E(T)=E(H)=1.5\), \(Var(T)=0.25\), \(Var(H)=2.25\).
  • When one has a good day the other has a bad one: \(Cov(T,H)=-0.75\) (correlation \(-1\)).
  • What do you expect that average to be? How jumpy is it compared with giving every lead to Tortoise?
  • Compute \(E(P)\) and \(Var(P)\), then compare \(Var(P)\) to \(Var(T)\).

Self-check: solution

  • \(E(P)=\tfrac12\cdot 1.5+\tfrac12\cdot 1.5=1.5\)
  • \(Var(P)=\left(\tfrac12\right)^2 0.25+\left(\tfrac12\right)^2 2.25+2\cdot\tfrac12\cdot\tfrac12\cdot(-0.75)=0.0625+0.5625-0.375=0.25\)
  • Same expected sales as Tortoise alone, and the same variance \(0.25\). Without the covariance term you would have \(0.625\), worse than Tortoise. Perfect negative correlation is what cancels Hare’s noise.
  • Under that joint, when Tortoise sells 1 Hare sells 3, and when Tortoise sells 2 Hare sells 0, so \(P\) is 2 or 1 at half each. The split book is not merely matched to Tortoise in mean and variance: it has Tortoise’s exact distribution.

Bayesian Updating

Bayes Rule: two events

Many decision problems are this. It is counterintuitive. It is the right answer. The denominator is the law of total probability.

\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)} = \frac{P(B \mid A)\, P(A)}{P(B)} \]

\[ P(B) = P(B \mid A)\, P(A) + P(B \mid \bar{A})\, P(\bar{A}) \]

Bayes’s Rule in Medical Diagnostics

Alice is a 40-year-old woman. What is the chance that she really has breast cancer when she gets a positive mammogram, given:

  1. The prevalence of breast cancer among people like Alice is 1%.
  2. The test has an 80% detection rate.
  3. The test has a 10% false-positive rate.

The posterior probability \(P(\text{cancer} \mid \text{positive mammogram})\)?

Medical Diagnostics - Visualization

Medical Screening

Of 1000 cases:

  • 10 have cancer, 990 do not.
  • 107 positive mammograms: 8 true positives, 99 false positives.
  • 893 negative mammograms: 2 false negatives, 891 true negatives.

Bayes Rule - Intuitive Explanation

Let’s think about this intuitively. Imagine 1000 people like Alice.

  • 10 have cancer, 990 do not.
  • 80% of those with cancer test positive: 8.
  • 10% of those without cancer test positive: 99.
  • In total, 107 positive mammograms.

Now pick one of those 107 at random. What is the chance she has cancer? \[P(\text{cancer} \mid \text{positive}) = \frac{8}{107} \approx 7.5\%\]

Calculation of Posterior Probability

\[P(\text{cancer} \mid \text{positive mammogram})=\frac{8}{107}\approx 7.5\%\]

Posterior Probability

Most women who test positive on a mammogram are healthy, because the vast majority of women who receive mammograms in the first place are healthy.

Apple Watch

The Apple Watch Series 4 can perform a single-lead ECG and detect atrial fibrillation. The software can correctly identify 98% of cases of atrial fibrillation (sensitivity) and 99% of cases of non-atrial fibrillation (specificity).

Take prevalence \(P(\text{AF})=0.02\) in the population we care about. What is \(P(\text{AF} \mid \text{watch says AF})\)?

Bayes’ Theorem: \[ P(A|B)=\frac{P(B|A)P(A)}{P(B)} \]

Apple Watch

Counts from 100,000 people at 2% prevalence, 98% sensitivity, 99% specificity:

Predicted atrial fibrillation no atrial fibrillation
atrial fibrillation 1960 980
no atrial fibrillation 40 97020

\[ 0.6667 = \frac{0.98\cdot 0.02}{ 0.0294} \]

The conditional probability of having atrial fibrillation when the Apple Watch Series 4 detects atrial fibrillation is about 67%.

Abraham Wald

How Abraham Wald improved aircraft survivability. Raw Reports from the Field

Type of damage suffered Returned (316 total) Shot down (60 total)
Engine 29 ?
Cockpit 36 ?
Fuselage 105 ?
None 146 0

This fact would allow Wald to estimate: \[ P(\text{damage on fuselage} \mid \text{returns safely}) = 105/316 \approx 32\% \] You need the inverse probability : \[ P(\text{returns safely} \mid \text{damage on fuselage}) \] Completely different!

Abraham Wald

Imputation: fill-in missing data.

Type of damage suffered Returned (316 total) Shot down (60 total)
Engine 29 31
Cockpit 36 21
Fuselage 105 8
None 146 0

Then Wald got:

\[\begin{align*} P(\text{returns safely} \mid \text{damage on fuselage}) & =\frac{105}{105+8}\approx 93\%\\ P(\text{returns safely} \mid \text{damage on engine}) & =\frac{29}{29+31}\approx 48\% \end{align*}\]

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

  • You brief tonight. Someone counted 36 cockpit holes on the planes that came back and wants cockpit armor because “that is a lot of damage.”
  • From the table: 316 returned. Cockpit 36 returned, 21 down. Engine 29 returned, 31 down.
  • Among the planes you can see, how common is cockpit damage?
  • Among planes that took a cockpit hit, how often did the plane come back? Same question for engine.
  • Which of those numbers goes in the brief? One sentence on what \(36/316\) is actually describing.

Self-check: solution

  • Among the 316 that came back, \(36/316 \approx 0.114\). That is “holes we saw.”
  • Cockpit: \(36/(36+21)=36/57 \approx 0.632\) came back. Engine: \(29/(29+31)\approx 0.48\).
  • Armor goes where returning was rare given the hit. Fuselage is full of holes on the planes you can see. Engine and cockpit are the ones that did not come back.
  • The 11% is what the general noticed. The 63% vs 48% is the decision.

“Personalization" \(=\)”Conditional Probability"

  • Conditional probability is how AI systems express judgments in a way that reflects their partial knowledge.
  • Personalization runs on conditional probabilities, all of which must be estimated from massive data sets in which you are the conditioning event.


Many Business Applications!! Suggestions vs Search….

Probability as Evidence

evidence: known facts about criminal (e.g. blood type, DNA, ...)

suspect: matches a trait with evidence at scene of crime

Let \(G\) denote the event that the suspect is the criminal.

Bayes computes the conditional probability of guilt

\[ P ( G | \text{evidence} ) \] Evidence \(E\): suspect and criminal possess a common trait

Probability as Evidence

Bayes Theorem yields \[ P ( G | \text{evidence} ) = \frac{ P ( \text{evidence} | G ) P ( G ) }{ P ( \text{evidence} )} \]

In terms of relative odds \[ \frac{ P ( I | \text{evidence} ) }{ P ( G | \text{evidence} ) } = \frac{ P ( \text{evidence} | I ) }{ P ( \text{evidence} | G ) } \frac{ P ( I ) }{ P ( G ) } \]

Bayes Factors

There are two terms:

  1. Prior Odds of Guilt \(O ( G ) = P ( I ) / P ( G )\) ?

How many people on the island?

Sensitivity “what if” analysis?

  1. The Bayes factor \[ \frac{ P ( \text{evidence} | I ) }{ P ( \text{evidence} | G ) } \] is common to all observers and updates everyone’s initials odds

Prosecutor’s Fallacy

The most common fallacy is confusing \[ P ( \text{evidence} | G ) \; \; \text{with} \; \; P ( G | \text{evidence} ) \]

Bayes rule yields \[ P ( G | \text{evidence} ) = \frac{ P ( \text{evidence} | G ) p( G )}{ P ( \text{evidence} )} \] Your assessment of \(P( G )\) will matter.

Island Problem

Suppose there’s a criminal on a island of \(N+1\) people.

  • Let \(I\) denote innocence and \(G\) guilt.
  • Evidence \(E\): the suspect matches a trait with the criminal.
  • The probabilities are \[ p(E|I)=p\;\;\mathrm{and}\;\;p(E|G)=1 \]

Bayes factor

Bayes factors are likelihood ratios

  • The Bayes factor is given by \[ \frac{p(E|I)}{p(E|G)}=p \]

  • If we start with a uniform prior distribution we have

\[ p(G)=\frac{1}{N+1},\qquad p(I)=\frac{N}{N+1},\qquad odds(I)=N \]

  • Priors will matter!

Island Problem

Posterior probability of innocence from the posterior odds of innocence: \[ p(I\mid y)=\frac{odds(I\mid y)}{1+odds(I\mid y)} \]

  • Prosecutor’s fallacy

The posterior \(p(I\mid y)\) is not \(p(y\mid I)=p\).

  • Suppose that \(N=10^{3}\) and \(p=10^{-3}\). Then \(odds(I\mid y)=1\) and

\[ p( I\mid y) = \frac{1}{1+1} = \frac{1}{2} \]

The odds on innocence are \(odds(I|y)=1\).

There’s a \(50/50\) chance that the criminal has been found.

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

  • A man is arrested on an island of 1,001 people. The crime-scene trait occurs in 1 in 10,000 people; it matches him. Uniform prior, \(P(\text{match}\mid\text{guilty})=1\).
  • The prosecutor tells the jury: “The match probability is 1 in 10,000, so there is a 99.99% chance he is guilty.”
  • You are the defense statistician. Prior odds he is innocent. Posterior odds. Then \(P(\text{guilty}\mid\text{match})\). One sentence you would actually say to the jury.

Self-check: solution

  • Prior odds of innocence \(O(I)=1000\). Bayes factor \(10^{-4}\), so posterior odds \(O(I\mid E)=0.1\). Then \(P(I\mid E)=0.1/1.1\approx 0.091\), hence \(P(G\mid E)\approx 0.91\).

  • The prosecutor reported \(1-p=0.9999\).

  • That is \(1-P(\text{match}\mid\text{innocent})\), not \(P(\text{guilty}\mid\text{match})\).

  • Expected matches among the other 1,000 people: \(1000\times 10^{-4}=0.1\).

  • That 0.1 is why \(P(I\mid E)=0.1/1.1\), not one half. Evidence, not a conviction.

OJ Simpson

The O.J. Simpson trial was possibly the trial of the century

The murder of his wife Nicole Brown Simpson, and a friend, Ron Goldman, in June 1994 and the trial dominated the TV networks

  • DNA evidence and probability: \(p( E| G)\)

  • Bayes Theorem: \(p( G | E )\)

  • Prosecutor’s Fallacy: \(p( G|E ) \neq p(E|G)\)

Odds ratio \[ \frac{ p( I|E) }{ p ( G | E ) } = \frac{ p( E|I )}{ p( E|G) } \frac{ p(I) }{p(G ) } \] Prior odds conditioned on background information.

OJ Simpson: Bayes Theorem

Suppose that you are a juror in a murder case of a husband who is accused of killing his wife.

The husband is known is have battered her in the past.

Consider the three events:

  1. \(G\) “husband murders wife in a given year”

  2. \(M\) “wife is murdered in a given year”

  3. \(B\) “husband is known to batter his wife”

OJ Simpson: Bayes Theorem

  • Only \(1/10\)th of one percent of husbands who batter their wife murder them in a given year, so \(p(G\mid B)=1/1000\).

In 1994, 5000 women were murdered, 1500 by their husband

Given a population of 100 million women at the time \[ p( M | I ) = \frac{ 3500 }{ 10^8 } \approx \frac{1}{30,000} . \] We’ll also need \(p( M | I , B ) = p( M | I )\)

OJ Simpson: Prosecutor’s Fallacy

  • Let \(G =\) Guilt and \(E=\) Evidence
  • Prosecutor’s Fallacy: \(P(G|E) \neq P(E|G)\).
  • DNA evidence gives \(P( E | I )\) – the \(p\)-value.

What’s the “match probability” for a rare event?

Bayes theorem in Odds \[ \frac{p(G|M,B)}{p(I|M,B)} = \frac{p(M|G,B)}{p(M|I,B)} \frac{p(G|B)}{p(I|B)} \]

OJ Simpson: Bayes Theorem

By assumption,

  • \(p(M|G,B)=1\)
  • \(p(M|I,B)= \frac{1}{30,000}\)
  • \(p( G|B) = \frac{1}{1000}\) and so

\[ \frac{p(G|B)}{p(I|B)} = \frac{1}{999} \]

Therefore, \[ \frac{p(G|M,B)}{p(I|M,B)} \approx 30 \; \text{and} \; p(G|M,B) = \frac{30}{31} \approx 97\% \] More than a 50/50 chance that your spouse murdered you!

Fallacy \(p ( G | B ) \neq p( G | B , M )\)

The defense stated to the press: in any given year

“Fewer than 1 in 2000 of batterers go on to murder their wives”.

  • Now estimate \(p( M | \bar{G} , B ) = p( M| \bar{G} ) = \frac{1}{20,000}\) (a round figure for murders not by the husband; the previous slide used \(1/30,000\)).

  • The posterior odds of guilt are then prior odds times the Bayes factor \(p(M\mid G,B)/p(M\mid \bar G,B)=1/(1/20,000)\):

\[ \frac{ p( G | M , B ) }{ p( \bar{G} | M , B ) } = \frac{1}{999} \times 20{,}000 \approx 20 \] which implies posterior probabilities

\[ p( \bar{G} | M , B ) = \frac{1}{1+20} \; \text{and} \; p( G | M , B ) = \frac{20}{21} \] Hence its over 95% chance that O.J. is guilty based on this information!

Defense intended this information to exonerate O.J.

Base Rate Fallacies

“Witness” 80 % certain saw a “checker” \(C\) taxi in the accident.

  • What’s your \(P ( C | E )\) ?

  • Need \(P ( C )\). Say \(P( C ) = 0.2\) and \(P( E | C) = 0.8\).

  • Then your posterior is

\[ P ( C | E ) = \frac{0.8 \cdot 0.2}{ 0.8 \cdot 0.2 + 0.2 \cdot 0.8 } = 0.5 \]

Therefore \(O ( C ) = 1\) a 50/50 bet.

Updating Fallacies

Most people don’t update quickly enough in light of new data.

Ward Edwards, 1960s. When you have a small sample, Bayes still updates.

  • Two players: either a 70% player or a 30% player, equal prior.
  • Observe \(A\) beats \(B\) in 3 games out of 4.
  • What is \(P(\text{70\% player} \mid \text{3 of 4})\)?

Updating Fallacies: solution

Likelihood ratio, binomial coefficients cancel: \[ \frac{0.7^3\cdot 0.3}{0.3^3\cdot 0.7} = \frac{0.7^2}{0.3^2} \approx 5.44 \] Equal priors, so \[ P(\text{70\%}\mid \text{data}) = \frac{5.44}{1+5.44} \approx 0.845 \]

Three wins in four games is not “pretty sure.” It is 85%, and most people stop well short of that.

Envelope Paradox

The following problem is known as the “exchange paradox”.

  • A swami puts \(m\) dollars in one envelope and \(2 m\) in another. He hands on envelope to you and one to your opponent.
  • The amounts are placed randomly and so there is a probability of \(\frac{1}{2}\) that you get either envelope.
  • You open your envelope and find \(x\) dollars. Let \(y\) be the amount in your opponent’s envelope.

Envelope Paradox

You know that \(y = \frac{1}{2} x\) or \(y = 2 x\). You are thinking about whether you should switch your opened envelope for the unopened envelope of your friend. It is tempting to do an expected value calculation as follows \[ E( y) = \frac{1}{2} \cdot \frac{1}{2} x + \frac{1}{2} \cdot 2 x = \frac{5}{4} x > x \] Therefore, it looks as if you should switch no matter what value of \(x\) you see. A consequence of this, following the logic of backwards induction, that even if you didn’t open your envelope that you would want to switch!

Bayes Rule: the envelope flaw

  • Where’s the flaw in this argument? Use Bayes rule to update the probabilities of which envelope your opponent has! Assume \(p(m)\) of dollars to be placed in the envelope by the swami.

  • Such an assumption then allows us to calculate an odds ratio \[ \frac{ p \left ( y = \frac{1}{2} x | x \right ) }{ p \left ( y = 2 x | x \right ) } \] concerning the likelihood of which envelope your opponent has.

  • Then, the expected value is given by

\[ E(y) = p \left ( y = \frac{1}{2} x \; \vert \; x \right ) \cdot \frac{1}{2} x + p \left ( y = 2 x | x \right ) \cdot 2 x \] and the condition \(E( y) > x\) becomes a decision rule.

Three Prisoners Problem

Three prisoners \(A , B , C\).

Each believe are equally likely to be set free.

Prisoner \(A\) goes to the warden \(W\) and asks if s/he is getting axed.

  • The Warden can’t tell \(A\) anything about him.

  • He provides the new information: \(WB\) = “\(B\) is to be executed”

Three Prisoners Problem

Uniform Prior Probabilities: \[ \begin{array}{c|ccc} Prior & A & B & C \\\hline P ( \text{Pardon} ) & 0.33 & 0.33 & 0.33 \end{array} \]

Posterior: Compute \(P ( A | WB )\)?


What happens if \(C\) overhears the conversation?


Compute \(P ( C | WB )\)?

Game Show Problem

Named after the host of the long-running TV show, Let’s make a Deal.

  • A contestant is given the choice of 3 doors.

There is a prize (a car, say) behind one of the doors and something worthless behind the other two doors: two goats.

  • The optimal strategy is counter-intuitive

Puzzle

The game is as follows:

  • You pick a door.

  • Monty then opens one of the other two doors, revealing a goat.

  • You have the choice of switching doors.


Is it advantageous to switch?


Assume you pick door \(A\) at random. Then \(P(A) = ( 1 /3 )\).

You need to figure out \(P( A | MB )\) after Monte reveals \(B\) is a goat.

Bayes Rule Meme

Sheldon Bayes

The Reverend and the Submarine

  • A missing submarine. A car in snow that has to know where it is. Same update.
  • Start with a prior over the map. Look. Move the probability to where the data now say.
  • John Craven did this for USS Scorpion. Larry Stone at Metron turned that hunt into a method you can run again: prior map, look, revise.
  • A self-driving stack does the same update every few milliseconds. That loop is SLAM: simultaneous localization and mapping.

\[P(H \mid D)=\frac{P(H)\,P(D\mid H)}{P(D)}\]

The Story of Scorpion

  • May 1968. USS Scorpion and 99 men are overdue, somewhere in thousands of miles of Atlantic.
  • The Pentagon calls John Craven. He does not sweep the ocean. He asks experts to bet on what happened: torpedo, battery, collision.
  • Those bets become a prior map. Search the hottest square. Find nothing: take probability off that square and put it elsewhere.
  • They found the wreck. The method was already old. The Allies had used it on U-boats.

Sensitivity and Specificity

Two errors: An infected person may test negative, a well person tests positive.

Sensitivity (or power) \(=\) true positive rate (or recall) % sick people who are correctly identified \(P(T \mid D)\).

In a perfect world, we’d like \(P(\bar{T} \mid D) \approx 0\)

Specificity \(=\) true negative rate % of negatives correctly identified as such \(P(\bar{T} \mid \bar{D})\).

  • False negative rate \(=\) 1 - sensitivity \(=\) \(\beta\), the type II error
  • False positive rate \(=\) 1 - specificity \(=\) \(\alpha\), the type I error

We want the probability: \(P(D \mid T)\)

Confusion Matrix

We can use accuracy rate: \[ \text{accuracy} = \frac{\text{Number of Correct answers}}{n} \]

or its dual, error rate \[ \text{error rate} = 1 - \text{accuracy} \]

You remember, we have two types of errors. We can use confusion matrix to quantify those

Predicted: YES Predicted: NO
Actual: YES TPR FNR
Actual: NO FPR TNR

True positive rate (TPR) is sensitivity. True negative rate (TNR) is specificity. False positive rate is \(FPR = 1 - \text{specificity}\), not specificity.

Test Marketing a New Product

Your company will test-market a new product. After a positive, neutral, or negative reaction, what are the probabilities of high and low sales?

  • New products have high sales 8% of the time, low sales 92%.
  • If sales are high: reaction is positive 70%, neutral 25%, negative 5%.
  • If sales are low: positive 15%, neutral 35%, negative 50%.

Netflix Bayes and AI

Test Marketing - Solution Steps

Step 1: Set-up your notation. Let \[H = \text{high sales} \quad L = \text{low sales}\] \[\text{Pos} = \text{positive} \quad \text{Neu = Neutral} \quad \text{Neg} = \text{Negative}\]

Step 2: List the known conditional probabilities For the marketing test we have \[\begin{align*} P(\text{Pos} \mid H) &= 0.70, P(\text{Neu} \mid H)=0.25, P(\text{Neg} \mid H) = 0.05 \\ P(\text{Pos} \mid L) &= 0.15, P(\text{Neu} \mid L)=0.35, P(\text{Neg} \mid L) = 0.50 \end{align*}\]

Finally, the base rates are \(P(H) = 0.08\) and \(P(L) = 0.92\)

Test Marketing - Calculation

Step 3: Describe the posterior probabilities that are required: \[P(H \mid \text{Pos})\]

The probability of high sales given a positive marketing test. Compute the probability of a positive test \[\begin{align*} P(\text{Pos}) &= P(\text{Pos} \mid H)P(H) +P(\text{Pos} \mid L)P(L) \\ &= 0.70 \times 0.08 + 0.15 \times 0.92 = 0.194 \end{align*}\]

Test Marketing - Final Answer

Now use Bayes Rule \[\begin{align*} P(H \mid \text{Pos}) &= \frac{P(\text{Pos} \mid H)P(H)}{P(\text{Pos})} \\ &= \frac{0.70 \times 0.08}{0.194} = 0.288 \end{align*}\]

Hence 28.8% you’ll have high sales in the market.

We should interpret this relative to our initial probability of only \(8\)%.

Two Headed Coin

Large jar containing \(1024\) fair coins and one two-headed coin.

  • You pick one at random and flip it \(10\) times and get all heads.
  • What’s the probability that the coin is the two-headed coin?

\(\frac{1}{1025}\) probability of initially picking the two headed coin. \(\frac{1}{1024}\) chance of getting \(10\) heads in a row from a fair coin Therefore, it’s a \(50/50\) bet.

Two Headed Coin - Calculation

Let \(E\) be the event that you get \(10\) Heads in a row \[P(\text{two headed} \mid E) = \frac{P(E \mid \text{two headed})P(\text{two headed})}{P(E \mid \text{fair})P(\text{fair}) + P(E \mid \text{two headed})P(\text{two headed})}\]

Therefore, the posterior probability \[P(\text{two headed} \mid E) = \frac{1 \times \frac{1}{1025}}{\frac{1}{1024} \times \frac{1024}{1025} + 1 \times \frac{1}{1025}} = 0.50\]

Graphical Models

Conditional Independence

  • Consider three variables a,b,c
  • Conditional distribution of a given b and c, is p(a|b,c)
  • If p(a|b,c) does not depend on value of b, we can write p(a|b,c) = p(a|c)
  • We say that a is conditionally independent of b given c

We can use the telescoping property of conditional probabilities to write the joint probability distribution as a product of conditional probabilities. This is the essence of the chain rule of probability. It is given by \[ p(x_1, x_2, \ldots, x_n) = p(x_1)p(x_2 \mid x_1)p(x_3 \mid x_1, x_2) \ldots p(x_n \mid x_1, x_2, \ldots, x_{n-1}). \]

right hand side can be simplified if some of the variables are conditionally independent

Bayes Classifier

Input \(X\) and label \(Y\):

\(X:\) the image \(Y:\) the label, “cat” or not

Silicon Valley: Season 4: Not Hotdog

What’s our best decision?

Pick \(\hat{y}\) as the most likely category given that \(X=x\), namely \[\hat{y} = \arg \max_y \; p(Y= y \mid X = x)\]

I need the probability table \(P(X=x, Y=y)\) and marginal \(P(X=x)\).

Naive Bayes

Use of the Bayes rule allows us to build our first predictive model, called Naive Bayes classifier.

  • Collection of classification algorithms based on Bayes Theorem
  • Every feature being classified is independent of any other feature
  • Features aren’t always independent → “naive” assumption

Naive Bayes: Example

A fruit may be considered an apple if it is:

  • Red, round, and about 3” in diameter

Each feature contributes independently to the probability:

Code
graph TB
    C((Color)) --> F((Fruit))
    S((Size)) --> F
    Sh((Shape)) --> F

graph TB
    C((Color)) --> F((Fruit))
    S((Size)) --> F
    Sh((Shape)) --> F

Naive Bayes: Advantages

  • Relatively simple to understand and build
  • Easily trained, even with small datasets
  • Fast execution
  • Not sensitive to irrelevant features

Naive Bayes: Fruit Classification Example

Fruit Long Sweet Yellow Total
Banana 400 350 450 500
Orange 0 150 300 300
Other 100 150 50 200
Total 500 650 800 1000

Naive Bayes: Conditional Probabilities

Bananas (500 total):

  • Long: 400/500 = 0.8
  • Sweet: 350/500 = 0.7
  • Yellow: 450/500 = 0.9

Oranges (300 total):

  • Long: 0/300 = 0
  • Sweet: 150/300 = 0.5
  • Yellow: 300/300 = 1.0

Other (200 total):

  • Long: 100/200 = 0.5
  • Sweet: 150/200 = 0.75
  • Yellow: 50/200 = 0.25

Naive Bayes: Classification

Given evidence \(E\) (Long, Sweet, Yellow), calculate probability for each class:

Banana: \[P(B \mid E) = \frac{0.8 \times 0.7 \times 0.9 \times 0.5}{P(E)} = \frac{0.252}{P(E)}\]

Orange: \[P(O \mid E) = 0\] (since P(Long|Orange) = 0)

Other Fruit: \[P(F \mid E) = \frac{0.5 \times 0.75 \times 0.25 \times 0.2}{P(E)} = \frac{0.01875}{P(E)}\]

Result: Long, Sweet, Yellow fruit is classified as a Banana

Naive Bayes: Spam Filtering

The original spam filtering algorithm was based on Naive Bayes.

Key Assumptions:

  • Words are conditionally independent given the class label
  • Ignores word order and grammatical relationships
  • Treats each word independently
Code
flowchart TB
  w1(w1)-->S(S)
  w2(w2)-->S
  w3(w3)-->S
  w4(w4)-->S
  w5(w5)-->S
  w6(w6)-->S
  w7(w7)-->S
flowchart TB
  w1(w1)-->S(S)
  w2(w2)-->S
  w3(w3)-->S
  w4(w4)-->S
  w5(w5)-->S
  w6(w6)-->S
  w7(w7)-->S
Figure 1: Naive Bayes Spam Filtering.

Naive Bayes: Spam Filtering Process

  1. Collect labeled data: emails marked as “spam” or “ham”
  2. Calculate prior probabilities: \(P(\text{spam})\), \(P(\text{ham})\)
  3. Convert to bag-of-words: ignore word order, count frequencies
  4. Calculate conditional probabilities: \[P(\text{word}_i \mid \text{spam}) = \frac{\text{Spam emails containing word}_i}{\text{Total spam emails}}\]

Naive Bayes: Spam Classification

For a new email with words \(\{w_{e1}, w_{e2}, \ldots, w_{ek}\}\):

\[P(\text{spam} \mid \text{email}) = \frac{P(\text{email} \mid \text{spam}) \times P(\text{spam})}{P(\text{email})}\]

Where: \[P(\text{email} \mid \text{spam}) = P(w_{e1} \mid \text{spam}) \times P(w_{e2} \mid \text{spam}) \times \ldots \times P(w_{ek} \mid \text{spam})\]

Naive Bayes: Limitations

The “naive” assumption:

  • Words are not truly independent
  • Ignores grammar and word order
  • Doesn’t understand context (e.g., “bank” as financial vs. river)

Despite limitations:

  • Often performs well in practice
  • Excellent for text classification tasks
  • Computational efficiency

Naive Bayes: Modern Context

While Naive Bayes has limitations, it paved the way for more sophisticated models:

  • Transformers consider sequential nature of language
  • Contextual embeddings capture word relationships
  • Deep learning models understand grammar and syntax

But Naive Bayes remains valuable for:

  • Quick prototyping
  • Baseline models
  • Resource-constrained applications

Graphical Representation: Line Structure

When two nodes are connected they are not independent.

Line Structure

\[ p(b\mid c,a) = p(b\mid c),~ p(a,b,c) = p(a)p(c\mid a)p(b\mid c) \]

\(a\) and \(b\) connected through \(c\). Thus, \(a\) can influence \(b\). However, once \(c\) is known, \(a\) and \(b\) are independent.

Graphical Representation: Lambda Structure

Lambda Structure

\[ p(a\mid b,c) = p(a\mid c), ~ p(a,b,c) = p(a\mid c)p(b\mid c)p(c) \]

\(a\) can influence \(b\) through \(c\), but once \(c\) is known, \(a\) and \(b\) are independent.

Graphical Representation: V-structure

V-structure

\[ p(a\mid b) = p(a),~ p(a,b,c) = p(c\mid a,b)p(a)p(b) \]

\(a\) and \(b\) are independent, but once \(c\) is known, \(a\) and \(b\) are not independent. You can formally derive these independencies from the graph by comparing \(p(a,b\mid c)\) and \(p(a\mid c)p(b\mid c)\).

Alarm: the story

  • Alarm system sends me a text notification when some motion inside my house is detected.
  • Prior: during an earthquake the alarm is triggered in 10% of the cases.
  • I get a text message, assess \(p(b\mid a)\) is high, and start driving back home.
  • While driving I hear on the radio about a small earthquake in our area; I need \(p(b \mid a,r)\).

\(b\) = burglary, \(e\) = earthquake, \(a\) = alarm, and \(r\) = radio message about small earthquake.

The joint distribution is then given by \[ p(b,e,a,r) = p(r \mid a,b,e)p(a \mid b,e)p(b\mid e)p(e). \] Since we know the causal relations, we can simplify this expression \[ p(b,e,a,r) = p(r \mid e)p(a \mid b,e)p(b)p(e). \]

Alarm: the CPT

\(p(a=1 \mid b,e)\) b e
0 0 0
0.1 0 1
1 1 0
1 1 1

Alarm: the DAG

Code
graph TB
    b((b)) --> a((a))
    e((e)) --> a
    e --> r((r))
graph TB
    b((b)) --> a((a))
    e((e)) --> a
    e --> r((r))
Figure 2: Bayesian network for alarm .

Alarm: the numbers

\[ p(a=1 \mid b,e) + p(a=0 \mid b,e) = 1. \] Also know \(p(r=1 \mid e=1) = 0.5\) and \(p(r=1 \mid e=0) = 0\), \(p(b) = 2\cdot10^{-4}\) and \(p(e) = 10^{-2}\) (historical data)

Graph allowed us to have a more compact representation of the joint probability distribution. The original naive representations requires specifying \(2^4\) parameters.

Alarm: \(P(\text{burglary}\mid\text{alarm})\)

\[ p(b \mid a) = \dfrac{p(a \mid b)p(b)}{p(a)},\qquad p(a) = p(a=1 \mid b=1)p(b=1) + p(a=1 \mid b=0)p(b=0). \] We have everything but \(p(a \mid b)\). This is obtained by marginalizing \(p(a=1 \mid b,e)\), to yield \[ p(a \mid b) = p(a \mid b,e=1)p(e=1) + p(a \mid b,e=0)p(e=0). \] We can calculate \[ p(a=1 \mid b=1) = 1, ~p(a=1 \mid b=0) = 0.1*10^{-2} + 0 = 10^{-3}. \] This leads to \(p(b \mid a) = 2\cdot10^{-4}/(2\cdot10^{-4} + 10^{-3}(1-2\cdot10^{-4})) = 1/6\).

Alarm: a higher crime rate

  • We get such a low probability of burglary because its prior is very low compared to prior probability of an earthquake.
  • What will happen to posterior if we live in an area with higher crime rates, say \(p(b) = 10^{-3}\). \[ p(b \mid a) = \dfrac{p(b)}{p(b) + 10^{-3}(1-p(b))} \]

Alarm: prior vs posterior

Code
prior <- seq(0, .1, length.out = 200)
post <- prior / (prior + 0.001 * (1 - prior))
plot(prior, post, type = "l", lwd = 3, col = "red")

Figure 3: Relationship between the prior and posterior

Alarm: explaining away

\[ p(b=1 \mid a=1,r=1) = \dfrac{p(a,r \mid b)p(b)}{p(a,r)} \] and \[ p(b=1 \mid a=1, r=1) = \dfrac{\sum_e p(b=1,e,a=1,r=1)}{\sum_b\sum_ep(b,e,a=1,r=1)} \] \[ =\dfrac{\sum_ep(r=1 \mid e)p(a=1 \mid b=1,e)p(b=1)p(e)}{\sum_b\sum_ep(r=1 \mid e)p(a=1 \mid b,e)p(b)p(e)} \] which is \(\approx 2\%\) in our case. This effect is called explaining away, namely when new information explains some previously known fact.

Bayes and AI

Translate a sentence. Hear a wake word. Stay in the lane. Pick the next show.

None of those is certain. Each is the question you have been answering all night: given what I just saw, what is likely?

  • An AI algorithm deals in probabilities, not certainties.
  • It does not arrive with the instructions. It updates them: prior, data, posterior.

That is Bayes. Next: will this subscriber like Saving Private Ryan?

How does Netflix Give Recommendations?

Will a subscriber like Saving Private Ryan, given that he or she liked the HBO series Band of Brothers?

Both are epic dramas about the Normandy invasion and its aftermath.

100 people in your database, and every one of them has seen both films.

Their viewing histories come in the form of a big “ratings matrix”.

Liked Band of Brothers Didn’t like it
Liked Saving Private Ryan 56 subscribers 6 subscribers
Didn’t like it 14 subscribers 24 subscribers

\[P(\text{likes Saving Private Ryan} \mid \text{likes Band of Brothers})=\frac{56}{56+14}=80\%\]

How does Netflix Give Recommendations? - Complexity

But real problem is much more complicated:

  1. Scale. It has 100 million subscribers and ratings data on more than 10,000 shows. The ratings matrix has more than a trillion possible entries.
  2. “Missingness”. Most subscribers haven’t watched most films. Moreover, missingness pattern is informative.
  3. Combinatorial explosion. In a database with 10,000 films, no one else’s history is exactly the same as yours.

The solution to all three issues is careful modeling.

How does Netflix Give Recommendations? - Fundamental Equation

The fundamental equation is: \[\text{Predicted Rating} =\text{Overall Average} + \text{Film Offset} + \text{User Offset} + \text{User-Film Interaction}\]

These three terms provide a baseline for a given user/film pair:

  • The overall average rating across all films is 3.7.
  • Every film has its own offset. Popular movies have positive offsets.
  • Every user has an offset. Some users are more or less critical than average.

Netflix - Latent Features

The leftover term, user-film interaction, is not a one-off. Ratings of similar shows move together because they share a hidden feature of the person.

  • You never observe the feature. You infer it from what they rated.
  • There are not one but dozens or hundreds: British murder mystery, gritty crime drama, cooking show, hipster comedy.
  • A film has a vector of how much it has each feature. A person has a vector of how much they like each feature.
  • The interaction is how well those two vectors line up. That is why two people with the same average rating still get different recommendations.

The Hidden Features Tell the Story

  • Those vectors put you in a corner of a high-dimensional space. That is a demographic of one, not an age-and-zip-code bin.
  • Netflix spent $130 million on 10 episodes of The Crown because the model said who would watch.
  • Network television spent $400 million on 113 pilots. Thirteen shows made a second season.

Statistics

Binomial Distribution

Bernoulli Trials: A sequence of repeated experiments are Bernoulli trials if:

  1. The result of each trial is either a success or failure.
  2. The probability \(p\) of a success is the same for all trials.
  3. The trials are independent.

If \(X\) is the number of successes it is a Binomial Random Variable.

New England Patriots and Coin Tossing

Patriots won 19 out of 25 coin tosses in 2014-15 season. What is the probability of that happening?

  • Each toss is a Bernoulli trial: \(X=1\) if they win, \(P(X=1)=\tfrac12\). Then \(Y\sim\mathrm{Binomial}(25, \tfrac12)\).
  • There are \(25\) choose \(19\), or \(177{,}100\), sequences with 19 wins. Each has probability \(0.5^{25}\).

\[\Pr(Y=19) = {25 \choose 19} 0.5^{25} = 177{,}100 \times 0.5^{25} = 0.005\]

Rare under a fair toss. Not a proof they cheated.

Binomial Distribution Formula

We calculate probabilities using: \[P(X=x) = {n \choose x} p^x(1-p)^{n-x}\] \({n \choose x}\) counts the number of ways of getting \(x\) successes in \(n\) trials.

The formula for \(n \choose x\) is \[{n \choose x} = \frac{n!}{x!(n-x)!}\] where \(n!=n\times(n-1)\times(n-2)\times...\times 2 \times 1\).

Binomial Mass Function

Binomial Distribution

In R: dbinom(z, n, p) and rbinom(1000, n, p)

Binomial Distribution Parameters

\(X\sim\mathrm{Binomial}(n,p)\)

  • \(E(X)=np\)
  • \(Var(X)=np(1-p)\)

A fair coin is the noisiest Bernoulli. At \(p=0\) or \(1\), variance is zero: you already know.

For the Patriots, \(n=25\), \(p=\tfrac12\): \(E=12.5\), \(Var=6.25\).

Variance peaks at a fair coin

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

  • Joe DiMaggio’s batting average is \(0.325\) per at-bat. Treat the four at-bats in a game as independent Bernoulli trials.
  • What is \(P(\text{more than 2 hits})\)? Name the distribution, then compute it.

Self-check: solution

  • \(X\sim\mathrm{Binomial}(4, 0.325)\). More than two hits is \(X=3\) or \(X=4\).
  • \(P(X>2)=\binom{4}{3}(0.325)^3(0.675)+\binom{4}{4}(0.325)^4=\) \(4\cdot 0.03433\cdot 0.675+0.01116=0.104\)
  • About 10%. Most games are not 3-for-4. The 56-game streak is that 10% stacked, not a typical night.

EPL Odds

EPL Odds

EPL 2017 Data

We have a historical set of data on scores

home team results visit team
Chelsea \(2\) \(1\) West Ham
Chelsea \(5\) \(1\) Sunderland
Watford \(1\) \(2\) Chelsea
Chelsea \(3\) \(0\) Burnley
\(\dots\)

Tomorrow Manchester United (MU) is playing Hall U. I want to place a bet.

How can I predict the outcome of this game?

Poisson Distribution

The Poisson distribution counts the occurrence of events Given the rate \(\lambda\) we calculate probabilities as follows

\[P(X = x) = \frac{e^{-\lambda} \lambda^x}{x!} \quad \text{where } x=0,1,2,3, \ldots\]

The Poisson Mean and Variance are:

Poisson Distribution Parameters
Expected value \(\mu = E(X) = \lambda\)
Variance \(\sigma^2 = Var(X) = \lambda\)

\(\lambda\) is the rate of occurrence of an event.

Self-check

Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.

For each, name Binomial or Poisson. Give the parameters if you can. One sentence on why.

  • 80 independently tested circuit boards. \(X\) = number that fail.
  • Cardiac-arrest calls to 911 between midnight and 6am.
  • A subscriber is shown 12 thumbnails. \(X\) = number they click. Assume each click is independent with the same \(p\).
  • Goals Hull scores against Man U on Saturday.

Self-check: solution

Binomial is a fixed number of independent yes/no trials. Poisson is a count in a window, with a rate and no \(n\).

  • \(\mathrm{Binomial}(80,p)\). Eighty boards, fail or not.
  • \(\mathrm{Poisson}(\lambda)\). A count overnight. There is no list of “possible calls.”
  • \(\mathrm{Binomial}(12,p)\). Twelve thumbnails, click or not.
  • \(\mathrm{Poisson}(\lambda)\). A count in 90 minutes. The EPL model is a rate, not 90 independent goal/no-goal minutes.

EPL MU

I can build a model assuming goals follow Poisson distribution.

I calculate \(\lambda\) by taking an average.

MU against (a) MU against

MU for (b) MU for

Our Poisson model fits the empirical data!!

English Premier League: EPL

Calculate Odds for the possible scores in a match?

\[0-0, \; 1-0, \; 0-1, \; 1-1, \; 2-0, \ldots\]

Let

\(X=\) Goals scored by Hall U

\(Y=\) Goals scored by MU

What’s the odds of a MU winning? \(P(X < Y)\) Odds of a draw? \(P(X = Y)\)

x = rpois(100,0.6)
y = rpois(100,1.4)
sum(x<y)/100   # Team 2 wins
sum(x==y)/100   # Draw

EPL: Attack and Defence Strength

Each team gets an “attack” strength and “defence” weakness rating Adjust home and away average goal estimates

EPL Table

EPL: Hull vs ManU

ManU (away). League away average \(1.20\) from epl.csv. Prediction: \(1.20 \times 1.46 \times 1.37 = 2.41\)

Average \(\times\) Attack strength \(\times\) Defense weakness

Hull (home). League home average \(1.60\). Prediction: \(1.60 \times 0.85 \times 0.52 = 0.71\).

The two league averages are different. Using one number for both would erase home advantage, which is the effect this model is built to capture.

Simulation (\(n=100\))

Team Expected Goals 0 1 2 3 4 5 \(\ge 6\)
Man U 2.41 11 22 27 17 13 5 5
Hull City 0.71 45 34 16 3 2 0 0

EPL Predictions

A model is only as good as its predictions

  • In our simulation Man U wins 72 games out of 100, we should bet when the quoted odds are worse than that.
  • Most likely Man U score in the simulation is 2.
  • The actual outcome was 0-1 (they played on 27 August 2016).
  • In our simulation 0-1 occurred 11 times out of 100.

Continuous Random Variables

Suppose we are trying to predict tomorrow’s return on the S&P500…

There’s a number of questions that come to mind

  • What is the random variable of interest?
  • How can we describe our uncertainty about tomorrow’s outcome?
  • Instead of listing all possible values we’ll work with intervals instead. The probability of an interval is defined by the area under the probability density function.

They are continuous (as opposed to discrete) random variables

Normal Distribution

There are infinitely many normals: every mean, every variance. They are all the same bell, just shifted and stretched. We keep one copy.

  • \(Z\sim N(0,1)\): mean \(0\), variance \(1\). That is the table.
  • \(P(|Z|<1)\approx 0.68\). \(P(|Z|<1.96)\approx 0.95\). Those numbers are the whole family, once you measure in units of \(\sigma\).
  • R: pnorm, qnorm, rnorm(1000, 0, 1).

The Normal Distribution - Standardization

Our probability model is written \(X \sim N(\mu,\sigma^2)\) \(\mu\) is the mean, \(\sigma^2\) is the variance

  • Standardization if \(X \sim N(\mu,\sigma^2)\) then \[Z =\frac{X-\mu}{\sigma} \sim N(0,1)\]
  • \(\mu:\) the center of the distribution \(\sigma:\) how spread out the data are

\(95\)% probability \(X\) is inside \(\mu \pm 1.96 \sigma\).

Normal Distribution - Mean Parameter

By changing the mean parameter \(\mu\), we change the center of the bell curve

Normal Distribution - Mean

Normal Distribution - Variance Parameter

By changing the variance parameter \(\sigma^2\), we change the “fatness” of the bell curve

Normal Distribution - Variance

Normal Distribution - Real Data

Chicago Wind Speed (2007-2014) data on a log scale seem to be well described by the Normal distribution

Normal Distribution - Wind Data

pnorm and qnorm

We can find probabilities and quantiles in R. Here are the important values

>pnorm(2.58)
[1] 0.9950
>pnorm(1.96)
[1] 0.9750
>pnorm(1.64)
[1] 0.9499

qnorm is the inverse of pnorm. Simulation rnorm. N=1000, x=rnorm(N,0,1), p=sum(x<1.96)/N

Normal Distribution with General Mean and Variance

Here are two useful facts: If \(X \sim \text{N}(\mu, \sigma^2)\), then

\[\begin{align*} P(\mu - 2.58 \sigma < X < \mu + 2.58 \sigma) =& 0.99 \\ P(\mu - 1.96 \sigma < X < \mu + 1.96 \sigma) =& 0.95 \end{align*}\]

  • The chance that \(X\) will be within \(2.58 \sigma\) of its mean is \(99\)%, and the chance that it will be within \(2\sigma\) of its mean is about \(95\)%.

Pictorially

Normal Distribution Tails

Examples of upper and lower tail areas. The lower tail area of \(0.1\) is at \(z = -1.28\). The upper tail area of \(0.05\) is at \(z=1.64\)

Example: The Crash

How extreme was the 1987 crash of \(-21.76\)%?

  1. Prior to the October, 1987 crash SP500 monthly returns were \(1.2\)% with a risk/volatility of \(4.3\)% \[X \sim N(0.012, 0.043^2)\] Standardize: \[Z =\frac{X-\mu}{\sigma} = \frac{X - 0.012}{0.043} \sim N(0,1)\]

  2. Calculate the observed \(Z\): \[Z = \frac{-0.2176 - 0.012}{0.043} = -5.34\] That’s a \(5\)-sigma event!

Example: The Crash - Model Validation

We assumed returns follow normal distribution. Using an inaccurate model can lead to inaccurate results.

S&P 500 Returns vs Normal

Normal as Approximation to Binomial

A real estate firm offers a free trip. Of those who accept, 5% buy a property. If the firm brings \(n=1000\) people, what is \(P(X \ge 60)\) for \(X\sim\mathrm{Binomial}(1000, 0.05)\)?

Mean \(\mu=np=50\), \(\sigma=\sqrt{np(1-p)}=\sqrt{47.5}=6.89\). Continuity correction: \[Z=\frac{59.5-50}{6.89}=1.38, \qquad P(Z\ge 1.38)\approx 0.084\]

In R the exact value is a one-liner, and the approximation is there to be checked, not to replace it:

1 - pbinom(59, 1000, 0.05)   # 0.087
1 - pnorm(59.5, 50, sqrt(47.5))