library(DATA606)
## Loading required package: shiny
## Loading required package: openintro
## Please visit openintro.org for free statistics materials
## 
## Attaching package: 'openintro'
## The following objects are masked from 'package:datasets':
## 
##     cars, trees
## Loading required package: OIdata
## Loading required package: RCurl
## Loading required package: bitops
## Loading required package: maps
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following object is masked from 'package:openintro':
## 
##     diamonds
## Loading required package: markdown
## 
## 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

Area under the curve, Part I. (4.1, p. 142) What percent of a standard normal distribution \(N(\m=0, \sigma=1)\) is found in each region? Be sure to draw a graph.

  1. \(Z < -1.35\)
  2. \(Z > 1.48\)
  3. \(-0.4 < Z < 1.5\)
  4. \(|Z| > 2\)

(a) Z < -1.35

# Find x
m <- 0
sd <- 1
z_a <- -1.35
x_a <- z_a * sd + m 
x_a
## [1] -1.35
# Find probability of norm for x
pnorm(x_a, m, sd)
## [1] 0.08850799
normalPlot(mean = 0, sd = 1, bounds = c(-Inf, -1.35), tails = FALSE)

The percent of a standard normal distribution found in Z < -1.35 is 8.85%.

(b) Z > 1.48

# Find x
z_b <- 1.48
x_b <- z_b * sd + m 
x_b
## [1] 1.48
# Find probability of norm for x
1 - pnorm(x_b, m, sd)
## [1] 0.06943662
normalPlot(mean = 0, sd = 1, bounds = c(1.48, Inf), tails = FALSE)

The percent of a standard normal distribution found in Z > 1.46 is 6.94%.

(c) -0.4 < Z < 1.5

# Find x
z_c <- -0.4
z_c2 <- 1.5
x_c <- z_c * sd + m 
x_c2 <- z_c2 * sd + m
x_c
## [1] -0.4
x_c2
## [1] 1.5
# Find probability of norm for x
p1 <- pnorm(x_c, m, sd)
p2 <- pnorm(x_c2, m, sd)
p2 - p1
## [1] 0.5886145
normalPlot(mean = 0, sd = 1, bounds = c(-0.4, 1.5), tails = FALSE)

The percent of a standard normal distribution found in -0.4 < Z > 1.5 is 58.9%.

(d) |Z| > 2

# Find x
z_d <- 2
x_d <- z_d * sd + m 
x_d2 <- - x_d
x_d
## [1] 2
x_d2
## [1] -2
# Find probability of norm for x
p_neg <- pnorm(x_d2, m, sd)
p_pos <- 1 - pnorm(x_d, m, sd)
p_pos + p_neg
## [1] 0.04550026
normalPlot(mean = 0, sd = 1, bounds = c(-2, 2), tails = TRUE)

The percent of a standard normal distribution found in |Z| > 2 is 4.55%.


Triathlon times, Part I (4.4, p. 142) 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:

Remember: a better performance corresponds to a faster finish.

  1. Write down the short-hand for these two normal distributions.
  2. What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?
  3. Did Leo or Mary rank better in their respective groups? Explain your reasoning.
  4. What percent of the triathletes did Leo finish faster than in his group?
  5. What percent of the triathletes did Mary finish faster than in her group?
  6. If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.

(a)

Men, Ages 30 - 34: N(µ = 4313, σ = 583)

Women, Ages 25 - 29: N(µ = 5261, σ = 807)

(b)

# Z'-score for Leo
Leo_x <- 4948
Leo_m <- 4313
Leo_sd <- 583
Leo_z <- (Leo_x - Leo_m) / Leo_sd
Leo_z
## [1] 1.089194
# Z-score for Mary
Mary_x <- 5513
Mary_m <- 5261
Mary_sd <- 807
Mary_z <- (Mary_x - Mary_m) / Mary_sd
Mary_z
## [1] 0.3122677

Leo’s Z-score is 1.089 while Mary’s Z-score is 0.312. Based on these Z-scores, it shows that Mary is closer to her age group’s mean than Leo is to his age group’s mean. The lower your Z-score is the faster your finishing time is.

(c)

Mary ranked better in her respective group than Leo did in his group. This is based off of their Z-scores, since Mary’s Z-score is lower than Leo’s Z-score that means that she better ranks in her group.

(d)

pnorm(Leo_z, lower.tail = FALSE)
## [1] 0.1380342

The percent of triathletes Leo finished faster than in his group is 13.80%.

(e)

pnorm(Mary_z, lower.tail = FALSE)
## [1] 0.3774186

The percent of triathletes Mary finished faster than in her group is 37.74%.

(f)

My answers to parts (b) and (c) would not change and parts (d) and (e) would change if the distribution of finishing times was not nearly normal. This is because the Z-scores wouls still be calculated the sameregardless of whether the distributions are normal or not. Finding the percent of faster finishing times will change since you would be looking at finishing times that are not nearly normal.


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

