-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMITx 6.431x -- Probability - The Science of Uncertainty and Data + Unit_4.Rmd
7259 lines (6433 loc) · 294 KB
/
MITx 6.431x -- Probability - The Science of Uncertainty and Data + Unit_4.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "MITx 6.431x -- Probability - The Science of Uncertainty and Data + Unit_4.Rmd"
author: "John HHU"
date: "2022-11-05"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
## Course / Unit 4: Discrete random variables / Lec. 5: Probability mass functions and expectations
# 1. Lecture 5 overview and slides
This lecture introduces random variables, the description of discrete random variables through probability mass functions, and the concept of expectation. The concepts are illustrated in the context of the most common discrete random variables: Bernoulli, uniform, binomial, and geometric.

In this lecture, we introduce the notion of a random variable. [][A random variable is, loosely speaking, a numerical quantity whose value is determined by the outcome of a probabilistic experiment].
The weight of a randomly selected
student is one example.
After giving a general definition, we will focus
exclusively on discrete random variables.
These are random variables that take values in finite or
countably infinite sets.
For example, random variables that take
integer values are discrete.
To any discrete random variable we will associate a
probability mass function, which tells us the likelihood
of each possible value of the random variable.
Then we will go over a few examples and introduce some
common types of random variables.
And finally we will introduce a new concept- the expected
value of the random variable, also called the
expectation or mean.
It is a weighted average of the values of the random
variable, weighted according to their respective
probabilities, and has an intuitive interpretation as
the average value we expect to see if we repeat the same
probabilistic experiment independently a
large number of times.
Expected values play a central role in probability theory.
We will look into some of their properties.
And we will also calculate the expected values of the example
random variables that we will have introduced.
Printable transcript available here.
https://courses.edx.org/assets/courseware/v1/ad8812366180058d90973ef50396e587/asset-v1:MITx+6.431x+2T2022+type@asset+block/transcripts_L05-Overview.pdf
Lecture slides: [clean] [annotated]
https://courses.edx.org/assets/courseware/v1/ca3078fab429bcc9db6f2b562e12f959/asset-v1:MITx+6.431x+2T2022+type@asset+block/lectureslides_L05-clean-slides.pdf
https://courses.edx.org/assets/courseware/v1/fe59e64db945dbc0bee1468169284f8e/asset-v1:MITx+6.431x+2T2022+type@asset+block/lectureslides_L05-annotated-slides.pdf
More information is given in Sections 2.1-2.4 of the text.
https://courses.edx.org/courses/course-v1:MITx+6.431x+2T2022/pdfbook/0/chapter/1/9
# 2. Definition of random variables


