Skip to content

Bootstrapping for residuals

4 messages · bubbles1990, David Winsemius

#
Hi, Ive been trying to write a program for bootstrapping residuals in R but
without much success.

A lecturer wants to predict the performance of students in an end-of-year
physics exam, y. The lecturer has the students results from a mid-term
physics exam, x, and a mid-term biology exam, z.
He proposes the following linear model for the end-of-year exam result 
yi = ? + ?xi + ?zi + qi, where q is the error.
Y is a matrix of the data and we have y=first column of the data and
X=second 2 columns(the x & z data)
Now I need to write a program for obtaining bootstrap estimates, i have:

x=scan(data)
Y=matrix(x,ncol=3,byrow=T)
y=Y[,1]
X=Y[,2:3]

ls=lsfit(X,y)
beta=ls$coef

yest=beta[1]+beta[2]*X[,1]+beta[3]*X[,2]
res=y-yest

boot=function(X,res,beta,b)
{
n=24
output=matrix(0,ncol=2,nrow=b)
for(i in 1:b)
{
error=sample(res,n,replace=T)
ystar=beta[1]+beta[2]*X[,1]+beta[3]*X[,2]+error
ls=lsfit(X,ystar)
output[i,]=ls$coef
}
output
}

I think the first 8 lines are right but my function might be wrong?
Any help?

--
View this message in context: http://r.789695.n4.nabble.com/Bootstrapping-for-residuals-tp4123657p4123657.html
Sent from the R help mailing list archive at Nabble.com.
#
On Nov 30, 2011, at 11:31 AM, bubbles1990 wrote:

            
You should ask your instructor or teaching assistant for help.

  
    
#
I study a part-time long distance learning course so only really have access
to online sources for help, i'm sure ill crack it eventually. I understand
how to do it with 2 variables, its just having 3 that is confusing me

--
View this message in context: http://r.789695.n4.nabble.com/Bootstrapping-for-residuals-tp4123657p4125325.html
Sent from the R help mailing list archive at Nabble.com.
#
On Nov 30, 2011, at 11:31 AM, bubbles1990 wrote:

            
You replied but included no context, a common and not appreciated (in  
both senses of that verb) failing in posts from Nabble. My question  
would be: bootstrap estimate ... of what?