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

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

a, Z > -1.13

pnorm(-1.13, mean = 0, sd = 1)
## [1] 0.1292381
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4), tails = FALSE)

b, Z < 0.18

pnorm(0.18, mean = 0, sd=1)
## [1] 0.5714237
normalPlot(mean = 0, sd = 1, bounds = c(-4, 0.18), tails = FALSE)

c, Z > 8

pnorm(8, mean = 0, sd=1)
## [1] 1
normalPlot(mean = 0, sd = 1, bounds = c(8, Inf), tails = FALSE)

d, |Z| < 0.5

pnorm(0.5, mean=0, sd=1) - pnorm(-0.5, mean=0, sd=1)
## [1] 0.3829249
normalPlot(mean = 0, sd = 1, bounds = c(-0.5, 0.5), tails = FALSE)

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.

Leo -> 4948 seconds

Mary -> 5513 seconds

Distribution approximately Normal

Men’s group: mean = 4313, sd = 583

Women’s group: mean = 5261, sd = 807

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

Distribution for men’s group: N(mean=4313, sd=583)

Distribution for women’s group: N(mean=5261, sd=807)

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

Z_scores_Leo <- (4948 - 4313) / 583
Z_scores_Leo
## [1] 1.089194
Z_scores_Mary <- (5513 - 5261) / 807
Z_scores_Mary
## [1] 0.3122677

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

Answer: Relative to their own group, Mary did better than Leo since Mary’s z-score is closer to the mean, which indicates a faster finish time. Because this is a race, a negative z-score would indicate a faster finish time.

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

normalPlot(0, 1, c(1.09, Inf))

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

normalPlot(0, 1, c(0.31, Inf))

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

Answer: We can answer (b) through (c) since we can calculate z-scores for distributions that are not normal. However, for parts (d) through (e) we cannot use the normal probability table to calculate the probabililties and percentiles without a normal model.

3.18, 18 Heights of female college students.

Below are heights of 25 female college students.

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

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 <- 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)
heightmean <- 61.52
heightsd <- 4.58
total_women <- 25
one_sd <- 100*sum(heights > (heightmean-1*heightsd) & heights < (heightmean+1*heightsd))/total_women
two_sd <- 100*sum(heights > (heightmean-2*heightsd) & heights < (heightmean+2*heightsd))/total_women
three_sd <- 100*sum(heights > (heightmean-3*heightsd) & heights < (heightmean+3*heightsd))/total_women
rule <- c(one_sd,two_sd,three_sd)
rule
## [1]  68  96 100

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

hist(heights)

qqnorm(heights)

Answer: The distribution appears to be nearly normal. Based on the pictures (in the homework), the bell curve on the histogram plot and the probability plot shows a pretty normal distribution.

3.22 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?

(0.98)^9 * 0.02
## [1] 0.01667496

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

(0.98)^100
## [1] 0.1326196

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

1/0.02
## [1] 50
sqrt(50*.98*.02)
## [1] 0.9899495

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?

1/0.05
## [1] 20
sqrt(20*.95*.05)
## [1] 0.9746794

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?

Answer: If we increase the probability of deffects, the mean for a defective product to be produced would lower, and the standard deviation would .70 as we approach 50% deffective rate after which it would return to .9899495 as we increase deffective rate towards 98%.

3.38 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.

boy <- 0.51
girl <- 0.49

a, Use the binomial model to calculate the probability that two of them will be boys.

prob_2_boys <- choose(3,2)*(boy^2)*(girl)
prob_2_boys
## [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

prob_2_boys <- boy*boy*girl + boy*girl*boy + girl*boy*boy
prob_2_boys
## [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).

Answer:The approach in part b is tedious because of the number of combinations (8 choose 3 = 56). Using combinatorics, we can simply this process as see in problem 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.

serve <- 0.15
no_serve <- 0.85

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

choose(9,2)*(serve^2)*(no_serve^7)*serve
## [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?

Answer: each attemp is iid so the probability of any given serve being successful will be 0.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?

Answer: n (a), we are explaining 2 series of events that are all iid. The first series of events is her having 2 successful serves out of 9. The second is her having just 1 successful serve, which is probability 0.15. In order to get the probability of event (a) we must multiply the probability of series 1 with the probability of series 2. In (b), we are only testing whether the 10th serve will be successful or not. As stated in the description, each serve is independent of each other, meaning the 10th serve is not affected by the outcomes of the previous 9 serves. It is only 1 event counting 1 serve as opposed to (b) that counts a series of events.