library(resampledata)
chlor <- na.omit(Bangladesh$Chlorine)
hist(chlor)
The distribution is skewed strongly to the right.
start_time <- Sys.time()
t.test(chlor)
One Sample t-test
data: chlor
t = 6.0979, df = 268, p-value = 3.736e-09
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
52.87263 103.29539
sample estimates:
mean of x
78.08401
end_time <- Sys.time()
end_time - start_time
Time difference of 0.007549047 secs
start_time <- Sys.time()
N <- 10^5
percboot <- numeric(N)
for (i in 1:N)
{samp <- sample(chlor, length(chlor), replace=T)
percboot[i] <- mean(samp)
}
end_time <- Sys.time()
end_time - start_time
Time difference of 5.656472 secs
hist(percboot)
quantile(percboot,c(.025, .975))
2.5% 97.5%
54.98024 104.60336
\[ \frac{\mu-\overline{X}}{\frac{S}{\sqrt{n}}} \] is usually written
\[ \frac{\overline{X}-\mu}{\frac{S}{\sqrt{n}}} \]
library(resampledata)
chlor <- na.omit(Bangladesh$Chlorine)
xbar=mean(chlor)
n=length(chlor)
start_time <- Sys.time()
N <- 10^5
bootT <- numeric(N)
for (i in 1:N)
{Xstar <- sample(chlor, n, replace=T)
Sstar <- sd(Xstar)
bootT[i] <- (xbar-mean(Xstar))/(Sstar/sqrt(n))
}
end_time <- Sys.time()
end_time - start_time
Time difference of 13.89275 secs
quantile(bootT, c(0.025, 0.975))
2.5% 97.5%
-1.660158 2.658922
samplesd <- sd(chlor)
xbar+quantile(bootT, 0.025)*samplesd/sqrt(length(chlor))
2.5%
56.82553
xbar+quantile(bootT, 0.975)*samplesd/sqrt(length(chlor))
97.5%
112.1318
xbar+quantile(bootT, c(0.025, 0.975))*samplesd/sqrt(length(chlor))
2.5% 97.5%
56.82553 112.13177