Bootstrap Resampling

Similar documents
Density and Distribution Estimation

Bootstrap, Jackknife and other resampling methods

STAT 830 Non-parametric Inference Basics

Regression with Polynomials and Interactions

The Nonparametric Bootstrap

Introduction to Nonparametric Regression

Fall 2017 STAT 532 Homework Peter Hoff. 1. Let P be a probability measure on a collection of sets A.

One-Sample Numerical Data

Introduction to Normal Distribution

4 Resampling Methods: The Bootstrap

MA 575 Linear Models: Cedric E. Ginestet, Boston University Bootstrap for Regression Week 9, Lecture 1

STAT440/840: Statistical Computing

Principal Components Analysis

The bootstrap. Patrick Breheny. December 6. The empirical distribution function The bootstrap

The assumptions are needed to give us... valid standard errors valid confidence intervals valid hypothesis tests and p-values

Lecture 1: Random number generation, permutation test, and the bootstrap. August 25, 2016

Nonparametric Independence Tests

Factorial and Unbalanced Analysis of Variance

Bootstrap Confidence Intervals

Week 9 The Central Limit Theorem and Estimation Concepts

Advanced Statistics II: Non Parametric Tests

Monte Carlo Studies. The response in a Monte Carlo study is a random variable.

Nonparametric Methods

Nonparametric Location Tests: k-sample

11. Bootstrap Methods

Some Assorted Formulae. Some confidence intervals: σ n. x ± z α/2. x ± t n 1;α/2 n. ˆp(1 ˆp) ˆp ± z α/2 n. χ 2 n 1;1 α/2. n 1;α/2

Chapter 2: Resampling Maarten Jansen

MIT Spring 2015

MS&E 226: Small Data. Lecture 11: Maximum likelihood (v2) Ramesh Johari

Peter Hoff Linear and multilinear models April 3, GLS for multivariate regression 5. 3 Covariance estimation for the GLM 8

Regression Estimation Least Squares and Maximum Likelihood

Resampling and the Bootstrap

Bootstrap tests. Patrick Breheny. October 11. Bootstrap vs. permutation tests Testing for equality of location

Multiple Linear Regression for the Supervisor Data

36. Multisample U-statistics and jointly distributed U-statistics Lehmann 6.1

Statistics - Lecture One. Outline. Charlotte Wickham 1. Basic ideas about estimation

Economics 583: Econometric Theory I A Primer on Asymptotics

The exact bootstrap method shown on the example of the mean and variance estimation

Constructing Prediction Intervals for Random Forests

Non-parametric Inference and Resampling

Bootstrap. Director of Center for Astrostatistics. G. Jogesh Babu. Penn State University babu.

Simple and Multiple Linear Regression

This produces (edited) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = aircondit, statistic = function(x, i) { 1/mean(x[i, ]) }, R = B)

First Year Examination Department of Statistics, University of Florida

Week 3: Learning from Random Samples

Better Bootstrap Confidence Intervals

Confidence Intervals in Ridge Regression using Jackknife and Bootstrap Methods

Association studies and regression

Formal Statement of Simple Linear Regression Model

Resampling and the Bootstrap

Brief Review on Estimation Theory

401 Review. 6. Power analysis for one/two-sample hypothesis tests and for correlation analysis.

The Bootstrap 1. STA442/2101 Fall Sampling distributions Bootstrap Distribution-free regression example

EC212: Introduction to Econometrics Review Materials (Wooldridge, Appendix)

Simple Linear Regression

SYSM 6303: Quantitative Introduction to Risk and Uncertainty in Business Lecture 4: Fitting Data to Distributions

Cross-Validation with Confidence

Statistics and Econometrics I

STAT5044: Regression and Anova. Inyoung Kim

Unbiased Estimation. Binomial problem shows general phenomenon. An estimator can be good for some values of θ and bad for others.

Robert Collins CSE586, PSU Intro to Sampling Methods

Contents 1. Contents

Unbiased Estimation. Binomial problem shows general phenomenon. An estimator can be good for some values of θ and bad for others.

Slides 12: Output Analysis for a Single Model

HT Introduction. P(X i = x i ) = e λ λ x i

Terminology Suppose we have N observations {x(n)} N 1. Estimators as Random Variables. {x(n)} N 1

F & B Approaches to a simple model

Statistics: Learning models from data

Categorical Predictor Variables

The Bootstrap Suppose we draw aniid sample Y 1 ;:::;Y B from a distribution G. Bythe law of large numbers, Y n = 1 B BX j=1 Y j P! Z ydg(y) =E

12 - Nonparametric Density Estimation

0.1 The plug-in principle for finding estimators

Math 494: Mathematical Statistics

Multivariate Distributions

STA205 Probability: Week 8 R. Wolpert

Chapter 3: Maximum Likelihood Theory

Statistics 3858 : Maximum Likelihood Estimators

Regression Estimation - Least Squares and Maximum Likelihood. Dr. Frank Wood

Section 4.6 Simple Linear Regression

Cross-Validation with Confidence

Ordinary Least Squares Linear Regression

1. Simple Linear Regression

For more information about how to cite these materials visit

Regression and Statistical Inference

Weighted Least Squares

Bias Variance Trade-off

Remedial Measures for Multiple Linear Regression Models

Topics on Statistics 2

Robert Collins CSE586, PSU Intro to Sampling Methods

Lecture 14 Simple Linear Regression

Ch 2: Simple Linear Regression

Nonlinear Regression

