OpenIntro Statistics 3rd Ed. (Chapter 3: Distributions of Random Variables)

#Let's begin by loading necessary libraries

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.
## 
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
## 
##     demo

Q# 3.2 Area under the curve, Part II. What percent of a standard normal distribution N(μ =0,! = 1) is found in each region? Be sure to draw a graph.

  1. Z > −1.13
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4))

87.1% of a standard normal distribution is found in each region


  1. Z < 0.18
normalPlot(mean = 0, sd = 1, bounds = c(-4, 0.18))

57.1% of a standard normal distribution is found in each region


  1. Z > 8
normalPlot(mean = 0, sd = 1, bounds = c(8,12))

0% of a standard normal distribution is found in each region

  1. |Z| < 0.5
normalPlot(mean = 0, sd = 1, bounds = c(-0.5,0.5))

38.3% of a standard normal distribution is found in each region

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

  1. Write down the short-hand for these two normal distributions.
Leo_mean <- 4313
Leo_observation <- 4948
Leo_sd <- 583
zScore <- (Leo_observation - Leo_mean)/Leo_sd
print(round(zScore, 4))
## [1] 1.0892

Leo’s Z Score is 1.0892

Mary_mean <- 5261
Mary_observation <- 5513
Mary_sd <- 807
zScore <- (Mary_observation - Mary_mean)/Mary_sd
print(round(zScore, 4))
## [1] 0.3123

Mary’s Z Score is 0.3123

  1. What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?

Looking at both Z scores, looks like Mary performed better compared to Leo.

  1. Did Leo or Mary rank better in their respective groups? Explain your reasoning.
#Mary ranked better in her group; compared to Leo her score was within 0.3 standard deviation. 

  1. What percent of the triathletes did Leo finish faster than in his group?
normalPlot(mean=Leo_mean,sd=Leo_sd,bounds=c(Leo_observation,Leo_mean+(4*Leo_sd)))

# 13.8% of the triathletes Leo finished faster. 

  1. What percent of the triathletes did Mary finish faster than in her group?
normalPlot(mean=Mary_mean,sd=Mary_sd,bounds=c(Mary_observation,Mary_mean + (4*Mary_sd))) 

37.7% —

  1. If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.
#The values could change if the distributions are not normal

Q# 3.18

Heights of female college students. Below are heights of 25 female college students. 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 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

  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.
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)
meanHeights = mean(heights)
sdHeights = sd(heights)
zScores <- (heights - meanHeights) / sdHeights
hist(zScores, col="white", freq=F, xlim=c(-5, 5))
curve(dnorm, -3, 3, add=T, col="blue") 
# 99.7% Rule
curve(dnorm,-2,2,add=T, col="red") 
# 95% Rule
curve(dnorm,-1,1,add=T, col="orange") 

# 68% Rule

Correct, the data set follows the rule of 68-95-99.7

  1. Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.
#Yes, a normal distribution is followed by the data. This is true as 65% of the data falls within 1 SD, within 2 SD's 95% of the data remains and 99.7% of the data is within 3 Standar Deviations.

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

  1. What is the probability that the 10th transistor produced is the first with a defect?
n <- 10
p <- 0.02
q <- 0.98

print(paste("Probability for the 10th transistor produced first with a defect is:", round(((q ^ (n-1)) * p)*100, 2), "%" ))
## [1] "Probability for the 10th transistor produced first with a defect is: 1.67 %"
  1. What is the probability that the machine produces no defective transistors in a batch of 100?
n <- 100
p <- 0.02
q <- 0.98
print(paste("Probability of the machine producing no defective transistors in a batch of 100 is:", round((q ^ n)*100, 2), "%" ))
## [1] "Probability of the machine producing no defective transistors in a batch of 100 is: 13.26 %"
  1. On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?
p <- 0.02
q <- 0.98
print(1/p)
## [1] 50
print(paste("The Standard Dev is: ", round(sqrt(q/(p^2)), 3) ))
## [1] "The Standard Dev is:  49.497"
  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?
p <- 0.05
q <- 0.95
print(1/p)
## [1] 20
print(paste("The Standard Dev is: ", round(sqrt(q/(p^2)), 3) ))
## [1] "The Standard Dev is:  19.494"
  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?
#When increasing the probability of an event, it will create a strong impact in the SD of the defective transitor production. 

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

  1. Use the binomial model to calculate the probability that two of them will be boys.
n <- 3
k <- 2
p <- 0.51
q <- 0.49
print( paste("Probability both of them will be boys: ", round((factorial(n)/(factorial(k) * factorial(n-k))) * (p^k) * (q^(n-k)) * 100, 2), "%"))
## [1] "Probability both of them will be boys:  38.23 %"
  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.
pBoy = 0.51
pGirl = 0.49
pByAddition <- (pBoy * pBoy * pGirl) + (pBoy * pGirl * pBoy) + (pGirl * pBoy * pBoy)
print(paste("Probability two of them will be boys using the addition rule : ", round(pByAddition * 100, 2), "%. The result matches between (a) and (b)"))
## [1] "Probability two of them will be boys using the addition rule :  38.23 %. The result matches between (a) and (b)"
  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).
n <- 8
k <- 3
p <- 0.51
q <- 0.49
print( paste("Probability of three of them will be boys (of 8 kids) is: ", round((factorial(n)/(factorial(k) * factorial(n-k))) * (p^k) * (q^(n-k)) * 100, 2), "%"))
## [1] "Probability of three of them will be boys (of 8 kids) is:  20.98 %"

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

  1. What is the probability that on the 10th try she will make her 3rd successful serve?
n <- 10
k <- 3
p <- 0.15
q <- 0.85
print( paste("The probability on the 10th try she will make the 3rd successful serve: ", round((factorial(n)/(factorial(k) * factorial(n-k))) * (p^k) * (q^(n-k)) * 100, 2), "%"))
## [1] "The probability on the 10th try she will make the 3rd successful serve:  12.98 %"
  1. Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?
n <- 1
k <- 1
p <- 0.15
q <- 0.85
print( paste("The probability of making 10th serve successful: ", round((factorial(n)/(factorial(k) * factorial(n-k))) * (p^k) * (q^(n-k)) * 100, 2), "%"))
## [1] "The probability of making 10th serve successful:  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?
#Since in part b, probability shows for only the final succesfful attempt, and for part a, probability of success for 3 in 10 attempts, k and n equals 1.