\[ \stackrel{1}{54}, \stackrel{2}{55}, \stackrel{3}{56}, \stackrel{4}{56}, \stackrel{5}{57}, \stackrel{6}{58}, \stackrel{7}{58}, \stackrel{8}{59}, \stackrel{9}{60}, \stackrel{10}{60}, \stackrel{11}{60}, \stackrel{12}{61}, \stackrel{13}{61}, \stackrel{14}{62}, \stackrel{15}{62}, \stackrel{16}{63}, \stackrel{17}{63}, \stackrel{18}{63}, \stackrel{19}{64}, \stackrel{20}{65}, \stackrel{21}{65}, \stackrel{22}{67}, \stackrel{23}{67}, \stackrel{24}{69}, \stackrel{25}{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.
  2. Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.

# Use the DATA606::qqnormsim function
qqnormsim(heights)

(a)

1 - 2 * pnorm(mean = 61.52, sd = 4.58, 61.52 + 4.58, lower.tail = FALSE)
## [1] 0.6826895
1 - 2 * pnorm(mean = 61.52, sd = 4.58, 61.52 + 2 * 4.58, lower.tail = FALSE)
## [1] 0.9544997
1 - 2 * pnorm(mean = 61.52, sd = 4.58, 61.52 + 3 * 4.58, lower.tail = FALSE)
## [1] 0.9973002

Based on the information above, the heights do approximately follow the 68-95-99.7% Rule.

(b)

The data does appear to follow a normal distribution. The histrogram appears to show a slight right skew with a normal distribution peak line. The QQ Plot shows some high and low data away from the line but majority of them follow the line. The QQnormsim expands on this by showing eight different simulations showing a normal distribution.


Defective rate. (4.14, p. 148) 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?
  2. What is the probability that the machine produces no defective transistors in a batch of 100?
  3. On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?
  4. 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?
  5. 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?

(a)

trans_error_10 <- (1 - 0.02) ^ 9 * 0.02
trans_error_10
## [1] 0.01667496

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

(b)

trans_error <- (1 - 0.02) ^ 100
trans_error
## [1] 0.1326196

The probability that the machine produces no defective transistors in a batch of 100 is 13.26%.

(c)

trans_error_mean <- 1 / 0.02
trans_error_mean
## [1] 50
trans_error_sd <- sqrt((1 - 0.02) / (0.02 ^ 2))
trans_error_sd
## [1] 49.49747

On average, you would expect 50 transistors to be produced before the first with a defect. The standard deviation is 49.50 = 50.

(d)

trans_error_mean2 <- 1 / 0.05
trans_error_mean2
## [1] 20
trans_error_sd2 <- sqrt((1 - 0.05) / (0.05 ^ 2))
trans_error_sd2
## [1] 19.49359

On average, you would expect 20 transistors to be produced before the first with a defect. The standard deviation is 19.49 = 19.

(e)

Increasing the probability of an event decreases the mean and decreases the standard deviation of the wait time until success, You can see this in parts (c) and (d), the mean goes from 50 to 20 and the standard deviation goes from 49 to 19.


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.
  2. 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.
  3. 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).

(a)

n <- 3
k <- 2
boy <- 0.51
girl <- 1 - boy
choose(n, k) * girl ^ (n - k) * boy ^ k
## [1] 0.382347

Based on the binomial model, the probability that two of them will be boys is 38.23%.

(b)

Order 1: boy, boy, girl

Order 2: boy. girl, boy

Order 3: girl, boy, boy

order_1 <- boy * boy * girl
order_2 <- boy * girl * boy
order_3 <- girl * boy * boy
probability <- order_1 + order_2 + order_3
probability
## [1] 0.382347

The probability that I found in part (a) is the same probability that I found in part (b).

(c)

To calculate the probability that a couple who plans to have 8 kids will have 3 boys, it would be more tedious to use the approach from part (b) than the approach from part (a). This is because for part (b) you would have to write down all the orders of all possible outcomes, calculate the probability of each, and then add them together. For part (a) you are using a function to calculate the probability which makes it more simpler to do.


Serving in volleyball. (4.30, p. 162) 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?
  2. Suppose she has made two successful serves in nine attempts. What is the probability that her 10th serve will be successful?
  3. 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?

(a)

n_2 <- 10
k_2 <- 3
prob <- 0.15
choose(n_2 - 1, k_2 - 1) * (1 - prob) ^ (n_2 - k_2) * prob ^ k_2
## [1] 0.03895012

The probability that on the 10th try she will make her 3rd successful serve is 38.95%.

(b)

The probability that her 10th serve will be successful if she made two successful serves in nine attempts is 15%. Since she already made two successful serves, this shows that the probability of her 10th serve being successful is just the probability of making a serve, which is 15%.

(c)

Parts (a) and (b) have the same scenario but different probabilities. This is because for part (a) we see that having two successful serves in nine attempts would increase the probability that the 10th serve would be the third successful serve. For part (b) each serve she takes is independent of the others, so each time she gets a successful serve, the probability would remain the same at 15%.