Init:

##Load DATA606 packages
#if(!require('DATA606')) {
#  install.packages('DATA606')
#  library(DATA606)
#}
normalPlot <- function(mean=0, sd=1, bounds=c(-1,1), tails=FALSE) {
    x <- seq(-4,4,length=100)*sd + mean
    hx <- dnorm(x,mean,sd)

    plot(x, hx, type="n", xlab="x-Axis", ylab="",
         main="Normal Distribution", axes=FALSE)
    lines(x, hx)

    if(tails) {
        i.low <- x <= bounds[1]
        i.high <- x >= bounds[2]
        polygon(c(x[i.low],bounds[1]), c(hx[i.low], 0), col="red")
        polygon(c(bounds[2],x[i.high]), c(0,hx[i.high]), col="red")
    } else {
        i <- x >= bounds[1] & x <= bounds[2]
        polygon(c(bounds[1],x[i],bounds[2]), c(0,hx[i],0), col="red")
        area <- pnorm(bounds[2], mean, sd) - pnorm(bounds[1], mean, sd)
        if(diff(bounds) > 0) {
            result <- paste("P(",bounds[1],"< x <",bounds[2],") =",
                            signif(area, digits=3))
            mtext(result,3)
        }
    }
    axis(1)
}
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))
}

Question 3.2

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.

Answer:

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

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

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

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

Question 3.4

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.

Answer:

  1. Write down the short-hand for these two normal distributions.

Group Men, Ages 30 - 34: N(µ =4313, sd =583), Group Women, Ages 25-29: N(µ =5261, sd =807)

  1. What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?
#Leo
leo_obs <- 4948
leo_mu <- 4313
leo_sd <- 583

leo_Z = (leo_obs - leo_mu )/leo_sd
leo_Z
## [1] 1.089194
#Mary
mary_obs <- 5261
mary_mu <- 4313
mary_sd <- 807
mary_Z <- (mary_obs - mary_mu)/mary_sd
mary_Z
## [1] 1.174721

z-score is the number of standard deviations from the mean. Leo’s z score is 1.089194 while Mary’s zscore is 1.174721. This shows Mary’s performance was better.

  1. Did Leo or Mary rank better in their respective groups? Explain your reasoning.
leo_rank <- 1-pnorm(leo_Z)
leo_rank
## [1] 0.1380342
mary_rank <- 1-pnorm(mary_Z)
mary_rank
## [1] 0.1200531

Mary did better in the group than Leo. Mary is in the top 12.0% (0.1200531) but Leo is in the top 13.8% (0.1380342).

  1. What percent of the triathletes did Leo finish faster than in his group?
pnorm(leo_obs, leo_mu, leo_sd)
## [1] 0.8619658

Leo did 86% better in his group.

  1. What percent of the triathletes did Mary finish faster than in her group?
pnorm(mary_obs, mary_mu, mary_sd)
## [1] 0.8799469

Mary did 88% better in her group.

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

If the mean is not in the middle like the normal distribution then the answers would change. It would make comparision difficult.

3.18

3.18 Heights of female college students. Below are heights of 25 female college students.

1 54, 2 55, 3 56, 4 56, 5 57, 6 58, 7 58, 8 59, 9 60, 10 60, 11 60, 12 61, 13 61, 14 62, 15 62, 16 63, 17 63, 18 63, 19 64, 20 65, 21 65, 22 67, 23 67, 24 69, 25 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.

hgt <- 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)
mean_hgt = mean(hgt)
sd_hgt = sd(hgt)
z_hgt <- (hgt - mean_hgt) / sd_hgt
hist(z_hgt, col="#c2c2c2", freq=F, xlim=c(-5, 5))

# 99.7% Rule
curve(dnorm, -3, 3, add=T, col="red")

# 95% Rule
curve(dnorm,-2,2,add=T, col="blue") 

# 68% Rule
curve(dnorm,-1,1,add=T, col="green") 

From the above histogram we see that it follows the 68-95-99.7% Rule

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

Yes, it does because 65% of the data falls within one standard deviation. 95% data falls within two standard deviations and 99.7% of the data falls within three standard deviations.

qqnormsim(hgt)

3.22

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

round(((q ^ (n-1)) * p)*100, 2)
## [1] 1.67

The probability that the 10th transistor produced is the 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

round((q ^ n)*100, 2)
## [1] 13.26

The probability that the machine produces 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
(1/p)
## [1] 50

On average 50 transistors could be produced before the first with a defect.

sqrt(q/(p^2))
## [1] 49.49747

Standard deviation is 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?
p <- 0.05
q <- 0.95
(1/p)
## [1] 20

Number of transistors expected to be produced with this machine before the first with a defect is 20

sqrt(q/(p^2))
## [1] 19.49359

Standard deviation is 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?

Increase in the probability of an event affect the mean and standard deviation. The probability and mean is has an inverse effect on each other. If the probability increases the mean decreases.

3.38

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.
p = 2
k = 3
q = 0.51

dbinom(p,k,q)
## [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.
boy = 0.51
girl = 0.49
(boy * boy * girl) + (boy * girl * boy) + (girl * boy * boy)
## [1] 0.382347
  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).

The second part required lot of calculation. It becomes impossible to work with larger possible outcomes. Function would make it easy and can be used for larger numbers.

3.42

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?
#Negative Binomial distribution
p <- 0.15
n <- 10
k <- 3
choose(n - 1, k - 1) * (1 - p)^(n - k) * p^k
## [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?

The events are independent of each other. So the probability of the 10th serve being successful after two successful serves in nine attempt will still be 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?

Although in (b) the probability of success is constant i.e 15% on every trial, in (a) we have a Negative Binomial distribution effect. Unlike the binomial distribution where we find the distribution of “number of successes” in a “fixed number” of Bernoulli trials, the negative binomial distribution is the distribution of “number of trials” needed to get a “fixed number of successes”.