Docsity

Probability and Statistics for Data Science, Summaries of Probability and Statistics

Partial preview of the text

Download Probability and Statistics for Data Science and more Summaries Probability and Statistics in PDF only on Docsity!

Probability and Statistics for Data Science

Carlos Fernandez-Granda

Preface

These notes were developed for the course Probability and Statistics for Data Science at the Center for Data Science in NYU. The goal is to provide an overview of fundamental concepts in probability and statistics from first principles. I would like to thank Levent Sagun and Vlad Kobzar, who were teaching assistants for the course, as well as Brett Bernstein and David Rosenberg for their useful suggestions. I am also very grateful to all my students for their feedback.

While writing these notes, I was supported by the National Science Foundation under NSF award DMS-1616340.

New York, August 2017

ii

  • 1 Basic Probability Theory
    • 1.1 Probability spaces
    • 1.2 Conditional probability
    • 1.3 Independence
  • 2 Random Variables
    • 2.1 Definition
    • 2.2 Discrete random variables
    • 2.3 Continuous random variables
    • 2.4 Conditioning on an event
    • 2.5 Functions of random variables
    • 2.6 Generating random variables
    • 2.7 Proofs
  • 3 Multivariate Random Variables
    • 3.1 Discrete random variables
    • 3.2 Continuous random variables
    • 3.3 Joint distributions of discrete and continuous variables
    • 3.4 Independence
    • 3.5 Functions of several random variables
    • 3.6 Generating multivariate random variables
    • 3.7 Rejection sampling
  • 4 Expectation
    • 4.1 Expectation operator
    • 4.2 Mean and variance
    • 4.3 Covariance
    • 4.4 Conditional expectation
    • 4.5 Proofs
  • 5 Random Processes
    • 5.1 Definition
    • 5.2 Mean and autocovariance functions
    • 5.3 Independent identically-distributed sequences
    • 5.4 Gaussian process
    • 5.5 Poisson process
    • 5.6 Random walk
    • 5.7 Proofs CONTENTS iv
  • 6 Convergence of Random Processes
    • 6.1 Types of convergence
    • 6.2 Law of large numbers
    • 6.3 Central limit theorem
    • 6.4 Monte Carlo simulation
  • 7 Markov Chains
    • 7.1 Time-homogeneous discrete-time Markov chains
    • 7.2 Recurrence
    • 7.3 Periodicity
    • 7.4 Convergence
    • 7.5 Markov-chain Monte Carlo
  • 8 Descriptive statistics
    • 8.1 Histogram
    • 8.2 Sample mean and variance
    • 8.3 Order statistics
    • 8.4 Sample covariance
    • 8.5 Sample covariance matrix
  • 9 Frequentist Statistics
    • 9.1 Independent identically-distributed sampling
    • 9.2 Mean square error
    • 9.3 Consistency
    • 9.4 Confidence intervals
    • 9.5 Nonparametric model estimation
    • 9.6 Parametric model estimation
    • 9.7 Proofs
  • 10 Bayesian Statistics
    • 10.1 Bayesian parametric models
    • 10.2 Conjugate prior
    • 10.3 Bayesian estimators
  • 11 Hypothesis testing
    • 11.1 The hypothesis-testing framework
    • 11.2 Parametric testing
    • 11.3 Nonparametric testing: The permutation test
    • 11.4 Multiple testing
  • 12 Linear Regression
    • 12.1 Linear models
    • 12.2 Least-squares estimation
    • 12.3 Overfitting
    • 12.4 Global warming
    • 12.5 Proofs
  • A Set theory CONTENTS v
    • A.1 Basic definitions
    • A.2 Basic operations
  • B Linear Algebra
    • B.1 Vector spaces
    • B.2 Inner product and norm
    • B.3 Orthogonality
    • B.4 Projections
    • B.5 Matrices
    • B.6 Eigendecomposition
    • B.7 Eigendecomposition of symmetric matrices
    • B.8 Proofs
CHAPTER 1. BASIC PROBABILITY THEORY 2

snow tomorrow ) we also need to assign a probability to their complements (i.e. it will not rain tomorrow or it will not snow tomorrow ) and to their union (it will rain or snow tomorrow ).

