-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path13-Solutions.Rmd
1570 lines (1517 loc) · 57.6 KB
/
13-Solutions.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
# Solutions to practice problems {#solutions}
```{r setup14, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
prompt = FALSE,
tidy = TRUE,
collapse = TRUE)
library("tidyverse")
EmpData <- read_csv("sampledata/EmploymentData.csv")
# Make permanent changes to EmpData
EmpData <- EmpData %>%
mutate(MonthYr = as.Date(MonthYr, "%m/%d/%Y")) %>%
mutate(UnempPct = 100*UnempRate) %>%
mutate(LFPPct = 100*LFPRate)
```
This appendix provides solutions to all end-of-chapter practice problems.
## **2** Basic data cleaning with Excel {-#answers-basic-data-cleaning-with-excel}
[Click here to see the problems](#problems-basic-data-cleaning-with-excel)
1. Table (b) shows a tidy data set.
2. Master, working, and archive versions have the following features:
a. The master version represents the project at its most recent completed
stage. There should be only one, and it should not be edited directly.
b. A working copy represents current work in progress. There should be one,
and it can be edited directly.
c. An archive copy represents an earlier master version or working copy that
you are keeping for future reference. There can be many, and they should
not be edited directly.
3. Characteristic (a) is necessary for a variable to function as an ID variable.
4. The relevant tools are:
a. Fill (copy/paste is also OK here).
b. Copy/paste (fill only works on adjacent cells).
c. Series.
d. Insert.
5. The formulas are:
a. `=SQRT(A2)`
b. `=MIN(A2:A100)`
c. `=ABS(A2-B2)`
6. Cell E15 is 2 columns and 3 rows away from cell C12. So we change all
relative references from column B to column D, and all relative references
from row 2 to row 5, and all relative references from row 10 to row 13.
Absolute references are not changed.
a. `=D5`
b. `=$B$2`
c. `=$B5`
d. `=D$2`
e. `=SUM(D5:D13)`
f. `=SUM($B$2:$B$10)`
g. `=SUM($B5,$B13)`
h. `=SUM(D$2,D$10)`
7. The formulas are:
a. `=IF(A2<0.05,"Reject","Fail to reject")`
b. `=CONCAT("A2 = ",A2)`
c. `=LEFT(A2,2)`
8. The formulas are:
a. `=MONTH(TODAY())`
b. `=TODAY()+100`
c. `=TODAY()-DATE(1969,11,20)` - using my birthday; yours will obviously be
different.
9. If you ran into trouble doing this, review the section on
[saving and exporting data](saving-and-exporting-data).
a. Note that there are actually multiple options for exporting CSV files,
including "CSV UTF-8", "CSV (comma delimited)", "CSV (Macintosh)" and
"CSV (MS-DOS)". These all have tiny differences in how the data is
stored, but any of them will work for our purposes.
b. Note that it is important to close Excel here. Saving the worksheet as a
CSV file involves the loss of information, but Excel will hold onto that
information until you close the file.
c. Note that Excel usually makes itself the default application for CSV
files, so you can open them in Excel directly or by double-clicking on
them.
d. The worksheets differ in many ways:
- The *Raw data* worksheet is not in the CSV file.
- The formatting (e.g. the boldface in the top row) is gone.
- Columns E, F, G, and H contain values rather than formulas.
## **3** Probability and random events {-#answers-probability}
[Click here to see the problems](#problems-probability)
1. The sample space is the set of all possible outcomes for $(r,w)$, and its
cardinality is just the number of elements it has.
a. The sample space is:
\begin{align}
\Omega &= \left\{ \begin{aligned}
& (1,1),(1,2),(1,3),(1,4),(1,5),(1,6), \\
& (2,1),(2,2),(2,3),(2,4),(2,5),(2,6), \\
& (3,1),(3,2),(3,3),(3,4),(3,5),(3,6), \\
& (4,1),(4,2),(4,3),(4,4),(4,5),(4,6), \\
& (5,1),(5,2),(5,3),(5,4),(5,5),(5,6), \\
& (6,1),(6,2),(6,3),(6,4),(6,5),(6,6) \\
\end{aligned}
\right\}
\end{align}
b. Counting up the number of elements in the set, we get $|\Omega| = 36$.
2. Each event is just a set listing the $(r,w)$ outcomes that satisfy the
relevant conditions.
a. Yo wins whenever $r+w = 11$.
\begin{align}
YoWins &= \{(5,6),(6,5)\}
\end{align}
b. Snake eyes wins when $r+w = 2$:
\begin{align}
SnakeEyesWins = \{(1,1)\}
\end{align}
c. Boxcars wins when $r+w = 12$:
\begin{align}
BoxcarsWins = \{(6,6)\}
\end{align}
d. Field wins when $r+w \in \{2,3,4,9,10,11,12\}$:
\begin{align}
FieldWins &= \left\{\begin{aligned}
& (1,1),(1,2),(1,3), \\
& (2,1),(2,2), \\
& (3,1),(3,6), \\
& (4,5),(4,6), \\
& (5,4),(5,5),(5,6), \\
& (6,3),(6,4),(6,5),(6,6) \\
\end{aligned}\right\}
\end{align}
3. Statements (b) and (c) are true.
4. Statements (a) and (d) are true.
5. Statements (b) and (c) are true.
6. Event (c) is an elementary event.
7. Statements (a), (c), (e), (g), and (i) are true.
8. Statements (b) and (c) are true.
9. Statements (a), (d), (e), (f), and (h) are true.
10. Statements (a) and (b) are true.
11. All three elementary events have probability $1/36 \approx 0.028$
12. The probability of each event can be calculated by adding up the
probabilities of its elementary events.
a. The probability a bet on Yo wins is:
\begin{align}
\Pr(YoWins) &= \Pr(\{(5,6),(6,5)\}) \\
&= \Pr(\{(5,6)\}) + \Pr(\{(6,5)\}) \\
&= 2/36 \\
&\approx 0.056
\end{align}
b. The probability a bet on Snake eyes wins is:
\begin{align}
\Pr(SnakeEyesWins) &= \Pr(\{(1,1)\}) \\
&= 1/36 \\
&\approx 0.028
\end{align}
c. The probability a bet on Boxcars wins is:
\begin{align}
\Pr(BoxcarsWins) &= \Pr(\{(6,6)\}) \\
&= 1/36 \\
&\approx 0.028
\end{align}
d. The probability a bet on Field wins is:
\begin{align}
\Pr(FieldWins) &= \Pr\left(\left\{\begin{aligned}
& (1,1),(1,2),(1,3), \\
& (2,1),(2,2), \\
& (3,1),(3,6), \\
& (4,5),(4,6), \\
& (5,4),(5,5),(5,6), \\
& (6,3),(6,4),(6,5),(6,6) \\
\end{aligned}\right\}\right) \\
&= \Pr(\{(1,1)\}) + \Pr(\{(1,2)\}) + \cdots + \Pr(\{(6,6)\}) \\
&= 16/36 \\
&\approx 0.444
\end{align}
13. To calculate the joint probability, start by calculating the intersection
of the two events:
a. The joint probability is:
\begin{align}
\Pr(YoWins \cap BoxcarsWins)
&= \Pr(\{(5,6),(6,5)\} \cap \{(6,6)\}) \\
&= \Pr(\emptyset) \\
&= 0
\end{align}
b. The joint probability is:
\begin{align}
\Pr(YoWins \cap FieldWins)
&= \Pr\left(\{(5,6),(6,5)\} \cap \left\{\begin{aligned}
& (1,1),(1,2),(1,3), \\
& (2,1),(2,2), \\
& (3,1),(3,6), \\
& (4,5),(4,6), \\
& (5,4),(5,5),(5,6), \\
& (6,3),(6,4),(6,5),(6,6) \\
\end{aligned}\right\}\right) \\
&= \Pr(\{(5,6),(6,5)\}) \\
&= 2/36 \\
&\approx 0.056
\end{align}
c. The joint probability is:
\begin{align}
\Pr(YoWins \cap BoxcarsWins^C)
&= \Pr(\{(5,6),(6,5)\} \cap \{(6,6)\}^C) \\
&= \Pr(\{(5,6),(6,5)\}) \\
&= 2/36 \\
&\approx 0.056
\end{align}
14. The conditional probability is just the ratio of the joint probability to
the probability of the event we are conditioning on:
a. The conditional probability is:
\begin{align}
\Pr(YoWins | BoxcarsWins)
&= \frac{Pr(YoWins \cap BoxcarsWins)}{\Pr(BoxcarsWins)} \\
&= \frac{0}{1/36} \\
&= 0
\end{align}
b. The conditional probability is:
\begin{align}
\Pr(YoWins | FieldWins)
&= \frac{Pr(YoWins \cap FieldWins)}{\Pr(FieldWins)} \\
&= \frac{2/36}{16/36} \\
&= 0.125
\end{align}
c. The conditional probability is:
\begin{align}
\Pr(YoWins | BoxcarsWins^C)
&= \frac{Pr(YoWins \cap BoxcarsWins^C)}{\Pr(BoxcarsWins^C)} \\
&= \frac{2/36}{1-1/36} \\
&\approx 0.057
\end{align}
d. The conditional probability is:
\begin{align}
\Pr(FieldWins | YoWins)
&= \frac{Pr(FieldWins \cap YoWins)}{\Pr(YoWins)} \\
&= \frac{2/36}{2/36} \\
&= 1
\end{align}
e. The conditional probability is:
\begin{align}
\Pr(BoxcarsWins | YoWins)
&= \frac{Pr(BoxcarsWins \cap Yo)}{\Pr(Yo)} \\
&= \frac{0}{2/36} \\
&= 0
\end{align}
15. The events in (e) are independent.
16. Statements (b) and (c) are true.
17. The probability that Pass wins is:
\begin{align*}
\Pr(PassWins) &= \Pr(PassWins|c = 2)\Pr(c = 2) + \cdots + \Pr(PassWins|c = 12)\Pr(c = 12) \nonumber \\
&= \begin{aligned}[t]
& (0 \times 1/36) + (0 \times 2/36) + (3/9 \times 3/36) \\
& + (4/10 \times 4/36) + (5/11 \times 5/36) + (1 \times 6/36) \\
& + (5/11 \times 5/36) + (4/10 \times 4/36) + (3/9 \times 3/36) \\
& + (1 \times 2/36) + (0 \times 1/36) \\
\end{aligned} \\
&= 244/495 \\
&\approx 0.4929
\end{align*}
Notice that this is less than 50\% (the house always has an advantage) but
it is greater than the probability of winning a bet on red or black in
roulette, which we earlier calculated to be about 0.486. Craps is typically
the most favorable casino game to players (lowest house advantage), if you
play Pass.
18. The conditional return probabilities are:
\begin{align*}
\Pr(Return|BodyHit) &= \frac{\Pr(BodyHit|Return)\Pr(Return)}{\Pr(BodyHit)} \\
&= \frac{0.7 \times 0.8}{0.6} \\
&\approx 0.93 \\
\Pr(Return|EngineHit) &= \frac{\Pr(EngineHit|Return)\Pr(Return)}{\Pr(EngineHit)} \\
&= \frac{0.1 \times 0.8}{0.6} \\
&\approx 0.13
\end{align*}
## **4** Introduction to random variables {-#answers-random-variables}
[Click here to see the problems](#problems-random-variables)
1. We can define $t = r+w$.
2. We can define $y = I(r+w = 11)$.
3. The support of a random variable is the set of all values with positive
probability.
a. The support of $r$ is $S_r = \{1,2,3,4,5,6\}$.
b. The support of $t$ is $S_t = \{2,3,4,5,6,7,8,9,10,11,12\}$.
c. The support of $y$ is $S_y = \{0,1\}$.
4. The range of a random variable is just the interval defined by the support's
minimum and maximum values.
a. The range of $r$ is $[1,6]$.
b. The range of $t$ is $[2,12]$.
c. The range of $y$ is $[0,1]$.
5. The PDF can be derived from the probability distribution of the underlying
outcome $(r,w)$, which was calculated in the previous chapter.
a. The PDF of $r$ is:
\begin{align}
f_r(a) &= \begin{cases}
1/6 & a \in \{1,2,3,4,5,6\} \\
0 & \textrm{otherwise} \\
\end{cases}
\end{align}
b. The PDF of $t$ is:
\begin{align}
f_t(a) &= \begin{cases}
1/36 & a \in \{2,12\} \\
2/36 \textrm{ (or $1/18$)} & a \in \{3,11\} \\
3/36 \textrm{ (or $1/12$)} & a \in \{4,10\} \\
4/36 \textrm{ (or $1/9$)} & a \in \{5,9\} \\
5/36 & a \in \{6,8\} \\
6/36 \textrm{ (or $1/6$)} & a = 7 \\
0 & \textrm{otherwise} \\
\end{cases}
\end{align}
c. The PDF of $y$ is:
\begin{align}
f_y(a) &= \begin{cases}
17/18 & a = 0 \\
1/18 & a = 1 \\
0 & \textrm{otherwise} \\
\end{cases}
\end{align}
6. We can construct the CDF by cumulatively summing up the PDF:
a. The CDF of $r$ is:
\begin{align}
F_r(a) &= \begin{cases}
0 & a < 1 \\
1/6 & 1 \leq a < 2 \\
1/3 & 2 \leq a < 3 \\
1/2 & 3 \leq a < 4 \\
2/3 & 4 \leq a < 5 \\
5/6 & 5 \leq a < 6 \\
1 & a \geq 6 \\
\end{cases}
\end{align}
b. The CDF of $y$ is:
\begin{align}
F_y(a) &= \begin{cases}
0 & a < 0 \\
17/18 & 0 \leq a < 1 \\
1 & a \geq 1 \\
\end{cases}
\end{align}
7. The interval probabilities are:
a. $\Pr(x \leq 5) = F_x(5) = 0.8$
b. $\Pr(x < 5) = F_x(5) - f_x(5) = 0.7$
c. $\Pr(x > 5) = 1 - F_x(5) = 0.2$
d. $\Pr(x \geq 5) 1 - F_x(5) + f_x(5) = 0.3$
e. $\Pr(0 < x \leq 5) = F_x(5) - F_x(0) = 0.5$
f. $\Pr(0 \leq x \leq 5) = F_x(5) - F_x(0) + f_x(0) = 0.6$
g. $\Pr(0 < x < 5) = F_x(5) - F_x(0) - f_x(5) = 0.4$
h. $\Pr(0 \leq x < 5) = F_x(5) - F_x(0) + f_x(0) - f_x(5) = 0.5$
8. We find the expected value by applying the definition:
a. The expected value is
\begin{align}
E(r) &= \sum_{a \in S_r} a\Pr(r=a) \\
&= 1*\frac{1}{6} + 2*\frac{1}{6} + 3*\frac{1}{6} + 4*\frac{1}{6} + 5*\frac{1}{6} + 6*\frac{1}{6} \\
&= 21/6 \\
&= 3.5
\end{align}
b. The expected value is
\begin{align}
E(r^2) &= \sum_{a \in S_r} a^2\Pr(r=a) \\
&= 1^2*\frac{1}{6} + 2^2*\frac{1}{6} + 3^2*\frac{1}{6} + 4^2*\frac{1}{6} + 5^2*\frac{1}{6} + 6^2*\frac{1}{6} \\
&= 91/6 \\
&= 15.17
\end{align}
9. The key here is to write down the definition of the specific quantile you are
looking for, then substitute the CDF you derived earlier.
a. The median of $r$ is:
\begin{align}
F_r^{-1}(0.5) &= \min \{a: \Pr(r \leq a) \geq 0.5\} \\
&= \min \{a: F_r(a) \geq 0.5\} \\
&= \min \{a: a \geq 3\} \\
&= 3
\end{align}
b. The 0.25 quantile of $r$ is
\begin{align}
F_r^{-1}(0.25) &= \min \{a: \Pr(r \leq a) \geq 0.25\} \\
&= \min \{a: F_r(a) \geq 0.25\} \\
&= \min \{a: a \geq 2\} \\
&= 2
\end{align}
c. The 75th percentile of $r$ is just its 0.75 quantile:
\begin{align}
F_r^{-1}(0.75) &= \min \{a: \Pr(r \leq a) \geq 0.75\} \\
&= \min \{a: F_r(a) \geq 0.75\} \\
&= \min \{a: a \geq 5\} \\
&= 5
\end{align}
10. Let $d = (y - E(y))^2$.
a. We can derive the PDF of $d$ from the PDF of $y$:
\begin{align}
f_{d}(a) &= \begin{cases}
17/18 & a = (0-1/18)^2 \\
1/18 & a = (1-1/18)^2 \\
0 & \textrm{otherwise} \\
\end{cases}
\end{align}
b. The expected value is:
\begin{align}
E(d) &= (0-1/18)^2 * \frac{17}{18} + (1-1/18)^2 *\frac{1}{18} \\
&\approx 0.0525
\end{align}
c. The variance is:
\begin{align}
var(y) &= E(d) \\
&\approx 0.0525
\end{align}
11. Earlier, you found $E(r) = 3.5$ and $E(r^2) = 15.17$. So we can apply
our result that $var(x) = E(x^2) - E(x)^2$ for a simpler way of calculating
the variance:
\begin{align}
var(r) &= E(r^2) - E(r)^2 \\
&= 15.17 - 3.5^2 \\
&= 2.92
\end{align}
12. The standard deviation is just the square root of the variance.
a. The standard deviation is:
\begin{align}
sd(y) = \sqrt{var(y)} \approx \sqrt{0.0525} \approx 0.229
\end{align}
b. The standard deviation is:
\begin{align}
sd(r) &= \sqrt{var(r)} = \sqrt{2.92} \approx 1.71
\end{align}
13. The key here is to apply the formulas for the expected value and variance
of a linear function of a random variable.
a. The expected value is:
\begin{align}
E(W) &= E(160*y - 10) \\
&= 160*E(y) - 10 \\
&= 160*1/18 - 10 \\
&\approx -1.11
\end{align}
b. The variance is:
\begin{align}
var(W) &= var(160*y - 10) \\
&= 160^2*var(y) \\
&= 160^2*1/18*17/18 \\
&\approx 1343.2
\end{align}
c. The event probability is
\begin{align}
\Pr(W > 0) &= \Pr(y=1) = 1/18 \approx 0.056
\end{align}
14. Applying the formulas for a linear function:
a. The expected value is:
\begin{align}
E(W_{10}) &= E(16*Y_{10} - 10) \\
&= 16*E(Y_{10}) - 10 \\
&= 16*10*1/18 - 10 \\
&\approx -1.11
\end{align}
b. The variance is:
\begin{align}
var(W_{10}) &= var(16*Y_{10} - 10) \\
&= 16^2var(Y_10) \\
&= 16^2 * 10*1/18*17/18 \\
&\approx 134.32
\end{align}
c. The event probability is
\begin{align}
\Pr(W_{10} > 0) &= \Pr(Y_{10} > 10/16) \approx 0.435
\end{align}
15. The standardized form is constructed by subtracting the mean and dividing
by the standard deviation.
a. Since $E(y) = 1/18 \approx 0.056$ and $sd(y) \approx 0.229$, the
standardized variable will be:
\begin{equation}
z = \frac{y - E(y)}{sd(y)} = \frac{y - 0.056}{0.229}
\end{equation}
b. The support of $y$ is $S_y = \{0,1\}$, so the support of $z$ is:
\begin{align}
S_z &= \left\{\frac{0 - 0.056}{0.229}, \frac{1 - 0.056}{0.229} \right\} \\
&= \{-0.245, 4.122\}
\end{align}
c. The PDF of $z$ is:
\begin{align}
f_z(a) &= \begin{cases}
17/18 & a = -0.245 \\
1/18 & a = 4.122 \\
0 & \textrm{otherwise} \\
\end{cases}
\end{align}
16. The Bernoulli distribution describes any random variable (like $y$) that
has a binary $\{0,1\}$ support.
a. $y$ has the $Bernouili(p)$ distribution with $p=1/18$, or
\begin{align}
y \sim Bernoulli(1/18)
\end{align}
b. In the Bernoulli distribution $E(y)=p =1/18$.
c. In the Bernoulli distribution, $var(y) = p*(1-p) = 1/18 * 17/18 \approx 0.525$.
17. The binomial distribution describes any random variable that describes the
number of times an event happens in a fixed number of independent trials.
a. $Y_{10}$ has the binomial distribution with $n=10$ and $p=1/18$. We can
also write that as:
\begin{align}
Y_{10} \sim Binomial(10,1/18)
\end{align}
b. For the Binomial distribution we have:
\begin{align}
E(Y_{10}) = np = 10*1/18 \approx 0.556
\end{align}
c. For the binomial distribution we have:
\begin{align}
var(Y_{10}) = np(1-p) = 10*1/18*17/18 \approx 0.525
\end{align}
d. The Excel formula for $\Pr(Y_{10} = 0)$ would be
`=BINOM.DIST(0,10,1/18,FALSE)` which produces the result
\begin{align}
\Pr(Y_{10} = 0) \approx 0.565
\end{align}
e. The Excel formula for $\Pr(Y_{10} \leq 10/16)$ would be
`=BINOM.DIST(10/16,10,1/18,TRUE)` which produces the result:
\begin{align}
\Pr(Y_{10} \leq 10/16) \approx 0.565
\end{align}
f. The Excel formula for $\Pr(Y_{10} > 10/16)$ would be
`=1-BINOM.DIST(10/16,10,1/18,TRUE)` which produces the result:
\begin{align}
\Pr(Y_{10} > 10/16) \approx 0.435
\end{align}
## **5** Basic data analysis with Excel {-#answers-basic-data-analysis}
[Click here to see the problems](#problems-basic-data-analysis)
1. The table should look like this:

2. The answers are:
a. Sample size is 3
b. Sample average of age is 45.
c. Sample median of age is 32.
d. Sample variance of age is 829.
e. Sample standard deviation of age is 28.8.
3. The numerical answers and Excel formulas (assuming the table starts in cell
A1) are:
a. 3 `=COUNT(B2:B4)`
b. 45 `=AVERAGE(B2:B4)`
c. 32 `=MEDIAN(B2:B4)`
d. 28.5 `=PERCENTILE.INC(B2:B4,0.25)`
e. 829 `=VAR.S(B2:B4)`
f. 28.8 `=STDEV.S(B2:B4)`
4. The binned frequency table should look something like this:
| Range | Frequency | % Freq |
|:------|:---------:|:------:|
| 0-10 | 0 | 0 |
| 11-20 | 0 | 0 |
| 21-30 | 1 | 33 |
| 31-40 | 1 | 33 |
| 41-50 | 0 | 0 |
| 51-60 | 0 | 0 |
| 61-70 | 0 | 0 |
| 71-80 | 1 | 33 |
5. The time series graph should look something like this:

6. The histogram should look something like this:

## **6** More on random variables {-#answers-more-on-random-variables}
[Click here to see the problems](#problems-more-on-random-variables)
1. Based on these figures:
a. $x$ is continuous.
b. The top graph shows the PDF and the bottom graph shows the CDF.
c. The median of $x$ is about 3.
d. $x$ is more likely to be between 0 and 10.
2. This question uses various formulas for the uniform distribution.
a. The PDF is:
\begin{align}
f_x(a) &= \begin{cases}
0 & a < -1 \\
0.5 & -1 \leq a \leq 1 \\
0 & a > 1 \\
\end{cases}
\end{align}
b. The CDF is:
\begin{align}
f_x(a) &= \begin{cases}
0 & a < -1 \\
\frac{a+1}{2} & -1 \leq a \leq 1 \\
1 & a > 1 \\
\end{cases}
\end{align}
c. $x$ is a continuous random variable so $\Pr(x = 0) = 0$
d. $x$ is a continuous random variable so:
\begin{align}
\Pr(0 < x < 0.5) &= F_x(0.5) - F_x(0) \\
&= \frac{0.5+1}{2} - \frac{1}{2} \\
&= 0.25
\end{align}
e. $x$ is a continuous random variable so:
\begin{align}
\Pr(0 \leq x \leq 0.5) &= F_x(0.5) - F_x(0) \\
&= \frac{0.5+1}{2} - \frac{1}{2} \\
&= 0.25
\end{align}
f. The median is:
\begin{align}
F_x^{-1}(0.5) &= \min \{a: \Pr(x \leq a) \geq 0.5\} \\
&= \min \{a: F_x(a) \geq 0.5\} \\
&= \min \{a: \frac{a+1}{2} \geq 0.5\} \\
&= \textrm{the $a$ that solves the equation $\frac{a+1}{2} = 0.5$} \\
&= 0
\end{align}
g. The 75th percentile is
\begin{align}
F_x^{-1}(0.75) &= \min \{a: \Pr(x \leq a) \geq 0.75\} \\
&= \min \{a: F_x(a) \geq 0.75\} \\
&= \min \{a: \frac{a+1}{2} \geq 0.75\} \\
&= \textrm{the $a$ that solves the equation $\frac{a+1}{2} = 0.75$} \\
&= 0.5
\end{align}
h. The mean of a $Uniform(a,b)$ random variable is $(a+b)/2$, so
\begin{align}
E(x) &= \frac{1 + (-1)}{2} \\
&= 0
\end{align}
i. The variance of a $Uniform(a,b)$ random variable is $(b-a)^2/12$, so
\begin{align}
var(x) &= (b-a)^2/12 \\
&= \frac{(1 - (-1))^2}{12} \\
&\approx 0.33
\end{align}
3. A linear function of a uniform random variable is also uniform.
a. When $x = -1$, we have $y = 3*(-1)+5 = 2$. When $x = 1$, we have
$y = 3*(1)+5 = 8$. Therefore $y \sim U(2,8)$
b. The expected value is $E(y) = (2+8)/2 = 5$.
4. This question applies various formulas for the normal distribution.
a. The expected value of a $N(\mu,\sigma^2)$ random variable is $\mu$,
so $E(x) = 10$
b. The median of a $N(\mu,\sigma^2)$ random variable is $\mu$,
so $Median(x) = 10$.
c. The variance of a $N(\mu,\sigma^2)$ random variable is $\sigma^2$,
so $var(x) = 4$.
d. The standard deviation is $sd(x) = \sqrt{var(x)} = \sqrt{4} = 2$
b. The Excel formula would be `=NORM.DIST(11,10,2,TRUE)` which
yields the result $\Pr(x \leq 11) \approx 0.691$
5. A linear function of a normal random variable is also normal.
a. The distribution of $y$ will be normal with mean $3E(x) + 5 = 35$ and
variance $3^2 var(x) = 36$, so $y \sim N(35,36)$
b. If $x \sim N(10,4)$ then $z = \frac{x - 10}{2} \sim N(0,1)$.
c. Solving for $x$ in terms of $z$ we get $x = 2z + 10$
\begin{align}
\Pr(x \leq 11) &= \Pr(2z + 10 \leq 11) \\
&= \Pr(z \leq (11-10)/2) \\
&= \Pr(z \leq 0.5) \\
&= \Phi(0.5)
\end{align}
d. The correct Excel formula would be `=NORM.S.DIST(0.5,TRUE)` which
yields the result $\Pr(x \leq 11) \approx 0.691$.
6. The key here is to redefine joint events for $y$ and $b$ as events for the
single random variable $t$.
a. The joint PDF is:
\begin{align}
f_{y,b}(1,1) &= \Pr(y = 1 \cap b = 1) \\
&= \Pr(t = 11 \cap t = 12) \\
&= \Pr(\emptyset) \\
&= 0
\end{align}
b. The joint PDF is:
\begin{align}
f_{y,b}(0,1) &= \Pr(y \neq 1 \cap b = 1) \\
&= \Pr(t \neq 11 \cap t = 12) \\
&= \Pr(t = 12) \\
&= f_t(12) \\
&= 1/36 \\
&\approx 0.028
\end{align}
c. The joint PDF is:
\begin{align}
f_{y,b}(1,0) &= \Pr(y = 1 \cap b = 0) \\
&= \Pr(t = 11 \cap t \neq 12) \\
&= \Pr(t = 11) \\
&= f_t(11) \\
&= 1/18 \\
&\approx 0.056
\end{align}
d. The joint PDF is:
\begin{align}
f_{y,b}(0,0) &= \Pr(y = 0 \cap b = 0) \\
&= \Pr(t \neq 11 \cap t \neq 12) \\
&= \Pr(t \notin \{11,12\}) \\
&= 1 - \Pr(t \in \{11,12\}) \\
&= 1 - 1/36 - 1/18 \\
&= 11/12 \\
&\approx 0.917
\end{align}
7. The marginal PDF is constructed by adding together the joint PDFs.
a. The marginal PDF is:
\begin{align}
f_b(0) &= f_{y,b}(0,0) + f_{y,b}(1,0) \\
&= 11/12 + 1/18 \\
&= 35/36 \\
&\approx 0.972
\end{align}
b. The marginal PDF is:
\begin{align}
f_b(1) &= f_{y,b}(0,1) + f_{y,b}(1,1) \\
&= 1/36 + 0 \\
&= 1/36 \\
&\approx 0.028
\end{align}
c. The expected value is:
\begin{align}
E(b) &= 0*f_b(0) + 1*f_b(1) \\
&= f_b(1) \\
&= 1/36 \\
&\approx 0.028
\end{align}
8. The conditional PDF is the ratio of the joint PDF to the marginal PDF:
a. The conditional PDF is:
\begin{align}
f_{y|b}(1,1) &= \Pr(y=1|b=1) \\
&= \frac{f_{y,b}(1,1)}{f_b(1)} \\
&= \frac{0}{1/36} \\
&= 0
\end{align}
b. The conditional PDF is:
\begin{align}
f_{y|b}(0,1) &= \Pr(y=0|b=1) \\
&= \frac{f_{y,b}(0,1)}{f_b(1)} \\
&= \frac{1/36}{1/36} \\
&= 1
\end{align}
c. The conditional PDF is:
\begin{align}
f_{y|b}(1,0) &= \Pr(y=1|b=0) \\
&= \frac{f_{y,b}(1,0)}{f_b(0)} \\
&= \frac{1/18}{35/36} \\
&\approx 0.057
\end{align}
d. The conditional PDF is:
\begin{align}
f_{y|b}(0,0) &= \Pr(y=0|b=0) \\
&= \frac{f_{y,b}(0,0)}{f_b(0)} \\
&= \frac{11/12}{35/36} \\
&\approx 0.943
\end{align}
9. Based on your previous calculations:
a. The probability you and Betty both win is $f_{y,b}(1,1) = 0$.
b. The probability you and Betty both lose is $f_{y,b}(0,0) \approx 0.917$.
c. The probability Betty wins is $f_b(1) \approx 0.028$.
d. The probability that you win when Betty loses is $f_{y|b}(1,0) \approx 0.057$.
10. $r$ and $w$ (item c) are independent.
11. Since $E(y) = 1/18$ and $E(b) = 1/36$ we have
\begin{align}
cov(y,b) &= E((y-E(y))(b-E(b))) \\
&= \begin{aligned}[t]
& (0-E(y))*(0-E(b))*f_{y,b}(0,0) \\
&+ (1-E(y))*(0-E(b))*f_{y,b}(1,0) \\
&+ (0-E(y))*(1-E(b))*f_{y,b}(0,1) \\
&+ (1-E(y))*(1-E(b))*f_{y,b}(1,1) \\
\end{aligned} \\
&= \begin{aligned}[t]
& (0-1/18)*(0-1/36)*(11/12) \\
&+ (1-1/18)*(0-1/36)*(1/18) \\
&+ (0-1/18)*(1-1/36)*(1/36) \\
&+ (1-1/18)*(1-1/36)*(0) \\
\end{aligned} \\
&\approx -0.00154
\end{align}
12. The alternate formula for the covariance is $cov(y,b) = E(yb) - E(y)E(b)$.
a. The expected value is:
\begin{align}
E(yb) &= \begin{aligned}
& 0*0*f_{y,b}(0,0) \\
&+ 1*0*f_{y,b}(1,0) \\
&+ 0*1*f_{y,b}(0,1) \\
&+ 1*1*f_{y,b}(1,1) \\
\end{aligned} \\
&= f_{y,b}(1,1) \\
&= 0
\end{align}
b. The covariance is:
\begin{align}
cov(y,b) &= E(yb) - E(y)E(b) \\
&= 0 - (1/18)*(1/36) \\
&\approx -0.00154
\end{align}
c. Yes, if you have done it right you should get the same answer.
13. The correlation is:
\begin{align}
corr(y,b) &= \frac{cov(y,b)}{\sqrt{var(y)var(b)}} \\
&\approx \frac{-0.00154}{\sqrt{ 0.0525*0.027}} \\
&\approx -0.04
\end{align}
14. In this question we know the correlation and several values of the formula
defining it, and we use this to solve for the missing value.
a. We know that $corr(b,t) = \frac{cov(b,t)}{\sqrt{var(b)var(t)}}$, so
we can substitute known values to get:
\begin{align}
0.35 &= \frac{cov(b,t)}{\sqrt{0.027*5.83}}
\end{align}
Solving for $cov(b,t)$ we get
\begin{align}
cov(b,t) &= 0.35*\sqrt{0.027*5.83} \\
&= 0.139
\end{align}
b. We know that $cov(b,t) = E(bt) - E(b)E(t)$, so we can substitute
known values to get:
\begin{align}
0.139 &= E(bt) - (1/36)*7
\end{align}
Solving for $E(bt)$ we get:
\begin{align}
E(bt) &= 0.139 + (1/36)*7 \\
&= 0.333
\end{align}
15. Remember that independent events are also uncorrelated. So:
a. The covariance is $cov(r,w) = 0$.
b. The correlation is $corr(r,w) = 0$.
16. This question uses the formulas for the mean of a linear function of two
random variables.
a. The expected value is:
\begin{align}
E(y+b) &= E(y) + E(b) \\
&= 1/18 + 1/36 \\
&= 3/36 \\
&= 1/12
\end{align}
b. The expected value is:
\begin{align}
E(16y + 31b - 2) &= 16 E(y) + 31 E(b) - 2 \\
&= 16/18 + 31/36 - 2 \\
&= -9/36
\end{align}
17. This question uses the formulas for the variance and covariance of a linear
function of two random variables.
a. The covariance is:
\begin{align}
cov(16y,31b) &= 16 * 31 * cov(y,b) \\
&\approx 16 * 31 * (-0.00154) \\
&\approx -0.7638
\end{align}
b. The variance is:
\begin{align}
var(y+b) &= var(y) + var(b) + 2 cov(y,b) \\
&\approx 0.0525 + 0.027 + 2*(-0.00154) \\
&\approx 0.07642
\end{align}
18. Statement (b) is correct: the result of a bet on Boxcars is *negatively*
related to the result of a bet on Yo.
## **7** Statistics {-#answers-statistics}
[Click here to see the problems](#problems-statistics)
1. Since we have a random sample, the joint PDF is just a product of the
marginal PDFs.
a. The support is just the set of all possible combinations:
\begin{align}
S_{D_n} = \{(1,1),(1,2),(2,1),(2,2)\}
\end{align}
b. Since we have a random sample, the joint PDF is the product of the
marginal PDFs:
\begin{align}
f_{D_n}(1,1) &= f_x(1)f_x(1) \\
&= 0.4*0.4 \\
&= 0.16
\end{align}
c. Since we have a random sample, the joint PDF is the product of the
marginal PDFs:
\begin{align}
f_{D_n}(2,1) &= f_x(2)f_x(1) \\
&= 0.6*0.4 \\
&= 0.24
\end{align}
d. Since we have a random sample, the joint PDF is the product of the
marginal PDFs:
\begin{align}
f_{D_n}(1,2) &= f_x(1)f_x(2) \\
&= 0.4*0.6 \\
&= 0.24
\end{align}
e. Since we have a random sample, the joint PDF is the product of the
marginal PDFs:
\begin{align}
f_{D_n}(2,2) &= f_x(2)f_x(2) \\
&= 0.6*0.6 \\
&= 0.36
\end{align}
2. A random sample needs to be independent (not just uncorrelated) and
identically distributed (not just the same mean and variance).
a. Possibly a random sample.
b. Possibly a random sample.
c. Not a random sample.
d. Definitely a random sample.
e. Possibly a random sample.
f. Not a random sample.
3. Identify the sampling type (random sample, time series, stratified sample.
cluster sample, census, convenience sample) for each of the following data
sets.
a. This is a convenience sample.
b. This is a random sample.
c. This is a stratified sample.
d. This is a time series.
e. This is a census.
4. This is a long question but we can make it easier by preparing a simple table
mapping each of the four possible values of $D_n$ into a value for each
statistic:
| $x_1$ | $x_2$ |$f_{D_n}(\cdot)$|$\hat{f}_1$ |$\bar{x}$ | $\hat{\sigma}_x^2$ | $\hat{\sigma}_x$ | $xmin$ | $xmax$ |
|-------|-------|--------------|-------------|----------|--------------------|------------------|--------|--------|
| 1 | 1 | 0.16 | 1 | 1 | 0 | 0 | 1 | 1 |
| 2 | 1 | 0.24 | 0.5 | 1.5 | 0.5 | 0.71 | 1 | 2 |
| 1 | 2 | 0.24 | 0.5 | 1.5 | 0.5 | 0.71 | 1 | 2 |
| 2 | 2 | 0.36 | 0 | 2 | 0 | 0 | 2 | 2 |
This will make our lives much easier.
a. The support is $S_{\hat{f}_1} = \{0,0.5,1\}$ and the sampling distribution
is:
\begin{align}
f_{\hat{f}_1}(0) &= \Pr(\hat{f}_1 = 0) \\
&= f_{D_n}(2,2) \\
&= 0.36 \\
f_{\hat{f}_1}(0.5) &= \Pr(\hat{f}_1 = 0.5) \\
&= f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.24 + 0.24 \\
&= 0.48 \\
f_{\hat{f}_1}(1) &= \Pr(\hat{f}_1 = 1) \\
&= f_{D_n}(1,1) \\
&= 0.16
\end{align}
b. The support is $S_{\bar{x}} = \{1,1.5,2\}$ and the sampling distribution
is:
\begin{align}
f_{\bar{x}}(1) &= \Pr(\bar{x} = 1) \\
&= f_{D_n}(1,1) \\
&= 0.16 \\
f_{\bar{x}}(1.5) &= \Pr(\bar{x} = 1.5) \\
&= f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.24 + 0.24 \\
&= 0.48 \\
f_{\bar{x}}(2) &= \Pr(\bar{x} = 2) \\
&= f_{D_n}(2,2) \\
&= 0.36
\end{align}
c. The support is $S_{\hat{\sigma}_x^2} = \{0,0.5\}$ and the sampling
distribution is:
\begin{align}
f_{\hat{\sigma}_x^2}(0) &= \Pr(\hat{\sigma}_x^2 = 0) \\
&= f_{D_n}(1,1) + f_{D_n}(2,2)\\
&= 0.16 + 0.36 \\
&= 0.52 \\
f_{\hat{\sigma}_x^2}(0.5) &= \Pr(\hat{\sigma}_x^2 = 0.5) \\
&= f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.24 + 0.24 \\
&= 0.48
\end{align}
d. The support is $S_{\hat{\sigma}_x} = \{0,0.71\}$ and the sampling
distribution is:
\begin{align}
f_{\hat{\sigma}_x^2}(0) &= \Pr(\hat{\sigma}_x = 0) \\
&= f_{D_n}(1,1) + f_{D_n}(2,2)\\
&= 0.16 + 0.36 \\
&= 0.52 \\
f_{\hat{\sigma}_x^2}(0.71) &= \Pr(\hat{\sigma}_x = 0.71) \\
&= f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.24 + 0.24 \\
&= 0.48
\end{align}
e. The support is $S_{xmin} = \{1,2\}$ and the sampling distribution is:
\begin{align}
f_{xmin}(1) &= \Pr(xmin = 1) \\
&= f_{D_n}(1,1) + f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.16 + 0.24 + 0.24 \\
&= 0.64 \\
f_{xmin}(2) &= \Pr(xmin = 2) \\
&= f_{D_n}(2,2) \\
&= 0.36
\end{align}
f. The support is $S_{xmax} = \{1,2\}$ and the sampling distribution is:
\begin{align}
f_{xmax}(1) &= \Pr(xmax = 1) \\
&= f_{D_n}(1,1) \\
&= 0.16 \\
f_{xmax}(2) &= \Pr(xmax = 2) \\
&= f_{D_n}(2,2) + f_{D_n}(2,1) + f_{D_n}(1,2) \\
&= 0.36 + 0.24 + 0.24 \\
&= 0.84
\end{align}
5. The mean can be calculated from each statistic's PDF.
a. The mean is:
\begin{align}
E(\hat{f}_1) &= 0*f_{\hat{f}_1}(0) + 0.5*f_{\hat{f}_1}(0) + 1*f_{\hat{f}_1}(1) \\
&= 0*0.36 + 0.5*0.48 + 1*0.16 \\
&= 0.4
\end{align}
b. The mean is:
\begin{align}
E(\bar{x}) &= 1*f_{\bar{x}}(1) +1.5*f_{\bar{x}}(1.5) + 2*f_{\bar{x}}(2) \\
&= 1*0.16 +1.5*0.48 + 2*0.36 \\
&= 1.6
\end{align}
c. The mean is:
\begin{align}
E(\hat{\sigma}_x^2) &= 0*f_{\hat{\sigma}_x^2}(0) + 0.5*f_{\hat{\sigma}_x^2}(0.5) \\
&= 0*0.52 + 0.5*0.48 \\
&= 0.24
\end{align}
d. The mean is:
\begin{align}
E(\hat{\sigma}_x) &= 0*f_{\hat{\sigma}_x}(0) + 0.71*f_{\hat{\sigma}_x}(0.71) \\
&= 0*0.52 + 0.71*0.48 \\
&= 0.34
\end{align}
e. The mean is: