[R] Filling a covariance matrix
emorway
emorway at usgs.gov
Wed Oct 31 16:26:07 CET 2012
Hi Joshua,
The code you put together is very helpful. I have run into a small issue,
however, and I am surprised you weren't getting similar error message when
you tried running the nested for loops? As an example, I've pared down the
for loop a bit to highlight the error message I'm getting (note also that I
had to modify xs[[i]]$Q to xs[[i]]$*x*Q):
for(i in seq_along(xs)) {
for(j in seq_along(xs)) {
xcov[paste0("Q",i),paste0("Q",j)] <- xcov[paste0("Q",j),paste0("Q",i)]
<- cov(xs[[i]]$xQ, xs[[j]]$xQ, use="complete.obs")
}
}
#Error in cov(xs[[i]]$xQ, xs[[j]]$xQ, use = "complete.obs") :
# incompatible dimensions
#Some investigation...
i
# 1
j
# 95
length(xs[[i]]$xQ)
# 96
length(xs[[j]]$xQ)
# 92
xs[[j]]$xQ[1:10]
# xQ
#2004-04-04 00:00:00 674
#2004-04-04 00:15:00 669
#2004-04-04 00:30:00 664
#2004-04-04 00:45:00 664
#2004-04-04 01:00:00 669
#2004-04-04 01:15:00 659
#2004-04-04 01:30:00 674
#2004-04-04 01:45:00 669
#2004-04-04 03:00:00 664
#2004-04-04 03:15:00 674
xs[[i]]$xQ[1:10]
# xQ
#2004-01-01 00:00:00 0.43
#2004-01-01 00:15:00 0.43
#2004-01-01 00:30:00 0.43
#2004-01-01 00:45:00 0.43
#2004-01-01 01:00:00 0.57
#2004-01-01 01:15:00 0.57
#2004-01-01 01:30:00 0.57
#2004-01-01 01:45:00 0.43
#2004-01-01 02:00:00 0.43
#2004-01-01 02:15:00 0.57
I suppose the reason use="complete.obs", use="pair", or
use="pairwise.complete.obs" won't work is because the date stamp is
different despite the fact there are similar time stamps during the
respective days. Thus, I'm wondering if there is a way to direct the cov
function to make the calculation using only the time stamp (and not the date
stamp) to determine pairs?
Thanks, Eric
--
View this message in context: http://r.789695.n4.nabble.com/Filling-a-covariance-matrix-tp4647170p4648015.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list