Lecture 09: Continuous RV Lisa Yan July 16, 2018
Announcements As of Sunday July 17 2pm, PS3 has been updated (typo in problem 10) Midterm: Practice midterm up in next 24hrs PS4 out on Wednesday SCPD email out later today 2
Counting successes vs counting time until success Counting # of successes 1. Start and finish experiment. 2. Review and count successes. 1 trial: Ber(p) Amount of time until success 1. Start experiment. 2. Once success is observed, finish the experiment. Geo(p) 1 success N trials: Bin(n,p) NegBin(r,p) r successes Duration of time: Poi(l) Today s lecture 3
Balls, Urns, and Supreme Court Supreme Court case: Berghuis v. Smith If a group is underrepresented in a jury pool, how do you tell? Article by Erin Miller Friday, January 22, 2010 Thanks to (former CS109er) Josh Falk for this article Justice Breyer [Stanford Alum] opened the questioning by invoking the binomial theorem. He hypothesized a scenario involving an urn with a thousand balls, and sixty are red, and nine hundred forty are black, and then you select them at random twelve at a time. According to Justice Breyer and the binomial theorem, if the red balls were black jurors then you would expect something like a third to a half of juries would have at least one black person on them. Justice Scalia s rejoinder: We don t have any urns here. 4
Balls, Urns, and Supreme Court If a group is underrepresented in a jury pool, how do you tell? Urn with 1000 balls, 60 red, 940 black. Select 12 at a time. What is P( 1 black person in a 12-person jury)? Solution: Note: Ball draws not independent (draw without replacement) Recall: HypGeo == combinatorics/equally likely outcomes P(draw 1 red ball) = 1 P(draw 12 black balls) 0.5261 P(draw 12 black balls) = "# $% / $### 0.4739 $% Approximate using Binomial: Assume P(red ball) = 60/1000 (with replacement) Define X = # red balls drawn out of 12, X ~ Bin(12, 60/1000 = 0.06) P(X 1) = 1 P(X = 0)» 1 0.4759 = 0.5240 5
Goals for today Continuous RV Probability Density Functions (PDFs) Cumulative Distribution Functions (CDFs) Uniform Random Variable Exponential Random Variable 6
From Discrete to Continuous So far, everything has been discrete: Finite or countably infinite values (e.g., integers) Values are binary or represent a count How many But not everything random in this world is discrete Continous random variables have (uncountably) infinite values Height (cm), weight (lbs), time (seconds), etc. How much The general TL;DR is replace b x=a p(x) " a bf(x)dx with 7
Continuous Random Variables X is a Continuous Random Variable if there is a function (#) 0 for x such that: % & ( ) = +. (#) /#, is a Probability Density Function (PDF) if: % ( = +. # /# = 1 1 The cumulative distribution function (CDF) of X is then: 3. & = +. # /# 1, - 8
Probability Density Functions is a Probability Density Function (PDF) if: " % = ' ) *) = 1 ( ()) is not a probability It is a density (probability/units of X) Meaningless without a subinterval over X. ". % / = ' 0 1 2 ()) *) 9
random.random() random.random() in Python: Let X = random.random(). 1. P(X = 0.6) 2. P(X < 0.6) 3. P(X 0.6) 4. P(X > 0.6) 5. P(0.4 < X < 0.6) = 0 = 0.6 = 0.6 = 1 0.6 = 0.4 = 0.2 10
PDFs (continuous) vs PMFs (discrete) Recall the PMF (discrete X): But for PDF (continuous X): + " = $ % = ", ' $ % = " =. / For continuous 0 and small e: $ " 4 5 % " + 4 5 = /9 : ; / /< : ; 0, 1, >0(") ()*, ( = 1 0, 1, = 0 P(X = a) for continuous X is meaningless $ % = 1 $ % = 2 >0 1 >0 2 = 0(1) 0(2) Ratio of probabilities is still meaningful 11
Cumulative Distribution Functions For a continuous random variable X, the CDF is: " = $ % < " = $ % " = ( +, -, ) Density + (PDF) is derivative of CDF : + " = - -" (") * 12
random.random() random.random() in Python: Let X = random.random(). 1. Draw the PDF of X. 2. Draw the CDF of X. 13
A simple example Let X be a continuous RV with PDF: " # = % & 4# 2#* if 0 # 2 0 otherwise 1. What is C? 1 = / 3 03 " # 1# = / Support of PDF 4 * " # 1# = / 4 * -. = / # 1# = 1 0 & 4# 2# * 1# = & 2# * 2 5 3 #7 4 * = & 8 9: 7 2. What is P(X > 1)? P X > 1 = / 9 3 C > 7 = 1 à C = 7 > " # 1# = / 9 * 3 8 4# 2#* 1# = 3 8 = 3 8 8 16 3 2 2 3 à P(X > 1) = 9 * 2# * 2 * 5 3 #7 9 Picture checks out 14
Expectation and Variance Discrete RV: Continuous RV: " = $ & ' ( & % )(") = $ )(&) ' ( & % ", = $ &, ' ( & % Both continuous and discrete RVs: " =. )(") =. ", =. 0 /0 0 /0 0 /0 3" + 5 = 3 " + 5 Var(") = (" ["]) < = " < (["]) < Var(3" + 5) = 3 < Var(") &1 ( & 2& )(&)1 ( & 2& &, 1 ( & 2& 16
Linearly increasing density 2# if 0 # 1 " # = % 0 otherwise " # 1. E[X] *, +, 2. Var(X) 4 5 6 = * # " #.# = *, +, / 0 # 6 " #.# = * # " #.# = * / / 0 0 # 6 " #.# = * Var 5 = 4 5 6 4 5 6 = 1 2 2 3 2 # 2#.# = 1 6 / = 1 18 0 0 3 #3 / = # 2 3 # 6 2 2#.# = 1 0 4 #8 / = 1 2 17
Break Attendance: tinyurl.com/cs109summer2018 18
Uniform Random Variable Uniform RV, X: X ~ Unif(a, b) 1 if $ *, ( " # $ = &( * 0 otherwise ; : =. 0 /0 $ " # $ 2$ =. 3 4 $ 1 ( * 2$ = 1 ( * 1 5 = 1 ( * 1 2 (7 * 7 = 1 2 ( + * ( * ( * 4 2 $7 3 = 1 2 * + ( E : = 1 2 * + ( Var : = ( * 7 12 19
Uniformly fun Let X ~ Unif(0, 20). 0. Draw the PDF of X. 1. P(X < 6)? 2. P(4 < X < 17)? ) 1 " # < 6 = ' ( 20 -. = 6 20 = 3 10 " 4 < # < 17 = ' : ;< 1 20 Let X ~ Unif(a,b). What is P(a X b), where a a b b? 17 -. = 20 4 20 = 13 20 3 1 " 0 < # < 1 = ' 2 4 6 -. =. 4 6 7 2 3 = 1 0 4 6 20
Riding the Marguerite Bus Suppose the Marguerite bus stops at the Gates building at 15-minute intervals (2:00, 2:15, 2:30, etc.). Passenger arrives at stop uniformly b/t 2:00-2:30pm. X ~ Unif(0, 30) 1. P(passenger waits < 5 minutes for bus)? " 10 < & < 15 + " 25 < & < 30 = -./.0 1 30 12 + - 30 4/ 1 2. P(passenger waits > 14 minutes for bus)? " 0 < & < 1 + " 15 < & < 16. 1.5 = - / 30 12 + - 1.0 30 12 30 12 = 5 30 + 5 30 = 1 3 = 1 30 + 1 30 = 1 15 2:00pm Must arrive: 2:10-2:15 2:25-2:30 2:00pm 2:15pm 2:30pm Must arrive: 2:00-2:01 2:15-2:16 2:15pm 21
Small Calculus Review Product rule for derivatives: " # $ = " # $ + " # $ Derivative and integral of exponential: ' ( ) '* Written another way: (fg) = f g + f g ', = +, '* +,. = +, Integration by parts: /. # 0 =. # 0 / 0 #. 22
Exponential Random Variable Exponential RV, X: X ~ Exp(l) " # $ = & '()*+ if $ 0 0 otherwise. / = 1 λ Var(/) = 1 λ 7 CDF (where a 0): 8 # 9 = : / 9 = < = > '( )*+?$ = ' 1 > @ ' ()*+ = = 1 ( )*> ( )* = = 1 ( )*> 1 8 # 9 = 1 ( )*> 23
Expectation of the Exponential < 0 5 12 = 0 5 2 < 2 5 10 Given that " # = %& '() for # 0, show:, - = 1 λ 1. Don t panic, think happy thoughts 2. Integration by parts: find u, v, du, dv 3. Substitute (a.k.a plug and chug ) Solution: 0 = # 12 = %& '() 1# 10 = 1# 2 = & '() f #%& '() 1# = 0 5 12 = 0 5 2 2 5 10 = #& '() & '() 1# f, - = #& '() 8 8 6 7 + 7 & '() 1# = #& '() 8 : 6 7 & '() 8 6 7 ; E, - = : ; = 0 : ; 0 0 : ; 24
PSA: The CDF is nice For a continuous random variable X, the CDF is: " = $ % < " = $ % " = ( +, -, ) If you learn how to use cumulative distribution functions, you can avoid integrals. For continuous X: P(X < a) = P(X a) = F(a) Consequently, P(X > a) = P(X a) = 1 F(a) Cool fact (if " <. and +, is continuous): P(a < X < b) = F(b) F(a) 1 * Proof:. " = ) +, -, ) +, -, * 1 * 1 Proof= ) +, -, + * +, -, ) +, -, = * +, -, * 25
Website visits X ~ Exp(l ): ) * + = 1 "./0 Suppose a visitor to your website leaves after X minutes. On average, visitors leave the site after 5 minutes. The length of stay, X, is exponentially distributed. 1. P(X > 10)? 2. P(10 < X < 20)? Solution: Define: X ~ Exp(l), where l = 1/E[X] = 1/5 1. P(X > 10)? 2. P(10 < X < 20)? = 1 F(10) = 1 (1 " 10(1/5) ) = " 2 0.1353 = F(20) F(10) = (1 " 4 ) (1 " 2 ) 0.1170 26
Discrete RV analogs to Continuous RVs Discrete PMF Die rolling, p(x) = 1/6, X {1,,6} Continuous PDF X ~ Unif(a, b ), X [",#] $ % (') X ~ Geo(p), X {1, 2, } ' X ~ Exp(l ), X [0, ) f (x) x 27