Chapter 2 - Probability
Practice: 3.1 (see normalPlot), 3.3, 3.17 (use qqnormsim from lab 3), 3.21, 3.37, 3.41
Graded: 3.2 (see normalPlot), 3.4, 3.18 (use qqnormsim from lab 3), 3.22, 3.38, 3.42
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.
(a) Z>-1.13 = .871
#load DATA606 library
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:lattice':
##
## ethanol, lsegments
## The following objects are masked from 'package:datasets':
##
## cars, chickwts, trees
## Loading required package: OIdata
## Loading required package: RCurl
## Warning: package 'RCurl' was built under R version 3.3.3
## Loading required package: bitops
## Loading required package: maps
## Warning: package 'maps' was built under R version 3.3.3
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following object is masked from 'package:openintro':
##
## diamonds
## Loading required package: markdown
## Warning: package 'markdown' was built under R version 3.3.3
##
## 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
normalPlot(bounds = c(-1.13,Inf))
(b) Z<0.18 = .571
normalPlot(bounds = c(-Inf,.18))
(c) Z>8 = .000
normalPlot(bounds = c(8,Inf))
(d) |Z| < 0.5 = .383
normalPlot(bounds = c(-.5,.5))
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 ???nished 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. (a) Write down the short-hand for these two normal distributions.
Men 30-34: \[N(\mu = 4313, \sigma = 583)\]
Women 25-29: \[N(\mu = 5261, \sigma = 807)\]
(b) What are the Z-scores for Leo’s and Mary’s finishing times? What do these Z-scores tell you?
#Z-score derived by (individual measure - mean)/sd
#Leo
Leo_z <- (4948-4313)/583
print("Leo's Z score:")
## [1] "Leo's Z score:"
Leo_z
## [1] 1.089194
#Mary
Mary_z <- (5513-5261)/807
print("Mary's Z score:")
## [1] "Mary's Z score:"
Mary_z
## [1] 0.3122677
#pnorm converts z-score to probability
#lower is better, so take 1 - probability of z-score to show percentage Leo beat
1-pnorm(Leo_z)
## [1] 0.1380342
(e) What percent of the triathletes did Mary finish faster than in her group?
#pnorm converts z-score to probability
#lower is better, so take 1 - probability of z-score to show percentage Mary beat
1-pnorm(Mary_z)
## [1] 0.3774186
3.18 Heights of female college students. Below are heights of 25 female college students.
Load the heights into vector.
female_college_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)
summary(female_college_heights)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 54.00 58.00 61.00 61.52 64.00 73.00
fch_mean <- mean(female_college_heights)
print("standard deviation:")
## [1] "standard deviation:"
fch_sd <- sd(female_college_heights)
fch_sd
## [1] 4.583667
(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.
Spin up a histogram for visualization.
hist(female_college_heights)
Look at the SD rules of thumb:
#Check within 1 SD
fch_sd1_lower <- fch_mean - fch_sd
fch_sd1_upper <- fch_mean + fch_sd
print("Within one SD - should be close to 68% if normal")
## [1] "Within one SD - should be close to 68% if normal"
sum(female_college_heights > fch_sd1_lower & female_college_heights < fch_sd1_upper)/length(female_college_heights)
## [1] 0.68
#Check within 2 SD
fch_sd2_lower <- fch_mean - (fch_sd * 2)
fch_sd2_upper <- fch_mean + (fch_sd * 2)
print("Within two SD - should be close to 96% if normal")
## [1] "Within two SD - should be close to 96% if normal"
sum(female_college_heights > fch_sd2_lower & female_college_heights < fch_sd2_upper)/length(female_college_heights)
## [1] 0.96
#Check within 3 SD
fch_sd3_lower <- fch_mean - (fch_sd * 3)
fch_sd3_upper <- fch_mean + (fch_sd * 3)
print("Within three SD - should be close to 99.7% if normal")
## [1] "Within three SD - should be close to 99.7% if normal"
sum(female_college_heights > fch_sd3_lower & female_college_heights < fch_sd3_upper)/length(female_college_heights)
## [1] 1
Based on this analysis, the heights approximate the distribution rule.
(b) Do these data appear to follow a normal distribution? Explain your reasoning using the graphs provided below.
Use qqnormsim per the homework instructions.
qqnormsim(female_college_heights)
Yes, the simulated normal data closely approximates our height data.
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 ???rst with a defect? - cdf
p_defective = .02
p_success = 1 - p_defective
p_success^9 * p_defective
## [1] 0.01667496
With dgeom
#9 is number of successes before first failure
dgeom(9,.02)
## [1] 0.01667496
(b) What is the probability that the machine produces no defective transistors in a batch of 100?
.98^100
## [1] 0.1326196
Alternatively, using dbinom
dbinom(0,100,.02)
## [1] 0.1326196
(c) On average, how many transistors would you expect to be produced before the ???rst with a defect? What is the standard deviation?
print("We would expect the first defect to be produced at number:")
## [1] "We would expect the first defect to be produced at number:"
1/.02
## [1] 50
print("The standard deviation is:")
## [1] "The standard deviation is:"
#sqrt((1-p)/p^2)
sqrt((1-.02)/(.02^2))
## [1] 49.49747
(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 ???rst with a defect? What is the standard deviation?
print("We would expect the first defect to be produced at number:")
## [1] "We would expect the first defect to be produced at number:"
1/.05
## [1] 20
print("The standard deviation is:")
## [1] "The standard deviation is:"
#sqrt((1-p)/p^2)
sqrt((1-.05)/(.05^2))
## [1] 19.49359
(e) Based on your answers to parts (c) and (d), how does increasing the probability of an event a???ect the mean and standard deviation of the wait time until success?
Increasing the probability of an event lowers the mean and standard deviation of the estimated wait time until success.
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.
p = probabiliy of success n = number of trials k = number of successes in \(n\)
\[n!/({k!(n-k)!})*p^k * (1-p)^{(n-k)}\]
p = .51
n = 3
k = 2
factorial(n)/(factorial(k)*factorial(n-k)) * p^k * (1-p)^(n-k)
## [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. Con???rm that your answers from parts (a) and (b) match.
BBB BBG BGB BGG GBB GBG GGB GGG
#BBG; BGB; GGB
#tempting to just write 3/8 here and assume .5 boy/girl probability
#BBG + BGB + GGB
(.51 * .51 * .49) + (.51 * .49 * .51) + (.49 * .51 * .51)
## [1] 0.382347
(c) If we wanted to calculate the probability that a couple who plans to have 8 kids will have 3 boys, brie???y describe why the approach from part (b) would be more tedious than the approach from part (a).
We go from 2^3 possibilities for births to 2^8, an exponential growth that becomes harder to do by hand.
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?
p = .15
n = 10
k = 3
factorial(n-1)/(factorial(k-1)*factorial(n-k)) * p^k * (1-p)^(n-k)
## [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?
It’s still 15%. Independent event.
(c) Even though parts (a) and (b) discuss the same scenario, the probabilities you calculated should be di???erent. Can you explain the reason for this discrepancy?
The scenario in A means that she made 2 of her first 9 and then makes the 10th. This is a very specific scenario. The scenario in B describes an independent 10th serve, which has the regular 15% chance of being made regardless of the outcomes of the nine previous serves. With A, you’re essentially saying what’s the probability that you made 2 of 9, and then multiply that by the .15 chance you’ll make the 10th attempt. It’s a negative binomial distribution.