Definition 1.1.2 (σ-algebra). A σ-algebra F is a collection of sets in Ω such that:

  1. If a set S ∈ F then Sc^ ∈ F.
  2. If the sets S 1 , S 2 ∈ F, then S 1 ∪ S 2 ∈ F. This also holds for infinite sequences; if S 1 , S 2 ,... ∈ F then ∪∞ i=1Si ∈ F.
  3. Ω ∈ F.

If our sample space is discrete, a possible choice for the σ-algebra is the power set of the sample space, which consists of all possible sets of elements in the sample space. If we are tossing a coin and the sample space is

Ω := {heads, tails} , (1.1)

then the power set is a valid σ-algebra

F := {heads or tails, heads, tails, ∅} , (1.2)

where ∅ denotes the empty set. However, in many cases σ-algebras do not contain every possible set of outcomes.

Example 1.1.3 (Cholesterol). A doctor is interested in modeling the cholesterol levels of her patients probabilistically. Every time a patient visits her, she tests their cholesterol level. Here the experiment is the cholesterol test, the outcome is the measured cholesterol level, and the sample space Ω is the positive real line. The doctor is mainly interested in whether the patients to have low, borderline-high, or high cholesterol. The event L (low cholesterol) contains all outcomes below 200 mg/dL, the event B (borderline-high cholesterol) contains all outcomes between 200 and 240 mg/dL, and the event H (high cholesterol) contains all outcomes above 240 mg/dL. The σ-algebra F of possible events therefore equals

F := {L ∪ B ∪ H, L ∪ B, L ∪ H, B ∪ H, L, B, H, ∅}. (1.3)

The events are a partition of the sample space, which simplifies deriving the corresponding σ-algebra. 4

The role of the probability measure P is to quantify how likely we are to encounter each of the events in the σ-algebra. Intuitively, the probability of an event A can be interpreted as the fraction of times that the outcome of the experiment is in A, as the number of repetitions tends to infinity. It follows that probabilities should always be nonnegative. Also, if two events A and B are disjoint (their intersection is empty), then

P (A ∪ B) = outcomes in A or B total

outcomes in A + outcomes in B total

outcomes in A total

outcomes in B total

= P (A) + P (B). (1.7)
CHAPTER 1. BASIC PROBABILITY THEORY 3

Probabilities of unions of disjoint events should equal the sum of the individual probabilities. Additionally, the probability of the whole sample space Ω should equal one, as it contains all outcomes

P (Ω) = outcomes in Ω total

total total

These conditions are necessary for a measure to be a valid probability measure.

Definition 1.1.4 (Probability measure). A probability measure is a function defined over the sets in a σ-algebra F such that:

  1. P (S) ≥ 0 for any event S ∈ F.
  2. If the sets S 1 , S 2 ,... , Sn ∈ F are disjoint (i.e. Si ∩ Sj = ∅ for i 6 = j) then

P (∪ni=1Si) =

∑^ n

i=

P (Si). (1.11)

Similarly, for a countably infinite sequence of disjoint sets S 1 , S 2 ,... ∈ F

P

lim n→∞ ∪ni=1Si

= lim n→∞

∑^ n

i=

P (Si). (1.12)

3. P (Ω) = 1.

The two first axioms capture the intuitive idea that the probability of an event is a measure such as mass (or length or volume): just like the mass of any object is nonnegative and the total mass of several distinct objects is the sum of their masses, the probability of any event is nonnegative and the probability of the union of several disjoint objects is the sum of their probabilities. However, in contrast to mass, the amount of probability in an experiment cannot be unbounded. If it is highly likely that it will rain tomorrow, then it cannot be also very likely that it will not rain. If the probability of an event S is large, then the probability of its complement Sc^ must be small. This is captured by the third axiom, which normalizes the probability measure (and implies that P (Sc) = 1 − P (S)).

It is important to stress that the probability measure does not assign probabilities to individual outcomes, but rather to events in the σ-algebra. The reason for this is that when the number of possible outcomes is uncountably infinite, then one cannot assign nonzero probability to all the outcomes and still satisfy the condition P (Ω) = 1. This is not an exotic situation, it occurs for instance in the cholesterol example where any positive real number is a possible outcome. In the case of discrete or countable sample spaces, the σ-algebra may equal the power set of the sample space, which means that we do assign probabilities to events that only contain a single outcome (e.g. the coin-toss example).

