Answer2.6b <- 4 * (1 / 6 * 1 /6)
Answer2.6b
## [1] 0.1111111
Answer2.6c <- 1 / 6 * 1 / 6
Answer2.6c
## [1] 0.02777778
BelowPoverty <- .146
NotEngHome <- .207
PovAndNotEng <- .042
# uploading Venn2.jpeg to github in the interest of time (gave troubleshooting 90min but couldn't get the image embedded using knitr, readjpeg, imager, raster, etc.)
# 
Answer2.8c <- BelowPoverty - PovAndNotEng
Answer2.8c
## [1] 0.104
Answer2.8d <- BelowPoverty + NotEngHome - PovAndNotEng
Answer2.8d
## [1] 0.311
Answer2.8e <- 1 - (BelowPoverty + NotEngHome - PovAndNotEng)
Answer2.8e
## [1] 0.689
# If indepedent, then P(A or B) = P(A) * P(B) should be true
Answer2.8f <- (BelowPoverty + NotEngHome - PovAndNotEng) == BelowPoverty * NotEngHome
Answer2.8f
## [1] FALSE
Self.Blue <- c(78, 23, 13)
Self.Brown <- c(19, 23, 12)
Self.Green <- c(11, 9, 16)
Assort.Mate <- rbind(Self.Blue, Self.Brown, Self.Green)
Assort.Mate <- cbind(Assort.Mate, rowSums(Assort.Mate))
colnames(Assort.Mate) <- c("Partner.Blue", "Partner.Brown", "Partner.Green", "Partner.Total")
Assort.Mate <- rbind(Assort.Mate, colSums(Assort.Mate))
rownames(Assort.Mate)[4] <- "Self.Total"
AM <- data.frame(Assort.Mate)
str(AM)
## 'data.frame': 4 obs. of 4 variables:
## $ Partner.Blue : num 78 19 11 108
## $ Partner.Brown: num 23 23 9 55
## $ Partner.Green: num 13 12 16 41
## $ Partner.Total: num 114 54 36 204
Answer2.20a <- (AM["Self.Blue", "Partner.Total"] + AM["Self.Total", "Partner.Blue"] - AM["Self.Blue", "Partner.Blue"]) / AM["Self.Total", "Partner.Total"]
Answer2.20a
## [1] 0.7058824
Answer2.20b <- AM["Self.Blue", "Partner.Blue"] / AM["Self.Blue", "Partner.Total"]
Answer2.20b
## [1] 0.6842105
Answer2.20c1 <- AM["Self.Brown", "Partner.Blue"] / AM["Self.Brown", "Partner.Total"]
Answer2.20c1
## [1] 0.3518519
(c cont’d) 30.6% is the probability that random chosen male respondent with green eyes has partner with blue eyes.
Answer2.20c2 <- AM["Self.Green", "Partner.Blue"] / AM["Self.Green", "Partner.Total"]
Answer2.20c2
## [1] 0.3055556
Type.Fiction <- c(13, 59, 72)
Type.Nonfiction <- c(15, 8, 23)
Type.Total <- c(28, 67, 95)
Bookshelf <- rbind(Type.Fiction, Type.Nonfiction, Type.Total)
colnames(Bookshelf) <- c("Format.Hardcover", "Format.Paperback", "Format.Total")
BS <- data.frame(Bookshelf)
str(BS)
## 'data.frame': 3 obs. of 3 variables:
## $ Format.Hardcover: num 13 15 28
## $ Format.Paperback: num 59 8 67
## $ Format.Total : num 72 23 95
Answer2.30a <- (BS["Type.Total", "Format.Hardcover"] / BS["Type.Total", "Format.Total"]) * (BS["Type.Fiction", "Format.Paperback"] / (BS["Type.Total", "Format.Total"] - 1))
Answer2.30a
## [1] 0.1849944
Answer2.30b <- (BS["Type.Fiction", "Format.Total"] / BS["Type.Total", "Format.Total"]) * (BS["Type.Total", "Format.Hardcover"] / (BS["Type.Total", "Format.Total"] - 1))
Answer2.30b
## [1] 0.2257559
Answer2.30c <- (BS["Type.Fiction", "Format.Total"] / BS["Type.Total", "Format.Total"]) * (BS["Type.Total", "Format.Hardcover"] / BS["Type.Total", "Format.Total"])
Answer2.30c
## [1] 0.2233795
x <- c(0, 25, 35)
Px <- c(.54, .34, .12)
Ex <- x * Px
ProbTable2.38 <- rbind(x, Px, Ex)
colnames(ProbTable2.38) <- c("No bag", "One checked", "Two checked")
ProbTable2.38 <- data.frame(ProbTable2.38)
ProbTable2.38
## No.bag One.checked Two.checked
## x 0.00 25.00 35.00
## Px 0.54 0.34 0.12
## Ex 0.00 8.50 4.20
(a cont’d) $12.70 is the average revenue per passenger.
Answer2.38a1 <- sum(Ex)
Answer2.38a1
## [1] 12.7
(a cont’d) $14.37 is the standard deviation.
xLessEx <- (x - Ex)
xLessExSquared <- xLessEx^2
xLessExSquaredbyProb <- xLessExSquared * Px
ProbTable2.38 <- rbind(ProbTable2.38, xLessEx, xLessExSquared, xLessExSquaredbyProb)
rownames(ProbTable2.38)[4:6] <- c("(x - Ex)", "(x - Ex)^2", "(x - Ex)^2 * Px")
ProbTable2.38
## No.bag One.checked Two.checked
## x 0.00 25.000 35.0000
## Px 0.54 0.340 0.1200
## Ex 0.00 8.500 4.2000
## (x - Ex) 0.00 16.500 30.8000
## (x - Ex)^2 0.00 272.250 948.6400
## (x - Ex)^2 * Px 0.00 92.565 113.8368
Varx <- sum(xLessExSquaredbyProb)
Answer2.38a2 <- sqrt(Varx)
Answer2.38a2
## [1] 14.36669
x.b <- c(0, 120*25, 120*35)
Px.b <- c(.54, .34, .12)
Ex.b <- x.b * Px.b
ProbTable2.38b <- rbind(x.b, Px.b, Ex.b)
colnames(ProbTable2.38b) <- c("No bag", "One checked", "Two checked")
ProbTable2.38b <- data.frame(ProbTable2.38b)
ProbTable2.38b
## No.bag One.checked Two.checked
## x.b 0.00 3000.00 4200.00
## Px.b 0.54 0.34 0.12
## Ex.b 0.00 1020.00 504.00
xLessEx.b <- (x.b - Ex.b)
xLessExSquared.b <- xLessEx.b^2
xLessExSquaredbyProb.b <- xLessExSquared.b * Px.b
ProbTable2.38b <- rbind(ProbTable2.38b, xLessEx.b, xLessExSquared.b, xLessExSquaredbyProb.b)
rownames(ProbTable2.38b)[4:6] <- c("(x - Ex)", "(x - Ex)^2", "(x - Ex)^2 * Px")
ProbTable2.38b
## No.bag One.checked Two.checked
## x.b 0.00 3000.00 4200.00
## Px.b 0.54 0.34 0.12
## Ex.b 0.00 1020.00 504.00
## (x - Ex) 0.00 1980.00 3696.00
## (x - Ex)^2 0.00 3920400.00 13660416.00
## (x - Ex)^2 * Px 0.00 1332936.00 1639249.92
Varx.b <- sum(xLessExSquaredbyProb.b)
Answer2.38b <- sqrt(Varx.b)
Answer2.38b
## [1] 1724.003
Answer2.44b <- .022 + .047 + .158 + .183 + .212
Answer2.44b
## [1] 0.622
Answer2.44c <- Answer2.44b * .41
Answer2.44c
## [1] 0.25502