I have the following code to calculate ADF statistics across ts data in a matrix raw.
raw <- matrix(rnorm(25000), nrow=1000,ncol=25)
for (i in 1:(ncol(raw)-1)) {
for (j in (i+1):ncol(raw)) {
df <- data.frame(N = integer(0), DFStat = numeric(0), PVAL = numeric(0))
name <- paste(i,j, sep="_")
dir <- paste("C:/Data/rOUT/", name,".txt",sep="")
for (t in 1:20) {
N <- 50*t
xtail <- tail(raw[,i],N)
ytail <- tail(raw[,j],N)
reg <- lm(ytail ~ xtail)
test <- adf.test(reg$residuals, k = 1)
df[t,] <- c(N, test$statistic, test$p.value)
write.table(df, dir, sep="\t", row.names=FALSE)
rm(df)
}
}
}
The block in the first two loops runs perfectly when not looping through the columns in raw, but when I try to traverse raw, I get the closure error below:
Error in df[t, ] <- c(N, test$statistic, test$p.value) :
object of type 'closure' is not subsettable
Does anyone know why I am encountering this difference and steps I can take to correct it?