CHAPTER 1. BASIC PROBABILITY THEORY 5

Example 1.2.1 (Flights and rain). JFK airport hires you to estimate how the punctuality of flight arrivals is affected by the weather. You begin by defining a probability space for which the sample space is

Ω = {late and rain, late and no rain, on time and rain, on time and no rain} (1.21)

and the σ-algebra is the power set of Ω. From data of past flights you determine that a reasonable estimate for the probability measure of the probability space is

P (late, no rain) =

, P (on time, no rain) =

P (late, rain) =

, P (on time, rain) =

The airport is interested in the probability of a flight being late if it rains, so you define a new probability space conditioning on the event rain. The sample space is the set of all outcomes such that rain occurred, the σ-algebra is the power set of {on time, late} and the probability measure is P (·|rain). In particular,

P (late|rain) =

P (late, rain) P (rain)

and similarly P (late|no rain) = 1/8.

4

Conditional probabilities can be used to compute the intersection of several events in a structured way. By definition, we can express the probability of the intersection of two events A, B ∈ F as follows,

P (A ∩ B) = P (A) P (B|A) (1.25) = P (B) P (A|B). (1.26)

In this formula P (A) is known as the prior probability of A, as it captures the information we have about A before anything else is revealed. Analogously, P (A|B) is known as the posterior probability. These are fundamental quantities in Bayesian models, discussed in Chapter 10. Generalizing (1.25) to a sequence of events gives the chain rule, which allows to express the probability of the intersection of multiple events in terms of conditional probabilities. We omit the proof, which is a straightforward application of induction.

Theorem 1.2.2 (Chain rule). Let (Ω, F, P) be a probability space and S 1 , S 2 ,... a collection of events in F,

P (∩iSi) = P (S 1 ) P (S 2 |S 1 ) P (S 3 |S 1 ∩ S 2 ) · · · (1.27)

i

P

Si| ∩i j−=1^1 Sj

Sometimes, estimating the probability of a certain event directly may be more challenging than estimating its probability conditioned on simpler events. A collection of disjoint sets A 1 , A 2 ,... such that Ω = ∪iAi is called a partition of Ω. The law of total probability allows us to pool conditional probabilities together, weighting them by the probability of the individual events in the partition, to compute the probability of the event of interest.

CHAPTER 1. BASIC PROBABILITY THEORY 6

Theorem 1.2.3 (Law of total probability). Let (Ω, F, P) be a probability space and let the collection of disjoint sets A 1 , A 2 ,... ∈ F be any partition of Ω. For any set S ∈ F

P (S) =

i

P (S ∩ Ai) (1.29)

i

P (Ai) P (S|Ai). (1.30)

Proof. This is an immediate consequence of the chain rule and Axiom 2 in Definition 1.1.4, since S = ∪i S ∩ Ai and the sets S ∩ Ai are disjoint.

Example 1.2.4 (Aunt visit). Your aunt is arriving at JFK tomorrow and you would like to know how likely it is for her flight to be on time. From Example 1.2.1, you recall that

P (late|rain) = 0. 75 , P (late|no rain) = 0. 125. (1.31)

After checking out a weather website, you determine that P (rain) = 0.2.

Now, how can we integrate all of this information? The events rain and no rain are disjoint and cover the whole sample space, so they form a partition. We can consequently apply the law of total probability to determine

P (late) = P (late|rain) P (rain) + P (late|no rain) P (no rain) (1.32) = 0. 75 · 0 .2 + 0. 125 · 0 .8 = 0. 25. (1.33)

So the probability that your aunt’s plane is late is 1/4.

4

It is crucial to realize that in general P (A|B) 6 = P (B|A): most players in the NBA probably own a basketball (P (owns ball|NBA) is large) but most people that own basketballs are not in the NBA (P (NBA|owns ball) is small). The reason is that the prior probabilities are very differ- ent: P (NBA) is much smaller than P (owns ball). However, it is possible to invert conditional probabilities, i.e. find P (A|B) from P (B|A), as long as we take into account the priors. This straightforward consequence of the definition of conditional probability is known as Bayes’ rule.

Theorem 1.2.5 (Bayes’ rule). For any events A and B in a probability space (Ω, F, P)

P (A|B) =
P (A) P (B|A)
P (B)

as long as P (B) > 0.

