Skip to content

Moving Windows Correlation----???

1 message · Zia Ahmed

#
Dear Garcia,

Thank you so much! Before running my data, I have tested your code using 
"meuse" data. It works fine. But it produce following output like below 
from V1 to V3103. I do not understand what does the values in rows mean 
(1 to 4). Here is  the code that I used.  I have questions How do I plot 
r-values with coordinates. Is it possible to get p-value for each estimate?

Thanks again
Zia

*# R code:*
#----------
library(gstat)
library(sp)
library(spdep)

data(meuse)
data(meuse.grid)
coordinates(meuse) <- ~x + y
coordinates(meuse.grid) <- ~x + y
str(meuse.grid)

# GRID 1:
v1 <- variogram(log(zinc) ~ 1, meuse)
x1<-fit.variogram(v1, vgm(1, "Sph", 800, 1))
G1 <- krige(zinc ~ 1, meuse, meuse.grid, x1, nmax = 30)
gridded(G1)<-TRUE
# GRID-2:
v2 <- variogram(log(lead) ~ 1, meuse)
x2<-fit.variogram(v2, vgm(.1, "Sph", 1000, .6))
G2 <- krige(zinc ~ 1, meuse, meuse.grid, x2, nmax = 30)
gridded(G2)<-TRUE
# Mooving Windows Correlation
# Define the size of the moving window,
dist = sqrt(2*((40*3)^2))
# Create a list of neighbours for the distance criteria
nb <- dnearneigh(coordinates(G1),0, dist)
v = sapply(nb, function(i) cor(G1 at data[i,], G2 at data[i,]))

When I run following codes it shows error.

coordinates(v) = coordinates(G1)

Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function "coordinates<-", for 
signature "matrix"

gridded(v) = TRUE

Error in `gridded<-`(`*tmp*`, value = TRUE) :
  gridded<- only works for SpatialPoints[DataFrame] or 
SpatialGrid[DataFrame]

*
# Output #--------
*
       V1         V2         V3         V4         V5         V6          V7
1  0.9996752  0.9996896  0.9997172 0.99971074  0.9996085  0.9996784  
0.99972521
2 -0.3807374 -0.3576051 -0.2260482 0.05467783 -0.2882067 -0.2124191 
-0.08551635
3 -0.3943537 -0.3750882 -0.2435564 0.03511977 -0.3081105 -0.2300869 
-0.10426607
4  0.9999324  0.9999349  0.9999442 0.99994815  0.9999047  0.9999104  
0.99992347
Jaime R. Garcia M. wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20091209/e6df660a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zua3.vcf
Type: text/x-vcard
Size: 281 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20091209/e6df660a/attachment.vcf>