We will now define the notion of a random variable. [][Very loosely speaking, a random variable is a numerical quantity that takes random values]. But what does this mean? We want to be a little more precise and I'm going to introduce the idea through an example. Suppose that our sample space is a set of students labeled according to their names. Or for simplicity, let's just label them as a, b, c, and d. Our probabilistic experiment is to pick a student at random according to some probability law and then record their weight in kilograms.
So for example, suppose that the outcome of the experiment was this particular student, and the weight of that student is 62. Or it could be that the outcome of the experiment is this particular student, and that particular student has a weight of 75 kilograms. *The weight of a particular student is a number, little w*. But let us think of the abstract concept of weight, something that we will denote by capital W. Weight is an object whose value is determined once you tell me the outcome of the experiment, once you tell me which student was picked. In this sense, weight is really a function of the outcome of the experiment. So think of weight as an abstract box that takes as input a student and produces a number, little w, which is the weight of that particular student.
Or more concretely, think of weight with a capital W as a
procedure that takes a student, puts him or her on a
scale, and reports the result.
In this sense, weight is an object of the same kind as the
square root function that's sitting inside your computer.
The square root function is a function.
It's a subroutine, perhaps it is a piece of code, that takes
as input a number, let's say the number 9, and produces
another number.
In this case, it would be the number 3, which is the
square root of 9.
Notice here the distinction that we will keep emphasizing
over and over.
Square root of 9 is a number.
It is the number 3.
The box square root is a function.
Now, let us go back to our probabilistic experiment.
Note that a probabilistic experiment such as the one in
our example can have several associated random variables.
For example, we could have another random variable
denoted by capital H, which is the height of a student
recorded in meters.
So if the outcome of the experiment, for example, was
student a, then this random variable would take a value
which is the height of that student, let's say it was 1.7.
Or if the outcome of the experiment was student c, then
we would record the height of that student.
And let's say it turns out to be 1.8.
Once again, height with a capital H is an abstract
object, a function whose value is determined once you tell me
the outcome of the experiment.
Now, given some random variables, we can create new
random variables as functions of the
original random variables.
For example, consider the quantity defined as weight
divided by height squared.
This quantity is the so-called body mass index, and it is
also a function on the sample space.
Why is it a function on the sample space?
Well, because once an outcome of the experiment is
determined, suppose that the outcome of the experiment was
the blue student, then these two numbers, 62 and 1.7, are
also determined.
And using those numbers, we can carry out this calculation
and find the body mass index of that particular student,
which in this case would be 21.5.
Or if it happened that this student was selected, then the
body mass index would turn out to be some other number.
In this case, it would be 23.
So again, we see that the body mass index can be viewed as an
abstract concept defined by this formula.
But once an outcome is determined, then the body mass
index is also determined.
And so the body mass index is really a function of which
particular outcome was selected.
Let us now abstract from the previous discussion.
We have seen that random variables are abstract objects
that associate a specific value, a particular number, to
any particular outcome of a probabilistic experiment.
So in that sense, random variables are functions from
the sample space to the real numbers.
They are numerical functions, but as numerical functions
they can either take discrete values, for example the
integers, or they can take continuous values, let's say
on the real line.
For example, if your random variable is the number of
heads in 10 consecutive coin tosses, this is a discrete
random variable that takes values in the
set from 0 to 10.
If your random variable is a measurement of the time at
which something happened, and if your timer has infinite
accuracy, then the timer reports a real number and we
would have a continuous random variable.
In this lecture sequence and in the next few ones, we will
concentrate on discrete random variables because they are
easier to handle.
And then later on, we will move to a discussion of
continuous random variables.
Throughout, we want to keep noting this very important
distinction that I already brought in the discussion for
a particular example, but it needs to be emphasized and
re-emphasized.
That we make a distinction between random variables,
which are abstract objects.
They are functions on the sample space and they are
denoted by uppercase letters.
In contrast, we will use lower case letters to indicate
numerical values of the random variables.
So little x is always a real number, as opposed to the
random variable, which is a function.
One point that we made earlier is that for the same
probabilistic experiment we can have several random
variables associated with that experiment.
And we can also combine random variables to
form new random variables.
In general, a function of random variables has numerical
values that are determined by the numerical values of the
original random variables.
And so, ultimately, they are determined by the outcome of
the experiment.
So a function of random variables has a numerical
value which is completely determined by the outcome of
the experiment.
And so a function of random variables is
also a random variable.
As an example, we could think of two random variables, X and
Y, associated with the same probabilistic experiment.
And then define a random variable, let's say X plus Y.
What does that mean?
X plus Y is a random variable that takes the value little x
plus little y when the random variable capital X takes the
value little x and capital Y takes the value little y.
So X and Y are random variables.
X plus Y is another random variable.
X and Y will take numerical values once the outcome of the
experiment has been obtained.
And if the numerical values that they take are little x
and little y, then the random variable X plus Y will take
the numerical value little x plus little y.
So we can now move on and start doing some interesting
things about random variables.
Characterize them, describe them, give some examples, and
introduce some new concepts associated with them.
# 3. Exercise: Random variables

# 4. Probability mass functions


