# Latihan 1: Data
set.seed(150)
myData <- rnorm(1000,30,2.5)
length(myData)
## [1] 1000
mean(myData)
## [1] 29.92068
sd(myData)
## [1] 2.475175
sample.size <- 1000
n.sample <- 50
bootstrap.results <- c()
for (i in 1:n.sample)
{
obs <- sample(1:sample.size, size=sample.size, replace = TRUE)
bootstrap.results[i] <- mean(myData[obs])
}
length(bootstrap.results)
## [1] 50
summary(bootstrap.results)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 29.75 29.89 29.92 29.93 29.97 30.10
sd(bootstrap.results)
## [1] 0.06342673
# Latihan 2: Visualisasi
par(mfrow=c(2,1), pin=c(3,1))
hist(bootstrap.results,
col= "lightpink",
xlab="Mean",
main=paste("Means of 50 bootstrap samples from the DGP"))
hist(myData,
col= "lightblue",
xlab="Value",
main=paste("Distribution of myData"))
