Rick DeShon
2007-Dec-03 18:57 UTC
[R] Efficient computation of average covariance matrix over a list
Hi All. I would like to compute a separate covariance matrix for a set of variables for each of the levels of a factor and then compute the average covariance matrix over the factor levels. I can loop through this computation but I need to perform the calculation for a large number of levels and am looking for something more elegant. To be concrete.... u <- 3 n <- 10 x <- rnorm((id*u)) y <- rnorm((id*u)) z <- rnorm((id*u)) id <- gl(u,n) df <- data.frame(id,x,y,z) df.s <- split(xxx,id) lcov <- lapply(df.s,cov) lcov What's an efficient way to compute the average covariance matrix over the list members in "lcov"? Thanks in advance, Rick [[alternative HTML version deleted]]
Rick DeShon
2007-Dec-03 21:02 UTC
[R] Efficient computation of average covariance matrix over a list
Hi All. I would like to compute a separate covariance matrix for a set of variables for each of the levels of a factor and then compute the average covariance matrix over the factor levels. I can loop through this computation but I need to perform the calculation for a large number of levels and am looking for something more elegant. To be concrete.... u <- 3 n <- 10 x <- rnorm((id*u)) y <- rnorm((id*u)) z <- rnorm((id*u)) id <- gl(u,n) df <- data.frame(id,x,y,z) df.s <- split(xxx,id) lcov <- lapply(df.s,cov) lcov What's an efficient way to compute the average covariance matrix over the list members in "lcov"? Thanks in advance, Rick DeShon
Apparently Analagous Threads
- Create an AR(1) covariance matrix
- Compute a correlation matrix from an existing covariance matrix
- Problem when creating matrix of values based on covariance matrix
- Customizing SBCC for lcov workflows
- How-To construct a cov list to use a covariance matrix in factanal?