I need to apply a corr.test
on all my 4 variables based on a sliding window of 4 and step 1. I could do it for 2 variables at a time, is it possible to do it on 4 variables?
library("gtools")
library("psych")
pos <- subs$POS
result <- running(subs[,2], subs[,3], fun=corr.test, width=4, by=1)
n <-length(pos)
intervals <- paste(pos[1:(n-3)],pos[4:n], sep =':')
names(result) <- intervals
subs <- structure(list(POS = c(92, 92, 94, 94, 101, 103, 105, 106, 107,
113, 114, 120, 120, 122, 132, 136, 140, 143, 143, 146), var1 = c(1,
6, 1, 1, 3, 1, 1, 2, 10, 1, 1, 5, 1, 1, 5, 8, 2, 1, 1, 17), var2 = c(11355.6578947368,
11355.6578947368, 11347.8157894737, 11347.8157894737, 11450.0789473684,
11478, 11473.1052631579, 11479.7105263158, 11495.1315789474,
11642.6052631579, 11691.2631578947, 11612.0526315789, 11612.0526315789,
11497.7368421053, 11580.1578947368, 11421.6842105263, 11288.1052631579,
11288.0263157895, 11288.0263157895, 11278), var3 = c(1.37171511940581,
1.37171511940581, 1.38015533583543, 1.38015533583543, 1.38285457974173,
1.38467221575929, 1.38728237171707, 1.38800712625898, 1.38790768043085,
1.39036602407455, 1.39189385417378, 1.39598161236479, 1.39598161236479,
1.39737128761462, 1.38302756354476, 1.37244652743204, 1.3632470398133,
1.35191834216266, 1.35191834216266, 1.33779404050067), var4 = c(1.04285684958464,
1.04285684958464, 1.04296690407379, 1.04296690407379, 1.04244689713763,
1.04242150761792, 1.04233095775203, 1.0422836372936, 1.04225281778793,
1.04210777961787, 1.04202037841291, 1.04165492323573, 1.04165492323573,
1.04161860236611, 1.04065255428577, 1.03999715968399, 1.03927165790059,
1.03890373057753, 1.03890373057753, 1.03861585865751)), row.names = c(NA,
20L), class = "data.frame")
If I try this:
result <- running(subs[,2:5], fun=corr.test,
width=4, by=1)
I get this error:
Error in seq.default(from = 1, to = length(run.elements), by = by) :
wrong sign in 'by' argument