1 00:00:01,020 --> 00:00:03,610 So for practice with expectation, 2 00:00:03,610 --> 00:00:06,640 let's calculate the expected number of heads in n coin 3 00:00:06,640 --> 00:00:11,710 flips, and just working directly from the definition, 4 00:00:11,710 --> 00:00:14,990 because we have tools to do that. 5 00:00:14,990 --> 00:00:19,045 So we're imagining n independent flips of a coin with bias p. 6 00:00:19,045 --> 00:00:20,720 So the coins might not be fair. 7 00:00:20,720 --> 00:00:23,000 The probability of heads is p. 8 00:00:23,000 --> 00:00:25,920 It would be biased in favor of heads if p is greater than 1/2 9 00:00:25,920 --> 00:00:29,310 and biased against heads if p is less than 1/2. 10 00:00:29,310 --> 00:00:32,600 And we want to know how many heads are expected. 11 00:00:32,600 --> 00:00:35,810 This is a basic question that will come up again and again 12 00:00:35,810 --> 00:00:40,140 when we look at random variables and probability theory. 13 00:00:40,140 --> 00:00:42,570 So what's the expected number of heads? 14 00:00:42,570 --> 00:00:46,000 Well, we already know-- we've examined the binomial 15 00:00:46,000 --> 00:00:47,980 distribution B n,p. 16 00:00:47,980 --> 00:00:50,920 B n,p is telling us how many heads there are in n 17 00:00:50,920 --> 00:00:52,210 independent flips. 18 00:00:52,210 --> 00:00:55,640 So we're asking about the expectation of the binomial 19 00:00:55,640 --> 00:00:57,360 variable B n,p. 20 00:00:57,360 --> 00:00:59,525 Well, let's look at the definition. 21 00:00:59,525 --> 00:01:03,880 The definition of B n,p is it's the sum over all the possible 22 00:01:03,880 --> 00:01:09,060 values of B, namely all the numbers from 0 to n-- 23 00:01:09,060 --> 00:01:13,870 that's k-- of the probability of getting k heads. 24 00:01:13,870 --> 00:01:16,010 And this formula here is the probability 25 00:01:16,010 --> 00:01:19,020 of getting k heads, which we've worked out previously. 26 00:01:19,020 --> 00:01:22,310 n choose k times p to the k, 1 minus p to the n minus k. 27 00:01:22,310 --> 00:01:24,600 Well, let's introduce an abbreviation, 28 00:01:24,600 --> 00:01:25,600 a standard abbreviation. 29 00:01:25,600 --> 00:01:30,850 Let's replace 1 minus p by q, where-- so p plus q equals 1, 30 00:01:30,850 --> 00:01:36,140 and they're both not negative and between 0 and 1. 31 00:01:36,140 --> 00:01:40,220 And when I express the expectation this way, 32 00:01:40,220 --> 00:01:44,050 it starts to look like something a little bit familiar. 33 00:01:44,050 --> 00:01:48,130 And our strategy is going to be to use the binomial theorem, 34 00:01:48,130 --> 00:01:50,180 and then the trick of differentiating it 35 00:01:50,180 --> 00:01:52,020 is going to wind up giving us a closed 36 00:01:52,020 --> 00:01:56,140 formula for this expression for the expectation 37 00:01:56,140 --> 00:01:59,240 of the binomial random variable. 38 00:01:59,240 --> 00:02:02,740 So let's remember the binomial theorem says 39 00:02:02,740 --> 00:02:07,510 that the nth power of x plus y is the sum all from k 40 00:02:07,510 --> 00:02:11,970 equals 0 to n of n choose k, x to the k, y to the n minus k. 41 00:02:11,970 --> 00:02:14,860 And if I differentiate this, what 42 00:02:14,860 --> 00:02:17,640 happens is that on the left hand side, 43 00:02:17,640 --> 00:02:21,190 if I differentiate with respect to x, I get x plus y 44 00:02:21,190 --> 00:02:24,030 to the n minus 1 times n. 45 00:02:24,030 --> 00:02:26,530 And if I differentiate the right hand side-- let's 46 00:02:26,530 --> 00:02:28,730 differentiate it term by term. 47 00:02:28,730 --> 00:02:30,630 And differentiating with respect to x 48 00:02:30,630 --> 00:02:34,710 is going to turn this n choose k x to the k, y to the n minus k 49 00:02:34,710 --> 00:02:40,130 into an x to the k minus 1 times k term. 50 00:02:40,130 --> 00:02:44,280 But I'd like to keep the n-- the k here 51 00:02:44,280 --> 00:02:45,950 and the k there matching. 52 00:02:45,950 --> 00:02:49,250 So that after differentiating, that 53 00:02:49,250 --> 00:02:51,810 becomes an x to the k minus 1. 54 00:02:51,810 --> 00:02:54,610 Let's multiply it by x to make it x to the k. 55 00:02:54,610 --> 00:02:57,670 And of course, I have to undo that multiplication by dividing 56 00:02:57,670 --> 00:02:59,820 the whole thing by 1/x. 57 00:02:59,820 --> 00:03:04,260 So by differentiating the binomial formula, 58 00:03:04,260 --> 00:03:10,170 we get the following formula for this sum that is starting 59 00:03:10,170 --> 00:03:13,810 to look just like the expectation of B n,p, 60 00:03:13,810 --> 00:03:17,880 1/x times the sum from k equals 0 to 1 of k times n choose k, 61 00:03:17,880 --> 00:03:19,920 x to the k, y to the n minus k. 62 00:03:19,920 --> 00:03:22,410 Well, let's compare the two terms. 63 00:03:22,410 --> 00:03:24,290 So here's this term and there's this one. 64 00:03:24,290 --> 00:03:28,040 I'm going to replace this line by the formula for expectation 65 00:03:28,040 --> 00:03:30,502 of the binomial random variable. 66 00:03:30,502 --> 00:03:32,210 So this is what we're trying to evaluate, 67 00:03:32,210 --> 00:03:33,460 and I have this great theorem. 68 00:03:33,460 --> 00:03:35,920 You can see how they match up. 69 00:03:35,920 --> 00:03:40,740 So what I'm going to do is replace p and q-- replace 70 00:03:40,740 --> 00:03:43,500 x and y in this general formula that I 71 00:03:43,500 --> 00:03:47,760 got by differentiating the binomial theorem with p and q. 72 00:03:47,760 --> 00:03:49,260 And what happens? 73 00:03:49,260 --> 00:03:51,170 So I just plug in the p and q. 74 00:03:51,170 --> 00:03:53,670 Now, the left hand side. p plus q is 1. 75 00:03:53,670 --> 00:03:59,020 So the left hand side is going to become n. 76 00:03:59,020 --> 00:04:05,580 And this right hand side now is exactly the expectation of B 77 00:04:05,580 --> 00:04:07,640 n,p-- this part of it, anyway. 78 00:04:07,640 --> 00:04:14,050 So what I'm going to wind up with is that n is equal to 1/p 79 00:04:14,050 --> 00:04:16,430 times the expectation of B n,p. 80 00:04:16,430 --> 00:04:20,800 In other words, the expectation of B n,p is n times p, 81 00:04:20,800 --> 00:04:25,820 and that is the basic formula that we were deriving by first 82 00:04:25,820 --> 00:04:28,210 principles without using any general properties 83 00:04:28,210 --> 00:04:31,830 of expectation, just the definition of expectation 84 00:04:31,830 --> 00:04:35,390 and the stuff that we had already worked out in terms 85 00:04:35,390 --> 00:04:38,400 of the binomial theorem.