Uncertainty Quantification for Inverse Problems. November 7, 2011

MA 575 Linear Models: Cedric E. Ginestet, Boston University Midterm Review Week 7

Homework # , Spring Due 14 May Convergence of the empirical CDF, uniform samples

5601 Notes: The Subsampling Bootstrap

Probability and Statistics Notes

Non-parametric Inference and Resampling

Bootstrap (Part 3) Christof Seiler. Stanford University, Spring 2016, Stats 205

ECON The Simple Regression Model

Transcription:

Bootstrap Resampling Nathaniel E. Helwig Assistant Professor of Psychology and Statistics University of Minnesota (Twin Cities) Updated 04-Jan-2017 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 1

Copyright Copyright c 2017 by Nathaniel E. Helwig Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 2

Outline of Notes 1) Background Information Statistical inference Sampling distributions Need for resampling 3) Bootstrap in Practice Bootstrap in R Bias and mean-squared error The Jackknife 2) Bootstrap Basics Overview Empirical distribution Plug-in principle 4) Bootstrapping Regression Regression review Bootstrapping residuals Bootstrapping pairs For a thorough treatment see: Efron, B. & Tibshirani, R.J. (1993). An Introduction to the Bootstrap. Chapman & Hall/CRC. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 3

Background Information Background Information Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 4

Background Information Statistical Inference The Classic Statistical Paradigm X is some random variable, e.g., age in years X = {x 1, x 2, x 3,...} is some population of interest, e.g., Ages of all students at the University of Minnesota Ages of all people in the state of Minnesota At the population level... F(x) = P(X x) for all x X is the population CDF θ = t(f) is population parameter, where t is some function of F At the sample level... x = (x 1,..., x n ) is sample of data with x i iid F for i {1,..., n} ˆθ = s(x) is sample statistic, where s is some function of x Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 5

Background Information Statistical Inference The Classic Statistical Paradigm (continued) ˆθ is a random variable that depends on x (and thus F) The sampling distribution of ˆθ refers to the CDF (or PDF) of ˆθ. If F is known (or assumed to be known), then the sampling distribution of ˆθ may have some known distribution. If x i iid N(µ, σ 2 ), then x N(µ, σ 2 /n) where x = 1 n n i=1 x i Note in the above example, θ µ and ˆθ x How can we make inferences about θ using ˆθ when F is unknown? Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 6

Background Information Sampling Distributions The Hypothetical Ideal Assume that X is too large to measure all members of population. If we had a really LARGE research budget, we could collect B independent samples from the population X x j = (x 1j,..., x nj ) is j-th sample with x ij iid F ˆθ j = s(x j ) is statistic (parameter estimate) for j-th sample Sampling distribution of ˆθ can be estimated via distribution of {ˆθ j } B j=1. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 7

Background Information Sampling Distributions The Hypothetical Ideal: Example 1 (Normal Mean) Sampling Distribution of x with x i iid N(0, 1) for n = 100: Sampling Distribution: B = 200 Sampling Distribution: B = 500 Sampling Distribution: B = 1000 Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 xbar xbar xbar Sampling Distribution: B = 2000 Sampling Distribution: B = 5000 Sampling Distribution: B = 10000 Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 xbar xbar xbar Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 8

Background Information Sampling Distributions The Hypothetical Ideal: Example 1 R Code # hypothetical ideal: example 1 (normal mean) set.seed(1) n = 100 B = c(200,500,1000,2000,5000,10000) xseq = seq(-0.4,0.4,length=200) quartz(width=12,height=8) par(mfrow=c(2,3)) for(k in 1:6){ X = replicate(b[k], rnorm(n)) xbar = apply(x, 2, mean) hist(xbar, freq=f, xlim=c(-0.4,0.4), ylim=c(0,5), main=paste("sampling Distribution: B =",B[k])) lines(xseq, dnorm(xseq, sd=1/sqrt(n))) legend("topright",expression(bar(x)*" pdf"),lty=1,bty="n") } Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 9

Background Information Sampling Distributions The Hypothetical Ideal: Example 2 (Normal Median) Sampling Distribution of median(x) with x i iid N(0, 1) for n = 100: Sampling Distribution: B = 200 Sampling Distribution: B = 500 Sampling Distribution: B = 1000 Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 xmed xmed xmed Sampling Distribution: B = 2000 Sampling Distribution: B = 5000 Sampling Distribution: B = 10000 Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf Density 0 1 2 3 4 5 x pdf 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 0.4 0.2 0.0 0.2 0.4 xmed xmed xmed Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 10

Background Information Sampling Distributions The Hypothetical Ideal: Example 2 R Code # hypothetical ideal: example 2 (normal median) set.seed(1) n = 100 B = c(200,500,1000,2000,5000,10000) xseq = seq(-0.4,0.4,length=200) quartz(width=12,height=8) par(mfrow=c(2,3)) for(k in 1:6){ X = replicate(b[k], rnorm(n)) xmed = apply(x, 2, median) hist(xmed, freq=f, xlim=c(-0.4,0.4), ylim=c(0,5), main=paste("sampling Distribution: B =",B[k])) lines(xseq, dnorm(xseq, sd=1/sqrt(n))) legend("topright",expression(bar(x)*" pdf"),lty=1,bty="n") } Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 11

