HW 9 Bootstrap, Jackknife, and Permutation Tests
HW 9 Bootstrap, Jackknife, and Permutation Tests
Permutation Tests
STAT 5400
Due: Nov 13, 2023 11:59 PM
Problems
Submit your solutions as an .Rmd file and accompanying .pdf file.
1. Use echo=TRUE, include=FALSE to ensure that all the code are provided but only the important output is
included. Try to write your homework in the form of a neat report and don’t pile up any redundant and
irrelevant output.
2. Always interpret your result whenever it is necessary. Try to make sure the interpretation can be understood
by people with a moderate level of statistics knowledge.
Reading assignments.
Here is an undergraduate-level introduction to the bootstrap.
https://statweb.stanford.edu/~tibs/stat315a/Supplements/bootstrap.pdf
(https://statweb.stanford.edu/~tibs/stat315a/Supplements/bootstrap.pdf)
Problems
1. Bootstrap and jackknife
Consider the airconditioning data listed below:
Suppose the mean of the underlying distribution is μ and our interest is to estimate log(μ). To estimate it, we use
¯
the log of the sample mean, i.e., log(X ) , as an estimator.
¯
a. Carry out a nonparametric bootstrap analysis to estimate the bias of log(X ).
¯ ¯
b. Based on the bootstrap analysis, is the bias of log(X) positive or negative? (In other word, does log(X )
overestimates or underestimates log(μ)) Can you explain the observation? (Hint: Jensen’s inequality)
c. Also run a nonparametric bootstrap to estimate the standard error of the log of the sample mean. In terms of
the mean square error of the estimator, do you think the bias is large given the standard error?
d. Carry out a parametric bootstrap analysis to estimate the bias of the log of sample mean. Assume that the
population distribution of failure times of airconditioning equipment is exponential.
e. Plot both the histograms of the bootstrap replications from nonparametric and parametric bootstrap.
f. Produce 95% confidence intervals by the standard normal, basic, percentile, and Bca methods. (You may
need to attend the lecture on Oct 17 for this question.)
g. Use jackknife to estimate the standard error and bias of the log of the sample mean.
# Parametric bootstrap
param_bootstrap_results <- boot(data, statistic = log_mean_exp, R = 1000)
param_bias_estimate <- mean(param_bootstrap_results$t - log_mean(data))
# Interpretation
param_bias_estimate
## [1] -4.715413
param_bootstrap_results
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = data, statistic = log_mean_exp, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* -0.026407 -0.006103388 0.3065978
The Bias is quite large at -4.7 compared to the std. error at .307
# Plot histograms
par(mfrow = c(1, 2))
hist(bootstrap_results$t, main = "Nonparametric Bootstrap", xlab = "Log Mean")
hist(param_bootstrap_results$t, main = "Parametric Bootstrap", xlab = "Log Mean")
# Function to calculate confidence intervals
calculate_ci <- function(results, method) {
ci_output <- boot.ci(results, type = method)
print(ci_output) # Add this line to check the output
return(ci_output$bca[, 4:5])
}
# Standard Normal CI
standard_normal_ci <- calculate_ci(bootstrap_results, "norm")
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = results, type = method)
##
## Intervals :
## Level Normal
## 95% ( 4.031, 5.464 )
## Calculations and Intervals on Original Scale
# Basic CI
basic_ci <- calculate_ci(bootstrap_results, "basic")
# Percentile CI
percentile_ci <- calculate_ci(bootstrap_results, "perc")
# BCa CI
bca_ci <- calculate_ci(bootstrap_results, "bca")
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = results, type = method)
##
## Intervals :
## Level BCa
## 95% ( 4.022, 5.391 )
## Calculations and Intervals on Original Scale
## Some BCa intervals may be unstable
When you observe 0 succeses with the non-parametric model it leads to the case of the confidence interval being
(0,0) ### 3. Bootstrap estimate of the standard error of trimmed mean.
Let θ^ be the 25% trimmed mean, which is computed by deleting two smallest numbers and two largest numbers,
and then taking the average of the remaining four numbers.
a. Calculate \widehat{\mathrm{se}_B for B = 25, 100, 200, 500, 1000, 2000. From these results estimate the
ideal bootstrap estimate \widehat{\mathrm{se}_{\infty} .
b. Repeat part (a) using twenty different random number seeds. Comment on the trend of the variablity of each
\widehat{\mathrm{se}_B .
# Given data
data <- c(1, 3, 4.5, 6, 6, 6.9, 13, 19.2)
# Values of B
B_values <- c(25, 100, 200, 500, 1000, 2000)
# Print results
cat("Bootstrap Standard Errors for Different B values:\n")
print(results)
##
## Ideal Bootstrap Estimate (B = Inf):
print(ideal_bootstrap_estimate)
## [1] NA
The mean of the estimated standard errors decreases as B increases, with a larger number of bootstrap samples,
the estimates tend to stabilize and become more precise. The standard deviation of the estimated standard errors
also decreases with increasing B, suggesting reduced variability in the estimates.
The plot shows a decreasing trend in the mean estimated standard errors as B increases. As B increases, the
bootstrap procedure becomes more robust, providing more consistent and reliable estimates of the standard error.
In practice, it is common to choose a sufficiently large B to achieve stable results.
> attach(chickwts)
> boxplot(formula(chickwts))
Use two-sample t-test to see whether the population weight of soybean and linseed are the same or not.
Comment on the assumptions of the t-test.
where zi is the pooled sample, Fn is the empirical CDF of X1 , … , Xn and Gm is the emprical CDF of
Y 1 , … , Y m . You may want to try ks.test in R.
In fact, the K-S statistic is primarily used for univariate distributions. Try another alternative to the K-S
statistics: perform permutation tests based on Cramer-von-Mises statistic:
n m
mn 2 2
W = [∑(Fn (x i ) − Gm (x i )) + ∑(Fn (yj ) − Gm (yj )) . ]
2
(m + n)
i=1 j=1