y <- rnorm(200, 20, 5)
n <-1000 # Simple normal distribution
tdata <- numeric(n)
for(i in 1:n) {
samp <- sample(y, 200, replace=TRUE)
tdata [i] <- mean(samp)
}
summary(tdata)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 19.01 19.89 20.10 20.11 20.32 21.31
hist(tdata)
##Normal distribution of size 100
x <- rnorm(100, 20, 5)
bar <- mean(x)
normdata <- numeric(2000) ## Find the pivot t-interval
for (i in 1:2000){
samp <- sample(y,size=70,replace=TRUE)
bootmean = mean(samp)
bootsd = sd(samp)
tpivot = (bootmean - bar)/(bootsd/sqrt(100))
normdata[i] <- tpivot
}
quantile <- quantile(normdata, c(0.025, 0.975)) # numbers at 2.5% and 97.5% quantile
quantile
## 2.5% 97.5%
## -2.768695 1.826441
n <- 30
exp <- numeric(2000)
for (i in 1:2000){
x <- exp(n)
exp[i] <- mean(x)
}
mean(exp)
## [1] 1.068647e+13
n <- 80
exp <- numeric(2000)
for (i in 1:2000){
x <- exp(n)
exp[i] <- mean(x)
}
mean(exp)
## [1] 5.540622e+34