#Plots a QQ-Norm plot
library(StMoSim)
## Warning: package 'StMoSim' was built under R version 3.4.2
## Loading required package: RcppParallel
## Warning: package 'RcppParallel' was built under R version 3.4.2
## Loading required package: Rcpp
##
## Attaching package: 'Rcpp'
## The following object is masked from 'package:RcppParallel':
##
## LdFlags
library(DATA606)
##
## 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 II.
What percent of a standard normal distribution N(??=0,sd=1) is found in each region?
*a) Z > -1.13* *b) Z < 0.18* *c) Z > 8* *d)Z > 0.5*
pnorm(q=-1.13, mean=0, sd=1, , lower.tail=FALSE)
## [1] 0.8707619
#Plots a nomral distribution with the area within the given bounds shaded
#Inf and -Inf are positive and negative infinity
normalPlot(mean = 0, sd = 1, bounds= c(-1.13,Inf), tail=FALSE)
pnorm(q=0.18, mean=0, sd=1)
## [1] 0.5714237
normalPlot(mean = 0, sd = 1, bounds= c(-Inf, 0.18), tail=FALSE)
pnorm(q=8, mean=0, sd=1, lower.tail=FALSE)
## [1] 6.220961e-16
normalPlot(mean = 0, sd = 1, bounds= c(8, Inf), tail=FALSE)
pnorm(q=0.5, mean=0, sd=1, lower.tail=FALSE)
## [1] 0.3085375
normalPlot(mean = 0, sd = 1, bounds= c(0.5, Inf), tail=FALSE)
3.4 Triathlon times, part I.
In triathlons, it is common for reacers 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 how they did within their respective groups. Here is the information on the performance of their groups:
*The finishing times of the Men Ages 30-34 group has a mean = 4313 sec, sd = 583 sec*
*The finishing times of the Women Ages 25-29 group has a mean = 5261 sec, sd = 807 sec*
*The Distributions of finishing times for both groups are approximately Normal.*
Write down the shorthand for these two normal distributions.
Men Ages 30-34 group : N(?? = 4313,sd = 583)
Women Ages 25-29 group : N(?? = 5261,sd = 807)
What are the Z scores for Leo’s and Mary’s finishing times
Formula: Z Score = (X - ??)/sd
Leo’s Z score:
LeoZ <- (4948 - 4313)/583
Mary's Z score :
MaryZ <- (5513 - 5261)/807
Yes, Leo perfomed better than Mary because Mary’s percentil is 0.6217 lower than Leo’s percentil 0.8599
100 - (pnorm(q=LeoZ)*100)
## [1] 13.80342
100 - (pnorm(q=MaryZ)*100)
## [1] 37.74186
The answer will be the same, the number of standard deviations falls above or below the mean.
3.18 Heights of female college students.
Below are heights of 25 female college students.
f.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)
hist(f.heights)
qqnormSim(f.heights, nSim=100)
a) The mean height is 61.52 inches with a standard deviation of 4.58 inches. Use this info to determine whether the heights approximately follow the 68-95-99.7% rule.
*R:/ The observation sample of 25 female hights doesn’t follow the 68-95-99.7% rule, However, the sample data follow the Z = 1 & Z = -1 about 68% and Z = -2 and Z = 2 about 95% but the 99.7 reach the maximum value of the data set 73 with a value of 74.56367.
summary(f.heights)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 54.00 58.00 61.00 61.52 64.00 73.00
#probabilities for falling within 1,2 or 3 standard deviations of the mean in a normal distribution
# 68% of 25 is 17
#P = vector of probabilities
p.68 = f.heights[17]
p.68
## [1] 63
qnorm(p=0.68, mean=61.52, sd=4.58)
## [1] 63.66206
qnorm(p=0.34, mean=61.52, sd=4.58)
## [1] 59.63092
qnorm(p=0.95, mean=61.52, sd=4.58)
## [1] 69.05343
qnorm(p=0.05, mean=61.52, sd=4.58)
## [1] 53.98657
qnorm(p=0.9978, mean=61.52, sd=4.58)
## [1] 74.56367
qnorm(p=0.0121, mean=61.52, sd=4.58)
## [1] 51.19696
hist(f.heights, probability = TRUE, main = "Histogram of Women Height", col = "red")
x <- 50:75
y <- dnorm(x = x, mean = 61.52, sd = 4.58)
lines(x = x, y = y , col = "blue")
qqnorm(f.heights)
qqline(f.heights)
# 3.6.3 Geometric distribution
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.
Bernoulli distribution p = # of success /# of trials
Number of failures before success
#dgeom(x, prob, log = FALSE)
dgeom(10-1,0.02)
## [1] 0.01667496
#pgeom(q, prob, lower.tail = TRUE, log.p = FALSE)
pgeom(100,0.02)
## [1] 0.8700328
#The probability of failure
q = 1 - 0.02
q
## [1] 0.98
# in AVG the probability of failure
mean = 1/0.02
mean
## [1] 50
sqrt((1-0.02)/0.02^2)
## [1] 49.49747
mean2 = 1/0.05
mean2
## [1] 20
sqrt((1-0.05)/0.05^2)
## [1] 19.49359
When the probability of failure increases the probability of success decreases and of course the mean and the standard deviation also decreases.
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.
#This is conventionally interpreted as the number of 'successes' in size trials.
#dbinom(x, size, prob, log = FALSE)
dbinom(x=2,size=3,prob=0.51)
## [1] 0.382347
Write out all possible orderings of 3 children, 2 of whom are boys. Use these scenarios to calculate the same probability from part B-B-G B-G-B G-B-B
(0.51^2*0.49) + (0.51*0.49*0.51) + (0.49*0.51^2)
## [1] 0.382347
The approach from part (b) would be more tedious because manually I have to write all possible scenarios of 3 boys from 8 kids and then use the addition rule to find the answer while in option a) the function dbinom() will do the calculation given the x, size and prob parameters.
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.
choose(9,2)*0.15^3*(.85)^(7)
## [1] 0.03895012
The probabilty of having k successful serves in n independent attempts is the same so in this sample the probability that n serve will be 15%
Because in part (b) no matter what is the probabilities of the first 9 attempts, we are looking the probability of success on the 10 attempt. while in part (a) we are looking the probability of that the 3rd serve will be success in 10th attempts.