Discrete Random Variable
coin3 <- data.frame(N_Heads = c(0, 1, 2, 3), C_Heads = c(1, 3, 3, 1))
attach(coin3)
coin3$P_Heads <- C_Heads/sum(C_Heads)
options(repr.plot.width=7, repr.plot.height=4)
barplot(coin3$P_Heads, names = coin3$N_Heads, main = "Discrete Probability Distribution of flipping three coins")
Expected Value
attach(coin3)
E_X=sum(N_Heads * P_Heads)
E_X
Variance
fees = data.frame(N_Bags = c(0, 1, 2), X = c(0, 25,60), P_X = c(0.54, 0.34, 0.12))
fees
attach(fees)
E_X <- sum(X * P_X)
cat("The expected revenue per passenger is $", E_X)
var <- sum((X-E_X)^2 * P_X)
cat("The expected revenue per passenger is $", var)
Normal Approximation
normal_dist <- function(x, b){
mu = mean(x)
sigma = sd(x)
x1 <- seq(mu - 6*sigma, mu + 6*sigma, length = 100)
# Normal curve
fun <- dnorm(x1, mean = mu, sd = sigma)
# Histogram
options(repr.plot.width=7, repr.plot.height=4)
hist(x, prob = TRUE, col = "white", breaks = b,
xlim = c(mu - 6*sigma, mu + 6*sigma),
ylim = c(0, max(fun)),
main = "Histogram overlayed with normal curve")
lines(x1, fun, col = 2, lwd = 2)
}
data(chickwts)
attach(chickwts)
normal_dist(chickwts$weight, 10)
Test of Normality
shapiro.test(chickwts$weight)
Z-Score
chickwts$zscore = (weight - mean(weight))/sd(weight)
tail(chickwts)
Problems from the Book
Solution
z_sophiaV = (160 - 151)/7
z_sophiaQ = (157 - 153)/7.67
cat("Z Score for Verbal= ", round(z_sophiaV,2), "\nZ Score for Quantitative Reasoning= ", round(z_sophiaQ, 2))
input_1
z_sophiaV = (160 - 151)/7
z_sophiaQ = (157 - 153)/7.67
cat("Z Score for Verbal= ", round(z_sophiaV,2), "\nZ Score for Quantitative Reasoning= ", round(z_sophiaQ, 2))