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.
## 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
za <- -1.35 #Z score needs to be below -1.35
sd <- 1 # standard deviation is 1
m <- 0 # mean is 0
# from this we can find the observeation for za
oa <- (sd * za)+m
oa
## [1] -1.35
# using pnorm to calculate the percentile
pnorm(oa, mean = 0, sd=1, lower.tail = TRUE)
## [1] 0.08850799
Area under the curve for -135 is 0.088
# using normalPlat function to plot the normal distribution
normalPlot(mean=0, sd=1, bounds = c(oa), tails = TRUE)
zb <- 1.48 #Z score needs to be above 1.48
# from this we can find the observeation for zb
ob <- (sd * zb)+m
ob
## [1] 1.48
# using pnorm to calculate the percentile
pnorm(ob, mean = 0, sd=1, lower.tail = FALSE)
## [1] 0.06943662
Area under the curve for 148 and above is 0.069
# using normalPlat function to plot the normal distribution
normalPlot(mean=0, sd=1, bounds = c(ob, 4))
zclower <- -0.4 #Z score needs to be between -0.4 and 1.5
zcupper <- 1.5 #Z score needs to be between -0.4 and 1.5
# from this we can find the observeation for zc
oclower <- (sd * zclower)+m
ocupper <- (sd * zcupper)+m
oclower
## [1] -0.4
ocupper
## [1] 1.5
# using normalPlat function to plot the normal distribution
normalPlot(mean=0, sd=1, bounds = c(oclower, ocupper))
** The area under the curve is 0.589**
zdlower <- -2 #Z needs to be greater than 2 and lower than -2
zdupper <- 2
odlower <- (sd * zdlower)+m
odupper <- (sd * zdupper)+m
odupper
## [1] 2
odlower
## [1] -2
#area below the curve that observation is less than -2 and area below the curve that the observation is greater than 2
# using normalPlat function to plot the normal distribution
normalPlot(mean=0, sd=1, bounds = c(odlower), tails = TRUE)
normalPlot(mean=0, sd=1, bounds = c(odupper, 4))
pnorm(odlower, mean = 0, sd=1, lower.tail = TRUE)
## [1] 0.02275013
pnorm(odupper, mean=0, sd=1, lower.tail = FALSE)
## [1] 0.02275013
Area under the curve for each plot is 0.0227= Total area= 0.0454
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.
Mens, Ages 30-34
\[N(\mu = 4313, \sigma = 583)\] Womens, Ages 25-29
\[N(\mu = 5261, \sigma = 807)\]
# looking at the normal distribution plot for Mens
normalPlot(mean=4313, sd=583)
# Z score for Leo
zl <- (4948-4313)/583
zl
## [1] 1.089194
# looking at the normal distribution for women
normalPlot(mean=5261, sd=807)
# calculating z score for Mary
zm <- (5513-5261)/807
zm
## [1] 0.3122677
The z score for Leo is 1.089 ; meaning Leo’s time is over 1 standard deviation away from the mean. Which means 1.089 standard deviation above the mean. On the other hand, Mary’s z score is 0.312 which is less than half standard deviation away from the mean(above the mean). In this case, Mary did better than Leo within her group because it is closer to the mean which is time in seconds to finish the triatlhon. (considering having high seconds in terms of finishing a triathlon is not a good thing)
# calculating Leo's percentile
pnorm(4948, mean = 4313, sd=583, lower.tail = TRUE)
## [1] 0.8619658
Percentile for Leo is 86%. He finish time was higher than 86% of the group. His finish time was lower(better) than 100-86= 14% of the group.
# calculating Mary's percentile
pnorm(5513, mean = 5261, sd=807, lower.tail = TRUE)
## [1] 0.6225814
Mary’s percentile is 62%. Mary’s finish time was higher than 62% of the group. Her finish time was lower(better) than 100-62=38 % of the group.
Yes, my responses to those questions would be different. If the distribution is not normal, we can not calculate the percentile. The density of the distribution would be different.
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} \]
In order to find out if the heights follow the 68-95-99.7% rule, we need to look at the distribution and confirm.
68% of the heights fall within 1 standard deviation away from the mean
95% of the heights fall within 2 standard deviation away from the mean
99.7% of the heights fall within 3 standard deviation away from the mean
This is used for normal distribution.
# creating the heights
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)
heights
## [1] 54 55 56 56 57 58 58 59 60 60 60 61 61 62 62 63 63 63 64 65 65 67 67
## [24] 69 73
# Use the DATA606::qqnormsim function
qqnormsim(heights)
We can see that there is a linear relationship for each plot outlined here. The Theoretical Quanties are following the normal distribution. We can confirm that the heights approximately follow the 68-95-99.7% rule.
As per the analysis provided in answer a, the data appear to follow normal distribution. When we look at the sample quantiles and theoretical quantiles we see the linear relationship. On the histrogram plot, we can see the normal distribution curve.
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-p)^{n-1}*p\]
p <- 0.02 # probability of defective
n <- 10 # 10 trials
(1-p)^(n-1)*p
## [1] 0.01667496
# no defective probability is 1- defective probability
p2 <- 1-p
n2 <- 100 # 100 trials
(1-p2)^(n2-1)*p2
## [1] 6.211488e-169
\[\mu = 1/p\]
m <- 1/p
m
## [1] 50
The mean is 50. On average 50 transistors would be produced before the first defect.
\[\sigma = \sqrt{(1-p)/p^2}\]
sd <- sqrt((1-p)/p^2)
sd
## [1] 49.49747
Standard deviation is 49.4.
p3 <- 0.05
m3 <- 1/p3
m3
## [1] 20
On average 20 transistors would be produced before the first defect.
sd3 <- sqrt((1-p3)/p3^2)
sd3
## [1] 19.49359
Standard deviation is 19.4
Increasing the probability of an event decreases the mean and standard deviation.
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.
pb <- 0.51 # probability of success
nb <- 3 # number of trials
kb <- 2 # number of success
dbinom(kb,nb,pb)
## [1] 0.382347
1- Boy, Boy, Girl 2- Boy, Girl, Boy 3- Girl, Boy, Boy
pg <- 1-pb
p1 <- pb*pb*pg
p2 <- pb*pg*pb
p3 <- pg*pb*pb
p1+p2+p3
## [1] 0.382347
Confirming answer a and answer b matches.
We increased the trial number from 3 to 8 and success number from 2 to 3. It would be a lot harder for us to outline each possibility option manually. So option b would be much harder. On the other hand, we can use the dbinom function to calculate the probability of k success in n trial.
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.
nv <- 9 # number of trials (10th try)
pv <- 0.15 # probability of success
kv <- 2 # number of success (3rd successfull serve)
dbinom(kv, nv, pv)*0.15 # on her 10th try to get the 3rd success probability is 0.15 again.
## [1] 0.03895012
They are independent events as per the question so the probability of her serving successfully would be same 0.15
Part b is calculating the probability of success for an event, which is provided by the question. In part a we are looking at all the probabilities for up to 10th try and multiplying them together for exact 3 successes out of 10 attempts.