Problem 1. (Bootstrap tests for goodness-of-fit)We saw in lecture that when it comes togoodness-of-fit (GOF) testing, it is quite “natural” to obtain a p-value by permutation. It is alsopossible, however, to use the bootstrap for that purpose. Consider the two-sample situation forsimplicity, although this generalizes to any number of samples. Thus assume a situation where weobserveX1, . . . , Xmiid fromFand (independently)Y1, . . . , Yniid fromG, whereFandGare twodistributions on the real line. We want to testF=GversusF6=G. We may want to use a statisticT=T(X1, . . . , Xm, Y1, . . . , Yn) for that purpose, and the question is how to obtain a p-value forTvia a bootstrap. The idea is, as usual, to estimate the “best” null distribution and bootstrap fromthat distribution. A natural approach to estimate the null distribution is to simply combine thetwo samples as one, and estimate the corresponding distribution via the empirical distribution. Wethus use the empirical distribution from thecombined sampleto bootstrap from.A.
Write a functionbootGOFdiff(x, y, B= 2000) that takes in two samples as vectorsxandy,and a number of replicatesB(Monte Carlo samples from the estimated null distribution),and returns the bootstrap GOF p-value for the difference in meansT=|X̄−Ȳ|.
Here I take samples of size 10 from standard normal distribution and the write the function for calculating the boostrap P-value. One can start with any arbitrary sample of arbitrary size. The function will work properly and it will return the P-value of the test. But every time you have to choose the critical region properly.
##.. boostrap sampling
x=rnorm(10) ##..sample X
y=rnorm(10) ##..sample Y
B=2000 ##.. no. of boostrap iteration
T=mean(x)-mean(y)
T=abs(T) ##value of the test statistic for the original sample
##.. function for boostrap
bootGOFdiff=function(x,y,B)
{
p=0
for(i in 1:B)
{
x.boot=sample(x,size=10,replace=T)
y.boot=sample(y,size=10,replace=T)
T.boot=mean(x.boot)-mean(y.boot)
T.boot=abs(T.boot)
if(abs(T-T.boot)>0.5) p=p+1
}
p=p/B
return(p)
}
bootGOFdiff(x,y,B) ##.. required P-value
Get Answers For Free
Most questions answered within 1 hours.