Example 1.2.6 (Aunt visit (continued)). You explain the probabilistic model described in Example 1.2.4 to your cousin Marvin who lives in California. A day later, you tell him that your aunt arrived late but you don’t mention whether it rained or not. After he hangs up, Marvin wants to figure out the probability that it rained. Recall that the probability of rain was 0.2, but since your aunt arrived late he should update the estimate. Applying Bayes’ rule and the

CHAPTER 1. BASIC PROBABILITY THEORY 8

Based on these data, we can evaluate whether voting behavior on the two issues was dependent. In other words, if we know how a member voted on issue 1, does this provide information about how they voted on issue 2? The answer is yes, since

P (issue 1 = yes) P (issue 2 = yes) = 0. 249 (1.46)

is very different from P (issue 1 = yes ∩ issue 2 = yes). If a member voted yes on issue 1, they were less likely to vote yes on issue 2. 4

Similarly, we can define conditional independence between two events given a third event. A and B are conditionally independent given C if and only if

P (A|B, C) = P (A|C) , (1.47)

where P (A|B, C) := P (A|B ∩ C). Intuitively, this means that the probability of A is not affected by whether B occurs or not, as long as C occurs.

Definition 1.3.3 (Conditional independence). Let (Ω, F, P) be a probability space. Two events A, B ∈ F are conditionally independent given a third event C ∈ F if and only if

P (A ∩ B|C) = P (A|C) P (B|C). (1.48)

Example 1.3.4 (Congress (continued)). The main factor that determines how members of congress vote is political affiliation. We therefore incorporate it into the probabilistic model in Example 1.3.2. Each outcome now consists of the votes for issues 1 and 2, and also the affiliation of the member, e.g. issue 1 = yes, issue 2 = no, affiliation = republican, or issue 1 = no, issue 2 = no, affiliation = democrat. The σ-algebra is the power set of the sample space. We again estimate the values of the probability measure associated to different events using the data:

P (issue 1 = yes | republican) ≈ republicans voting yes on issue 1 total republican votes on issue 1

P (issue 2 = yes | republican) ≈

republicans voting yes on issue 2 total republican votes on issue 2

P (issue 1 = yes ∩ issue 2 = yes | republican) ≈

republicans voting yes on issues 1 and 2 republicans voting on both issues = 0. 134. (1.53)

Based on these data, we can evaluate whether voting behavior on the two issues was dependent conditioned on the member being a republican. In other words, if we know how a member voted on issue 1 and that they are a republican, does this provide information about how they voted on issue 2? The answer is no, since

P (issue 1 = yes | republican) P (issue 2 = yes | republican) = 0. 133 (1.54)

is very close to P (issue 1 = yes ∩ issue 2 = yes | republican). The votes are approximately inde- pendent given the knowledge that the member is a republican. 4

CHAPTER 1. BASIC PROBABILITY THEORY 9

As suggested by Examples 1.3.2 and 1.3.4, independence does not imply conditional indepen- dence or vice versa. This is further illustrated by the following examples. From now on, to simplify notation, we write the probability of the intersection of several events in the following form

P (A, B, C) := P (A ∩ B ∩ C). (1.55)

Example 1.3.5 (Conditional independence does not imply independence). Your cousin Marvin from Exercise 1.2.6 always complains about taxis in New York. From his many visits to JFK he has calculated that

P (taxi|rain) = 0. 1 , P (taxi|no rain) = 0. 6 , (1.56)

where taxi denotes the event of finding a free taxi after picking up your luggage. Given the events rain and no rain, it is reasonable to model the events plane arrived late and taxi as conditionally independent,

P (taxi, late|rain) = P (taxi|rain) P (late|rain) , (1.57) P (taxi, late|no rain) = P (taxi|no rain) P (late|no rain). (1.58)

The logic behind this is that the availability of taxis after picking up your luggage depends on whether it’s raining or not, but not on whether the plane is late or not (we assume that availability is constant throughout the day). Does this assumption imply that the events are independent?

If they were independent, then knowing that your aunt was late would give no information to Marvin about taxi availability. However,

P (taxi) = P (taxi, rain) + P (taxi, no rain) (by the law of total probability) (1.59) = P (taxi|rain) P (rain) + P (taxi|no rain) P (no rain) (1.60) = 0. 1 · 0 .2 + 0. 6 · 0 .8 = 0. 5 , (1.61)