Background Information Need for Resampling Back to the Real World In most cases, we only have one sample of data. What do we do? If n is large and we only care about x, we can use the CLT. Sampling Distribution of x with x i iid U[0, 1] for B = 10000: Sampling Distribution: n = 3 Sampling Distribution: n = 5 Sampling Distribution: n = 10 Density 0.0 0.5 1.0 1.5 2.0 2.5 asymp pdf Density 0.0 0.5 1.0 1.5 2.0 2.5 3.0 asymp pdf Density 0 1 2 3 4 asymp pdf 0.0 0.2 0.4 0.6 0.8 1.0 xbar 0.2 0.4 0.6 0.8 xbar 0.2 0.4 0.6 0.8 xbar Sampling Distribution: n = 20 Sampling Distribution: n = 50 Sampling Distribution: n = 100 Density 0 1 2 3 4 5 6 asymp pdf Density 0 2 4 6 8 10 asymp pdf Density 0 2 4 6 8 10 12 14 asymp pdf 0.3 0.4 0.5 0.6 0.7 0.8 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.40 0.45 0.50 0.55 0.60 xbar xbar xbar Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 12

Background Information Need for Resampling The Need for a Nonparametric Resampling Method For most statistics other than the sample mean, there is no theoretical argument to derive the sampling distribution. To make inferences, we need to somehow obtain (or approximate) the sampling distribution of any generic statistic ˆθ. Note that parametric statistics overcome this issue by assuming some particular distribution for the data Nonparametric bootstrap overcomes this problem by resampling observed data to approximate the sampling distribution of ˆθ. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 13

Bootstrap Basics Bootstrap Basics Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 14

Problem of Interest Bootstrap Basics Overview In statistics, we typically want to know the properties of our estimates, e.g., precision, accuracy, etc. In parametric situation, we can often derive the distribution of our estimate given our assumptions about the data (or MLE principles). In nonparametric situation, we can use the bootstrap to examine properties of our estimates in a variety of different situations. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 15

Bootstrap Procedure Bootstrap Basics Overview Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to make inferences about some statistic ˆθ = s(x). Can use Monte Carlo Bootstrap: 1 Sample x i with replacement from {x 1,..., x n } for i {1,..., n} 2 Calculate ˆθ = s(x ) for b-th sample where x = (x 1,..., x n) 3 Repeat 1 2 a total of B times to get bootstrap distribution of ˆθ 4 Compare ˆθ = s(x) to bootstrap distribution Estimated standard error of ˆθ is standard deviation of {ˆθ b }B b=1 : 1 ˆσ B = B b=1 B 1 (ˆθ b θ ) 2 where θ = 1 B ˆθ B b=1 b is the mean of the bootstrap distribution of ˆθ. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 16

Bootstrap Basics Empirical Distribution Empirical Cumulative Distribution Functions Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to estimate the cdf F. The empirical cumulative distribution function (ecdf) ˆF n is defined as ˆF n (x) = ˆP(X x) = 1 n i=1 n I {x i x} where I { } denotes an indicator function. The ecdf assigns probability 1/n to each value x i, which implies that ˆP n (A) = 1 n i=1 n I {x i A} for any set A in the sample space of X. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 17

Bootstrap Basics Empirical Distribution Some Properties of ECDFs For any fixed value x, we have that E[ˆF n (x)] = F(x) V [ˆF n (x)] = 1 nf(x)[1 F(x)] As n we have that sup ˆF n (x) F(x) as 0 x R which is the Glivenko-Cantelli theorem. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 18

Bootstrap Basics Empirical Distribution ECDF Visualization for Normal Distribution n = 100 n = 500 n = 1000 Fn(x) 0.0 0.2 0.4 0.6 0.8 1.0 Fn(x) 0.0 0.2 0.4 0.6 0.8 1.0 Fn(x) 0.0 0.2 0.4 0.6 0.8 1.0 2 1 0 1 2 x 2 0 2 4 x 4 2 0 2 4 x set.seed(1) par(mfrow=c(1,3)) n = c(100,500,1000) xseq = seq(-4,4,length=100) for(j in 1:3){ x = rnorm(n[j]) plot(ecdf(x),main=paste("n = ",n[j])) lines(xseq,pnorm(xseq),col="blue") } Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 19

ECDF Example Bootstrap Basics Empirical Distribution Table 3.1 An Introduction to the Bootstrap (Efron & Tibshirani, 1993). School LSAT (y) GPA (z) School LSAT (y) GPA (z) 1 576 3.39 9 651 3.36 2 635 3.30 10 605 3.13 3 558 2.81 11 653 3.12 4 578 3.03 12 575 2.74 5 666 3.44 13 545 2.76 6 580 3.07 14 572 2.88 7 555 3.00 15 594 2.96 8 661 3.43 Defining A = {(y, z) : 0 < y < 600, 0 < z < 3.00}, we have ˆP 15 (A) = (1/15) 15 i=1 I {(y i,z i ) A} = 5/15 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 20

Bootstrap Basics Plug-In Principle Plug-In Parameter Estimates Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to estimate some parameter θ = t(f) that depends on the cdf F. Example: want to estimate expected value E(X) = xf (x)dx The plug-in estimate of θ = t(f) is given by ˆθ = t(ˆf) which is the statistic calculated using the ecdf in place of the cdf. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 21

Bootstrap Basics Plug-In Estimate of Mean Plug-In Principle Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to estimate the expected value θ = E(X) = xf (x)dx. The plug-in estimate of the expected value is the sample mean ˆθ = EˆF (x) = n x iˆfi = 1 n i=1 n x i = x i=1 where ˆf i = 1 n is sample probability from the ecdf. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 22

