<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Dear Garcia,<br>
<br>
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?<br>
<br>
Thanks again<br>
Zia<br>
<small><font face="Courier New, Courier, monospace"><br>
<big><big><b># R code:</b></big></big><br>
#----------<br>
library(gstat)<br>
library(sp)<br>
library(spdep)<br>
<br>
data(meuse)<br>
data(meuse.grid)<br>
coordinates(meuse) <- ~x + y<br>
coordinates(meuse.grid) <- ~x + y<br>
str(meuse.grid)<br>
<br>
# GRID 1:<br>
v1 <- variogram(log(zinc) ~ 1, meuse)<br>
x1<-fit.variogram(v1, vgm(1, "Sph", 800, 1))<br>
G1 <- krige(zinc ~ 1, meuse, meuse.grid, x1, nmax = 30)<br>
gridded(G1)<-TRUE<br>
# GRID-2:<br>
v2 <- variogram(log(lead) ~ 1, meuse)<br>
x2<-fit.variogram(v2, vgm(.1, "Sph", 1000, .6))<br>
G2 <- krige(zinc ~ 1, meuse, meuse.grid, x2, nmax = 30)<br>
gridded(G2)<-TRUE<br>
# Mooving Windows Correlation<br>
# Define the size of the moving window,<br>
dist = sqrt(2*((40*3)^2))<br>
# Create a list of neighbours for the distance criteria<br>
nb <- dnearneigh(coordinates(G1),0, dist) <br>
v = sapply(nb, function(i) cor(G1@data[i,], G2@data[i,]))<br>
<br>
When I run following codes it shows error.<br>
<br>
coordinates(v) = coordinates(G1)<br>
<br>
<font color="#ff6666">Error in function (classes, fdef, mtable) : <br>
unable to find an inherited method for function "coordinates<-",
for signature "matrix"<br>
</font><br>
gridded(v) = TRUE<br>
<br>
<font color="#ff6666">Error in `gridded<-`(`*tmp*`, value = TRUE) : <br>
gridded<- only works for SpatialPoints[DataFrame] or
SpatialGrid[DataFrame]<br>
<br>
</font></font></small><b><big><br>
# Output #--------<br>
</big></b><font face="Courier New, Courier, monospace"><small><br>
V1 V2 V3 V4 V5
V6 V7<br>
1 0.9996752 0.9996896 0.9997172 0.99971074 0.9996085 0.9996784
0.99972521<br>
2 -0.3807374 -0.3576051 -0.2260482 0.05467783 -0.2882067 -0.2124191
-0.08551635<br>
3 -0.3943537 -0.3750882 -0.2435564 0.03511977 -0.3081105 -0.2300869
-0.10426607<br>
4 0.9999324 0.9999349 0.9999442 0.99994815 0.9999047 0.9999104
0.99992347</small><br>
</font><br>
<br>
<br>
Jaime R. Garcia M. wrote:
<blockquote cite="mid:1260325289.2631.27.camel@jaime" type="cite">
<pre wrap="">On Tue, 2009-12-08 at 21:54 +0100, Jaime R. Garcia M. wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Tue, 2009-12-08 at 14:32 -0500, Zia Ahmed wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I have two grid maps (100 m cell size). I want to a create another
raster gird of correlation coefficient ( r value) of two maps using
moving windows approach. Has someone any idea how to do it in R?
Thanks
Zia
_______________________________________________
R-sig-Geo mailing list
<a class="moz-txt-link-abbreviated"
href="mailto:R-sig-Geo@stat.math.ethz.ch">R-sig-Geo@stat.math.ethz.ch</a>
<a class="moz-txt-link-freetext"
href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
</blockquote>
<pre wrap="">Dear Zia,
Some time ago I did exactly that and the script was based on a earlier
post by Prof. Roger Bivand in this list. (Sorry I couldn't find the link
anymore)
Suppose "G1" and "G2" are the two grid maps.
I assume they are "SpatialGridDataFrames" and have exactly the same
extent and number of columns and rows. Also that you have libraries (sp)
and (spdep) loaded
# Define the size of the moving window, for example (7*7) so you have
enough neighbors for reliable correlation estimation:
dist = sqrt(2*((100*3)^2))
# Create a list of neighbours for the distance criteria
nb <- dnearneigh(coordinates(G1),0, dist)
# And then calculate correlations
v <- sapply(nb, function(i) cor(G1@data, G2@data))
</pre>
</blockquote>
<pre wrap=""><!---->
# Small correction
v = sapply(nb, function(i) cor(G1@data[i,], G2@data[i,]))
# And in this case the result should be a numeric vector
coordinates(v) = coordinates(G1)
gridded(v) = TRUE
fullgrid(v) = TRUE
_______________________________________________
</pre>
<blockquote type="cite">
<pre wrap="">R-sig-Geo mailing list
<a class="moz-txt-link-abbreviated"
href="mailto:R-sig-Geo@stat.math.ethz.ch">R-sig-Geo@stat.math.ethz.ch</a>
<a class="moz-txt-link-freetext"
href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
</body>
</html>