[][A random variable can take different numerical values depending on the outcome of the experiment]. Some outcomes are more likely than others, and similarly some of the possible numerical values of a random variable will be more likely than others. We restrict ourselves to discrete random variables, and we will describe these relative likelihoods in terms of the so-called probability mass function, or PMF for short, which gives the probability of the different possible numerical values.
The PMF is also sometimes called the probability law or
the probability distribution of a discrete random variable.
Let me illustrate the idea in terms of a simple example.
We have a probabilistic experiment with
four possible outcomes.
We also have a probability law on the sample space.
And to keep things simple, we assume that all four outcomes
in our sample space are equally likely.
We then introduce a random variable that associates a
number with each possible outcome as
shown in this diagram.
The random variable, X, can take one of
three possible values--
namely 3, 4, or 5.
Let us focus on one of those numbers--
let's say the number 5.
So let us focus on x being equal to 5.
We can think of the event that X is equal to 5.
Which event is this?
This is the event that the outcome of the experiment led
to the random variable taking a value of 5.
So it is this particular event which consists of two
elements, namely a and b.
More formally, the event that we're talking about is the set
of all outcomes for which the value, the numerical value of
our random variable, which is a function of the outcome,
that numerical value happens to be equal to 5.
And in this example it is a set
consisting of two elements.
It's a subset of the sample space.
So it is an event.
And it has a probability.
And that probability we will be
denoting with this notation.
And in our case this probability is equal to 1/2.
Because we have two outcomes, each one has probability 1/4.
The probability of this event is equal to 1/2.
More generally, we will be using this notation to denote
the probability of the event that the random variable, X ,
takes on a particular value, x.
This is just a piece of notation, not a new concept.
We're dealing with a probability, and we indicate
it using this particular notation.
More formally, the probability that we're dealing with is the
probability, the total probability, of all outcomes
for which the numerical value of our random variable is this
particular number, x.
A few things to notice.
We use a subscript, X, to indicate which random variable
we're talking about.
This will be useful if we have several
random variables involved.
For example, if we have another random variable on the
same sample space, Y, then it would have its own probability
mass function which would be denoted with this particular
notation here.
The argument of the PMF, which is x, ranges over the possible
values of the random variable, X. So in this sense, here
we're really dealing with a function.
A function that we could denote just by p with a
subscript x.
This is a function as opposed to the specific
values of this function.
And we can produce plots of this function.
In this particular example that we're dealing with, the
interesting values of x are 3, 4, and 5.
And the associated probabilities are the value of
5 is obtained with probability 1/2, the value of 4--
this is the event that the outcome is c, which has
probability 1/4.
And the value of 3 is also obtained with probability 1/4
because the value of 3 is obtained when the outcome is
d, and that outcome has probability 1/4.
So the probability mass function is a function of an
argument x.
And for any x, it specifies the probability that the
random variable takes on this particular value.
A few more things to notice.
The probability mass function is always non-negative, since
we're talking about probabilities and
probabilities are always non-negative.
In addition, since the total probability of all outcomes is
equal to 1, the probabilities of the different possible
values of the random variable should also add to 1.
So when you add over all possible values of x, the sum
of the associated probabilities
should be equal to 1.
In terms of our picture, the event that x is equal to 3,
which is this subset of the sample space, the event that x
is equal to 4, which is this subset of the sample space,
and the event that x is equal to 5, which is this subset of
the sample space.
These three events--
the red, green, and blue--
they are disjoint, and together they cover the entire
sample space.
So their probabilities should add to 1.
And the probabilities of these events are the probabilities
of the different values of the random variable, X. So the
probabilities of these different values
should also add to 1.
Let us now go through a simple example to illustrate the
general method for calculating the PMF of a
discrete random variable.
We will revisit our familiar example involving two rolls of
the tetrahedral die.
And let X be the result of the first roll, Y be the result of
the second roll.
And notice that we're using uppercase letters.
And this is because X and Y are random variables.
In order to do any probability calculations, we also need the
probability law.
So to keep things simple, let us assume that every possible
outcome, there's 16 of them, has the same probability which
is therefore 1 over 16 for each one of the outcomes.
We will concentrate on a particular random variable
defined to be the sum of the random variables, X and Y. So
if X and Y both happen to be 1, then Z will take
the value of 2.
If X is 2 and Y is 1 our random variable will take the
value of 3.
And similarly if we have this outcome, in those outcomes
here, the random variable takes the value of 4.
And we can continue this way by marking, for each
particular outcome, the corresponding value of the
random variable of interest.
What we want to do now is to calculate the PMF of this
random variable.
What does it mean to calculate the PMF?
We need to find this value for all choices of z, that is for
all possible values in the range of our random variable.
The way we're going to do it is to consider each possible
value of z, one at a time, and for any particular value find
out what are the outcomes--
the elements of the sample space--
for which our random variable takes on the specific value,
and add the probabilities of those outcomes.
So to illustrate this process, let us calculate the value of
the PMF for z equal to 2.
This is by definition the probability that our random
variable takes the value of 2.
And this is an event that can only happen here.
It corresponds to only one element of the sample space,
which has probability 1 over 16.
We can continue the same way for other values of z.
So for example, the value of PMF at z equal to 3, this is
the probability that our random variable takes the
value of 3.
This is an event that can happen in two ways--
it corresponds to two outcomes--
and so it has probability 2 over 16.
Continuing similarly, the probability that our random
variable takes the value of 4 is equal to 3 over 16.
And we can continue this way and calculate the remaining
entries of our PMF.
After you are done, you end up with a table--
or rather a graph--
a plot that has this form.
And these are the values of the different probabilities
that we have computed.
And you can continue with the other values.
It's a reasonable guess that this was going to be 4 over
16, this is going to be 3 over 16, 2 over 16, and 1 over 16.
So we have completely determined the PMF of our
random variable.
We have given the form of the answers.
And it's always convenient to also provide a plot with the
answers that we have.
# 5. Exercise: PMF calculation


