Resampling Methods in R: A Guide
Resampling Methods in R: A Guide
Contents
1
1. Sampling from known distributions and simulation
In introductory statistics courses we are told that the t-test is “robust” to departures from
normality, especially if the sample size is large. What this means is if we specify a particular
Type I error rate, then the actual proportion of false rejections will be close to the Type I error
rate. Let’s create and run a simulation to explore this.
Steps.
1. Generate a random sample from some population distribution
2. Calculate sample mean, standard deviation and t test statistic
3. Decide if the null hypothesis is rejected
4. Repeat 1-3, counting the number of rejections
for (i in 1:1000)
{
x <‐ rnorm(15, 25, 4) # draw a random sample of size 15
from a N(25,4) distribution
t <‐ (mean(x)‐25)*sqrt(15)/sd(x)
if (t >= [Link]) # check to see if result is significant
counter <‐ counter + 1 # increase counter by 1
}
## [1] 0.06
If we execute this code again, a different set of random samples will be selected, and a different
estimate obtained
for (i in 1:1000)
{
x <‐ rnorm(15, 25, 4) # draw a random sample of size 15
from a N(25,4) distribution
t <‐ (mean(x)‐25)*sqrt(15)/sd(x)
if (t >= [Link]) # check to see if result is significant
2
counter <‐ counter + 1 # increase counter by 1
}
## [1] 0.043
[Link](4123)
counter <‐ 0 # set counter to 0
for (i in 1:1000)
{
x <‐ rnorm(15, 25, 4) # draw a random sample of size 15
from a N(25,4) distribution
t <‐ (mean(x)‐25)*sqrt(15)/sd(x)
if (t >= [Link]) # check to see if result is significant
counter <‐ counter + 1 # increase counter by 1
}
## [1] 0.043
for (i in 1:1000)
{
x <‐ rnorm(15, 25, 4) # draw a random sample of size 15
from a N(25,4) distribution
t <‐ (mean(x)‐25)*sqrt(15)/sd(x)
if (t >= [Link]) # check to see if result is significant
counter <‐ counter + 1 # increase counter by 1
}
## [1] 0.043
3
Instead of using a counter, we may want to store the results so they can be explored later. In the
code below, a vector is created and used to store the calculated t-statistics.
[Link](4123)
nsims <‐ 1000
[Link] <‐ qt(0.95,14) #5% critical value
results <‐ numeric(nsims) #Vector to store t statistics
for (i in 1:nsims)
{
x <‐ rnorm(15, mean=0, sd=1) # draw a random sample of size 15
## [1] 0.043
Having the results saved in a vector allows us to explore the actual sampling distribution. Below
we graphically assess agreement between theoretical and actual distributions.
4
1.3 Sampling from an exponential distributions
[Link](4123)
nsims <‐ 1000
[Link] <‐ qt(0.95,14) #5% critical value
results <‐ numeric(nsims) #Vector to store t statistics
for (i in 1:nsims)
{
x <‐ rexp(15, rate=1/25) # draw a random sample of size 15 from an
Exp(mean=25) distribution
results[i] <‐ (mean(x)‐25)*sqrt(15)/sd(x)
}
## [1] 0.015
5
Available distributions ([Link]
Distribution Functions
Beta pbeta qbeta dbeta rbeta
Binomial pbinom qbinom dbinom rbinom
Cauchy pcauchy qcauchy dcauchy rcauchy
Chi-Square pchisq qchisq dchisq rchisq
Exponential pexp qexp dexp rexp
F pf qf df rf
Gamma pgamma qgamma dgamma rgamma
Geometric pgeom qgeom dgeom rgeom
Hypergeometric phyper qhyper dhyper rhyper
Logistic plogis qlogis dlogis rlogis
Log Normal plnorm qlnorm dlnorm rlnorm
Negative Binomial pnbinom qnbinom dnbinom rnbinom
Normal pnorm qnorm dnorm rnorm
Poisson ppois qpois dpois rpois
Student t pt qt dt rt
Studentized Range ptukey qtukey dtukey rtukey
Uniform punif qunif dunif runif
6
Weibull pweibull qweibull dweibull rweibull
Wilcoxon Rank Sum Statistic pwilcox qwilcox dwilcox rwilcox
Wilcoxon Signed Rank Statistic psignrank qsignrank dsignrank rsignrank
7
2. Bootstrap Confidence intervals
- Classical World: Observe one sample and the value of the sample statistic. Sampling
distribution is determined by considering all possible (unobserved) samples from the same
assumed population. Cannot directly observe the sampling distribution.
- Bootstrap World: Rather than assume a population, consider the observed sample to be the
best estimate of the population. In fact, we will assume that it represents the probability
distribution for the population. We can then generate all (or at least very many) possible
samples by taking bootstrap samples (with replacement), from this estimated population and
thus observe the sampling distribution of the sample estimator.
We start with a very small data set, a set of new employee test scores:
First select a sample of size 7, with replacement and compute the mean of the bootstrap sample.
## [1] 42.57143
## [1] 31 37 31 31 31 37 31
## [1] 32.71429
8
We need to do this many times to estimate the sampling distribution of the mean.
## [1] 42.57143
N <‐ length(score)
hist([Link])
9
2.2 Bootstrap confidence intervals
Example. Suppose we have a random sample of size 30 from an exponential distribution with
mean 25. We want to use the sample mean to estimate the population mean.
boxplot([Link])
10
n <‐ length([Link])
[Link] <‐ mean([Link])
hist([Link])
11
[Link]
## [1] 31.96579
quantile([Link], c(0.025,0.975))
## 2.5% 97.5%
## 22.49355 42.19327
A pivot quantity is a function of the estimator whose distribution does not depend on the
parameter being estimated.
Example: Estimating the population mean, based on the sample mean, Y . Then the
Y
statistic T ~ t (n 1) has a Student’s t distribution with n-1 degrees of freedom.
S/ n
Because the distribution of T does not depend on , T is a pivot quantity.
12
When such a quantity exists, we can then use bootstrapping to estimate the distribution of
the pivot quantity—essentially a custom table—and use quantiles from the table to create
the confidence interval.
Y
For the statistic T , the confidence interval is given by
S/ n
S S
Y tb ,0.975 Y tb ,0.025 ,
n n
n <‐ length([Link])
[Link] <‐ mean([Link])
[Link] <‐ sd([Link])
hist([Link])
13
[Link] <‐ quantile([Link], 0.975)
[Link] <‐ quantile([Link], 0.025)
## 97.5%
## 22.80743
[Link]
## 2.5%
## 44.39896
quantile([Link], c(0.005,0.025,0.05,0.95,0.975,0.995))
qt(c(0.005,0.025,0.05,0.95,0.975,0.995),n‐1)
14
“Theory” behind T-pivot interval
Suppose we wish to estimate the mean of a population. The pivotal method can be used,
assuming we can find a statistic whose distribution does not depend on the parameters to be
estimated.
X
Ex: t . If X N ( , ) , then t t (n 1) . The distribution of t does not depend on
2
s
n
either or 2 , and thus t is a pivotal quantity. Then since
X
P t t1 1 , we have
2 s 2
n
s s
t X t1
2 n 2 n
s s
X t X t1
2 n 2 n
s s
X t X t1 ,
2 n 2 n
s s
X t1 X t
2 n 2 n
is a 100(1 )% confidence interval for .
X t1 (s ) X t1 (s ),
2 n 2 n
where if .05,1 2 .975 .
If the sample does not come from a normal population, t is still a pivotal quantity so we can still
write
X
P t t1 1
2 s 2
n
15
s s
X t1 X t (1)
2 n 2 n
Xb X
*For each bootstrap sample of size n from the data, compute tb , then find tb , and
sb 2
n
tb,1 and substitute into (1) above.
2
16
2.2.3 Using bootstrap samples to estimate standard error.
The “original” or often called “standard” bootstrap method. This method is motivated by
the “Wald” interval which assumes that many statistics are approximately
normally distributed for large sample sizes, and creates the interval as
Estimator Z / 2 * SE .
If a formula for the SE is not available, then SE can be estimated using bootstrapping. For
example, to estimate the standard error of the mean:
X b ,i X , where X is the
1 n 2
1. Compute the mean squared error, MSE
n i 1
mean of the original sample and X b ,i is the mean of the ith bootstrap sample.
2. Compute SE MSE
[Link](4123)
[Link] <‐ rexp(30, rate=1/25)
n <‐ length([Link])
[Link] <‐ mean([Link])
SE <‐ sqrt(mean([Link]))
## [1] 22.07738
[Link]
17
## [1] 41.85421
18
3. Randomization/Permutation tests--Comparing two or more groups
A company is trying to decide whether to augment its traditional instruction for new employees
with computer assisted instruction. Seven new employees are selected. Four are assigned at
random to the new method and the remaining three to the traditional method. A test is given at
the end of instruction for all employees, and the scores are given below.
New method Smith (37), Lin (49), O’Neal (55), Zedillo (57)
Traditional method Johnson (23), Green (31), Zook (46)
Suppose we would like to test for evidence that the new method tends to produce higher scores.
We might test H 0 : μN μT vs. H a : μN μT , using a t-test.
Permutation/Randomization test.
Sampling distribution based upon all possible assignments of the experimental units to
treatments.
Important assumption: Each assignment is equally likely under the null hypothesis—
guaranteed by random assignment.
[Link](4123)
score <‐ c(37,49,55,57,23,31,46)
perm <‐ sample(score, replace=F)
perm
## [1] 46 55 37 31 23 57 49
Now, compute the mean of the first 4 entries, the last 3 and compute the difference
[Link] <‐ mean(perm[1:4])
[Link]
## [1] 42.25
19
## [1] 43
## [1] ‐0.75
Another way is to create an index vector, and sample for just one group.
[Link](4123)
N <‐ length(score)
index <‐ sample(N, size=4,replace=F)
index
## [1] 7 3 1 6
score[index]
## [1] 46 55 37 31
score[‐index]
## [1] 49 57 23
## [1] ‐0.75
Steps of the permutation test using mean difference as the test statistic:
20
Randomization New1 New2 New3 New4 Trad5 Trad6 Trad7 X New X Trad Sum New
1 46 49 55 57 23 31 37 21.4167 207
*2 37 49 55 57 46 23 31 16.1667 198
3 37 46 55 57 31 49 23 14.4167 195
4 31 49 55 57 46 23 37 12.6667 192
5 31 46 55 57 37 49 23 10.9167 189
6 37 46 49 57 31 23 55 10.9167 189
7 37 46 49 55 31 23 57 9.7500 187
8 23 49 55 57 46 31 37 8.0000 184
9 31 46 49 57 23 37 55 7.4167 183
10 23 46 55 57 37 49 31 6.2500 181
11 31 46 49 55 23 37 57 6.2500 181
12 31 37 55 57 46 49 23 5.6667 180
13 23 46 49 57 31 37 55 2.7500 175
14 31 37 49 57 46 23 55 2.1667 174
15 23 46 49 55 31 37 57 1.5833 173
16 23 37 55 57 46 49 31 1.0000 172
17 31 37 49 55 46 23 57 1.0000 172
18 31 37 46 57 23 49 55 0.4167 171
19 31 37 46 55 23 49 57 -0.7500 169
20 23 31 55 57 46 49 37 -2.5000 166
21 23 37 49 57 46 31 55 -2.5000 166
22 23 37 49 55 46 31 57 -3.6667 164
23 23 37 46 57 31 49 55 -4.2500 163
24 31 37 46 49 23 55 57 -4.2500 163
25 23 37 46 55 31 49 57 -5.4167 161
26 23 31 49 57 46 37 55 -6.0000 160
27 23 31 49 55 46 37 57 -7.1667 158
28 23 31 46 57 37 49 55 -7.7500 157
29 23 31 46 55 37 49 57 -8.9167 155
30 23 37 46 49 31 55 57 -8.9167 155
31 23 31 46 49 37 55 57 -12.4167 149
32 23 31 37 57 46 49 55 -13.0000 148
33 23 31 37 55 46 49 57 -14.1667 146
34 23 31 37 49 46 55 57 -17.6667 140
35 23 31 37 46 49 55 57 -19.4167 137
21
Two of 35 possible assignments of units to observations were as large or larger than the
observed value of Dobs 16.2 (one of these is Dobs 16.2 ). Thus the p-value is
P D Dobs 2 / 35 0.057 .
Now, we use a for loop as before to create many random permutations and corresponding
mean differences, store all the mean differences and then compute the p-value.
hist([Link])
22
(sum([Link] >= [Link])+1)/(nperms + 1) #P‐value
## [1] 0.0562
When sample sizes are moderate to large, enumerating all possible arrangements may be very
time consuming at best and practically impossible at worst. As the table below illustrates, with
two samples of 25, there are over 100 trillion arrangements to consider!
Solution:
95% margin
R of error
1000 0.013784
5000 0.006164
10000 0.004359
100000 0.001378
24
Example. This dataset contains results from an experiment in visual perception using random dot
stereograms, such as that shown below. Both images appear to be composed entirely of random
dots. However, they are constructed so that a 3D image (of a diamond) will be seen, if the
images are viewed with a stereo viewer, causing the separate images to fuse. Another way to fuse
the images is to fixate on a point between them and defocus they eyes, but this technique takes
some effort and practice. An experiment was performed to determine whether knowledge of the
form of the embedded image affected the time required for subjects to fuse the images. One
group of subjects (group NV-43 subjects) received either no information or just verbal
information about the shape of the embedded object. A second group (group VV-35 subjects)
received both verbal information and visual information (e.g., a drawing of the object).
[Cleveland, W. S. (1993). Visualizing Data. Original source: Frisby, J. P. and Clatworthy, J.L.,
"Learning to see complex random-dot stereograms," Perception, 4, (1975), pp. 173-178]
78
A randomization test on these data involves over 1.8 10 22 permutations. In the following
43
code, the data are read and a boxplot created that shows several outliers in each group. Thus we
consider using the median difference as the test statistic instead of the mean difference. The p-
value is estimated based on 10,000 randomly sampled randomizations.
fusion=[Link]("C:/Users/sjricht2/Documents/DataSets/Independent samples T
‐test/Fusion_data.txt", header=TRUE)
boxplot(fusion$time~fusion$treatment)
25
names(fusion)
N <‐ length(fusion$time)
Treat1 <‐ subset(fusion, Select=time, treatment=="NV", drop=T)
Treat2 <‐ subset(fusion, Select=time, treatment=="VV", drop=T)
N1 <‐ length(Treat1)
head(Treat1,5)
## time treatment
## 1 47.20001 NV
## 2 21.99998 NV
## 3 20.39999 NV
## 4 19.70001 NV
## 5 17.40000 NV
head(Treat2,5)
## time treatment
## 44 19.70001 VV
## 45 16.19998 VV
## 46 15.90000 VV
## 47 15.40002 VV
## 48 9.70000 VV
26
[Link] <‐ median(Treat1$time)‐median(Treat2$time)
[Link]
## [1] 3.3
## [1] 0.3213
27
What hypotheses are being tested by the permutation test?
No population distribution is assumed, and thus it does not make sense to test parameters
(e.g., equality of means).
Another advantage of the permutation test is that the function of the sample that is best suited
to address the research question may be used. For a test of location difference, we may use
Difference of means
Difference of medians
others (e.g., trimmed means, ratios)
28
3.3 Wilcoxon Rank sum test: Permutation test on rank transformed data
1. Combine observations and assign ranks, with tied observations receiving the average rank
2. Perform permutation test on ranks (mean difference or sum of ranks in sample 1 can be
used as test statistic)
fusion=[Link]("C:/Users/sjricht2/Documents/DataSets/Independent samples T
‐test/Fusion_data.txt", header=TRUE)
N <‐ length(fusion$time)
Treat1 <‐ subset(fusion, Select=[Link], treatment=="NV", drop=T)
Treat2 <‐ subset(fusion, Select=[Link], treatment=="VV", drop=T)
N1 <‐ length(Treat1)
## [1] 11.42791
## [1] 0.2064
1) t-test—If selecting independent random sample from normal populations, is optimal for
detecting location difference
3) Permutation test using medians—Can have higher power than tests on means, especially
for skewed and heavy-tailed distributions
4) Permutation test using ranks (Wilcoxon rank-sum test)-- Can have higher power than
tests on means, especially for skewed and heavy-tailed distributions
The WRS test has been studied extensively in relation to the t-test. The t-test tends to have higher
power for symmetric distributions, especially for lighter tailed distributions and smaller sample
sizes. The WRS test generally has higher power for heavier-tailed distributions and moderate to
large sample sizes.
The methods of this section can be extended to more than two groups. The ANOVA F-statistic
can be used as the test statistic if using the raw, numeric data. The randomization test based on
ranks is known as the Kruskal-Wallis test.
30
3.6 Randomization tests for contingency tables
Example. Seven patients are included in a study to compare two methods of relieving
postoperative pain. Three are allowed to control the amount of pain-relief medicine themselves,
while the other four are given a physician prescribed level of medicine according to standard
practice. Afterward, the patients evaluate their satisfaction as either “not satisfied (NS)”,
“somewhat satisfied (SS)” or “very satisfied (VS)”.
NS SS VS
Physician prescribed 2 2 0
Self-administered 0 1 2
Typically a chi-squared test would be considered to assess these hypotheses, using the test
statistic
X
2
,
all cells exp ected
which has an approximate 2 rows 1 cols 1 distribution for large sample sizes.
However, the approximation can be poor when there are small expected counts.
31
The randomization test can be viewed as identical to the two-group permutation test with a
quantitative response, i.e.,
Physician prescribed NS1, NS2, SS3, SS4
Self-administered SS5, VS6, VS7
2. Randomly assign units to treatments, construct the corresponding table and compute
X perm
2
Example. The expected frequencies are computed below as (row total)*(column total)/n.
table <‐ matrix(
c(2, 2, 0,
0, 1, 2),
nrow = 2, byrow = TRUE
)
table
chitest
32
##
## Pearson's Chi‐squared test
##
## data: [Link](table)
## X‐squared = 4.2778, df = 2, p‐value = 0.1178
chitest$expected
## A B C
## A 1.1428571 1.714286 1.1428571
## B 0.8571429 1.285714 0.8571429
33
[Link]([Link](table),[Link]=T, B=10000)
##
## Pearson's Chi‐squared test with simulated p‐value (based on 10000
## replicates)
##
## data: [Link](table)
## X‐squared = 4.2778, df = NA, p‐value = 0.3247
[Link]([Link](table))
##
## Fisher's Exact Test for Count Data
##
## data: [Link](table)
## p‐value = 0.3143
## alternative hypothesis: [Link]
[Link]([Link](table))
##
## Pearson's Chi‐squared test
##
## data: [Link](table)
## X‐squared = 4.2778, df = 2, p‐value = 0.1178
34
35
4. Methods for correlation and regression
E[( X X )(Y Y )]
Correlation -- (population correlation)
XY
(X i X )(Yi Y )
Estimate of -- r
i 1
n
(X
i 1
i X ) 2 (Yi Y ) 2
To test H0 : 0 :
n2
The test statistic t r t (n 2) can be used if the (X,Y) pairs are a random sample
2
1 r
from a bivariate normal population.
36
1(b): Fit the model Yi 0 1 Xi i where i ’s are iid with mean 0 and variance 2 . 1
is the slope of the regression line.
1 : ˆi
( X X )(Y Y )
i i
( X X )
Estimator of 2
i
SY
It can be shown that ˆ1 r and also that tcorr tslope .
SX
So, to test for a linear relation between X & Y, we can use either statistic.
A permutation test may be used to obtain an exact p-value, regardless of the form of the
distribution of i ’s. Under H0 : 1 0 or Ho : 0, X does not affect the value of Y, so an
observed Y is just as likely to occur with any X. Thus, the permutation distribution is derived
from all possible assignments of the observed Ys to the observed Xs.
2. Randomly assign observations (Y’s) to treatments (X’s), and recompute the test
statistic, rperm .
37
3. Repeat #2 for all possible random assignments of observations to treatments
4. The p-value is
P rperm robs (# rperm values at least as large as robs )/(# permutations).
Example. Lea (1965) discussed the relationship between mean annual temperature and the
mortality rate for a type of breast cancer in women. The subjects were residents of certain
regions of Great Britain, Norway, and Sweden.
[Link](4123)
cancer <‐ [Link]('C:/Users/sjricht2/Documents/DataSets/Regression/Breast
Cancer [Link]', header=T)
cancer
## Mortality Temperature
## 1 102.5 51.3
## 2 104.5 49.9
## 3 100.4 50.0
## 4 95.9 49.2
## 5 87.0 48.5
## 6 95.0 47.8
## 7 88.6 47.3
## 8 89.2 45.1
## 9 78.9 46.3
## 10 84.6 42.1
## 11 81.7 44.2
## 12 72.2 43.5
## 13 65.1 42.3
## 14 68.1 40.2
## 15 67.3 31.8
## 16 52.5 34.0
plot(cancer$Temperature,cancer$Mortality)
38
[Link] <‐ cor(cancer$Temperature,cancer$Mortality)
[Link]
## [1] 0.8748544
## cancer$Temperature
## 2.357695
n <‐ length(cancer$Mortality)
nperms <‐ 9999 #set number of times to repeat this process
39
## [1] "Permutation test p‐value"
## [1] 1e‐04
## [1] 1e‐04
The randomization test can be carried out on rank transformed data. The X and Y values are
ranked separately, and Pearson correlation calculated on the rank-transformed data. Pearson
correlation calculated on rank transformed data is called Spearman correlation. The alternative
hypothesis for this test is that the rank-transformed data have a linear association, or that the
original data have a monotonic (strictly increasing or decreasing) relation.
plot([Link],[Link])
40
[Link] <‐ cor([Link],[Link])
[Link]
## [1] 0.9029412
n <‐ length([Link])
nperms <‐ 9999 #set number of times to repeat this process
for(i in 1:nperms)
{
index <‐ sample(n, size=n, replace = FALSE)
result.r[i] <‐
cor([Link],[Link][index])
}
'Permutation test p‐value'
## [1] 1e‐04
41
4.2 Bootstrap confidence intervals for correlation and slope
Intervals for
Suppose we have a random sample of ordered pairs, ( Xi ,Yi ), i 1,2,..., n . If the distribution of
(Xi ,Yi ) is bivariate normal, then it can be shown that:
1 1 r 1 1 1
Z ln N ln , ,
2 1 r 2 1 n 3
which can be used to construct an interval estimator for . This interval is not robust to
departures from normality, however. Notice also that the distribution of Z depends on the
population correlation, , and thus Z is not a pivot quantity.
Bootstrap interval.
1) Draw a specified number of bivariate bootstrap samples of size n, i.e., sample pairs
of observations.
3) Use the percentile method to construct confidence interval. (No pivot quantity exists).
## [1] 8 1 16 13 13 16 1 3 15 3 6 14 7 2 14 12
cancer
## Mortality Temperature
## 1 102.5 51.3
## 2 104.5 49.9
## 3 100.4 50.0
## 4 95.9 49.2
## 5 87.0 48.5
## 6 95.0 47.8
## 7 88.6 47.3
42
## 8 89.2 45.1
## 9 78.9 46.3
## 10 84.6 42.1
## 11 81.7 44.2
## 12 72.2 43.5
## 13 65.1 42.3
## 14 68.1 40.2
## 15 67.3 31.8
## 16 52.5 34.0
## Mortality Temperature
## 8 89.2 45.1
## 1 102.5 51.3
## 16 52.5 34.0
## 13 65.1 42.3
## 13.1 65.1 42.3
## 16.1 52.5 34.0
## 1.1 102.5 51.3
## 3 100.4 50.0
## 15 67.3 31.8
## 3.1 100.4 50.0
## 6 95.0 47.8
## 14 68.1 40.2
## 7 88.6 47.3
## 2 104.5 49.9
## 14.1 68.1 40.2
## 12 72.2 43.5
[Link](4123)
cancer <‐ [Link]('C:/Users/sjricht2/Documents/DataSets/Regression/Breast
Cancer [Link]', header=T)
for (i in 1:nboot) {
[Link] <‐ sample(1:nrow(cancer), replace = TRUE)
[Link] <‐ cancer[[Link],]
[Link][i]=cor([Link]$Mortality, [Link]$Temperature)
}
43
cor(cancer$Mortality,cancer$Temperature)
## [1] 0.8748544
quantile([Link],c(0.01,.025,.05,.10,.90,.95,.975,0.99))
The observed correlation is 0.875, and a 95% confidence interval is (0.768, 0.965).
44
Extra.
1) Draw a specified number of bivariate bootstrap samples of size n, i.e., sample pairs of
observations.
2) Compute ˆ1,b , the slope of the regression line, for each bootstrap sample.
Since a pivot quantity exists for the sample slope, a t-pivot interval may also be computed.
ˆ1 ˆ MSE
The statistic t , where SE ( ˆ1 ) , is a pivotal quantity.
SE ( ˆ1 ) ( n 1) S X2
Thus:
1) Draw a specified number of bivariate bootstrap samples of size n, i.e., sample pairs
of observations.
ˆ1,b ˆ MSE b
2) Compute tb , where SE ( ˆ1,b ) ;
SE(ˆ1,b ) ( n 1) S X2 ,b
45
Assumes Y h ( X ) , where h ( X ) is some function, say a linear function, are
independent, identically distributed with mean 0, variance 2 .
Steps:
1) Compute hˆ( X ) from the observed sample.
ˆ1,e
te , where ˆ1, e is the slope of the pairs ( Xi , ei ) for each bootstrap sample, and
SE(ˆ1,e )
(e e
i i ,b )2
MSEe n2
SE(ˆ1,e ) ;
(n 1)S X2 (n 1)S X2
2) Then for a given confidence level, 1 , determine the quantiles te , and te ,1 .
2 2
3) The confidence interval is given by ˆ1 te,1 /2 SE (ˆ1 ) 1 ˆ1 te, /2 SE (ˆ1 ) .
If these assumptions are questionable, use bivariate sampling. Bivariate sampling will
usually result in a larger standard error if assumptions for fixed-X sampling appear
violated.
47
5. Two-Sample Confidence Intervals
Pivot quantity:
(Y1 Y2 ) ( 1 2 )
t
1 1
sp
n1 n2
SE(Y1 Y2 )
Bootstrap interval:
ii) Select n1 errors, with replacement, from the set of all errors and assign to 1st
sample. Then select n2 in similar fashion and assign to second sample.
iii) Compute t
e1,b e2,b
, s p
2
(e ij ei )2
1 1 (n1 n2 2)
s p
n1 n2
e1 e2 (eij ei ) 2
SE (Y1 Y2 )
s12 s 22
. Compute t , where s E2
n1 n 2 s21 s22 ni 1
n1 n2
Interval is: (Y1 Y2 ) te,1 /2 SE(Y1 Y2 ) 1 2 (Y1 Y2 ) te, /2 SE(Y1 Y2 ) .
48
49