library(DATA606)
##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
library(ggplot2)
library(moments)
Area under the curve, Part I. (4.1, p. 142) What percent of a standard normal distribution \(N(\mu=0, \sigma=1)\) is found in each region? Be sure to draw a graph.
Answer:
# Z< -3.15
normalPlot(bounds = c(-Inf,-1.35))
pnorm(-1.35)
## [1] 0.08850799
# Z > 1.48
normalPlot(bounds = c(1.48,Inf))
1-pnorm(1.48)
## [1] 0.06943662
# -0.4 < Z < 1.5
normalPlot(bounds = c(-0.4,1.5))
pnorm(1.5)-pnorm(-0.4)
## [1] 0.5886145
# |Z| > 2 -> Z > 2 | Z < -2
normalPlot(bounds = c(-2,2), tails = TRUE)
pnorm(-2)*2
## [1] 0.04550026
Triathlon times, Part I (4.4, p. 142) In triathlons, it is common for racers to be placed into age and gender groups. Friends Leo and Mary both completed the Hermosa Beach Triathlon, where Leo competed in the Men, Ages 30 - 34 group while Mary competed in the Women, Ages 25 - 29 group. Leo completed the race in 1:22:28 (4948 seconds), while Mary completed the race in 1:31:53 (5513 seconds). Obviously Leo finished faster, but they are curious about how they did within their respective groups. Can you help them? Here is some information on the performance of their groups:
Remember: a better performance corresponds to a faster finish.
(a) Write down the short-hand for these two normal distributions.
Answer:
a. [Men's finishing time / Ages 30 - 34]: $M~N(\mu=4313, \sigma=583)$
b. [Women's finishing time / Ages 25 - 29]: $W~N(\mu=5261, \sigma=807)$
mean_m <- 4313
sd_m <-583
mean_w <- 5261
sd_w <-807
(b) What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?
Answer:
a. Leo's Z-score: 1.089,
b. Mary's Z-score: 0.3123
c. The time Leo used to finish the race is 1.089 standard deviation longer than average.
D. The time Mary used to finish the race is 0.3123 standard deviation longer than average.
#Z-scores for Leo
z_leo <-(4948-mean_m)/sd_m
z_mary<-(5513-mean_w)/sd_w
print(c(z_leo, z_mary))
## [1] 1.0891938 0.3122677
(c) Did Leo or Mary rank better in their respective groups? Explain your reasoning.
Answer: Mary ranked better in their respective groups. Leo ranked 86% according to his Z score, which means he finished the race faster than 1-86%=14% of the racers in his group. Mary ranked 62% according to her Z score, which means she finished the race 1-62%=38% of the racers in her goup. Because a better performance corresponds to a faster finish, Mary performed better than Leo.
rank_leo <- pnorm(z_leo)
rank_mary <- pnorm(z_mary)
print(c(rank_leo,rank_mary))
## [1] 0.8619658 0.6225814
Heights of female college students Below are heights of 25 female college students.
\[ \stackrel{1}{54}, \stackrel{2}{55}, \stackrel{3}{56}, \stackrel{4}{56}, \stackrel{5}{57}, \stackrel{6}{58}, \stackrel{7}{58}, \stackrel{8}{59}, \stackrel{9}{60}, \stackrel{10}{60}, \stackrel{11}{60}, \stackrel{12}{61}, \stackrel{13}{61}, \stackrel{14}{62}, \stackrel{15}{62}, \stackrel{16}{63}, \stackrel{17}{63}, \stackrel{18}{63}, \stackrel{19}{64}, \stackrel{20}{65}, \stackrel{21}{65}, \stackrel{22}{67}, \stackrel{23}{67}, \stackrel{24}{69}, \stackrel{25}{73} \]
Answer:
(a)
a. 68% rule means approximately 1 standard deviation away from mean, which is the range [56.94, 66.10] with the given mean and sd. In data `heights`, the 68% range is ranking approximately from #5 to #21, which is [57, 65]. The real data approximately follows the 68% rule.
b. 95% rule means approximately 2 standard deviation away from mean, which is the range [52.36, 70.68] with the given mean and sd. In data `heights`, the 95% range is ranking approximately from #2 to #24, which is [55, 69]. The real data approximately follows the 95% rule.
c. 97.5% rule means approximately 3 standard deviation away from mean, which is the range [47.78, 75.26] with the given mean and sd. In data `heights`, the 97.5% range is ranking approximately from #1 to #25, which is [54, 73]. The real data approximately follows the 97.5% rule, but not as close as the result in 68% and 95%.
# Use the DATA606::qqnormsim function
mean_hgt <- 61.52
sd_hgt <- 4.58
## 68%
r68 <- c(mean_hgt-sd_hgt,mean_hgt+sd_hgt)
r68
## [1] 56.94 66.10
## 95%
r95 <- c(mean_hgt-sd_hgt*2,mean_hgt+sd_hgt*2)
r95
## [1] 52.36 70.68
## 97.5%
r975 <- c(mean_hgt-sd_hgt*3,mean_hgt+sd_hgt*3)
r975
## [1] 47.78 75.26
## Range Data Heights
25*(1-0.68)/2 #number of values should exclude from both side each to get the 68% range
## [1] 4
25*(1-0.95)/2 #number of values should exclude from both side each to get the 95% range
## [1] 0.625
25*(1-0.975)/2 #number of values should exclude from both side each to get the 97.5% range
## [1] 0.3125
(b)
a. The `heights` data appear to follow a normal distribution.
b. The histogram shows a unimodal distribution with mean approximately at the center of the plot. The simulated normal line fits the histogram well.
c. The QQNorm plot shows the data points are very close to the line.
d. The skewness is between -0.5 and 0.5, which shows the distribution is nearly normal, and so verified the above assumption.
skewness(heights)
## [1] 0.4967256
Defective rate. (4.14, p. 148) A machine that produces a special type of transistor (a component of computers) has a 2% defective rate. The production is considered a random process where each transistor is independent of the others.
Answer: This can be solved by geometric distribution \(P(n)=(1-p)^{n-1}p\)
\(P(10)=(1-0.02)^9*0.02=1.67\%\)
or in R:
dgeom(10-1,0.02)
## [1] 0.01667496
Answer: This can be solved by binomial distribution \(P(k,n)=\binom{n}{k}p^k(1-p)^{n-k}\)
\(P(0,100)=\binom{100}{0}*0.02^0(1-0.02)^{100-0}=0.98^{100}=13.26\%\)
or in R:
dbinom(0,100,0.02)
## [1] 0.1326196
Answer: This question is equivalent to asking the mean and SD of a geometric distribution which is \(\mu=\frac1{p}\) and \(\sigma=\sqrt{\frac{1-p}{p^2}}\)
\(\mu=\frac1{0.02}=50\), \(\sigma=\sqrt{\frac{1-0.02}{0.02^2}}=49.4975\).
Therefore, 50-1=49 transistors are expected to be producted before the first with a defect. The standard deviation is 49.4975. Or in R:
# mean
1/0.02
## [1] 50
# SD
sqrt((1-0.02)/0.02^2)
## [1] 49.49747
Answer:
\(\mu=\frac1{0.05}=20\), \(\sigma=\sqrt{\frac{1-0.05}{0.05^2}}=49.4975\).
Therefore, 20-1=19 transistors are expected to be producted before the first with a defect. The standard deviation is 19.4936. Or in R:
# mean
1/0.05
## [1] 20
# SD
sqrt((1-0.05)/0.05^2)
## [1] 19.49359
Answer:
\(\lim_{p\to1}\mu=lim_{p\to1}\frac1{p}=1\)
\(\lim_{p\to1}\sigma=\lim_{p\to1}\sqrt{\frac{1-p}{p^2}}=0\)
Increasing the probability of an event decrease the mean and standard deviation of the wait time until success. Eventually when p = 1, we expected to get success in one trail with sd = 0.
Male children. While it is often assumed that the probabilities of having a boy or a girl are the same, the actual probability of having a boy is slightly higher at 0.51. Suppose a couple plans to have 3 kids.
Answer:
Binomial distribution: \(P(k,n)=\binom{n}{k}p^k(1-p)^{n-k}\)
\(P(2,3)=\binom{3}{2}0.51^2(1-0.51)^{3-2}=38.23\%\)
or in R:
dbinom(2,3,0.51)
## [1] 0.382347
Answer: \(P(2\ boys\ in\ 3\ children) \\= P(1=boy)*P(2=boy)*P(3=girl)+P(1=boy)*P(2=girl)*P(3=boy)+P(1=girl)*P(2=boy)*P(3=boy)\\=0.51*0.51*0.49+0.51*0.49*0.51+0.49*0.51*0.51\\=38.23\%\)
or in R:
0.51*0.51*0.49+0.51*0.49*0.51+0.49*0.51*0.51
## [1] 0.382347
It is confirmed that the answers in Parts(a) and Part(b) are the same.
Answer:
There are total \(C(8,3)=56\) combinations of possible outcomes to have 3 boys in 8 kids. It will not be a good idea to list the probability of all 56 combinations then sum them up.
choose(8,3)
## [1] 56
Serving in volleyball. (4.30, p. 162) A not-so-skilled volleyball player has a 15% chance of making the serve, which involves hitting the ball so it passes over the net on a trajectory such that it will land in the opposing team’s court. Suppose that her serves are independent of each other.
Answer: This can be solved by negative binomial distribution \(P(X=n\|p,r)=\binom{n-1}{r-1}p^r(1-p)^{n-r}\)
The probability \(P(X=10|0.15,3)=3.895\%\)
dnbinom(7,3,0.15)
## [1] 0.03895012
Answer"
Her serves are independent of each other, therefore the probability of any serve would not be affected by previous serves. The probability that her 10th serve will be successful is 15%.
Answer:
Parts (a) and Parts (b) are asking probabilities of different scopes of events. Part (a) is asking for joint probability of a sequence of 10 event, while Part (b) is asking for probability of one last event, which is independent from all pervious events in the sequence.