# 6. Exercise: Random variables versus numbers


[][I am so confused on this, please help]
question posted less than a minute ago by john_hhu2020
"Let X be a random variable that takes integer values, with PMF p_X(x). "
Here is my thinking,
this statement means the outcome of experiment is a int, saying a Bingo game, outcome is a int on the ball.
And X is a mapping function from our experiment with certain ball occurring event to the value on that ball.
So x is the possible ints on the balls, and since y is an int, so p_X(y) give us a certain probability.
Then p_X(x) is another function, mapping certain occurred values to its' probability of occurring in all balls.
Am I thinking it correctly? Please help me
This post is visible to everyone.
# 7. Bernoulli and indicator random variables

We now want to introduce some examples of random variables, and we will start with the simplest conceivable random variable--a random variable that takes the values of 0 or 1, with certain given probabilities. Such a random variable is called a Bernoulli random variable. And the distribution of this random variable is determined by this parameter p, which is a given number that lies in the interval between 0 and 1. Using PMF notation, we have the probability of 0 being equal to 1 minus p and the probability of taking the value 1 equal to p. If you wish to plot this particular PMF, the plot is rather simple. It consists of two bars, one at 0 and one at 1. This one has a height of p and this has a height of 1 minus p.
Bernoulli random variables show up whenever you're trying to model a situation where you run a trial. And that trial can result in two alternative outcomes, either success or failure, or heads versus tails, and so on. *Another situation where Bernoulli random variables show up is when we're making a connection between events and random variables*. Here's how this connection is made. We have our sample space, omega. And within that sample space, we have a certain event, A. And outside of the event A, of course, we have the complement of A. **Our random variable is defined so that it takes a value of 1, whenever the outcome of the experiment lies in A**. And it takes a value of 0 whenever the outcome of the experiment lies outside the event A, so that it lies in the complement. [][This random variable is called the indicator random variable of the event A]. It is equal to 1 if and only if event A occurs.
And the PMF of that random variable
can be found as follows.
This is PMF notation.
This is the equivalent probabilistic notation.
This is the probability that the random variable
takes a value 1.
Now the random variable takes the value of 1 if and only if
event A occurs.
And so what we have is that our random variable, the
indicator random variable, is a Bernoulli random variable
with a parameter p equal to the probability of the event
of interest.
Indicator random variables are very useful because they allow
us to translate a manipulation of events to a manipulation of
random variables.
And sometimes the algebra of working with random variable
is easier than working with events, as we will see in some
later examples.
# 8. Exercise: Indicator variables



# 9. Uniform random variables

