##
## 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.
What percent of a standard normal distribution N(µ = 0, σ = 1) is found in each region? Be sure to draw a graph.
percent = 0.8708
Z = x - µ / σ
mean <- 0
sd <- 1
Z <- -1.13
x <- Z * sd + mean
x## [1] -1.13
1 - pnorm(x, mean = 0, sd = 1)## [1] 0.8707619
normalPlot(mean = 0, sd = 1, bounds = c(-1.13, 4))mean <- 0
sd <- 1
Z <- 0.18
x <- Z * sd + mean
x## [1] 0.18
1 - pnorm(x, mean = 0, sd = 1)## [1] 0.4285763
normalPlot(mean = 0, sd = 1, bounds = c(-4, 0.18))mean <- 0
sd <- 1
Z <- 8
x <- Z * sd + mean
x## [1] 8
1 - pnorm(x, mean = 0, sd = 1)## [1] 6.661338e-16
normalPlot(mean = 0, sd = 1, bounds = c(8, 4)) (d) |Z| < 0.5
mean <- 0
sd <- 1
Z <- 0.5
x <- Z * sd + mean
x## [1] 0.5
1 - pnorm(x, mean = 0, sd = 1)## [1] 0.3085375
normalPlot(mean = 0, sd = 1, bounds = c(-4, 0.5))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.
Men: X = 4948 Mean = 4313 SD = 583
Women: X = 5513 Mean = 5261 SD = 807
Z = x - µ / σ
Z_Leo <- (4948 - 4313)/583
Z_Leo## [1] 1.089194
Leo’s Z score is 1.089 standard deviations from the mean. This Z scores corresponds to a percentile of approximately 86% which means that 86% of the other runners had a faster time than Leo.
Z_Mary <- (5513 - 5261)/807
Z_Mary## [1] 0.3122677
Mary’s Z score is .312 standard deviations from the mean. This Z scores corresponds to a percentile of approximately 62.3% or that 62.3% had a faster time than Mary.
Mary did better than Leo because her Z score is lower and her standard deviation from the mean is less.
pnorm(Z_Leo)## [1] 0.8619658
The percentile that Leo ranked higher than is:
pnorm(Z_Leo, lower.tail = FALSE)## [1] 0.1380342
#or
1-.86## [1] 0.14
or in other words he was only faster than 14% of the other male runners.
pnorm(Z_Mary)## [1] 0.6225814
Mary’s z score puts of .623 puts her in the percentile higher than:
pnorm(Z_Mary, lower.tail = FALSE)## [1] 0.3774186
#or
1- .623## [1] 0.377
Which means that Mary is faster than 37.7% of the other women runners.
Leo’s z score ranking of .86 describes the runners who had time faster than Leo’s.
Mary is faster than 37.7% of the other women runners.
Even if the distributions were not nearly normal, the rankings of Leo and Mary to their groups would be the same and the comparisons of the two groups to each other in terms of standard deviations from the mean would still be valid.
Below are heights of 25 female college students.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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
student.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)
table(student.heights)## student.heights
## 54 55 56 57 58 59 60 61 62 63 64 65 67 69 73
## 1 1 2 1 2 1 3 2 2 3 1 2 2 1 1
summary(student.heights)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 54.00 58.00 61.00 61.52 64.00 73.00
1st Standard Deviation above the mean:
pnorm(61.52 + 4.58, mean = 61.52, sd = 4.58)## [1] 0.8413447
2nd Standard Deviation above the mean:
pnorm(61.52 + 4.58 + 4.58, mean = 61.52, sd = 4.58)## [1] 0.9772499
3rd Standard Deviation above the mean:
pnorm(61.52 + 4.58 + 4.58 + 4.58, mean = 61.52, sd = 4.58)## [1] 0.9986501
The probability of falling within the first standard deviation above the mean is 84% while the 2nd and 3rd are closer to the 95% and 99.7% rule. It does not closely follow the 68-95-99.7% Rule.
hist(student.heights)qqnorm(student.heights)The histogram is clearly skewed from the center towards the lower heights and is not normally distributed.
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.
Probability of success in the nth trial = (1-p)^n-1 *p
(1-.02)**(10-1)*.02## [1] 0.01667496
#or
dgeom(10-1, .02)## [1] 0.01667496
(1-.02)**(100-1)*.02## [1] 0.002706522
#or
dgeom(100-1, .02)## [1] 0.002706522
The expected value of the number of transistors produced before the first defect is the mean µ = 1 / p
1/.02## [1] 50
The standard deviation is σ = ((1-p)/p2).5
((1-.02)/.02^2)^.5## [1] 49.49747
1/.05## [1] 20
The standard deviation is:
((1-.05)/.05^2)^.5## [1] 19.49359
The higher hte probability a defect will occur, the sooner you are likely the have a defect. The standard deviation gets lower as the defect probability increases.
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.
dbinom(2, size=3, prob=0.51)## [1] 0.382347
(.51)^2*.49*3## [1] 0.382347
Th addition of all the different scenarios is much more complicated with that number of trials or possibilities.
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.
dbinom(2, size=9, prob=0.15)*0.15## [1] 0.03895012
The probability is .15 because they are independent.
The probability for each serve to be successful is 15% independent of all the other serves. In part a we were discussing the probability that 2 serves in 9 have been successful and that the 10th is also a success.