11.1 a)

 x<-seq(-4,4,by=0.01)
compare3<-matplot(x,cbind(dt(x,df=2),dt(x,df=8),dnorm(x)),type="l", col=1:3, ylab="Density") 
legend(1.6,0.35, c("t(2)", "t(8)", "N(0,1)"), lty=1:3, col =1:3)
title("Density functions of t(2), t(8) and N(0,1)")

11.1 b)

compare6<-matplot(x,cbind(dt(x,df=1),dt(x,df=2),dt(x,df=4),dt(x,df=8), dt(x,df=16),dnorm(x)),type="l", col=1:6, ylab="Density") 
legend(1.6,0.35, c("t(1)","t(2)","t(4)", "t(8)","t(16)", "N(0,1)"), lty=1:6, col = 1:6)
title("Density functions of t(1), t(2), t(4), t(8), t(16) and N(0,1)")

As the degrees of freedom grow, the t-distribution approaches normal.

11.4

1)

set.seed(988) #
mu<-15 #unknown population mean
sig<-9 # known population standard deviation  
n<-25 # sample size
m<-5000 #number of CIs to be constructed
result<-data.frame(matrix(0, nrow=m, ncol=2))  
names(result)<-c("L95", "U95")
for(i in 1:m){
x<-rnorm(n, mean=mu, sd=sig)
err<-1.64*sig/sqrt(n)
xbar<-mean(x)
result[i,1]<-xbar-err
result[i,2]<-xbar+err
}
y<-(result[,1]<=mu) & (result[,2]>=mu)
mean(y)
## [1] 0.8924

2)

set.seed(988) #
mu<-15 #unknown population mean
sig<-9 # known population standard deviation  
n<-25 # sample size
m<-5000 #number of CIs to be constructed
result<-data.frame(matrix(0, nrow=m, ncol=2))  
names(result)<-c("L95", "U95")
for(i in 1:m){
x<-rnorm(n, mean=mu, sd=sig)
err<-1.96*sig/sqrt(n)
xbar<-mean(x)
result[i,1]<-xbar-err
result[i,2]<-xbar+err
}
y<-(result[,1]<=mu) & (result[,2]>=mu)
mean(y)
## [1] 0.9468

3)

set.seed(988) #
mu<-15 #unknown population mean
sig<-9 # known population standard deviation  
n<-25 # sample size
m<-5000 #number of CIs to be constructed
result<-data.frame(matrix(0, nrow=m, ncol=2))  
names(result)<-c("L95", "U95")
for(i in 1:m){
x<-rexp(20,rate=1.0)
err<-1.96*sig/sqrt(n)
xbar<-mean(x)
result[i,1]<-xbar-err
result[i,2]<-xbar+err
}
y<-(result[,1]<=mu) & (result[,2]>=mu)
mean(y)
## [1] 0