In this segment and the next two, we will introduce a few
useful random variables that show up in many applications--
discrete uniform random variables, binomial random
variables, and geometric random variables So let's
start with a discrete uniform.
A discrete uniform random variable is one that has a PMF
of this form.
It takes values in a certain range, and each one of the
values in that range has the same probability.
To be more precise, a discrete uniform is completely
determined by two parameters that are two integers, a and
b, which are the beginning and the end of the range of that
random variable.
We're thinking of an experiment where we're going
to pick an integer at random among the values that are
between a and b with the end points a and b included.
And all of these values are equally likely.
To be more formal, our sample space is the set of integers
from a until b.
And the number of points that we have in our sample space is
b minus a plus 1 possible values.
What is the random variable that we're talking about?
If this is our sample space, the outcome of the experiment
is already a number.
And the numerical value of the random variable is just the
number that we happen to pick in that range.
So in this context, there isn't really a distinction
between the outcome of the experiment and the numerical
value of the random variable.
They are one in the same.
Now since each one of the values is equally likely, and
since we have so many possible values, this means that the
probability of any particular value is going to be 1 over b
minus a plus 1.
This is the choice for the probability that would make
all the probabilities in the PMF sum to one.
What does this random variable model in the real world?
It models a case where we have a range of possible values,
and we have complete ignorance, no reason to
believe that one value is more likely than the other.
As an example, suppose that you look at your digital
clock, and you look at the time.
And the time that it tells you is 11:52 and 26 seconds.
And suppose that you just look at the seconds.
The seconds reading is something that takes values in
the set from 0 to 59.
So there are 60 possible values.
And if you just choose to look at your clock at a completely
random time, there's no reason to expect that one reading
would be more likely than the other.
All readings should be equally likely, and each one of them
should have a probability of 1 over 60.
One final comment--
let us look at the special case where the beginning and
the endpoint of the range of possible values is the same,
which means that our random variable can only take one
value, namely that particular number a.
In that case, the random variable that we're dealing
with is really a constant.
It doesn't have any randomness.
It is a deterministic random variable that takes a
particular value of a with probability equal to 1.
It is not random in the common sense of the world, but
mathematically we can still consider it a random variable
that just happens to be the same no matter what the
outcome of the experiment is.
# 10. Binomial random variables


