# Simulate n standard normal random variables
n=20
set.seed(11)
x <- rnorm(n,0,1)
options(warn=-1)
#Bootstrap
#load(boot)
boot <-numeric(200) #specifies a vector of real values length 200
for (i in 1:2000){
boot[i]<- sample(x, replace=T)
}
hist(boot, col= "light blue", main="Histogram of Bootstrap ReSampling")

mean(boot)
## [1] -0.3611196
var(boot)
## [1] 0.6585006
#Jackknife
jack <- numeric(length(x)-1)
pseudo <- numeric(length(x))
for (j in 1:length(x)) {
if(j < i) jack[j] <- x[j]
else if(j > i) Jack[j-1] <- x[j] }
pseudo[i] <- length(x)*sample(x, replace=T) -(length(x)-1)*sample(jack, replace=T)
Jack <- numeric(length(x)-1)
pseudo <- numeric(length(x))
for (i in 1:length(x))
{for (j in 1:length(x))
{if(j < i) jack[j] <- x[j] else if(j > i) jack[j-1] <- x[j]
}
pseudo[i] <- length(x)*sample(x, replace=T) -(length(x)-1)*sample(jack, replace=T)
}
hist(jack, col = "light green", main="Histogram of Jackknife ReSampling")

mean(jack)
## [1] -0.3495979
var(jack)
## [1] 0.718789
# Compare variance estimates between Bootstrap & Jackknife
simulation.variance <- c(var(boot), var(jack))
simulation.variance
## [1] 0.6585006 0.7187890