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

Chapter 3: Distributions of Random Variables

3.2 Area under the curve, Part II.

What percent of a standard normal distribution N(mean = 0,sd = 1) is found in each region? Be sure to draw a graph.

    1. Z > -1.13 —> Answer: 0.8707619
    1. Z < 0.18 —> Answer: 5714237
    1. Z > 8 —> Answer: 6.661338e-16 (practically zero)
    1. |Z| < 0.5 —> -0.5 < z < 0.5 —> Answer: 0.3829249

Please see below for calculations for (a) through (d).

#a)  Z > -1.13
1 - pnorm(-1.13, mean=0, sd=1)
## [1] 0.8707619
#NOTE: for the upper bound, I need to enter a number
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 1000), tails = FALSE)

#b) Z < 0.18
pnorm(0.18, mean=0, sd=1)
## [1] 0.5714237
normalPlot(mean = 0, sd = 1, bounds = c(0.18), tails = TRUE)

#c) Z > 8
1 - pnorm(8, mean=0, sd=1)
## [1] 6.661338e-16
# NOTE: for the upper bound, I need to enter a number
normalPlot(mean = 0, sd = 1, bounds = c(8,1000), tails = FALSE)

#d) |z| < 0.5 -->  -0.5 < z < 0.5
pnorm(0.5, mean=0, sd=1) - pnorm(-0.5, mean=0, sd=1)
## [1] 0.3829249
normalPlot(mean = 0, sd = 1, bounds = c(-0.5, 0.5), tails = FALSE)



3.4 Triathlon times, Part I.

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 Men, Ages 30 - 34 group has a mean of 4313 seconds with a standard deviation of 583 seconds. The finishing times of the Women, Ages 25 - 29 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.

  • Leo —> 4948 seconds
  • Mary —> 5513 seconds
  • Distribution approximately Normal
  • Men’s group: mean = 4313, sd = 583
  • Women’s group: mean = 5261, sd = 807

(a) Write down the short-hand for these two normal distributions.

  • Distribution for men’s group: N(mean=4313, sd=583)
  • Distribution for women’s group: N(mean=5261, sd=807)

(b) What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?

Mary’s z-score is 0.3122677. Leo’s z-score is 1.089194. The z-score indicate how far the value is (in this case finish time) from the mean in terms of standard deviations. A z-score of 1 is 1 standard deviation away from the mean. So, Mary’s finish time is 0.31 sd above the mean. Leo’s finish time is 1.09 sd above the mean.

z_score_mary <- (5513-5261)/807
z_score_leo <- (4948-4313)/583
z_score_mary #0.3122677
## [1] 0.3122677
z_score_leo #1.089194
## [1] 1.089194

(c) Did Leo or Mary rank better in their respective groups? Explain your reasoning.

Relative to their own group, Mary did better than Leo since Mary’s z-score is closer to the mean, which indicates a faster finish time. Because this is a race, a negative z-score would indicate a faster finish time.

(d) What percent of the triathletes did Leo finish faster than in his group?

Leo finished faster than 13.80% of the triathletes in his group.

1 - pnorm(1.089194, mean=0, sd=1)  #0.1380342
## [1] 0.1380342
#or alternatively, 
1 - pnorm(4948, mean=4313, sd=583) #0.1380342
## [1] 0.1380342

(e) What percent of the triathletes did Mary finish faster than in her group?

Mary finished faster than 37.74% of the triathletes in her group.

1 - pnorm(0.3122677, mean=0, sd=1)  #0.3774185
## [1] 0.3774185
#or alternatively,
1 - pnorm(5513, mean=5261, sd=807)  #0.3774186
## [1] 0.3774186

(f) If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.

We can answer (b) through (c) since we can calculate z-scores for distributions that are not normal. However, for parts (d) through (e) we cannot use the normal probability table to calculate the probabililties and percentiles without a normal model.



3.18 Heights of female college students.

Below are heights of 25 female college students.

54,55,56,56,57,58,58,59,60,60,60,61,61,62,62,63,63,63,64,65,65,67,67,69,73

(a) 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.

The data set approximately follow the 68-95-99.7% rule.

Findings based on calculations below:

  • 68% fall within 1 standard deviation
  • 96% fall within 2 standard deviations
  • 100% fall within 3 standard deviations
heights <- c(54,55,56,56,57,58,58,59,60,60,60,61,61,62,62,63,63,63,64,65,65,67,67,69,73)
length(heights)
## [1] 25
mean_height <- mean(heights) # 61.52
sd_height <- sd(heights)  # 4.583667
mean_height
## [1] 61.52
sd_height
## [1] 4.583667
#mean_height + sd_height #66.10367
#mean_height - sd_height #56.93633
#mean_height + 2*sd_height #70.68733
#mean_height - 2*sd_height # 52.35267
#mean_height + 3*sd_height # 75.271
#mean_height - 3*sd_height # 47.769

within_1_sd <- heights[which(heights < mean_height + sd_height & heights > mean_height - sd_height)]
within_2_sd <- heights[which(heights < mean_height + 2*sd_height & heights > mean_height - 2*sd_height)]
within_3_sd <- heights[which(heights < mean_height + 3*sd_height & heights > mean_height - 3*sd_height)]