The next random variable that we will discuss is the
binomial random variable.
It is one that is already familiar
to us in most respects.
It is associated with the experiment of taking a coin
and tossing it n times independently.
And at each toss, there is a probability, p,
of obtaining heads.
So the experiment is completely specified in terms
of two parameters--
n, the number of tosses, and p, the probability of heads at
each one of the tosses.
We can represent this experiment by the usual
sequential tree diagram.
And the leaves of the tree are the possible outcomes of the
experiment.
So these are the elements of the sample space.
And a typical outcome is a particular sequence of heads
and tails that has length n.
In this diagram here, we took n to be equal to 3.
We can now define a random variable associated with this
experiment.
Our random variable that we denote by capital X is the
number of heads that are observed.
So for example, if the outcome happens to be this one--
tails, heads, heads-- we have 2 heads that are observed.
And the numerical value of our random variable is equal to 2.
In general, this random variable, a binomial random
variable, can be used to model any kind of situation in which
we have a fixed number of independent trials and
identical trials, and each trial can result in success or
failure, and we have a probability of success equal
to some given number, p.
The number of successes obtained in these trials is,
of course, random and it is modeled by a
binomial random variable.
We can now proceed and calculate the PMF of this
random variable.
Instead of calculating the whole PMF, let us look at just
one typical entry of the PMF.
Let's look at this entry, which, by definition, is the
probability that our random variable takes the value of 2.
Now, the random variable taking the numerical value of
2, this is an event that can happen in three possible ways
that we can identify in the sample space.
We can have 2 heads followed by a tail.
We can have heads, tails, heads.
Or we can have tails, heads, heads.
The probability of this outcome is p times p
times (1 minus p).
So it's p squared times (1 minus p).
And the other two outcomes also have the same
probability, so the overall probability is 3 times this.
Which can also be written this way, 3 is the same as
3-choose-2.
It's the number of ways that you can choose 2 heads, where
they will be placed in a sequence of
3 slots or 3 trials.
More generally, we have the familiar binomial formula.
So this is a formula that you have already seen.
It's the probability of obtaining k successes in a
sequence of n independent trials.
The only thing that is new is that instead of using the
traditional probability notation, now
we're using PMF notation.
To get a feel for the binomial PMF, it's instructive to look
at some plots.
So suppose that we toss the coin three times and that the
coin tosses are fair, so that the probability of heads is
equal to 1/2.
Then we see that 1 head or 2 heads are equally likely, and
they are more likely than the outcome of 0 or 3 heads.
Now, if we change the number of tosses and toss the coin 10
times, then we see that the most likely result
is to have 5 heads.
And then as we move away from 5 in either direction, the
probability of that particular result
becomes smaller and smaller.
Now, if we toss the coin many times, let's say 100 times,
the coin is still fair, then we see that the number of
heads that we're going to get is most likely to be somewhere
in this range between, let's say, 35 and 65.
These are values of the random variable that have some
noticeable or high probabilities.
But anything below 30 or anything about 70 is extremely
unlikely to occur.
We can generate similar plots for unfair coins.
So suppose now that our coin is biased and the probability
of heads is quite low, equal to 0.2.
In that case, the most likely result is that we're going to
see 0 heads.
And then, there's smaller and smaller probability of
obtaining more heads.
On the other hand, if we toss the coin 10 times, we expect
to see a few heads, not a very large number, but some number
of heads between, let's say, 0 and 4.
Finally, if we toss the coin 100 times and we take the coin
to be an extremely unfair one, what do we expect to see?
If we think of probabilities as frequencies, we expect to
see heads roughly 10% of the time.
So, given that n is 100, we expect to see about 10 heads.
But when we say about 10 heads, we do not
mean exactly 10 heads.
About 10 heads, in this instance, as this plot tells
us, is any number more or less in the range from 0 to 20.
But anything above 20 is extremely unlikely.
# 11. Exercise: The binomial PMF


# 12. Geometric random variables

