To whom it may concern:

 

I am in the process of creating a ".GWT" file to create a distance list
matrix  to run gstlshet that requires two critical arguments - weight matrix
and distance matrix - in the same definition.  I perused sphet vignette and
couldn't find albeit its excellent write-up, the option to specify in terms
of discrete distance cutoff which I have.  All other R and Google searches
led to the same sphet vignette.  As shown in the R codes below, I
successfully created the weight matrix (MDTpropShape_kd1_w), but not so with
distance matrix (MDTdist).  I would appreciate any pointers on better to
specify arguments for read.gwt2dist to match the weight matrix (neighbors
within discrete distance of within 1 mile or 5280 feet) if you could.  

 

#to import  Stata data

library(foreign)

MDTprop <-read.dta("C:/Users/Susan
Gorelick/Documents/MANUSCRIPTS/WIND/RforWind/MDTpropSFH.dta")

library(maptools)

library(rgdal)

library(spdep)

#import a shafile to R

MDTpropShape <- readOGR("C:/Users/Susan
Gorelick/Documents/MANUSCRIPTS/WIND/RforWind", "MDTpropSFH")

#project in RI SPF

MDTpropShape_SP <-spTransform(MDTpropShape, CRS("+init=ESRI:102730"))

#Distance-Based Neighbors Using K Nearest Neighbors (KNN)

coords <- coordinates (MDTpropShape_SP)

IDs <-row.names(as(MDTpropShape_SP, "data.frame"))

MDTpropShape_kn1 <- knn2nb(knearneigh(coords, k =1) , row.names=IDs)

dist <-unlist(nbdists(MDTpropShape_kn1, coords))

summary(dist)

MDTpropShape_kd1 <- dnearneigh(coords, d1 =0, d2 = 5280, row.names=IDs)

summary(MDTpropShape_kd1)

 

#Spatial Weights matix: Row standardized

MDTpropShape_kd1_w <- nb2listw(MDTpropShape_kd1)

 

#With Type = "distance"

> tmp <- distance(coords, region.id =IDs, output = TRUE, 

+ type ="distance", cutoff =1, measure = "euclidean", 

+ shape.name="shapefile", region.id.name= "IDs",

+ firstline= TRUE, file.name= "MDT.GWT") 

Error in quantile.default(tmp) : 

  missing values and NaN's not allowed if 'na.rm' is FALSE

In addition: Warning message:

In matrix(X, nrow(Y), 2, byrow = TRUE) : data length exceeds size of matrix

 

#Back with Type = "NN" 

> tmp <- distance(coords, region.id =IDs, output = TRUE, 

+ type ="NN", nn=1, shape.name="shapefile", region.id.name= "IDs",

+ firstline= TRUE, file.name= "MDT.GWT") 

Warning message:

In matrix(X, nrow(Y), 2, byrow = TRUE) : data length exceeds size of matrix

> class(tmp)

[1] "matrix"          "distance.matrix"

 

> MDTdist <- read.gwt2dist(file = "MDT.GWT",region.id=IDs, skip=1)

Warning messages:

1: In read.gwt2dist(file = "MDT.GWT", region.id = IDs, skip = 1) : 1 are not
origins

2: In read.gwt2dist(file = "MDT.GWT", region.id = IDs, skip = 1) :

 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222 [... truncated]

> MDTdist <- read.gwt2dist(file = "MDT.GWT",region.id=IDs)

Warning messages:

1: In read.gwt2dist(file = "MDT.GWT", region.id = IDs) : 1 are not origins

2: In read.gwt2dist(file = "MDT.GWT", region.id = IDs) :

  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222 [... truncated]

> class(MDTdist)

[1] "sphet"    "distance" "nb"       "GWT"   

 

> summary(MDTdist)

 

Number of observations:

n: 2828 

 

Distance summary:

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 

   -Inf    -Inf    -Inf    -Inf    -Inf    -Inf    2827 

 

Neighbors summary:

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 

 0.0000  1.0000  1.0000  0.9996  1.0000  1.0000 

 

Warning message:

In FUN(X[[2828L]], ...) : no non-missing arguments to max; returning -Inf

 

 

Thank you for your time and attention in advance.

 

Susan Shim Gorelick

 


	[[alternative HTML version deleted]]

