round(10/52, 4)
## [1] 0.1923
round(10/36 ,4)
## [1] 0.2778
m <- c(233, 159, 102, 220, 250)
f <- c(208, 138, 280, 265, 146)
class <- c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")
df <- data.frame(class, m, f)
names(df) <- c("Class", "Males", "Females")
df
## Class Males Females
## 1 Apartment 233 208
## 2 Dorm 159 138
## 3 With Parent(s) 102 280
## 4 Sorority/Fraternity House 220 265
## 5 Other 250 146
round(sum(df$Males) / (sum(df$Males) + sum(df$Females)), 4)
## [1] 0.4818
c1 <- 13/52
c2 <- 26/52
c3 <- 12/52
round(c1*c2*c3, 4)
## [1] 0.0288
pA <- 13/52
pB <- 13/51
pAandB <- pA * pB
round(pAandB/pA, 4)
## [1] 0.2549
pA <- 13/52
pB <- 25/51
round(pA * pB, 4)
## [1] 0.1225
m <- c(12, 19, 12, 7)
f <- c(12, 15, 4, 4)
grade <- c("Freshmen", "Sophomores", "Juniors", "Seniors")
df <- data.frame(grade, m, f)
names(df) <- c("Level","Males", "Females")
df
## Level Males Females
## 1 Freshmen 12 12
## 2 Sophomores 19 15
## 3 Juniors 12 4
## 4 Seniors 7 4
p1 <- 4/85
p2 <- 12/84
p3 <- round(p1 * p2, 4)
p3
## [1] 0.0067
P_m <- 141/300
P_mANDd<- 52/300
round(P_mANDd / P_m, 4)
## [1] 0.3688
P_d <- 102/300
round(P_mANDd / P_d, 4)
## [1] 0.5098
6 * 5 * 3
## [1] 90
factorial(5)
## [1] 120
permutation = function(n, r) {
factorial(n) / factorial(n-r)
}
permutation(8, 5)
## [1] 6720
## [1] 6720
factorial(9) / (factorial(3) * factorial(5) * factorial(1))
## [1] 504
combination = function(n, r) {factorial(n) / (factorial(n-r) * factorial(r))}
combination(14,6)
## [1] 3003
combination(52, 3)
## [1] 22100
12 * 9 * 5
## [1] 540
permutation(26, 5) * permutation(10, 3)
## [1] 5683392000
permutation(9, 4)
## [1] 3024
combination(11, 8)
## [1] 165
permutation(12, 8) / combination(12, 4)
## [1] 40320
permutation(13, 7)
## [1] 8648640
factorial(10) / (factorial(2) * factorial(2))
## [1] 907200
x <- c(5, 6, 7, 8, 9)
px <- c(0.1, 0.2, 0.3, 0.2, 0.2)
df <- data.frame(x, px)
df
## x px
## 1 5 0.1
## 2 6 0.2
## 3 7 0.3
## 4 8 0.2
## 5 9 0.2
class(df)
## [1] "data.frame"
str(df)
## 'data.frame': 5 obs. of 2 variables:
## $ x : num 5 6 7 8 9
## $ px: num 0.1 0.2 0.3 0.2 0.2
step1
expvalue <- sum(df$x * df$px)
expvalue
## [1] 7.2
step2
variance <- sum((df$x - expvalue)^2 * df$px)
variance
## [1] 1.56
step3
sd <- sqrt(variance)
sd
## [1] 1.249
step4
with(df, sum(px[x >= 9]))
## [1] 0.2
step5
with(df, sum(px[x <= 7]))
## [1] 0.6
px <- 188/376
#step 1
eV <- round(23*(px^3) - 4*(1-px^3), 2)
eV
## [1] -0.62
#step2
eV * 994
## [1] -616.28
#step 1
Pwin <- pbinom(8, size=11, prob=1/2)
eV <- round(1 * Pwin - 7 * (1-Pwin), 2)
eV
## [1] 0.74
#step 2
eV * 615
## [1] 455.1
#step 1
win <- 13/52 * 12/51
ev <- round(Pwin * 583 - (1 - win) * 35, 2)
ev
## [1] 530.99
#step 2
ev * 632
## [1] 335585.7
#P(X>=2)
round(pbinom(2, 10, .3), 3)
## [1] 0.383
5 * .3
## [1] 1.5
round(ppois(5, 5.5, lower=FALSE), 4)
## [1] 0.4711
round(ppois(4, 5.7, lower=FALSE), 4)
## [1] 0.6728
crash <- 0.4 * 7
round(ppois(1, crash), 4)
## [1] 0.2311
round(phyper(1, m=6, n=19, 8, lower.tail=FALSE), 3)
## [1] 0.651
round(phyper(6, m=10, n=15, 8), 3)
## [1] 0.998
Z = (979-1300)/(40000)^(1/2)
Z
## [1] -1.605
round(pnorm(979, mean=1300, sd=(40000)^0.5, lower.tail=FALSE),4)
## [1] 0.9458
round(pnorm(8340, mean=11000, sd=(1960000)^0.5,lower.tail=FALSE),4)
## [1] 0.9713
round(pnorm(85, mean=80, sd=3, lower.tail=TRUE) - pnorm(83, mean=80, sd=3, lower.tail=TRUE),4)
## [1] 0.1109
465 + .36*123 # 0.36 is z-value with the closest probability to 14% (0.14)
## [1] 509.28
# Lowest 7%
6.13 - 1.48 * 0.06
## [1] 6.0412
# Upper 7%
6.13 + 1.48 * 0.06
## [1] 6.2188
round(78.8 - 0.84 * 9.8) # bottom limit
## [1] 71
round(78.8 + 0.13 * 9.8) # upper limit
## [1] 80
round(21.2 + 0.13 * 5.4,1)
## [1] 21.9
round(pnorm(11, mean=13.59, sd=(12.3669)^0.5, lower.tail = TRUE),4)
## [1] 0.2307
s <- 7/(147)^0.5
round(pnorm(48.83,mean=48, sd=s, lower.tail = FALSE),4)
## [1] 0.0753
s <- 10/(68)^0.5
round(pnorm(93.54,mean=91,sd=s,lower.tail = FALSE),4)
## [1] 0.0181
se <- (0.07*0.93/540)^0.5
round(pnorm(0.10, mean = 0.07, sd = se, lower.tail = TRUE) - pnorm(0.04, mean = 0.07, sd = se, lower.tail = TRUE),4)
## [1] 0.9937
se <- (0.23*0.77/602)^0.5
round(1 - (pnorm(0.27, mean = 0.23, sd = se, lower.tail = TRUE) - pnorm(0.19, mean = 0.23, sd = se, lower.tail = TRUE)),4)
## [1] 0.0197
# Since we're using a sample standard deviation, we use T distribution
z <- abs(qt(0.10,207)) # 2-tailed, so 10% each side
lower <- round(3.9 - z*sqrt(0.8),1)
upper <- round(3.9 + z*sqrt(0.8),1)
The confidence interval is 2.8 to 5.
z <- abs(qt(0.01,7471))
lower <- round(16.6 - z*sqrt(11),1)
upper <- round(16.6 + z*sqrt(11),1)
The upper-right graph describes this problem visually. t=-1.7056179.
sam <- c(383.6,347.1,371.9, 347.6, 325.8, 337)
m <- round(mean(sam),2)
stdDev <- round(sd(sam),2)
t <- round(abs(qt(0.05,5)),3)
lower <- round(m - (stdDev/sqrt(6)) * t,2)
upper <- round(m + (stdDev/sqrt(6)) * t,2)
The sample mean is 352.17. The standard deviation of the sample is 21.68. The critical value is 2.015. Our 90% confidence interval would be from 334.34 to 370.
#step 1
t <- abs(round(qt(0.10,15),3))
#step 2
lower = round(46.4 - (2.45/sqrt(16) * t),1)
upper = round(46.4 + (2.45/sqrt(16) * t),1)
The confidence interval for the mean is 45.6 to 47.2.
z <- abs(qnorm(0.005,mean=0, sd = 1))
ceiling((z^2 * 1.9^2)/0.13^2)
## [1] 1418
z <- abs(qnorm(0.025,mean=12.6,sd=sqrt(3.61)))
ceiling((z^2 * 3.61)/0.19^2)
## [1] 7879
#step 1
p <- 1 - 1734/2089
p
## [1] 0.1699378
#step 2
z <- abs(qnorm(0.01, mean = 0, sd = 1))
lower <- round(p - (z * sqrt((p*(1-p))/2089)),3)
upper <- round(p + (z * sqrt((p*(1-p))/2089)),3)
The lower limit is 0.151 and the upper limit is 0.189.
#step 1
p <- 156 / 474
p
## [1] 0.3291139
#step 2
z <- abs(qnorm(0.025, mean = 0, sd = 1))
lower <- round(p - (z * sqrt((p*(1-p))/474)),3)
upper <- round(p + (z * sqrt((p*(1-p))/474)),3)
The lower limit is 0.287 and the upper limit is 0.371.