The last discrete random variable that we will discuss
is the so-called geometric random variable.
It shows up in the context of the following experiment.
We have a coin and we toss it infinitely many times and
independently.
And at each coin toss we have a fixed probability of heads,
which is some given number, p.
This is a parameter that specifies the experiment.
When we say that the infinitely many tosses are
independent, what we mean in a mathematical and formal sense
is that any finite subset of those tosses are independent
of each other.
I'm only making this comment because we introduced a
definition of independence of finitely many events, but had
never defined the notion of independence or infinitely
many events.
The sample space for this experiment is the set of
infinite sequences of heads and tails.
So a typical outcome of this experiment
might look like this.
It's a sequence of heads and tails in some arbitrary order.
And of course, it's an infinite sequence, so it
continues forever.
But I'm only showing you here the
beginning of that sequence.
We're interested in the following random variable, X,
which is the number of tosses until the first heads.
So if our sequence looked like this, our random variable
would be taking a value of 5.
A random variable of this kind appears in many applications
and many real world contexts.
In general, it models situations where we're waiting
for something to happen.
Suppose that we keep doing trials at each time and the
trial can result either in success or failure.
And we're counting the number of trials it takes until a
success is observed for the first time.
Now, these trials could be experiments of some kind,
could be processes of some kind, or they could be whether
a customer shows up in a store in a particular second or not.
So there are many diverse interpretations of the words
trial and of the word success that would allow us to apply
this particular model to a given situation.
Now, let us move to the calculation of the PMF of this
random variable.
By definition, what we need to calculate is the probability
that the random variable takes on a
particular numerical value.
What does it mean for X to be equal to k?
What it means is that the first heads was observed in
the k-th trial, which means that the first k minus 1
trials were tails, and then were followed by heads in the
k-th trial.
This is an event that only concerns the first k trials,
and the probability of this event can be calculated using
the fact that different coin tosses or different trials are
independent.
It is the probability of tails in the first coin toss times
the probability of tails in the second coin toss, and so
on, k minus 1 times.
So we get an exponent here of k minus 1 times the
probability of heads in the k-th coin toss.
So this is the form of the PMF of this particular random
variable, and that formula applies for the possible
values of k, which are the positive integers.
Because the time of the first head can only
be a positive integer.
And any positive integer is possible, so our random
variable takes values in a discrete but infinite set.
The geometric PMF has a shape of this type.
Here we see the plot for the case where p equals to 1/3.
The probability that the first head shows up in the first
trial is equal to p, that's the probability of heads.
The probability that it shows up in the next trial, that the
first head appears in the second trial, this is the
probability that we had heads following a tail.
So we have the probability of a tail and then times the
probability of a head.
And then each time that we move to a further entry, we
multiply by a further factor of 1 minus p.
Finally, one little technical remark.
There's a possible and rather annoying outcome of this
experiment, which would be that we observe a sequence of
tails forever and no heads.
In that case, our random variable is not well-defined,
because there is no first heads to consider.
You might say that in this case our random variable takes
a value of infinity, but we would rather not have to deal
with random variables that could be infinite.
Fortunately, it turns out that this particular event has 0
probability of occurring, which I will now try to show.
So this is the event that we always see tails.
Let us compare it with the event where we see tails in
the first k trials.
How do these two events relate?
If we have always tails, then we will have tails in the
first k trials.
So this event implies that event.
This event is smaller than that event.
So the probability of this event is less than or equal to
the probability of that second event.
And the probability of that second event is 1
minus p to the k.
Now, this is true no matter what k we choose.
And by taking k arbitrarily large, this number here
becomes arbitrarily small.
Why does it become arbitrarily small?
Well, we're assuming that p is positive, so 1 minus p is a
number less than 1.
And when we multiply a number strictly less than 1 by itself
over and over, we get arbitrarily small numbers.
So the probability of never seeing a head is less than or
equal to an arbitrarily small positive number.
So the only possibility for this is that it is equal to 0.
So the probability of not ever seeing any heads is equal to
0, and this means that we can ignore
this particular outcome.
And as a side consequence of this, the sum of the
probabilities of the different possible values of k is going
to be equal to 1, because we're certain that the random
variable is going to take a finite value.
And so when we sum probabilities of all the
possible finite values, that sum will have
to be equal to 1.
And indeed, you can use the formula for the geometric
series to verify that, indeed, the sum of these numbers here,
when you add over all values of k, is, indeed, equal to 1.
# 13. Exercise: Geometric random variables



# 14. Expectation




