
 
returnFromData<-function(Data,regTime)

{

Sort = rollapply(Data,regTime, GetCoeff,toReg=1,onReg=2:ncol(Data),Nb=ncol(Data)-1,align="right", by.column = FALSE)

return(Sort)

}

 

GetCoeff<-function(zooreturn,toReg,onReg,Nb)

{

LinReg = lm((zooreturn[,toReg])~zooreturn[,onReg],na.action=na.omit)

Coeff.LinReg = LinReg$coefficients

RSquared = summary(LinReg)["adj.r.squared"][[1]]

Stats = cbind(t(as.numeric(Coeff.LinReg)),RSquared)

genNames = gsub(" ","",paste(rep("Expl",ncol(zooreturn)-1),seq(1,ncol(zooreturn)-1)))

names(Stats) = c("Intercept",genNames,"rSquared")

return(Stats)

}
Sent using BlackBerry® from Orange

-----Original Message-----
From: Lu Fan <lfanff@gmail.com>
Date: Wed, 18 May 2011 09:34:33 
To: <p.desmazis@gmail.com>
Cc: <r-sig-finance@r-project.org>
Subject: Re: [R-SIG-Finance] rolling regression estimate std. error / t value

Des Mazis,

Sorry to bother you again, but I still couldn't figure it out.

My code is :
read.table("C:/.../dataset.txt")
library(zoo)
mydata=zoo(z)
fct_computeCoeffAndStats<-function(zooObject)
{
reg_lm=lm(y~f1+f2+f3+f4+f5,data=mydata)
reg_coeff=reg_lm$coefficients
reg_ci=confint(reg_lm,level=0.95)
dataToReturn = cbind(reg_coeff,reg_ci)
Return(as.numeric(dataToReturn))
}
rollapply(mydata, width=60, fct_computeCoeffAndStats,align="right")

The error message is:
Error in FUN(cdata[st, i], ...) : could not find function "Return"

I am not quite sure what to replace zooObject; I tried 'mydata' and 'z', but
unfortunately they didn't work.

Thanks again!


	[[alternative HTML version deleted]]

