Skip to content

negative local R2 in gwr

9 messages · Jorge Fernando Saraiva de Menezes, Roger Bivand, Zia Ahmed +1 more

#
On Wed, 27 Jan 2010, Jorge Fernando Saraiva de Menezes wrote:

            
No, please don't use attach(), it is irrelevant here (as would coords= be 
if you use an sp class as is recommended).
coords=cbind(islands$LONG,islands$LAT))
coords=cbind(islands$LONG,islands$LAT), bnd)
(do use spaces in quoted commands to reduce mailer mangling).

Please document this using a dataset that others have access to 
(preferably a built-in data set, such as meuse in sp). Please state what 
version of spgwr you are trying to use, local R2 has changed fairly 
recently, and continues not to be well founded (GWR3's local R2 cannot be 
reproduced, the current ones are from the unpublished GWR4).

With a very tight bandwidth (longlat coordinates maybe, why not use GC 
distances?), the sum of weights (reported - always store the output 
object) may be little more than unity - the local R2 could go almost 
anywhere. Have you looked at pairs() of the local coefficients?

Roger

  
    
#
I have created one data table and one polygon in R. Both have a similar 
type of column.  I want to combine or join them with this column or 
field ("MUKEY").  Then  I will convert this polygon  as  a ESRI  shape 
file.
But  when  I  used  spCbind,   I got error. I think i miss something here.
Is there any way join attribute table with polygon? Thanks
Zia

poly.data1 <- spCbind(poly.data, data.table)
 Error in spCbind(poly.data, data.table) : different numbers of rows


names(poly.data) # polygoan
[1] "AREASYMBOL" "SPATIALVER" "MUSYM"      "MUKEY"    
 > names(data.table) # data
 [1] "MUKEY" "Sand"  "Silt"  "Clay"  "pH"    "CEC"   "EC"    "SAR"   "CaCO3"
[10] "SOM"   "BD"    "AWC"   "KSAT"  "Kf"    "Kw"    "LL"    "LEP" 

 > length(poly.data$MUKEY)
[1] 76969
 > length(data.table$MUKEY)
[1] 184
 >


poly.data1 <- spCbind(poly.data, data.table)

combinedShp1 <- "D:/test/combined1.shp" 
writeOGR(poly.data1, dsn=combinedShp1, layer="combined1", driver="ESRI 
Shapefile")
#
Zia, something like this might work as long as MUKEY has no NA values:

poly.data = merge(poly.data, data.table, by="MUKEY" ,all.x = TRUE)

Robert
On Wed, Jan 27, 2010 at 1:58 PM, Zia Ahmed <zua3 at cornell.edu> wrote:
#
Thank you so much Roberts! it works.

Zia
Robert J. Hijmans wrote:
#
Hi, Roberts,
In my last mail, I mentioned it works fine,  but when I try write shape 
file after merging it shows error. I think I need to  define  spatial 
object or data frame after merging. I do not know  how to do this. 
Thanks again.
Zia

 > poly.data1 = merge(poly.data, data.table, by="MUKEY" ,all.x = TRUE)
 > names(poly.data1) # polygoan
 [1] "MUKEY"      "AREASYMBOL" "SPATIALVER" "MUSYM"      "Sand"     
 [6] "Silt"       "Clay"       "pH"         "CEC"        "EC"       
[11] "SAR"        "CaCO3"      "SOM"        "BD"         "AWC"      
[16] "KSAT"       "Kf"         "Kw"         "LL"         "LEP"      

 >polyShp <- "D:/test/mapunit_poly.shp" 
 > writeOGR(poly.data1, dsn=polyShp, layer="mapunit_poly", driver="ESRI 
Shapefile")
Error in writeOGR(poly.data1, dsn = polyShp, layer = "mapunit_poly", 
driver = "ESRI Shapefile") :
  obj of wrong class
Zia Ahmed wrote:
#
Here is reproducible example, #1 fails because what I suspect is a bug
in merge, but #2 works. Robert

 library(maptools)
 data(wrld_simpl)
# create some data to merge with
 m = sort(unique(wrld_simpl at data$REGION))
 m = cbind(m, 1:length(m))
 colnames(m) = c('REGION', 'v')
# merge
 wrld_simpl at data = merge(wrld_simpl at data, m, by='REGION', all.x=TRUE,
sort=FALSE)

# but this does not work:
col = terrain.colors(nrow(m))
plot(wrld_simpl, col=col[wrld_simpl$v])
# he data.frame is rearanged; despite "sort=FALSE"
# this looks like a bug in merge to me. Anyone, am I wrong?


Therefore, I would do

library(maptools)
data(wrld_simpl)
# get the data.frame out of the SPGDF; to simplify code
d = wrld_simpl at data
# add a sort key
d$sort = 1:nrow(d)
# create some data to merge with
 m = sort(unique(d$REGION))
 m = cbind(m, 1:length(m))
 colnames(m) = c('REGION', 'v')
# merge
 x = merge(d, m, by='REGION', all.x=TRUE)
# sort
 x = x[order(x$sort),]
# put the data back
 wrld_simpl at data = x


# now it works
col = terrain.colors(nrow(m))
plot(wrld_simpl, col=col[wrld_simpl$v])
On Wed, Jan 27, 2010 at 6:59 PM, Zia Ahmed <zua3 at cornell.edu> wrote:
#
I think I can use this accordingly. Thank you so much. I have a simple 
question. How do I plot a map without boundary (transparency)  ? I have 
to plot a shape files with  thousands of polygons!
Thanks again zia

# now it works
col = terrain.colors(nrow(m))
plot(wrld_simpl, col=col[wrld_simpl$v])
Robert J. Hijmans wrote:
-------------- 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/20100128/52bcc468/attachment.vcf>
#
Zia:

?polygon

plot(wrld_simpl, col=col[wrld_simpl$v], border=NA)

or:

plot(wrld_simpl, col=col[wrld_simpl$v], border=col[wrld_simpl$v])


Robert
On Thu, Jan 28, 2010 at 10:14 AM, Zia Ahmed <zua3 at cornell.edu> wrote: