Below are the solutions to these exercises on data display.
#################### # # # Exercise 1 # # # #################### n <- 100 p <- 0.3 #a dbinom(34, n, p)
## [1] 0.05788395
sum(dbinom(34:n, n, p))
## [1] 0.2207422
pbinom(34, n, p)
## [1] 0.8371417
#b sum(dbinom(30:60, n, p))
## [1] 0.5376603
#c qbinom(0.025,n,p)
## [1] 21
qbinom(0.975,n,p)
## [1] 39
#################### # # # Exercise 2 # # # #################### m <- 3 s <- 1 #a pnorm(2,m,s)
## [1] 0.1586553
pnorm(4,m,s) - pnorm(2,m,s)
## [1] 0.6826895
#b qnorm(0.025,m,s)
## [1] 1.040036
qnorm(0.975,m,s)
## [1] 4.959964
qnorm(0.5,m,s)
## [1] 3
#################### # # # Exercise 3 # # # #################### df <- 8 #a pt(1,df)
## [1] 0.8267032
1-pt(2,df)
## [1] 0.04025812
pt(1,df)-pt(-1,df)
## [1] 0.6534065
#b qt(0.025,df)
## [1] -2.306004
qt(0.5,df)
## [1] 0
1-qt(0.075,df)
## [1] 2.592221
#################### # # # Exercise 4 # # # #################### df <- 5 #a pchisq(2,df)
## [1] 0.150855
1-pchisq(4,df)
## [1] 0.549416
# OR pchisq(4,df,lower.tail = FALSE)
## [1] 0.549416
pchisq(6,df)-pchisq(4,df)
## [1] 0.243197
#b qchisq(0.025, df, lower.tail=TRUE)
## [1] 0.8312116
qchisq(0.5, df, lower.tail=TRUE)
## [1] 4.35146
qchisq(0.075, df, lower.tail=FALSE)
## [1] 10.00831
#################### # # # Exercise 5 # # # #################### df_1 <- 6 df_2 <- 3 pf(2, df_1, df_2)
## [1] 0.6958948
1 - pf(3, df_1, df_2)
## [1] 0.1977977
pf(4, df_1, df_2) - pf(1, df_1, df_2)
## [1] 0.4039858
qf(0.025,df_1, df_2)
## [1] 0.1515427
qf(0.975,df_1, df_2)
## [1] 14.73472
#################### # # # Exercise 6 # # # #################### data <- data.frame(case = factor(rep(c("A","B","C"), each=100)), gen = c(rbinom(100, 20, 0.3), rbinom(100, 20, 0.5), rbinom(100, 20, 0.7))) ggplot(data, aes(x=gen, fill=case)) + geom_density(alpha=.3)

#################### # # # Exercise 7 # # # #################### data <- data.frame(case = factor(rep(c("A","B","C"), each=100)), gen = c(rnorm(100, 0, 1), rnorm(100, 0, 3), rnorm(100, 0, 7))) ggplot(data, aes(x=gen, fill=case)) + geom_density(alpha=.3)

#################### # # # Exercise 8 # # # #################### data <- data.frame(case = factor(rep(c("A","B","C"), each = 100)), gen = c(rt(100, 5), rt(100, 10), rt(100, 25))) ggplot(data, aes(x=gen, fill=case)) + geom_density(alpha=.3)

#Notice the variance, which decreases as the degrees of freedom increase #################### # # # Exercise 9 # # # #################### data <- data.frame(case = factor(rep(c("A","B","C"), each = 100)), gen = c(rchisq(100, 5), rchisq(100, 10), rchisq(100, 25))) ggplot(data, aes(x=gen, fill=case)) + geom_density(alpha=.3)

#Observe that the graphs change from heavily skew to the right into more bell-shaped. #################### # # # Exercise 10 # # # #################### data <- data.frame(case = factor(rep(c("A","B","C"), each = 100)), gen = c(rf(100, 3, 9), rf(100, 9, 3), rf(100,15, 15))) ggplot(data, aes(x=gen, fill=case)) + geom_density(alpha=.3)+xlim(0, 10)

Leave a Reply