s-news
[Top] [All Lists]

Bootstrapping a statistic containing a do loop

To: <s-news@lists.biostat.wustl.edu>
Subject: Bootstrapping a statistic containing a do loop
From: "JT Toman" <J.Toman@econ.usyd.edu.au>
Date: Thu, 7 Aug 2003 17:28:52 +1000
Thread-index: AcNctQU4bdpeJppMSNGtzY4qty/jzg==
Thread-topic: Bootstrapping a statistic containing a do loop

The aim of my program is to perform the following bootstrap:

1. Run the regression on the restricted model (yt on x)

2. Save the residuals and rescale them (res1)

3. Bootstrap on the residuals

4. Re-estimate new yt as the fitted values + bootstrapped residuals

5. Estimated the LR statistic using the new data (LRstat function)

6. Repeat 999 times

 

My bootstrap program does not do this. It is coming up with extreme bias issue.

The LR stat function is not the problem, so the problem must be in

constructing the residuals or in the bootstrap set-up.

 

I am new to S+, and can’t see the bug. Can someone point me in the right direction?

 

The program is below:

 

#test1crit.ssc

 

# Function to create LR statistic

LRstat_function(slave1)

{

  

 LR_c(0,0,0,0,0,0,0,0,0,0,0,0,0)

 yt_slave1$yt

 x_as.matrix(slave1[,2:22])

 n_nrow(x)

 slabor_slave1$slabor

 for (i in 2:14)

 {

  

# define xmat

   smallslave_x[slabor<=i,]

   largeslave_x[slabor>i,]

   xmat1_matrix(c(0),n,21)

   xmat2_matrix(c(0),n,21)

   ns_nrow(smallslave)

   xmat1[1:ns,]_smallslave

   xmat2[(ns+1):n,]_largeslave

   xmat_cbind(xmat1,xmat2)

 

# fit two regressions

   lm1.fit_lsfit(x,yt,int=F)

   lm2.fit_lsfit(xmat,yt,int=F)

 

# evaluate LR statistic for split i

   sser_sum((lm1.fit$res)^2)

   sseu_sum((lm2.fit$res)^2)

   LR[i-1]_((sser-sseu)*n)/sseu

 }

 

 LRmax_max(LR)

}

   # define residuals of restricted model for bootstrap

   restr_lsfit(slavedat[,2:22],slavedat[,1],int=F)

   res_restr$res

   fit_slavedat[,1]-res

  

 #rescale residuals

   res1_res*sqrt(n/(n-21))

#create data of data, residuals, and fitted vals

   slavedat1_data.frame(slavedat,fit=fit,res1=res1)

 

#function that creates (ytstar=fit+booterror)

   slave.fun_function(slavedat1)

   {slave1_slavedat1

       slave1$yt_slave1$fit+slave1$res1

       LRstat(slave1)

   }

bootlr_bootstrap(slavedat1, slave.fun(slavedat1), B=999, seed=123)

summary(bootlr)

 

_________________________________________
Dr. J.T. Toman
Econometrics and Business Statistics
School of Economics and Political Science
University of
Sydney, 2006, Australia
61-2-9036-9118
j.toman@econ.usyd.edu.au

 

<Prev in Thread] Current Thread [Next in Thread>
  • Bootstrapping a statistic containing a do loop, JT Toman <=