[R] Creating an array from correlation matrices
Max Frisch
rstatistics.user at gmail.com
Fri Aug 31 18:24:53 CEST 2012
Hello everyone,
a hopefully easy to solve problem from an R novice...
I try to calculate a number of correlation matrices that finally should be combined in a three-dimensional array.
Here the my code with an R dataset as an example.
-----------------------------------
## Creation an array of correlation matrices from a rolling window application
TS <- EuStockMarkets
# Load internal dataset
n <- 30
# Choose size of rolling time window
T <- c(1:nrow(TS))
# Define number of steps
X <- array(data = NA, dim = c(ncol(TS), ncol(TS), nrow(TS)))
# Create data array
for (t in T[1:(length(T)-n)]){
X[t] = cor(TS[t:(t+n), 1:ncol(TS)], use = "pairwise.complete.obs")
}
# Calculate correlation matrices
---------------------------------
Unfortunately, I only get a warning that the dimensions do not fit... Where is the mistake?
THANKS A LOT!
Nico
More information about the R-help
mailing list