library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
library(DATA606)
## Loading required package: shiny
## 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, 4th Edition. You can read this by typing 
## vignette('os4') 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 objects are masked from 'package:openintro':
## 
##     calc_streak, present, qqnormsim
## 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(\mu=0, \sigma=1)\) is found in each region? Be sure to draw a graph.

  1. \(Z < -1.35\)
pnorm(-1.35)
## [1] 0.08850799
normal_plot(cv=(-1.35), tails="less")

  1. \(Z > 1.48\)
1- pnorm(1.48)
## [1] 0.06943662
normal_plot(cv=c(1.48), tails="greater")

  1. \(-0.4 < Z < 1.5\)
pnorm(1.5) - pnorm(-.4)
## [1] 0.5886145
normal_plot(cv=c(-.4,1.5))

(d) \(|Z| > 2\)

(1- pnorm(2)) * 2
## [1] 0.04550026
normal_plot(cv=c(2), tails="two.sided")


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:

men_mean <- 4313
men_sd <- 583

women_mean <- 5261
women_sd <- 807

Remember: a better performance corresponds to a faster finish.

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

Answer:

  1. N(4313, 583)

  2. N(5261, 807)

  1. What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?
leo_z <- (4948 - men_mean) / men_sd
mary_z <- (5513 - women_mean) / women_sd

print(c(leo_z, mary_z))
## [1] 1.0891938 0.3122677

ANSWER:

Both Leo and Mary performed worse than average in their respective groups. Leo’s finish time was above the mean by over 1 standard deviation, while Mary’s finish time was above the mean by .31

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

ANSWER:

Relatively speaking, Mary performed better than Leo because her finish time was .31 standard deviations above the group mean, while Leo’s finish time was 1.08 standard deviations above the group mean. (remember that a higher finish time is worse in a race)

  1. What percent of the triathletes did Leo finish faster than in his group?
1 - pnorm(1.089)
## [1] 0.1380769
  1. What percent of the triathletes did Mary finish faster than in her group?
1 - pnorm(.3122)
## [1] 0.3774443
  1. If the distributions of finishing times are not nearly normal, would your answers to parts (b) - (e) change? Explain your reasoning.

ANSWER:

All answers would change except for (b). Z-Score calculation would be the same, regardless of whether or not the underlying distribution is normal. However, even though the Z-Score’s remain the same, their usefullness changes. If the underlying distribution is not normal, then using the Z-Scores in the pnorm() function would provide incorrect probabilities.


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.
mean_heights <- 61.52
sd_heights <- 4.58
pnorm(mean_heights+sd_heights,mean=mean_heights,sd=sd_heights) - 
  pnorm(mean_heights-sd_heights,mean=mean_heights,sd=sd_heights)
## [1] 0.6826895
pnorm(mean_heights+2*sd_heights,mean=mean_heights,sd=sd_heights) - 
  pnorm(mean_heights-2*sd_heights,mean=mean_heights,sd=sd_heights)
## [1] 0.9544997
pnorm(mean_heights+3*sd_heights,mean=mean_heights,sd=sd_heights) - 
  pnorm(mean_heights-3*sd_heights,mean=mean_heights,sd=sd_heights)
## [1] 0.9973002
  1. Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.

qqnormsim(heights)

ANSWER:

Yes, the data appears to follow a normal distribution. The histogram is bell-shaped with no significant skew. When looking at the QQ-plot, we see that the data falls nicely along the diagonal, other than a slight deviation towards the upper values. Still, when comparing this QQ-plot against simulated QQ-plots, we see this sort of deviation can be expected.


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?

Here we want to use Geometric distribution, which helps us answer the question “what is the probability of first success at n trial?”

p=.02
n=10

probability <- (1-p)^(n-1)*p

probability
## [1] 0.01667496
  1. What is the probability that the machine produces no defective transistors in a batch of 100?
(1-p)^100
## [1] 0.1326196
  1. On average, how many transistors would you expect to be produced before the first with a defect? What is the standard deviation?
geom_mean <- 1/p

geom_sd <- sqrt((1-p)/(p^2))

print(c(geom_mean, geom_sd))
## [1] 50.00000 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?
new_p <- .05

geom_mean <- 1/new_p

geom_sd <- sqrt((1-new_p)/(new_p^2))

print(c(geom_mean, geom_sd))
## [1] 20.00000 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?

ANSWER:

As probability of “success” increases, mean and standard deviation decrease.

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.
```r p <- .51 n <- 3 k <- 2
probability <- choose(3,2) * (p^k) * (1-p)^(n-k)
probability ```
## [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.
ANSWER:
(boy, boy, girl), (boy, girl, boy), (girl, boy, boy)
```r singple_p <- .51.51.49
singple_p*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).
r choose(8,3)
## [1] 56
ANSWER:
With “8 choose 3”, there are 56 unique orderings that would need to be written down. This would be very tedious.

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?
p <- .15
n <- 10
k <- 3

probability <- choose(n-1,k-1) * (p^k)*((1-p)^(n-k))

probability
## [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?

ANSWER:

Given that she has served 2 successful shots in 9 attempts, the probability that the 10th attempt will be a success is just the probability of success: 0.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?

ANSWER:

The discrepancy is due to the fact that (a) wanted us to find the probability that the 10th shot is the third success, considering all possible outcomes for the first 9 shots. However for (b), they want us to find the probability that the 10th shot is the third success, GIVEN than the first 9 shots had two successes.