mu <- 0
sd <- 1

#option a
Z <- -1.13
x <- Z * sd + mu
# prob of x > -1.13
1 - pnorm(x, mean = 0, sd = 1)
## [1] 0.8707619
#option b
Z <- 0.18
x <- Z * sd + mu
# prob of x > -1.13
pnorm(x, mean = 0, sd = 1)
## [1] 0.5714237
#option c
Z <- 8
x <- Z * sd + mu
# prob of x > 8
1 - pnorm(x, mean = 0, sd = 1)
## [1] 6.661338e-16
#option d
Z <- 0.5
x <- Z * sd + mu
# prob of |x| < 0.5 = -x < 0.5 < x
x1 <- pnorm(-x, mean = 0, sd = 1)
x2 <- pnorm(x, mean = 0, sd = 1)
x2 - x1
## [1] 0.3829249
library(fastGraph)
mean <- 0 
SD <- 1
x <- seq(-4, 4, length = 10000)
y <- dnorm(x, mean, SD)
par(mfrow=c(2,2))
shadeDist(-1.13, lower.tail = FALSE, col = c("blue", "light green"))
shadeDist(0.18, col = c("blue", "light green"))
shadeDist(8, lower.tail = FALSE, col = c("blue", "light green"))
shadeDist(c(-0.5,0.5), lower.tail = FALSE, col = c("blue", "light green"))

Ans: Percent of Standard deviation distribution:
(a) 87.08%
(b) 57.14%
(c) 0%
(d) 38.29%

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

#For Men, Ages 30 - 34:
#N(mean = 4313, sd = 583)

#For Women, Ages 25 - 29:
#N(mean = 5261, sd = 807)

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

#Z score for Leo:
Z.Leo <- (4948 - 4313)/583
paste0("Z score for Leo: ", round(Z.Leo,2))
## [1] "Z score for Leo: 1.09"
#Z score for Mary:
Z.Mary <- (5513 - 5261)/807
paste0("Z score for Mary: ", round(Z.Mary,2))
## [1] "Z score for Mary: 0.31"

This tell us that Leo scored 1.09 SD and Mary scored 0.31 SD above the mean, respectively.

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

Ans: Mary ranks better that Mark their respective group. MArk had more “seconds” in time in his respective group as compared to Mary’s. Mark is 1.09 SD above the mean, whereas, Mary is 0.31 above the SD for her group.

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

Percent.Leo <- (1 - pnorm(4948, mean = 4313, sd = 583)) * 100
paste0("Percentage of triathletes Leo finished faster than: ", round(Percent.Leo,2))
## [1] "Percentage of triathletes Leo finished faster than: 13.8"

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

Percent.Mary <- (1 - pnorm(5513, mean = 5261, sd = 807)) * 100
paste0("Percentage of triathletes Leo finished faster than: ", round(Percent.Mary,2))
## [1] "Percentage of triathletes Leo finished faster than: 37.74"

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

Ans: The z-scores won’t change, but the probabilities associated with these z-scores will be affected because Z-scores are calculated based on normal distribution.

Female.Height <- 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)
h.mean <- 61.52 # mean(fheights$heighs)
h.sd <- 4.58 # sd(fheights$heighs)
length(which(Female.Height > (h.mean - h.sd) & Female.Height < (h.mean + h.sd)))/length(Female.Height)
## [1] 0.68

