Anyone who can help me speed up some code:
n = seq_len(ncol(mat))
sym.pr<-outer(n,n,Vectorize(function(a,b) {
return(adf.test(LinReg(mat[,c(a,b)]),k=0,alternative="stationary")$p.value)
}))
Where matis a matrix of NxMobjects of observation Nand M, for example:
Obj1 Obj2 Obj3
1 . . .
2 . . .
3 . . .
LinReg defined as:
LinReg=function(vals) {
regline<-lm(vals[,1]~as.matrix(vals[,2:ncol(vals)])+0)
return(as.matrix(regline$residuals))
}
Basically, I perform regression analysis (OLS) for each combination of objects (i.e., Obj1, Obj2and Obj2,Obj3and Obj1, Obj3) in mat, and then using the function adf.testfrom the package tseriesand saving p-value. The end result sym.pris a symmetric matrix of all p-values(but in fact it is not 100% symmetrical, see here for more information ), however, this will be enough.
With the above code on the matrix 600x300(600 observations and 300 objects), it takes about 15 minutes.
, , , .
?
.