P (taxi|late) =

P (taxi, late, rain) + P (taxi, late, no rain) P (late) (by the law of total probability)

P (taxi|rain) P (late|rain) P (rain) + P (taxi|no rain) P (late|no rain) P (no rain) P (late) =

P (taxi) 6 = P (taxi|late) so the events are not independent. This makes sense, since if the airplane is late, it is more probable that it is raining, which makes taxis more difficult to find.

4

Example 1.3.6 (Independence does not imply conditional independence). After looking at your probabilistic model from Example 1.2.1 your contact at JFK points out that delays are often caused by mechanical problems in the airplanes. You look at the data and determine that

P (problem) = P (problem|rain) = P (problem|no rain) = 0. 1 , (1.63)

Chapter 2

Random Variables

Random variables are a fundamental tool in probabilistic modeling. They allow us to model numerical quantities that are uncertain: the temperature in New York tomorrow, the time of arrival of a flight, the position of a satellite... Reasoning about such quantities probabilistically allows us to structure the information we have about them in a principled way.

2.1 Definition

Formally, we define a random variables as a function mapping each outcome in a probability space to a real number.

Definition 2.1.1 (Random variable). Given a probability space (Ω, F, P), a random variable X is a function from the sample space Ω to the real numbers R. Once the outcome ω ∈ Ω of the experiment is revealed, the corresponding X (ω) is known as a realization of the random variable.

Remark 2.1.2 (Rigorous definition). If we want to be completely rigorous, Definition 2.1.1 is missing some details. Consider two sample spaces Ω 1 and Ω 2 , and a σ-algebra F 2 of sets in Ω 2. Then, for X to be a random variable, there must exist a σ-algebra F 1 in Ω 1 such that for any set S in F 2 the inverse image of S, defined by

X−^1 (S) := {ω | X (ω) ∈ S} , (2.1)

belongs to F 1. Usually, we take Ω 2 to be the reals R and F 2 to be the Borel σ-algebra, which is defined as the smallest σ-algebra defined on the reals that contains all open intervals (amazingly, it is possible to construct sets of real numbers that do not belong to this σ-algebra). In any case, for the purpose of these notes, Definition 2.1.1 is sufficient (more information about the formal foundations of probability can be found in any book on measure theory and advanced probability theory).

Remark 2.1.3 (Notation). We often denote events of the form

{X (ω) ∈ S : ω ∈ Ω} (2.2)

for some random variable X and some set S as

{X ∈ S} (2.3)

CHAPTER 2. RANDOM VARIABLES 12

to alleviate notation, since the underlying probability space is often of no significance once we have specified the random variables of interest.

A random variable quantifies our uncertainty about the quantity it represents, not the value that it happens to finally take once the outcome is revealed. You should never think of a random variable as having a fixed numerical value. If the outcome is known, then that determines a realization of the random variable. In order to stress the difference between random variables and their realizations, we denote the former with uppercase letters (X, Y ,... ) and the latter with lowercase letters (x, y,... ).

If we have access to the probability space (Ω, F, P) in which the random variable is defined, then it is straightforward to compute the probability of a random variable X belonging to a certain set S:^1 it is the probability of the event that comprises all outcomes in Ω which X maps to S,

P (X ∈ S) = P ({ω | X (ω) ∈ S}). (2.4)

However, we almost never model the probability space directly, since this requires estimating the probability of every possible event in the corresponding σ-algebra. As we explain in Sections 2. and 2.3, there are more practical methods to specify random variables, which automatically imply that a valid underlying probability space exists. The existence of this probability space ensures that the whole framework is mathematically sound, but you don’t really have to worry about it.

2.2 Discrete random variables

Discrete random variables take values on a finite or countably infinite subset of R such as the integers. They are used to model discrete numerical quantities: the outcome of the roll of a die, the score in a basketball game, etc.

2.2.1 Probability mass function

To specify a discrete random variable it is enough to determine the probability of each value that it can take. In contrast to the case of continuous random variables, this is tractable because these values are countable by definition.

Definition 2.2.1 (Probability mass function). Let (Ω, F, P) be a probability space and X : Ω → Z a random variable. The probability mass function (pmf ) of X is defined as

pX (x) := P ({ω | X (ω) = x}). (2.5)