Bootstrap Basics Standard Error of Mean Plug-In Principle Let µ F = E F (x) and σ 2 F = V F (x) = E F [(x µ F ) 2 ] denote the mean and variance of X, and denote this using the notation X (µ F, σ 2 F ). If x = (x 1,..., x n ) with x i iid F (x) for i {1,..., n}, then the sample mean x = 1 n n i=1 x i has mean and variance x (µ F, σ 2 F /n). The standard error of the mean x is the square root of the variance of x SE F ( x) = σ F / n Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 23

Bootstrap Basics Plug-In Principle Plug-In Estimate of Standard Error of Mean Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to estimate the standard error of the mean SE F ( x) = σ F / n = E F [(x µ F ) 2 ]/n. The plug-in estimate of the standard deviation is given by ˆσ = σˆf = { } 1 1/2 n i=1 n (x i x) 2 so the plug-in estimate of the standard error of the mean is ˆσ/ n = σˆf / n = { } 1 1/2 n n 2 i=1 (x i x) 2 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 24

Bootstrap in Practice Bootstrap in Practice Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 25

Bootstrap in Practice Bootstrap in R Bootstrap Standard Error (revisited) Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to make inferences about some statistic ˆθ = s(x). Estimated standard error of ˆθ is standard deviation of {ˆθ b }B b=1 : 1 ˆσ B = B b=1 B 1 (ˆθ b θ ) 2 where θ = 1 B B b=1 ˆθ b is the mean of the bootstrap distribution of ˆθ. As the number of bootstrap samples goes to infinity, we have that lim B ˆσ B = SEˆF (ˆθ) where SEˆF (ˆθ) is the plug-in estimate of SE F (ˆθ). Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 26