Our discussion of random variable so far has involved nothing but standard probability calculations. Other than using the PMF notation, we have done nothing new. It is now time to introduce a truly new concept that plays a central role in probability theory. This is the concept of the expected value or expectation or mean of a random variable. It is a single number that provides some kind of summary of a random variable by telling us what it is on the average. Let us motivate with an example. You play a game of chance over and over, let us say 1,000 times. *Each time that you play, you win an amount of money, which is a random variable, and that random variable takes the value 1, with probability 2/10, the value of 2, with probability 5/10, the value of 4, with probability 3/10*. You can plot the PMF of this random variable. It takes values 1, 2, and 4. And the associated probabilities are 2/10, 5/10, and 3/10. [][How much do you expect to have at the end of the day]?
Well, if you interpret probabilities as frequencies, in a thousand plays, you expect to have about 200 times this outcome to occur and this outcome about 500 times and this outcome about 300 times. So your average gain is expected to be your total gain, which is 1, 200 times, plus 2, 500 times, plus 4, 300 times. This is your total gain. And to get to the average gain, you divide by 1,000. And the expression that you get can also be written in a simpler form as 1 times 2/10 plus 2 times 5/10 plus 4 times 3/10. So this is what you expect to get, on the average, if you keep playing that game.
What have we done? We have calculated a certain quantity which is a sort of average of the random variable of interest. And what we did in this summation here, we took each one of the possible values of the random variable. Each possible value corresponds to one term in the summation. And what we're adding is the numerical value of the random variable times the probability that this particular value is obtained. So when x is equal to 1, we get 1 here and then the probability of 1. When we add the term corresponding to x equals 2,
we get little x equals to 2 and next to it the probability
that x is equal to 2, and so on.
So this is what we call the expected value of the random
variable x.
This is the formula that defines it, but it's also
important to always keep in mind the interpretation of
that formula.
The expected value of a random variable is to be interpreted
as the average that you expect to see in a large number of
independent repetitions of the experiment.
One small technical caveat, if we're dealing with a random
variable that takes values in a discrete but infinite set,
this sum here is going to be an infinite sum
or an infinite series.
And there's always a question whether an infinite series has
a well-defined limit or not.
In order for it to have a well-defined limit, we will be
making the assumption that this infinite series is, as
it's called, absolutely convergent, namely that if we
replace the x's by their absolute values--
so we're adding positive numbers,
or nonnegative numbers--
the sum of those numbers is going to be finite.
So this is a technical condition that we need in
order to make sure that this expected value is a
well-defined and finite quantity.
Let us now calculate the expected value of a very
simple random variable, the Bernoulli random variable that
takes the value 1 with probability p and the value 0
with probability 1 minus p.
The expected value consists of two terms.
X can take the value 1.
This happens with probability p.
Or it can take the value of zero.
This happens with probability 1 minus p.
And therefore, the expected value is just equal to p.
As a special case, we may consider the situation where X
is the indicator random variable of a certain event,
A, so that X is equal to 1 if and only if event A occurs.
In this case, the probability that X equals to 1, which is
our parameter p, is the same as the probability
that event A occurs.
And we have this relation.
And so with this correspondence, we readily
conclude that the expected value of an indicator random
variable is equal to the probability of that event.
Let us move now to the calculation of the expected
value of a uniform random variable.
Let us consider, to keep things simple, a random
variable which is uniform on the set from 0 to n.
It's uniform, so the probability of the values that
it can take are all equal to each other.
It can take one of n plus 1 possible values, and so the
probability of each one of the values is 1 over n plus 1.
We want to calculate the expected value
of this random variable.
How do we proceed?
We just recall the definition of the expectation.
It's a sum where we add over all of the possible values.
And for each one of the values, we multiply by its
corresponding probability.
So we obtain a summation of this form.
We can factor out a factor of 1 over n plus 1, and we're
left with 0 plus 1 plus all the way up to n.
And perhaps you remember the formula for us summing those
numbers, and it is n times n plus 1 over 2.
And after doing the cancellations, we obtain a
final answer, which is n over 2.
Incidentally, notice that n over 2 is just the midpoint of
this picture that we have here in this diagram.
This is always the case.
Whenever we have a PMF which is symmetric around a certain
point, then the expected value will be
the center of symmetry.
More general, if you do not have symmetry, the expected
value turns out to be the center of gravity of the PMF.
If you think of these bars as having weight, where the
weight is proportional to their height, the center of
gravity is the point at which you should put your finger if
you want to balance that diagram so that it doesn't
fall in one direction or the other.
And we now close this segment by providing one more
interpretation of expectations.
Suppose that we have a class consisting of n students and
that the ith student has a weight which
is some number xi.
We have a probabilistic experiment where we pick one
of the students at random, and each student is equally likely
to be picked as any other student.
And we're interested in the random variable X, which is
the weight of the student that was selected.
To keep things simple, we will assume that the
xi's are all distinct.
And we first find the PMF of this random variable.
Any particular xi that this possible is associated to
exactly one student, because we assumed that
the xi's are distinct.
So this probability would be the probability or selecting
the ith student, and that probability is 1 over n.
And now we can proceed and calculate the expected value
of the random variable X. This random variable X takes
values, and the values that it takes are the xi's.
A particular xi would be associated with a probability
1 over n, and we're adding over all the i's or over all
of the students.
And so this is the expected value.
What we have here is just the average of the weights of the
students in this class.
So the expected value in this particular experiment can be
interpreted as the true average over the entire
population of the students.
Of course, here we're talking about two
different kinds of averages.
In some sense, we're thinking of expected values as the
average in a large number of repetitions of experiments.