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)

Question 1

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.

  1. \(Z < -1.35\)
  2. \(Z > 1.48\)
  3. \(-0.4 < Z < 1.5\)
  4. \(|Z| > 2\)

Answer:

  1. 8.85%
  2. 6.94%
  3. 58.86%
  4. 4.55%
# 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

Question 2

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:

  • The finishing times of the group has a mean of 4313 seconds with a standard deviation of 583 seconds.
  • The finishing times of the group has a mean of 5261 seconds with a standard deviation of 807 seconds.
  • The distributions of finishing times for both groups are approximately Normal.

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
  1. What percent of the triathletes did Leo finish faster than in his group?
  2. What percent of the triathletes did Mary finish faster than in her group?
  3. If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.

Question 3

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} \]

  1. The mean height is 61.52 inches with a standard deviation of 4.58 inches. Use this information to determine if the heights approximately follow the 68-95-99.7% Rule.
  2. Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.

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

Question 4

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.

  1. What is the probability that the 10th transistor produced is the first with a defect?

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
  1. What is the probability that the machine produces no defective transistors in a batch of 100?

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
  1. On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?

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
  1. Another machine that also produces transistors has a 5% defective rate where each transistor is produced independent of the others. On average how many transistors would you expect to be produced with this machine before the first with a defect? What is the standard deviation?

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
  1. Based on your answers to parts (c) and (d), how does increasing the probability of an event affect the mean and standard deviation of the wait time until success?

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.


Question 5

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.

  1. Use the binomial model to calculate the probability that two of them will be boys.

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
  1. Write out all possible orderings of 3 children, 2 of whom are boys. Use these scenarios to calculate the same probability from part (a) but using the addition rule for disjoint outcomes. Confirm that your answers from parts (a) and (b) match.

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.

  1. If we wanted to calculate the probability that a couple who plans to have 8 kids will have 3 boys, briefly describe why the approach from part (b) would be more tedious than the approach from part (a).

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

Question 6

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.

  1. What is the probability that on the 10th try she will make her 3rd successful serve?

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
  1. Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?

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%.

  1. Even though parts (a) and (b) discuss the same scenario, the probabilities you calculated should be different. Can you explain the reason for this discrepancy?

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.