Bootstrap in Practice Bootstrap in R Illustration of Bootstrap Standard Error 48 THE BOOTSTRAP ESTIMATE OF STANDARD ERROR Figure 6.1. The bootstrap algorithm for estimating the standard error of a statistzc ij = s(x); each bootstrap sample zs an mdependent random Figure 6.1: An Introduction sample of szze n from tof the The number Bootstrap of bootstrap replications (Efron B & for Tibshirani, 1993). estimating a standard error zs usually between 25 and 200. As B ---> oo, ies approaches the plug-m estimate of sep ( ij). Empirical Distribution Bootstrap Bootstrap Samples of Replications Size n of 8 t t I ::: = x* 3 -----+ S*(3) = s(x* 3 ) F / *b A x -----+ S*(b) = s(x*b) - Bootstrap Estimate of Standard Error EXAMPLE: THE CORREL tion g( x*), the expectat according to (6.1). The reader is asked in of enn- 1 ) distinct bootst where m = enn- 1 ). Fo ples are ( x1, xt), ( x2, Xz) ter, ( x2, xt) 1s the same one of these samples und tained frotu Llw multino 6.7 Denote the probabil 1, 2,.-- enn- 1 ). Then a d estimate of standard erro deviation of them boots sep(o*) = ( where s( ) = I:;"= 1 Wjs( that unless n is quite sma making computation of ( strap sampling as describ 6.3 Example: the cor We have already seen two estimate, for the mean a of the mouse data, Tabl sample correlation coeffi for then= 15 law school How accurate is the estim estimate of standard erro last value, sca2ou =.132 A word about notation: m (G.7) we write sep(ij*) rather than Will see that SC200 is near Looking at the nght st sep(o) to avoid confuswn between o, the value of s(x) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling based on Updated 04-Jan-2017 the bootstrap : Slide sampling 27 p J

Bootstrap in Practice Bootstrap in R Illustration of Bootstrap Procedure Figure 8.1: An Introduction to the Bootstrap (Efron & Tibshirani, 1993). ONE-SAMPLE PROBLEMS 87 REAL WORLD BOOTSTRAP WORLD Unknown Probability Distribution Observed Random Sample D1stnbution Bootstrap Sample Statistic of interest Bootstrap Replication Figure 8.1. A schematic diagram of the bootstrap as it applies to onesample problems. In the r eal world, the unknown probability distribution Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 28

Bootstrap in Practice Bootstrap in R An R Function for Bootstrap Resampling We can design our own bootstrap sampling function: bootsamp <- function(x,nsamp=10000){ x = as.matrix(x) nx = nrow(x) bsamp = replicate(nsamp,x[sample.int(nx,replace=true),]) } If x is a vector of length n, then bootsamp returns an n B matrix, where B is the number of bootstrap samples (controlled via nsamp). If x is a matrix of order n p, then bootsamp returns an n p B array, where B is the number of bootstrap samples. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 29

Bootstrap in Practice Bootstrap in R An R Function for Bootstrap Standard Error We can design our own bootstrap standard error function: bootse <- function(bsamp,myfun,...){ if(is.matrix(bsamp)){ theta = apply(bsamp,2,myfun,...) } else { theta = apply(bsamp,3,myfun,...) } if(is.matrix(theta)){ return(list(theta=theta,cov=cov(t(theta)))) } else{ return(list(theta=theta,se=sd(theta))) } } Returns a list where theta contains bootstrap statistic {ˆθ b }B b=1, and se contains the bootstrap standard error estimate (or cov contains bootstrap covariance matrix). Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 30

Bootstrap in Practice Example 1: Sample Mean Bootstrap in R > set.seed(1) > x = rnorm(500,mean=1) > bsamp = bootsamp(x) > bse = bootse(bsamp,mean) > mean(x) [1] 1.022644 > sd(x)/sqrt(500) [1] 0.04525481 > bse$se [1] 0.04530694 > hist(bse$theta) Frequency 0 500 1000 1500 Histogram of bse$theta 0.9 1.0 1.1 1.2 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 31

Bootstrap in Practice Example 2: Sample Median Bootstrap in R > set.seed(1) > x = rnorm(500,mean=1) > bsamp = bootsamp(x) > bse = bootse(bsamp,median) > median(x) [1] 0.9632217 > bse$se [1] 0.04299574 > hist(bse$theta) Frequency 0 1000 2000 3000 4000 5000 Histogram of bse$theta 0.8 0.9 1.0 1.1 1.2 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 32

Bootstrap in Practice Example 3: Sample Variance Bootstrap in R > set.seed(1) > x = rnorm(500,sd=2) > bsamp = bootsamp(x) > bse = bootse(bsamp,var) > var(x) [1] 4.095996 > bse$se [1] 0.2690615 > hist(bse$theta) Frequency 0 500 1000 1500 Histogram of bse$theta 3.5 4.0 4.5 5.0 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 33

Bootstrap in Practice Example 4: Mean Difference Bootstrap in R > set.seed(1) > x = rnorm(500,mean=3) > y = rnorm(500) > z = cbind(x,y) > bsamp = bootsamp(z) > myfun = function(z) mean(z[,1]) - mean(z[,2]) > bse = bootse(bsamp,myfun) > myfun(z) [1] 3.068584 > sqrt( (var(z[,1])+var(z[,2]))/nrow(z) ) [1] 0.06545061 > bse$se [1] 0.06765369 > hist(bse$theta) Frequency 0 500 1000 1500 2000 2500 Histogram of bse$theta 2.8 2.9 3.0 3.1 3.2 3.3 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 34

Bootstrap in Practice Example 5: Median Difference Bootstrap in R > set.seed(1) > x = rnorm(500,mean=3) > y = rnorm(500) > z = cbind(x,y) > bsamp = bootsamp(z) > myfun = function(z) median(z[,1]) - median(z[,2]) > bse = bootse(bsamp,myfun) > myfun(z) [1] 2.984479 > bse$se [1] 0.07699423 > hist(bse$theta) Frequency 0 500 1000 2000 3000 Histogram of bse$theta 2.8 3.0 3.2 3.4 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 35

Bootstrap in Practice Bootstrap in R Example 6: Correlation Coefficient > set.seed(1) > x=rnorm(500) > y=rnorm(500) > Amat=matrix(c(1,-0.25,-0.25,1),2,2) > Aeig=eigen(Amat,symmetric=TRUE) > evec=aeig$vec > evalsqrt=diag(aeig$val^0.5) > Asqrt=evec%*%evalsqrt%*%t(evec) > z=cbind(x,y)%*%asqrt > bsamp=bootsamp(z) > myfun=function(z) cor(z[,1],z[,2]) > bse=bootse(bsamp,myfun) > myfun(z) [1] -0.2884766 > (1-myfun(z)^2)/sqrt(nrow(z)-3) [1] 0.04112326 > bse$se [1] 0.03959024 > hist(bse$theta) Frequency 0 500 1000 1500 2000 Histogram of bse$theta 0.45 0.35 0.25 0.15 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 36

Bootstrap in Practice Bootstrap in R Example 7: Uniform[0, θ] = bootstrap failure > set.seed(1) > x = runif(500) > bsamp = bootsamp(x) > myfun = function(x) max(x) > bse = bootse(bsamp,myfun) > myfun(x) [1] 0.9960774 > bse$se [1] 0.001472801 > hist(bse$theta) ˆF is not a good estimate of F in extreme tails. Frequency 0 1000 3000 5000 Histogram of bse$theta 0.986 0.988 0.990 0.992 0.994 0.996 bse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 37

Bootstrap in Practice Bias and Mean-Squared Error Measuring the Quality of an Estimator We have focused on standard error to measure the precision of ˆθ. Small standard error is good, but other qualities are important too! Consider the toy example: Suppose {x i } n iid i=1 (µ, σ 2 ) and want to estimate mean of X Define ˆµ = 10 + x to be our estimate of µ Standard error of ˆµ is σ/ n and lim n σ/ n = 0 But ˆµ = 10 + x is clearly not an ideal estimate of µ Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 38

Bootstrap in Practice Bias and Mean-Squared Error Bias of an Estimator Suppose x = (x 1,..., x n ) with x i iid F(x) for i {1,..., n}, and we want to make inferences about some statistic ˆθ = s(x). The bias of an estimate ˆθ = s(x) of θ = t(f) is defined as Bias F = E F [s(x)] t(f) where the expectation is taken with respect to F. Bias is difference between expectation of estimate and parameter In the example on the previous slide, we have that Bias F = E F (ˆµ) µ = E F (10 + x) µ = 10 + E F ( x) µ = 10 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 39

Bootstrap in Practice Bias and Mean-Squared Error Bootstrap Estimate of Bias The bootstrap estimate of bias substitutes ˆF for F in bias definition BiasˆF = EˆF [s(x)] t(ˆf) where the expectation is taken with respect to the ecdf ˆF. Note that t(ˆf) is the plug-in estimate of θ t(ˆf) is not necessarily equal to ˆθ = s(x) Given B bootstrap samples, we can estimate bias using Bias B = θ t(ˆf) where θ = 1 B B b=1 ˆθ b is the mean of the bootstrap distribution of ˆθ Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 40

Bootstrap in Practice An R Function for Bootstrap Bias Bias and Mean-Squared Error We can design our own bootstrap bias estimation function: bootbias <- function(bse,theta,...){ if(is.matrix(bse$theta)){ return(apply(bse$theta,1,mean) - theta) } else{ return(mean(bse$theta) - theta) } } The first input bse is the object output from bootse, and the second input theta is the plug-in estimate of theta used for bias calculation. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 41

Bootstrap in Practice Sample Mean is Unbiased Bias and Mean-Squared Error > set.seed(1) > x = rnorm(500,mean=1) > bsamp = bootsamp(x) > bse = bootse(bsamp,mean) > mybias = bootbias(bse,mean(x)) > mybias [1] 0.0003689287 > mean(x) [1] 1.022644 > sd(x)/sqrt(500) [1] 0.04525481 > bse$se [1] 0.04530694 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 42

Toy Example Bootstrap in Practice Bias and Mean-Squared Error > set.seed(1) > x = rnorm(500,mean=1) > bsamp = bootsamp(x) > bse = bootse(bsamp,function(x) mean(x)+10) > mybias = bootbias(bse,mean(x)) > mybias [1] 10.00037 > mean(x) [1] 1.022644 > sd(x)/sqrt(500) [1] 0.04525481 > bse$se [1] 0.04530694 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 43

Bootstrap in Practice Bias and Mean-Squared Error Mean Squared Error (MSE) The mean-squared error (MSE) of an estimate ˆθ = s(x) of θ = t(f) is MSE F = E F {[s(x) t(f)] 2 } = V F (ˆθ) + [Bias F (ˆθ)] 2 where the expectation is taken with respect to F. MSE is expected squared difference between ˆθ and θ In the toy example on the previous slide, we have that MSE F = E F {(ˆµ µ) 2 } = E F {(10 + x µ) 2 } = E F (10 2 ) + 2E F [10( x µ)] + E F [( x µ) 2 ] = 100 + σ 2 /n Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 44

Bootstrap in Practice Toy Example (revisited) Bias and Mean-Squared Error > set.seed(1) > x = rnorm(500,mean=1) > bsamp = bootsamp(x) > bse = bootse(bsamp,function(x) mean(x)+10) > mybias = bootbias(bse,mean(x)) > c(bse$se,mybias) [1] 0.04530694 10.00036893 > c(bse$se,mybias)^2 [1] 2.052718e-03 1.000074e+02 > mse = (bse$se^2) + (mybias^2) > mse [1] 100.0094 > 100 + 1/length(x) [1] 100.002 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 45

Bootstrap in Practice Bias and Mean-Squared Error Balance between Accuracy and Precision MSE quantifies both the accuracy (bias) and precision (variance). Ideal estimators are accurate (small bias) and precise (small variance). Having some bias can be an ok (or even good) thing, despite the negative connotations of the word biased. For example: Q: Would you rather have an estimator that is biased by 1 unit with a standard error of 1 unit? Or one that is unbiased but has a standard error of 1.5 units? A: The first estimator is better with respect to MSE Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 46

Bootstrap in Practice Bias and Mean-Squared Error Accuracy and Precision Visualization 3 2 1 0 1 2 3 3 2 1 0 1 2 3 low accuracy and low precision x y Truth Estimates 3 2 1 0 1 2 3 3 2 1 0 1 2 3 low accuracy and high precision x y Truth Estimates 3 2 1 0 1 2 3 3 2 1 0 1 2 3 high accuracy and low precision x y Truth Estimates 3 2 1 0 1 2 3 3 2 1 0 1 2 3 high accuracy and high precision x y Truth Estimates Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 47

Bootstrap in Practice The Jackknife Jackknife Sample Before the bootstrap, the jackknife was used to estimate bias and SE. The i-th jackknife sample of x = (x 1,..., x n ) is defined as x (i) = (x 1,..., x i 1, x i+1,..., x n ) for i {1,..., n}. Note that... x (i) is original data vector without the i-th observation x (i) is a vector of length (n 1) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 48

Jackknife Replication Bootstrap in Practice The Jackknife The i-th jackknife replication ˆθ (i) of the statistic ˆθ = s(x) is ˆθ (i) = s(x (i) ) which is the statistic calculated using the i-th jackknife sample. For plug-in statistics ˆθ = t(ˆf), we have that ˆθ (i) = t(ˆf (i) ) where ˆF (i) is the empirical distribution of x (i). Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 49

Bootstrap in Practice The Jackknife Jackknife Estimate of Standard Error The jackknife estimate of standard error is defined as ˆσ jack = n 1 n (ˆθ n (i) ˆθ ( ) ) 2 where ˆθ ( ) = 1 n n i=1 ˆθ (i) is the mean of the jackknife estimates of θ. i=1 Note that the n 1 n factor is derived considering the special case ˆθ = x ˆσ jack = 1 (n 1)n n (x i x) 2 i=1 which is an unbiased estimator of the standard error of x. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 50

Bootstrap in Practice The Jackknife Jackknife Estimate of Bias The jackknife estimate of bias is defined as Bias jack = (n 1)(ˆθ ( ) ˆθ) where ˆθ ( ) = 1 n n i=1 ˆθ (i) is the mean of the jackknife estimates of θ. This approach only works for plug-in statistics ˆθ = t(ˆf ). Only works if t(ˆf) is smooth (e.g., mean or ratio) Doesn t work if t(ˆf) is unsmooth (e.g., median) Gives bias estimate using only n recomputations (typically n B) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 51

Bootstrap in Practice Smooth versus Unsmooth t(ˆf ) The Jackknife Suppose we have a sample of data (x 1,..., x n ), and consider the mean and median as a function of x 1 : mean median meanval 0.08 0.10 0.12 0.14 medval 0.08 0.10 0.12 0.14 4 2 0 2 4 4 2 0 2 4 x 1 x 1 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 52

Bootstrap in Practice The Jackknife Smooth versus Unsmooth t(ˆf ) R Code # mean is smooth meanfun <- function(x,z) mean(c(x,z)) set.seed(1) z = rnorm(100) x = seq(-4,4,length=200) meanval = rep(0,200) for(j in 1:200) meanval[j] = meanfun(x[j],z) quartz(width=6,height=6) plot(x,meanval,xlab=expression(x[1]),main="mean") # median is unsmooth medfun <- function(x,z) median(c(x,z)) set.seed(1) z = rnorm(100) x = seq(-4,4,length=200) medval = rep(0,200) for(j in 1:200) medval[j] = medfun(x[j],z) quartz(width=6,height=6) plot(x,medval,xlab=expression(x[1]),main="median") Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 53

Bootstrap in Practice The Jackknife Some R Functions for Jackknife Resampling We can design our own jackknife functions: jacksamp <- function(x){ nx = length(x) jsamp = matrix(0,nx-1,nx) for(j in 1:nx) jsamp[,j] = x[-j] jsamp } jackse <- function(jsamp,myfun,...){ nx = ncol(jsamp) theta = apply(jsamp,2,myfun,...) se = sqrt( ((nx-1)/nx) * sum( (theta-mean(theta))^2 ) ) list(theta=theta,se=se) } These functions work similar to the bootsamp and bootse functions if x is a vector and the statistic produced by myfun is unidimensional. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 54

Bootstrap in Practice The Jackknife Example 1: Sample Mean (revisited) > set.seed(1) > x = rnorm(500,mean=1) > jsamp = jacksamp(x) > jse = jackse(jsamp,mean) > mean(x) [1] 1.022644 > sd(x)/sqrt(500) [1] 0.04525481 > jse$se [1] 0.04525481 > hist(jse$theta) Frequency 0 20 40 60 80 100 Histogram of jse$theta 1.016 1.020 1.024 1.028 jse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 55

Bootstrap in Practice The Jackknife Example 2: Sample Median (revisited) > set.seed(1) > x = rnorm(500,mean=1) > jsamp = jacksamp(x) > jse = jackse(jsamp,median) > median(x) [1] 0.9632217 > jse$se [1] 0.01911879 > hist(jse$theta) Frequency 0 50 100 150 200 250 Histogram of jse$theta 0.9625 0.9630 0.9635 0.9640 jse$theta Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 56

Bootstrapping Regression Bootstrapping Regression Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 57

Bootstrapping Regression Regression Review Simple Linear Regression Model: Scalar Form The simple linear regression model has the form for i {1,..., n} where y i = b 0 + b 1 x i + e i y i R is the real-valued response for the i-th observation b 0 R is the regression intercept b 1 R is the regression slope x i R is the predictor for the i-th observation e i iid (0, σ 2 ) is zero-mean measurement error Implies that (y i x i ) ind (b 0 + b 1 x i, σ 2 ) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 58

Bootstrapping Regression Regression Review Simple Linear Regression Model: Matrix Form The simple linear regression model has the form where y = Xb + e y = (y 1,..., y n ) R n is the n 1 response vector X = [1 n, x] R n 2 is the n 2 design matrix 1 n is an n 1 vector of ones x = (x 1,..., x n ) R n is the n 1 predictor vector b = (b 0, b 1 ) R 2 is the 2 1 vector of regression coefficients e = (e 1,..., e n ) (0 n, σ 2 I n ) is the n 1 error vector Implies that (y x) (Xb, σ 2 I n ) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 59

Bootstrapping Regression Regression Review Ordinary Least Squares: Scalar Form The ordinary least squares (OLS) problem is min b 0,b 1 R n (y i b 0 b 1 x i ) 2 i=1 and the OLS solution has the form ˆb 0 = ȳ ˆb 1 x ˆb 1 = n i=1 (x i x)(y i ȳ) n i=1 (x i x) 2 where x = (1/n) n i=1 x i and ȳ = (1/n) n i=1 y i Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 60

Bootstrapping Regression Regression Review Ordinary Least Squares: Matrix Form The ordinary least squares (OLS) problem is min y Xb 2 b R 2 where denotes the Frobenius norm; the OLS solution has the form ˆb = (X X) 1 X y where ( X X ) ( 1 1 n = n i=1 x i 2 n i=1 x i n i=1 (x i x) 2 n i=1 x i n ( n X y = i=1 y ) i n i=1 x iy i ) Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 61

Bootstrapping Regression Regression Review OLS Coefficients are Random Variables Note that ˆb is a linear function of y, so we can derive the following. The expectation of ˆb is given by E(ˆb) = E[(X X) 1 X y] = E[(X X) 1 X (Xb + e)] = E[b] + (X X) 1 X E[e] = b and the covariance matrix is given by V(ˆb) = V[(X X) 1 X y] = (X X) 1 X V[y]X(X X) 1 = (X X) 1 X (σ 2 I n )X(X X) 1 = σ 2 (X X) 1 Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 62

Bootstrapping Regression Regression Review Fitted Values are Random Variables Similarly ŷ = Xˆb is a linear function of y, so we can derive... The expectation of ŷ is given by E(ŷ) = E[X(X X) 1 X y] = E[X(X X) 1 X (Xb + e)] = E[Xb] + X(X X) 1 X E[e] = Xb and the covariance matrix is given by V(ŷ) = V[X(X X) 1 X y] = X(X X) 1 X V[y]X(X X) 1 X = X(X X) 1 X (σ 2 I n )X(X X) 1 X = σ 2 X(X X) 1 X Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 63

Bootstrapping Regression Regression Review Need for the Bootstrap If the residuals are Gaussian e i iid N(0, σ 2 ), then we have that ˆb N(b, σ 2 (X X) 1 ). ŷ N(Xb, σ 2 X(X X) 1 X ) so it is possible to make probabilistic statements about ˆb and ŷ. If e i iid F for some arbitrary distribution F with E F (e i ) = 0, we can use the bootstrap to make inferences about ˆb and ŷ. Use bootstrap with ecdf ˆF as distribution of e i Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 64

Bootstrapping Regression Bootstrapping Residuals Bootstrapping Regression Residuals Can use following bootstrap procedure: 1 Fit regression model to obtain ŷ and ê = y ŷ 2 Sample e i with replacement from {ê 1,..., ê n } for i {1,..., n} 3 Define y i = ŷ i + e i and ˆb = (X X) 1 X y 4 Repeat 2 3 a total of B times to get bootstrap distribution of ˆb Don t need Monte Carlo simulation to get bootstrap standard errors: V(ˆb ) = (X X) 1 X V(y )X(X X) 1 = ˆσ 2 F (X X) 1 given that V(y ) = ˆσ 2 F I n where ˆσ 2 F = n i=1 e2 i /n Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 65

Bootstrapping Regression Bootstrapping Residuals Bootstrapping Regression Residuals in R > set.seed(1) > n = 500 > x = rexp(n) > e = runif(n,min=-2,max=2) > y = 3 + 2*x + e > linmod = lm(y~x) > linmod$coef (Intercept) x 2.898325 2.004220 > yhat = linmod$fitted.values > bsamp = bootsamp(linmod$residuals) > bsamp = matrix(yhat,n,ncol(bsamp)) + bsamp > myfun = function(y,x) lm(y~x)$coef > bse = bootse(bsamp,myfun,x=x) > bse$cov (Intercept) x (Intercept) 0.006105788-0.003438571 x -0.003438571 0.003605852 > sigsq = mean(linmod$residuals^2) > solve(crossprod(cbind(1,x))) * sigsq x 0.006112136-0.003412774 x -0.003412774 0.003573180 > par(mfcol=c(2,1)) > hist(bse$theta[1,],main=expression(hat(b)[0])) > hist(bse$theta[2,],main=expression(hat(b)[1])) Frequency Frequency 0 1000 0 1500 3000 b^0 2.6 2.7 2.8 2.9 3.0 3.1 3.2 bse$theta[1, ] b^1 1.8 1.9 2.0 2.1 2.2 2.3 bse$theta[2, ] Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 66

Bootstrapping Regression Bootstrapping Pairs Bootstrapping Pairs Instead of Residuals We could also use the following bootstrap procedure: 1 Fit regression model to obtain ŷ and ê = y ŷ 2 Sample z i = (xi, yi ) with replacement from {(x 1, y 1 ),..., (x n, y n )} for i {1,..., n} 3 Define x = (x 1,..., x n), X = [1 n, x ], y = (y 1,..., y n ),, and ˆb = (X X ) 1 X y 4 Repeat 2 3 a total of B times to get bootstrap distribution of ˆb Bootstrapping pairs only assumes (x i, y i ) are iid from some F. Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 67

Bootstrapping Regression Bootstrapping Pairs Bootstrapping Regression Pairs in R > set.seed(1) > n = 500 > x = rexp(n) > e = runif(n,min=-2,max=2) > y = 3 + 2*x + e > linmod = lm(y~x) > linmod$coef (Intercept) x 2.898325 2.004220 > z = cbind(y,x) > bsamp = bootsamp(z) > myfun = function(z) lm(z[,1]~z[,2])$coef > bse = bootse(bsamp,myfun) > bse$cov (Intercept) z[, 2] (Intercept) 0.006376993-0.003913989 z[, 2] -0.003913989 0.004308720 > sigsq = mean(linmod$residuals^2) > solve(crossprod(cbind(1,x))) * sigsq x 0.006112136-0.003412774 x -0.003412774 0.003573180 > par(mfcol=c(2,1)) > hist(bse$theta[1,],main=expression(hat(b)[0])) > hist(bse$theta[2,],main=expression(hat(b)[1])) Frequency Frequency 0 1000 2500 0 1000 2500 b^0 2.6 2.7 2.8 2.9 3.0 3.1 3.2 bse$theta[1, ] b^1 1.8 1.9 2.0 2.1 2.2 bse$theta[2, ] Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 68

Bootstrapping Regression Bootstrapping Regression: Pairs or Residuals? Bootstrapping pairs requires fewer assumptions about the data Bootstrapping pairs only assumes (x i, y i ) are iid from some F Bootstrapping residuals assumes (y i x i ) iid (b 0 + b 1 x i, σ 2 ) Bootstrapping pairs can be dangerous when working with categorical predictors and/or continuous predictors with skewed distributions Bootstrapping residuals is preferable when regression model is reasonably specified (because X remains unchanged). Nathaniel E. Helwig (U of Minnesota) Bootstrap Resampling Updated 04-Jan-2017 : Slide 69