In words, pX (x) is the probability that X equals x.

We usually say that a random variable is distributed according to a certain pmf.

If the discrete range of X is denoted by D, then the triplet

D, 2 D, pX

is a valid probability space (recall that 2D^ is the power set of D). In particular, px is a valid probability measure

(^1) Strictly speaking, S needs to belong to the Borel σ-algebra. Again, this comprises essentially any subset of the reals that you will ever encounter in probabilistic modeling

CHAPTER 2. RANDOM VARIABLES 14

Bernoulli

Bernoulli random variables are used to model experiments that have two possible outcomes. By convention we usually represent an outcome by 0 and the other outcome by 1. A canonical example is flipping a biased coin, such that the probability of obtaining heads is p. If we encode heads as 1 and tails as 0, then the result of the coin flip corresponds to a Bernoulli random variable with parameter p.

Definition 2.2.3 (Bernoulli). The pmf of a Bernoulli random variable with parameter p ∈ [0, 1] is given by

pX (0) = 1 − p, (2.11) pX (1) = p. (2.12)

A special kind of Bernoulli random variable is the indicator random variable of an event. This random variable is particularly useful in proofs.

Definition 2.2.4 (Indicator). Let (Ω, F, P) be a probability space. The indicator random vari- able of an event S ∈ F is defined as

(^1) S (ω) =

1 , if ω ∈ S, 0 , otherwise.

By definition the distribution of an indicator random variable is Bernoulli with parameter P (S).

Geometric

Imagine that we take a biased coin and flip it until we obtain heads. If the probability of obtaining heads is p and the flips are independent then the probability of having to flip k times is

P (k flips) = P (1st flip = tails,... , k − 1th flip = tails, kth flip = heads) (2.14) = P (1st flip = tails) · · · P (k − 1th flip = tails) P (kth flip = heads) (2.15) = (1 − p)k−^1 p. (2.16)

This reasoning can be applied to any situation in which a random experiment with a fixed prob- ability p is repeated until a particular outcome occurs, as long as the independence assumption is met. In such cases the number of repetitions is modeled as a geometric random variable.

Definition 2.2.5 (Geometric). The pmf of a geometric random variable with parameter p is given by

pX (k) = (1 − p)k−^1 p, k = 1, 2 ,... (2.17)

Figure 2.2 shows the probability mass function of geometric random variables with different parameters. The larger p is, the more the distribution concentrates around smaller values of k.

CHAPTER 2. RANDOM VARIABLES 15

p = 0. 2 p = 0. 5 p = 0. 8

2 4 6 8 10 0

  1. 2

  2. 4

  3. 6

  4. 8

k

pX

(k )

2 4 6 8 10 0

  1. 2

  2. 4

  3. 6

  4. 8

k 2 4 6 8 10 0

  1. 2

  2. 4

  3. 6

  4. 8

k

Figure 2.2: Probability mass function of three geometric random variables with different parameters.

Binomial

Binomial random variables are extremely useful in probabilistic modeling. They are used to model the number of positive outcomes of n trials modeled as independent Bernoulli random variables with the same parameter. The following example illustrates this with coin flips.

Example 2.2.6 (Coin flips). If we flip a biased coin n times, what is the probability that we obtain exactly k heads if the flips are independent and the probability of heads is p?

Let us first consider a simpler problem: what is the probability of first obtaining k heads and then n − k tails? By independence, the answer is

P (k heads, then n − k tails) (2.18) = P (1st flip = heads,... , kth flip = heads, k + 1th flip = tails,... , nth flip = tails) = P (1st flip = heads) · · · P (kth flip = heads) P (k + 1th flip = tails) · · · P (nth flip = tails) = pk^ (1 − p)n−k^. (2.19)

Note that the same reasoning implies that this is also the probability of obtaining exactly k heads in any fixed order. The probability of obtaining exactly k heads is the union of all of these events. Because these events are disjoint (we cannot obtain exactly k heads in two different orders simultaneously) we can add their individual to compute the probability of our event of interest. We just need to know the number of possible orderings. By basic combinatorics, this is given by the binomial coefficient

(n k

, defined as ( n k

n! k! (n − k)!

We conclude that

P (k heads out of n flips) =

n k

pk^ (1 − p)(n−k)^. (2.21)

The random variable representing the number of heads in the example is called a binomial random variable.