Search code examples
rstatistics-bootstrap

bootstrap a linear regression


I am trying to run a bootstrap from a linear regression in R. The code I have so far is

hprice<-lm(dat[,1]~dat[,3]+dat[,4]+dat[,5]+dat[,6])
print (hprice)
pricefunc<-function(data,ind) lm(data[ind,1]~data[ind,3]+data[ind,4]+data[ind,5]+data[ind,6])
hpboot<-boot(dat,pricefunc, 1000)

this doesn't seem to work.

I don't really understand the statistic argument and I would say this is where I am going wrong.

thanks


Solution

  • If you need the coefficients estimates you have to add $coef to the lm function

    pricefunc<-function(data,ind) lm(data[ind,1]~data[ind,3]+data[ind,4]+data[ind,5]+data[ind,6])$coef
    

    Then you can run:

    boot(dat,pricefunc, 1000)