length(within_1_sd)/length(heights) # 1 standard deviation: 68%
## [1] 0.68
length(within_2_sd)/length(heights) # 2 standard deviation: 96%
## [1] 0.96
length(within_3_sd)/length(heights) # 3 standard deviation: 100%
## [1] 1

(b) Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.

The data set (size 25) is too small, but the histogram resembles a normal distribution. The normal probability plot mostly stay within a the straight line with some amount of deviation from the line. The data set is too small, and this kind of deviation is to be expected.



3.22 Defective rate.

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.

  • Probability of success (p) is .02 –> defective transistor
  • Probability of failure is .98 –> not defective transistor

(a) What is the probability that the 10th transistor produced is the first with a defect?

The probability that the 10th transistor is the first with a defect is 1.67%.

# probability 10th transister is the first with a defect: 0.01667496 or 1.67%
(1-.02)^9 * .02   
## [1] 0.01667496

(b) What is the probability that the machine produces no defective transistors in a batch of 100?

The probability that there are no defective transistors in a batch of 100 is 13.26%.

# probability no defective transistor in a batch of 100: 0.1326196 or 13.26%
(1-.02)^100
## [1] 0.1326196

(c) On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?

  • We would expect to see 50 transistors without defect before the first one with a defect.
  • The standard deviation is 49.50
#mean: 50
1/.02
## [1] 50
#sd: 49.49747
sqrt((1-.02)/(.02^2))
## [1] 49.49747

(d) 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?

  • Probability of success (p) is .05 –> defective transisitor
  • Probability of failure is .95 –> not defective transistor

  • We would expect to see 20 nondefective transistors before seeing the first defective one.
  • The standard deviation is 19.49359.

#mean (average waiting time in terms of no. of nondefective transistors before the 1st defective): 20
1/.05
## [1] 20
#standard deviation: 19.49359
sqrt((1-.05)/(.05^2))
## [1] 19.49359
20/19.49359
## [1] 1.025978

(e) 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?

Increasing the probability of the “successful” event decreases the wait time and the standard deviation. The ratio between standard deviation to mean decreases. This suggests to me that as the probability increases, the variability in the wait time becomes less spread out. Below you will see the ratio between standard deviation and mean decrease as probability of success increases.

#sd/mean when p = .02 ---> 0.9899495
(sqrt((1-.02)/(.02^2))) / (1/.02)
## [1] 0.9899495
#sd/mean when p = .05 ---> 0.9746794
(sqrt((1-.05)/(.05^2))) / (1/.05)
## [1] 0.9746794
#sd/mean when p = .10 ---> 0.9486833
(sqrt((1-.10)/(.10^2))) / (1/.10)
## [1] 0.9486833
#sd/mean when p = .50 --->  0.7071068
(sqrt((1-.50)/(.50^2))) / (1/.50)
## [1] 0.7071068
#sd/mean when p = .80 ---> 0.4472136
(sqrt((1-.80)/(.80^2))) / (1/.80)
## [1] 0.4472136


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

(a) Use the binomial model to calculate the probability that two of them will be boys.

  • success = having a boy
  • probability of success, p = 0.51
  • n = 3
  • k = 2

The probablity of having 2 boys in 3 children: 38.23%

choose(3,2) * (0.51)^2 * (1 - 0.51) #0.382347
## [1] 0.382347

(b) 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.

  • P(Boy, Boy, Girl) –> 0.127449
  • P(Boy, Girl, Boy) –> 0.127449
  • P(Girl, Boy, Boy) –> 0.127449

Probability of having 2 boys in 3 children: 3 * 0.127449 = 0.382347 –> 38.23%

#order 1: Boy, Boy, Girl
outcome1 <- (0.51) * (0.51) * (1 - .51)

#order 2: Boy, Girl, Boy
outcome2 <- (0.51) * (1 - 0.51) * (0.51)

# order 3: Girl, Boy, Boy
outcome3 <- (1 - 0.51) * (0.51) * (0.51)

#probability of having 2 boys in 3 children: 0.382347
outcome1 + outcome2 + outcome3
## [1] 0.382347

(c) 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).

The approach in part (b) would be more tedious than (a) because we would need to write down each possibility, calculate the probability of each possibility and then take the sum of the probabilities. But, if we use the approach in part (a), calculating the probability is more straightforward by using the generalized formula.



3.42 Serving in volleyball. 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.

  • p = .15 (success = make a successful serve)

(a) What is the probability that on the 10th try she will make her 3rd successful serve?

Negative Binomial. p = .15 k = 3 n = 10 P(10th trial is 3rd success) = 0.03895012 or 3.9%

# probability 10th try is 3rd successful serve
choose(9,2) * (.15)^2 * (1 - .15)^(9-2) * (.15) # 0.03895012
## [1] 0.03895012

(b) Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?

She has already made 2 successful serves within the first nine attempts. So based on this condition, the probability that the 10th serve will be successful is simply the probability of making one successful serve, which is .15 or 15%.

(c) 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?

In part (a) we are calculating the marginal probability of making the 3rd successful serve on the 10th serve, but in part (b) we are calculating the conditional probability of making the 3rd successful serve on the 10th serve given that the first 2 successful serves already occured within the first 9 serves.