3.2

a) Z > -1.13

library(IS606)
## 
## Welcome to CUNY IS606 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='IS606') will list the demos that are available.
library(dplyr)
z1 <- -1.13 
blueA <- 1-pnorm(z1)
blueA
## [1] 0.8707619
normalPlot(mean = 0, sd = 1, bounds =c(-1.13, 4))

b) Z < 0.18

z2 <- 0.18
blueB <- pnorm(z2)
blueB
## [1] 0.5714237
normalPlot(mean = 0, sd = 1, bounds =c(-4, 0.18))

c) Z > 8

z3 <- 8
blueC <- 1 - pnorm(z3)
blueC
## [1] 6.661338e-16
normalPlot(mean = 0, sd = 1, bounds =c(8, 4))

d) |Z| < 0.5

z4 <- 0.5
blueD <- 2* (0.5 - pnorm(-1 * z4))
blueD
## [1] 0.3829249
lowerBound <- qnorm(.5-(blueD/2))
upperBound <- qnorm(.5+(blueD/2))


normalPlot(mean = 0, sd = 1, bounds =c(lowerBound, upperBound))

3.4

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

Men (30-34): N(μ = 4313, σ = 583) Women (25-29): N(μ = 5261, σ = 807)

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

meanM <- 4313
SDM <- 583
leo <- 4948

meanF <- 5261
SDF <- 807
mary <- 5513

leoZ <- (leo - meanM) / SDM
leoZ
## [1] 1.089194
maryZ <- (mary - meanF) / SDF
maryZ
## [1] 0.3122677
normalPlot(mean = 0, sd = 1, bounds = c(maryZ, leoZ))

A Z score of 1.09 tells us that Leo finished 1.09 standard deviations above the mean for his group while Mary’s time was 0.31 standard deviations above the mean.

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

Because a lower time is better, Mary had a better race, when compared to her peer group, than Leo. Because this is a normal distribution, and both finished with average times above the mean, the racer with the Z score closest to the mean (0) performed better in their peer group.

normalPlot(mean = 0, sd = 1, bounds = c(-4, leoZ))

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

leoP <- 1 - pnorm(leoZ) 
leoP
## [1] 0.1380342
#Leo finished faster than 13.8% of his peer group
normalPlot(mean = 0, sd = 1, bounds = c(leoZ, 4))

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

maryP <- 1 - pnorm(maryZ)
maryP
## [1] 0.3774186
#Mary finished faster than 37.8% of her peer group

normalPlot(mean = 0, sd = 1, bounds = c(maryZ, 4))

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

Our answers to parts b-e would change as the normal probability calculations would be no longer apply. The use of Z scores to determine probabilities assumes/requires a normal distribution to provide any accuracy.

3.18

Below are heights of 25 female college students.

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.

heights <- data.frame(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))
colnames(heights) <- "hgt"

meanH <- mean(heights$hgt)
SDH <- sd(heights$hgt)

SDtest <- function(SDnum) {
  count(heights, heights>=(meanH - SDH * SDnum) & heights<=(meanH + SDH * SDnum)) / 25}

#1SD
SDtest(1)
##   heights >= (meanH - SDH * SDnum) & he...    n
## 1                                     0.00 0.32
## 2                                     0.04 0.68
#2SD
SDtest(2)
##   heights >= (meanH - SDH * SDnum) & he...    n
## 1                                     0.00 0.04
## 2                                     0.04 0.96
#3SD
SDtest(3)
##   heights >= (meanH - SDH * SDnum) & he... n
## 1                                     0.04 1

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

Yes, the heights approximately do follow the 68-95-99.7% rule with our test equating to 68%-96%-100% on a relatively small data set.

sim_hgt <- rnorm(length(heights$hgt), meanH, SDH)

qqnorm(sim_hgt)
qqline(sim_hgt)

qqnormsim(sim_hgt)

Yes, this data appears to come from a normal distribution. The normal probaility plot data points stay in nearly a straight line and have a similar appearance to the 9 simulated probability plots which assume the same number of observations in our data set but with the guarantee of a normal distribution.

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.

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

p <- .02


n <- 10

(1 - p)^(n - 1) * p
## [1] 0.01667496

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

n = 100
b = (1 - p)**n
round(b, 4)
## [1] 0.1326

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

u = 1/p
u
## [1] 50
#We would expect to see an average of 50 transistors produced to results in one defect. 

sd <- sqrt((1-p)/(p^2))
sd
## [1] 49.49747
#SD is 49.5

d) Another machine that also produces transistors has a 5% defective rate where each transistoris 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

u <- 1/p
u
## [1] 20
#We would expect to see an average of 20 transistors produced to results in one defect. 

sd <- sqrt((1 - p)/(p^2))
sd
## [1] 19.49359
#SD is 19.5

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?

The mean and standard deviation decrease when the probability increases

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.

boyP <- 0.51
k = 2
n = 3

facN <- factorial(n)
facK <- factorial (k)
facN_K <- factorial(n-k)

boys2 <- (facN / (facK * facN_K)) * boyP^k * (1 - boyP)^(n-k)
boys2
## [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.

ex1 <- c("boy", "boy", "girl")
ex2 <- c("boy", "girl", "boy")
ex3 <- c("girl", "boy", "boy")
df <- data.frame(ex1,ex2,ex3)
df
##    ex1  ex2  ex3
## 1  boy  boy girl
## 2  boy girl  boy
## 3 girl  boy  boy
add <- boyP * boyP * (1 - boyP) + boyP * (1 - boyP) * boyP + (1 - boyP) * boyP * boyP
add
## [1] 0.382347
#This value matches our previous calculation. More simply, however we could have done the following: 

(boyP * boyP * (1 - boyP))*3
## [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).

This would greatly add to the number of possible sequences that would match the given parameters, making it much more tedious to use the method in part b than the more efficient formula used in part a.

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.

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

n <- 10    #number of attempts
k <- 3     #successful serves
p <- 0.15  #successful serve prob

nFac <- factorial(n-1)
kFac <- factorial(k-1)


tenth <- factorial(n - 1) / (factorial(k-1) * (factorial(n - k))) * p^k * (1-p)^(n-k)
tenth
## [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?

Becuase the serves are independent of each other, the probability that she successfully makes any one individual serve is 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?