Question (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.

Upper.Limit.SD1 <- qnorm(.84, mean = 61.52, sd = 4.58)
Lower.Limit.SD1 <- qnorm(.16, mean = 61.52, sd = 4.58)
paste("Upper Limit of 1st SD in Height: ", round(Upper.Limit.SD1, 2))
## [1] "Upper Limit of 1st SD in Height:  66.07"
paste("Lower Limit of 1st SD in Height: ", round(Lower.Limit.SD1, 2))
## [1] "Lower Limit of 1st SD in Height:  56.97"
Within.1SD <- Female.Height[Female.Height < Upper.Limit.SD1 & Female.Height > Lower.Limit.SD1]
Percent.1SD <- length(Within.1SD)/length(Female.Height)
paste("According to this data set, 1st Standard Deviation is approximately: ", round(Percent.1SD,2))
## [1] "According to this data set, 1st Standard Deviation is approximately:  0.68"
Upper.Limit.SD2 <- qnorm(.975, mean = 61.52, sd = 4.58)
Lower.Limit.SD2 <- qnorm(.025, mean = 61.52, sd = 4.58)
Within.2SD <- Female.Height[Female.Height < Upper.Limit.SD2 & Female.Height > Lower.Limit.SD2]
Percent.2SD <- length(Within.2SD)/length(Female.Height)
paste("According to this data set, 2nd Standard Deviation is approximately: ", round(Percent.2SD,2))
## [1] "According to this data set, 2nd Standard Deviation is approximately:  0.96"
Upper.Limit.SD3 <- qnorm(.9985, mean = 61.52, sd = 4.58)
Lower.Limit.SD3 <- qnorm(.0015, mean = 61.52, sd = 4.58)
Within.3SD <- Female.Height[Female.Height < Upper.Limit.SD3 & Female.Height > Lower.Limit.SD3]
Percent.3SD <- length(Within.3SD)/length(Female.Height)
paste("According to this data set, 3rd Standard Deviation is approximately: ", round(Percent.3SD,2))
## [1] "According to this data set, 3rd Standard Deviation is approximately:  1"

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

qqnormsim <- function (dat) 
{
    par(mfrow = c(3, 3))
    qqnorm(dat, main = "Normal QQ Plot (Data)")
    qqline(dat)
    for (i in 1:8) {
        simnorm <- rnorm(n = length(dat), mean = mean(dat), sd = sd(dat))
        qqnorm(simnorm, main = "Normal QQ Plot (Sim)")
        qqline(simnorm)
    }
    par(mfrow = c(1, 1))
}

qqnormsim(Female.Height)

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

(1-.02)^9 * (.02)
## [1] 0.01667496

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

(1-.02)^100
## [1] 0.1326196

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

paste("First defect: ",1/.02)
## [1] "First defect:  50"
paste("SD: ", sqrt((1-.02)/(.02)^2))
## [1] "SD:  49.4974746830583"

Question (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?

paste("On average, how many transistors would you expect to be produced with this machine before the first with a defect? ", 1/.05)
## [1] "On average, how many transistors would you expect to be produced with this machine before the first with a defect?  20"
paste("What is the standard deviation? ", sqrt((1-.05)/(.05)^2))
## [1] "What is the standard deviation?  19.4935886896179"

Question (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?

Ans: When probability is increased, the event is less rare, meaning the expected number of trials before a success and the standard deviation of the waiting time are lower.

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

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

Question (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.

# 1: {B, B, G} 
# 2: {B, G, B} 
# 3: {G, B, B}
P2B1G <- (.51)^2 * (.49)
Total.P2B1G <- 3 * P2B1G
Total.P2B1G
## [1] 0.382347
Confirm that your answers from parts (a) and (b) match.
Ans: confirmed

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

# Part A is a formula that we can simply plug in and calculate via R or by a calculator. If we performed the calcuation by part B, then we would need to figure out every possible combination and then calculate it by hand, making it significantly tedious.

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

# Using the negative binomial equation, given that the last serve is succesful.
# P(making serve) = .15, therefore, P(NOT making serve) = .85
choose((10-1),(3-1)) * (.15)^3 * (.85)^7
## [1] 0.03895012
Question (b) Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?

Ans: As stated in the question stem, all hits are independent of each other. Therefore, the probability that the 10th serve will be successful is 0.15 or 15% of chance.

Question (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?

Ans: Part B indicates 10th serve only, where the first 9 outcomes had already occurred with probability of 10th serve with 15% of chance. Whereas, in Part A, the first 9 attempts have NOT yet been attempted, and we do not know the outcomes of these events. Thats the main reason why we used negative binomial equation.