[R] Subsetting NaN values in localG()

dab98 dab98 at cornell.edu
Tue Jul 12 18:24:12 CEST 2011


Hi,

I'm currently trying to calculate local Getis-Ord Gi* statistics for a
169x315 cell matrix of temperature values, below is the code I currently
have (diffc is the data vector I am removing NaN values from, and I am
moving said values to diffD; -999 represents NaN values; id contains ID
values for cells I want to use in the calculation, which I already know to
contain 25064 values):

/counter = 1
diffD = array(0,25064)
id = array(0,25064)
for(i in 1:53235){
        if(diffc[i]!=-999){
		diffD[counter] = diffc[i]
		id[counter] = i
		counter = counter+1
	}
}               ##Isolates values I want to use in localG calculation

neigh = cell2nb(169,315,type=='queen')
neigh2 = subset.nb(neigh,(1:length(neigh) %in% id)
mylist = nb2listw(neigh2,style="B")
stats = localG(diffD,mylist)/

Unfortunately, when I get to the last line of the code, I receive the
following error:

/"Error in matrix(0, nrow = nrow(x), ncol = ncol(x)) : 
  invalid 'ncol' value (too large or NA)"/

I can't figure out what it is referring to, as I have verified that there
are no NA values and "ncol" should only be 1, as diffD and mylist are the
same size (25064 data regions). My data works when I don't remove the cells
with values of -999, however it returns some ridiculous Z-values (as
expected). All I can think of is that I'm either using subset.nb()
incorrectly or subset.nb() isn't returning a useable nb object in localG().
I'm basically trying to mimic ArcGIS' "Hot Spot Analysis" to locate cold and
hot spots spatially in this code.

Thanks,
Dan

--
View this message in context: http://r.789695.n4.nabble.com/Subsetting-NaN-values-in-localG-tp3662781p3662781.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list