Stats for Engineers: Lecture 3 Conditional probability Suppose there are three cards: A red card that is red on both sides, A white card that is white on both sides, and A mixed card that is red on one side and white on the other. All the cards are placed into a hat and one is pulled at random and placed on a table. If the side facing up is red, what is the probability that the other side is also red? 44% 1. 2. 3. 4. 5. 1/6 1/3 1/2 2/3 5/6 29% 14% 11% 3% 1 2 3 4 5 Conditional probability Suppose there are three cards: A red card that is red on both sides, A white card that is white on both sides, and A mixed card that is red on one side and white on the other. All the cards are placed into a hat and one is pulled at random and placed on a table. If the side facing up is red, what is the probability that the other side is also red? Probability tree Let R=red card, TR = top red. 1 1 3 1 3 1 3 Top Red 1 3 Top White 1 3 1 2 Top Red 1 6 1 2 Top White Red card 1 White card Mixed card 1 6 π π ∩ ππ π π ππ = π ππ 1 = 3 1 1 3+6 = 2 3 Conditional probability Suppose there are three cards: A red card that is red on both sides, A white card that is white on both sides, and A mixed card that is red on one side and white on the other. All the cards are placed into a hat and one is pulled at random and placed on a table. If the side facing up is red, what is the probability that the other side is also red? Let R=red card, W = white card, M = mixed card. Let TR = top is a red face. For a random draw P(R)=P(W)=P(M)=1/3. Total probability rule: π ππ = π ππ π π π + π ππ π π π 1 1 1 1 =1× + × = 3 2 3 2 The probability we want is P(R|TR) since having the red card is the only way for the other side also to be red. This is π ππ π π π π π ππ = π ππ = 1 1×3 2 = 3 1 2 Intuition: 2/3 of the three red faces are on the red card. Summary From Last Time Bayes’ Theorem π π΅π΄ π π΄ π π΄π΅ = π π΅ Total Probability Rule: π π΅ = e.g. from π π΄π΅ = π π΄∩π΅ π π΅ π π΅ π΄π π(π΄π ) π Permutations - ways of ordering k items: k! Ways of choosing k things from n, irrespective of ordering: πΆππ π! π = = π π! π − π ! Random Variables: Discreet and Continuous Mean π=πΈ π π ≡ π π = π π π(π = π) π Means add: ππ + ππ = ππ + ππ = π π + π π = πππ + πππ Mean of a product of independent random variables If π and π are independent random variables, then π π ∩ π = π π π(π) ππ = π π₯ ∩ π¦ π₯π¦ = π₯ π¦ π π₯ π π¦ π₯π¦ π₯ = π¦ π π₯ π₯ π₯ π π¦ π¦ π¦ = π π = ππ ππ Note: in general this is not true if the variables are not independent Example: If I throw two dice, what is the mean value of the product of the throws? The mean of one throw is π = 6 π=1 ππ π=π 1 1 1 1 1 1 =1× +2× +3× +4× +5× +6× 6 6 6 6 6 6 1 21 = 1+2+3+4+5+6 × = = 3.5 6 6 Two throws are independent, so π1 π2 = ππ1 ππ2 = 3.52 = 12.25 Variance and standard deviation of a distribution For a random variable X taking values 0, 1, 2 the mean π is a measure of the average value of a distribution, π = 〈π〉. The standard deviation, π , is a measure of how spread out the distribution is π(π = π) π π π π Definition of the variance (=π 2 ) 2 ππ22 ≡ ≡ var(π) var(π) = = ππ − −ππ 2 = = π − π 2 π(π = π) π π π = π2 Note that π−π 2 = π 2 − 2 π π + π2 = π 2 − 2 ππ + π2 = π 2 − 2π2 + π2 = π 2 − π2 So the variance can also be written π 2 = var π = 〈π 2 〉 − π2 = π 2 π π = π − π2 π This equivalent form is often easier to evaluate in practice, though can be less numerically stable (e.g. when subtracting two large numbers). Example: what is the mean and standard deviation of the result of a dice throw? Answer: Let π be the random variable that is the number on the dice The mean is π = 3.5 as shown previously. The variance is π 2 = 6π=1 π 2 π π = π − π2 1 = (12 + 22 + 32 + 42 + 52 + 62 ) × 6 − 3.52 = 91 6 − 3.52 ≈ 2.917 π = 3.5 Hence the standard deviation is π = 2.917 ≈ 1.71 π π Sums of variances For two independent (or just uncorrelated) random variables X and Y the variance of X+Y is given by the sums of the separate variances. Why? If π has π = ππ , and π has π = ππ , then π + π = π + π = ππ + ππ . Hence since var π = var π + π = π − ππ 2 π + π − ππ − ππ , if π = π + π then 2 = 〈 π − ππ + π − ππ = 〈 π − ππ 2 + π − ππ 2 2〉 + 2 π − ππ π − ππ¦ 〉 = 〈 π − ππ 2 〉 + 〈 π − ππ 2 〉 + 2〈 π − ππ π − ππ¦ 〉 If X and Y are independent (or just uncorrelated) then π − ππ π − ππ = π − ππ π − ππ Hence var π + π = π − ππ = (ππ − ππ )(ππ − ππ ) = 0 2 + = var π + var π π − ππ 2 [“Variances add”] In general, for both discrete and continuous independent (or uncorrelated) random variables var π + π + π + β― = var π + var π + var π + β― Example: The mean weight of people in England is μ=72.4kg, with standard deviation π =15kg. What is the mean and standard deviation of the weight of the passengers on a plane carrying 200 people? In reality be careful - assumption of independence unlikely to be accurate Answer: The total weight π = Since means add ππ = 200 π=1 ππ 200 π=1 〈ππ 〉 = 200 × 72.4Kg = 14480Kg Assuming weights independent, variances also add, with π 2 = 152 Kg 2 = 225 Kg 2 200 2 ππ = 225Kg 2 = 200 × 225 Kg 2 = 45000Kg 2 π=1 π= 45000Kg 2 ≈ 212 Kg Error bars A bridge uses 100 concrete slabs, each weighing (10 ± 0.1) tonnes [i.e. the standard deviation of each is 0.1 tonnes] What is the total weight in tonnes of the concrete slabs? 1. 2. 3. 4. 5. 1000 ± 0.01 1000 ± 0.1 1000 ± 1 1000 ± 10 1000 ± 100 43% 30% 13% 7% 1 2 6% 3 4 5 Error bars A bridge uses 100 concrete slabs, each weighing (10 ± 0.1) tonnes [i.e. the standard deviation of each is 0.1 tonnes] What is the total weight in tonnes of the concrete slabs? Means add, so ππ‘ππ‘ = 100 × 10 = 1000 π‘πππππ 2 Variances add, with π 2 = 0.12 , so ππ‘ππ‘ = 100 × 0.12 = 1 Hence ππ‘ππ‘ = 1000 ± 1 π‘πππππ = 1000 ± 1 π‘πππππ Note: Error grows with the square root of the number: ∝ But the mean of the total is ∝ π ⇒ fractional error decreases ∝ 1/ π π Reminder: Discrete Random Variables = πΆππ Binomial distribution π! = π! π − π ! A process with two possible outcomes, "success" and "failure" (or yes/no, etc.) is called a Bernoulli trial. e.g. coin tossing: quality control: Polling: Heads or Tails Satisfactory or Unsatisfactory Agree or disagree An experiment consists of n independent Bernoulli trials and p = probability of success for each trial. Let X = total number of successes in the n trials. Then π π = π = π π π 1−π π π−π for k = 0, 1, 2, ... , n. This is called the Binomial distribution with parameters n and p, or B(n, p) for short. X ~ B(n, p) stands for "X has the Binomial distribution with parameters n and p." Situations where a Binomial might occur 1) Quality control: select n items at random; X = number found to be satisfactory. 2) Survey of n people about products A and B; X = number preferring A. 3) Telecommunications: n messages; X = number with an invalid address. 4) Number of items with some property above a threshold; e.g. X = number with height > A Justification "X = k" means k successes (each with probability p) and n-k failures (each with probability 1-p). Suppose for the moment all the successes come first. Assuming independence probability = π × π × π … × π × 1 − π × 1 − π × β― × (1 − π) π successes: ππ = ππ 1 − π π − π failures: 1 − π π−π π−π Every possible different ordering also has this same probability. The total number of π π ways of choosing k out of the n trails to be successes is , so there are , π π possible orderings. Since each ordering is an exclusive possibility, by the special addition rule the π overall probability is ππ 1 − π π−π added times: π π π=π = π π π 1−π π π−π π = 0.5 π−π π π=π π π=π = π π π 1−π π Example: If I toss a coin 100 times, what is the probability of getting exactly 50 tails? Answer: Let X = number tails in 100 tosses Bernoulli trial: tail or head, π ∼ π΅ π, π = π΅(100,0.5) 100 π π = 50 = πΆππ ππ (1 − π)π−π = πΆ50 0.550 1 − 0.5 ≈ 0.0796 50 Example: A component has a 20% chance of being a dud. If five are selected from a large batch, what is the probability that more than one is a dud? Answer: Let X = number of duds in selection of 5 Bernoulli trial: dud or not dud, π ∼ π΅(5,0.2) P(More than one dud) = π π > 1 = 1 − π π ≤ 1 = 1 − P X = 0 − P(X = 1) = 1 − πΆ05 0.20 1 − 0.2 5 − πΆ15 0.21 1 − 0.2 = 1 − 1 × 1 × 0.85 − 5 × 0.2 × 0.84 = 1 - 0.32768 - 0.4096 ≈ 0.263. 4