When I replace the time series variables comes Warnings [number of items to replace is not a multiple of replacement length]

Hello community! First post, please pardon any inaccuracies.
So I'm trying to develop a function with loops to conduct the quantile-on-quantile (QQ) regression (a type of time series analysis) between two time series. The function is developed as:

coverLLsr=function(y,x,coverNum=3,h=3,kernel=c('Gauss','Laplace','Bessel'),ylag=1,xlag=NULL)
{
call=match.call()
mAll=sapply((1:coverNum)/(coverNum+1),function(p){
sapply((1:coverNum)/(coverNum+1),function(t){
llsr(y=y,x=x,h=h,theta=p,tao=t,kernel=kernel,ylag=ylag,xlag=xlag)
})
})
coefAll=array(dim=c(coverNum,coverNum,length(ylag)+length(xlag)+2,4))
R2All=matrix(NA,coverNum,coverNum)
AICAll=matrix(NA,coverNum,coverNum)
thetaAll=matrix(NA,coverNum,coverNum)
taoAll=matrix(NA,coverNum,coverNum)
for(i in 1:coverNum)
for(j in 1:coverNum)
{
coefAll[i,j,,]=mAll[[6*(i-1)+6coverNum(j-1)+2]]
R2All[i,j]=mAll[[6*(i-1)+6coverNum(j-1)+3]]
AICAll[i,j]=mAll[[6*(i-1)+6coverNum(j-1)+4]]
thetaAll[i,j]=mAll[[6*(i-1)+6coverNum(j-1)+5]]
taoAll[i,j]=mAll[[6*(i-1)+6coverNum(j-1)+6]]
}
callUse=as.character(call)
dimnames(coefAll)[[3]]=c('intercept',callUse[3],paste0(callUse[2],'_lag',seq(1:length(ylag))))
dimnames(coefAll)[[4]]=c('value','stdError','t value','P-value')
dimnames(thetaAll)[[1]]=dimnames(taoAll)[[1]]=dimnames(R2All)[[1]]=dimnames(AICAll)[[1]]=dimnames(coefAll)[[1]]=paste0('tao',round((1:coverNum)/(coverNum+1),3))
dimnames(thetaAll)[[2]]=dimnames(taoAll)[[2]]=dimnames(R2All)[[2]]=dimnames(AICAll)[[2]]=dimnames(coefAll)[[2]]=paste0('theta',round((1:coverNum)/(coverNum+1),3))
mAll=list(mAll=mAll,coefAll=coefAll,R2All=R2All,AICAll=AICAll,thetaAll=thetaAll,taoAll=taoAll)
class(mAll)='llsrs'
return(mAll)
}

And I first use this function to conduct the regression between two time series as:

data=read.csv('r_oil.csv')
r1=data2[,1]
r2=data2[,2]
m2=coverLLsr(r1,r2,coverNum=49,h=1/5);
write.xlsx(m2$coefAll[,,1,1],'coef.xlsx','intercept')
write.xlsx(m2$coefAll[,,2,1],'coef.xlsx','b1',append = T)
write.xlsx(m2$coefAll[,,3,1],'coef.xlsx','aerfa(theta)',append = T)
write.xlsx(m2$AICAll,'coef.xlsx','AIC',append = T)
write.xlsx(m2$thetaAll,'coef.xlsx','theta',append = T)
write.xlsx(m2$taoAll,'coef.xlsx','tao',append = T)

r1 and r2 are the two time series with 5774 observations each
And it works out fine. However, when I replace the time series variable with the other two time series with shorter time range with 157 observations each as:


and again run the above function, and it comes the warning
Error in coefAll[i, j, , ] <- mAll[[6 * (i - 1) + 6 * coverNum * (j - : number of items to replace is not a multiple of replacement length

It troubles me a lot! Any help will be deeply appreciated! Thanks in advance!

Do you really need to program it?

The quatreg package may do what you want.

Thanks for the reply! I will check it though I may need to conduct the quantile on quantile regression rather than the quantile regression.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.