diff --git a/docs/articles/CO69.html b/docs/articles/CO69.html index 537198ea..39cb4255 100644 --- a/docs/articles/CO69.html +++ b/docs/articles/CO69.html @@ -410,9 +410,9 @@

Spatial weights## 1 2 3 4 5 6 7 8 ## 1 2 5 5 8 1 2 1 ## 1 least connected region: -## with 1 link +## E with 1 link ## 1 most connected region: -## with 8 links +## V with 8 links ## ## Weights style: B ## Weights constants summary: @@ -446,9 +446,9 @@

Spatial weights## 1 2 3 4 5 6 7 8 ## 1 2 5 5 8 1 2 1 ## 1 least connected region: -## with 1 link +## E with 1 link ## 1 most connected region: -## with 8 links +## V with 8 links ## ## Weights style: B ## Weights constants summary: @@ -565,7 +565,7 @@

Measures of spatial autocorrelation Prop_stdR <- lapply(vars, function(x) moran.test(eire_ge1[[x]], listw=lw_std, randomisation=TRUE)) })
##    user  system elapsed 
-##   0.121   0.000   0.121
+## 0.118 0.000 0.119
 res <- sapply(c("MoranN", "MoranR", "GearyN", "GearyR", "Prop_unstdN", "Prop_unstdR", "Prop_stdN", "Prop_stdR"), function(x) sapply(get(x), "[[", "statistic"))
 rownames(res) <- vars
@@ -839,7 +839,7 @@ 

Simulating measures of s Prop_stdEx <- lapply(lm_objs, function(x) lm.morantest.exact(x, listw=lw_std)) })

##    user  system elapsed 
-##   0.083   0.000   0.083
+## 0.085 0.000 0.085
 res <- sapply(c("MoranEx", "Prop_unstdEx", "Prop_stdEx"), function(x) sapply(get(x), "[[", "statistic"))
 rownames(res) <- vars
diff --git a/docs/articles/nb.html b/docs/articles/nb.html index ad9ea526..7167ee8a 100644 --- a/docs/articles/nb.html +++ b/docs/articles/nb.html @@ -168,9 +168,9 @@

Introduction## 1 2 3 4 5 6 7 8 9 ## 1 1 5 9 14 17 9 6 1 ## 1 least connected region: -## with 1 link +## 164 with 1 link ## 1 most connected region: -## with 9 links +## 136 with 9 links

Creating Contiguity Neighbours diff --git a/docs/articles/nb_sf.html b/docs/articles/nb_sf.html index 3a020026..ca1a7cdd 100644 --- a/docs/articles/nb_sf.html +++ b/docs/articles/nb_sf.html @@ -258,7 +258,7 @@

Contiguity neighbours for pol eps <- sqrt(.Machine$double.eps) system.time(for(i in 1:reps) NY8_sf_1_nb <- poly2nb(NY8_sf, queen=TRUE, snap=eps))/reps

##    user  system elapsed 
-##  0.0925  0.0038  0.0965
+## 0.0938 0.0042 0.0984

Using spatial indices to check intersection of polygons is much faster than the legacy method in poly2nb. From spdep 1.1-7, use is made of GEOS through sf to find candidate @@ -427,12 +427,12 @@

K-nearest neighbours
 system.time(for (i in 1:reps) NY88_nb_sf <- knn2nb(knearneigh(NY8_ct_sf, k=1)))/reps
##    user  system elapsed 
-##  0.0174  0.0009  0.0183
+## 0.0179 0.0011 0.0191

Legacy code may be used omitting the kd-tree:

 system.time(for (i in 1:reps) NY89_nb_sf <- knn2nb(knearneigh(NY8_ct_sf, k=1, use_kd_tree=FALSE)))/reps
##    user  system elapsed 
-##  0.0174  0.0013  0.0188
+## 0.0182 0.0016 0.0199

Distance neighbours @@ -451,7 +451,7 @@

Distance neighbours
 system.time(for (i in 1:reps) NY810_nb <- dnearneigh(NY8_ct_sf, d1=0, d2=0.75*max_1nn))/reps

##    user  system elapsed 
-##  0.0315  0.0011  0.0327
+## 0.0319 0.0015 0.0337

By default, the function uses dbscan::frNN() to build a kd-tree in 2D or 3D which is then used to find distance neighbours. For small n, the argument use_kd_tree=FALSE may speed up @@ -461,7 +461,7 @@

Distance neighbours
 system.time(for (i in 1:reps) NY811_nb <- dnearneigh(NY8_ct_sf, d1=0, d2=0.75*max_1nn, use_kd_tree=FALSE))/reps
##    user  system elapsed 
-##  0.0163  0.0015  0.0178
+## 0.0166 0.0017 0.0183
@@ -491,7 +491,7 @@

K-nearest neighbourssf_use_s2(TRUE) system.time(for (i in 1:reps) pts_ll1_nb <- knn2nb(knearneigh(pts_ll, k=6)))/reps

##    user  system elapsed 
-##  0.0252  0.0000  0.0252
+## 0.0248 0.0000 0.0248

For this smaller data set, the legacy approach without spatial indexing is adequate, but slows down as the number of observations increases:

@@ -501,7 +501,7 @@

K-nearest neighbours
 system.time(for (i in 1:reps) pts_ll2_nb <- knn2nb(knearneigh(pts_ll, k=6)))/reps
##    user  system elapsed 
-##  0.0191  0.0000  0.0191
+## 0.0194 0.0000 0.0194

The WGS84 ellipsoid Great Circle distances differ a very little from the s2 spherical distances, yielding output that here diverges for two tract centroids:

@@ -554,7 +554,7 @@

Distance neighbours=0.75*max_1nn_ll))/(reps/5) }
##    user  system elapsed 
-##  0.0440  0.0000  0.0445
+## 0.0445 0.0000 0.0445

Alternatively, spherical distances can be used with dwithin=FALSE and s2::s2_closest_edges(); although running in similar time, s2::s2_closest_edges() @@ -563,7 +563,7 @@

Distance neighbours
 system.time(for (i in 1:(reps/5)) pts_ll5_nb <- dnearneigh(pts_ll, d1=0, d2=0.75*max_1nn_ll, dwithin=FALSE))/(reps/5)
##    user  system elapsed 
-##   0.027   0.000   0.027
+## 0.0270 0.0005 0.0275
 if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3_nb, pts_ll5_nb, check.attributes=FALSE)
## [1] TRUE
@@ -586,7 +586,7 @@

Distance neighbours=0.75*max_1nn_ll))/(reps/5) }
##    user  system elapsed 
-##  0.0725  0.0000  0.0725
+## 0.0730 0.0000 0.0735
 if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3a_nb, pts_ll5a_nb, check.attributes=FALSE)
## [1] TRUE
@@ -595,7 +595,7 @@

Distance neighbours
 system.time(for (i in 1:reps) pts_ll6_nb <- dnearneigh(pts_ll, d1=0, d2=0.75*max_1nn_ll, use_s2=FALSE))/reps
##    user  system elapsed 
-##  0.0097  0.0000  0.0097
+## 0.0097 0.0000 0.0098

Minor differences may occur between the legacy ellipsoid and s2 spherical approaches:

@@ -625,7 +625,7 @@ 

Distance neighbours
 system.time(for (i in 1:reps) pts_ll6a_nb <- dnearneigh(pts_ll, d1=5, d2=0.75*max_1nn_ll, use_s2=FALSE))/reps

##    user  system elapsed 
-##  0.0097  0.0000  0.0097
+## 0.0098 0.0000 0.0097
 if (packageVersion("s2") > "1.0.7") all.equal(pts_ll5a_nb, pts_ll6a_nb, check.attributes=FALSE)
##  [1] "Component 20: Numeric: lengths (6, 5) differ"       
@@ -676,7 +676,7 @@ 

Contiguity neighbours for spherical polygon support
 system.time(for (i in 1:reps) NY8_sf_1_nb_ll <- poly2nb(NY8_sf_ll, queen=TRUE, snap=eps))/reps
##    user  system elapsed 
-##  0.1553  0.0013  0.1572
+## 0.1524 0.0019 0.1548

 all.equal(NY8_sf_1_nb, NY8_sf_1_nb_ll, check.attributes=FALSE)
## [1] TRUE
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 5f78f8ad..a8b299ea 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -6,5 +6,5 @@ articles: nb: nb.html nb_sf: nb_sf.html sids: sids.html -last_built: 2023-11-04T17:52Z +last_built: 2023-11-06T13:06Z diff --git a/docs/reference/EBImoran.mc.html b/docs/reference/EBImoran.mc.html index db555f47..4886f83f 100644 --- a/docs/reference/EBImoran.mc.html +++ b/docs/reference/EBImoran.mc.html @@ -184,7 +184,7 @@

Examples

#> weights: nb2listw(ncCC89_nb, style = "B", zero.policy = TRUE) #> number of simulations + 1: 1000 #> -#> statistic = 0.25789, observed rank = 998, p-value = 0.004 +#> statistic = 0.25789, observed rank = 1000, p-value < 2.2e-16 #> alternative hypothesis: two.sided #> sids.p <- nc.sids$SID74 / nc.sids$BIR74 diff --git a/docs/reference/LOSH.mc-1.png b/docs/reference/LOSH.mc-1.png index 5a905795..3b4cabfc 100644 Binary files a/docs/reference/LOSH.mc-1.png and b/docs/reference/LOSH.mc-1.png differ diff --git a/docs/reference/LOSH.mc.html b/docs/reference/LOSH.mc.html index c0a6763a..30a4b3ed 100644 --- a/docs/reference/LOSH.mc.html +++ b/docs/reference/LOSH.mc.html @@ -154,10 +154,10 @@

Examples

summary(resLOSH_mc) #> Hi x_bar_i ei Pr() #> Min. :0.03438 Min. :13.85 Min. : 0.0298 Min. :0.009901 -#> 1st Qu.:0.23838 1st Qu.:24.71 1st Qu.: 7.0114 1st Qu.:0.118812 -#> Median :0.66689 Median :35.90 Median : 52.1094 Median :0.702970 -#> Mean :1.06592 Mean :34.88 Mean : 151.9232 Mean :0.542332 -#> 3rd Qu.:1.59680 3rd Qu.:45.39 3rd Qu.: 105.0551 3rd Qu.:0.891089 +#> 1st Qu.:0.23838 1st Qu.:24.71 1st Qu.: 7.0114 1st Qu.:0.079208 +#> Median :0.66689 Median :35.90 Median : 52.1094 Median :0.712871 +#> Mean :1.06592 Mean :34.88 Mean : 151.9232 Mean :0.554860 +#> 3rd Qu.:1.59680 3rd Qu.:45.39 3rd Qu.: 105.0551 3rd Qu.:0.910891 #> Max. :4.68765 Max. :54.91 Max. :2455.2201 Max. :0.990099 resLOSH_cs <- LOSH.cs(columbus$CRIME, nb2listw(col.gal.nb)) summary(resLOSH_cs) diff --git a/docs/reference/bhicv.html b/docs/reference/bhicv.html index 2e1f9102..072425ba 100644 --- a/docs/reference/bhicv.html +++ b/docs/reference/bhicv.html @@ -105,7 +105,7 @@

Examples

bh <- st_read(system.file("etc/shapes/bhicv.shp",
       package="spdep")[1])
 #> Reading layer `bhicv' from data source 
-#>   `/tmp/Rtmpu0jdcX/temp_libpath70612704761e5/spdep/etc/shapes/bhicv.shp' 
+#>   `/tmp/RtmpU193Yl/temp_libpath9f2c94443f9d4/spdep/etc/shapes/bhicv.shp' 
 #>   using driver `ESRI Shapefile'
 #> Simple feature collection with 98 features and 8 fields
 #> Geometry type: POLYGON
diff --git a/docs/reference/cell2nb.html b/docs/reference/cell2nb.html
index 9b67215a..e3badaf1 100644
--- a/docs/reference/cell2nb.html
+++ b/docs/reference/cell2nb.html
@@ -137,9 +137,9 @@ 

Examples

#> 2 3 4 #> 4 20 25 #> 4 least connected regions: -#> with 2 links +#> 1:1 7:1 1:7 7:7 with 2 links #> 25 most connected regions: -#> with 4 links +#> 2:2 3:2 4:2 5:2 6:2 2:3 3:3 4:3 5:3 6:3 2:4 3:4 4:4 5:4 6:4 2:5 3:5 4:5 5:5 6:5 2:6 3:6 4:6 5:6 6:6 with 4 links xyc <- attr(nb7rt, "region.id") xy <- matrix(as.integer(unlist(strsplit(xyc, ":"))), ncol=2, byrow=TRUE) plot(nb7rt, xy) @@ -156,9 +156,9 @@

Examples

#> 4 #> 49 #> 49 least connected regions: -#> with 4 links +#> 1:1 2:1 3:1 4:1 5:1 6:1 7:1 1:2 2:2 3:2 4:2 5:2 6:2 7:2 1:3 2:3 3:3 4:3 5:3 6:3 7:3 1:4 2:4 3:4 4:4 5:4 6:4 7:4 1:5 2:5 3:5 4:5 5:5 6:5 7:5 1:6 2:6 3:6 4:6 5:6 6:6 7:6 1:7 2:7 3:7 4:7 5:7 6:7 7:7 with 4 links #> 49 most connected regions: -#> with 4 links +#> 1:1 2:1 3:1 4:1 5:1 6:1 7:1 1:2 2:2 3:2 4:2 5:2 6:2 7:2 1:3 2:3 3:3 4:3 5:3 6:3 7:3 1:4 2:4 3:4 4:4 5:4 6:4 7:4 1:5 2:5 3:5 4:5 5:5 6:5 7:5 1:6 2:6 3:6 4:6 5:6 6:6 7:6 1:7 2:7 3:7 4:7 5:7 6:7 7:7 with 4 links run <- FALSE if (require("sp", quietly=TRUE)) run <- TRUE if (run) { diff --git a/docs/reference/dnearneigh.html b/docs/reference/dnearneigh.html index afbf4662..937dd9d6 100644 --- a/docs/reference/dnearneigh.html +++ b/docs/reference/dnearneigh.html @@ -149,9 +149,9 @@

Examples

#> 1 2 3 4 5 6 7 8 9 10 11 #> 4 8 6 2 5 8 6 2 6 1 1 #> 4 least connected regions: -#> with 1 link +#> 6 10 21 47 with 1 link #> 1 most connected region: -#> with 11 links +#> 28 with 11 links opar <- par(no.readonly=TRUE) plot(st_geometry(columbus), border="grey", reset=FALSE, main=paste("Distance based neighbours 0-", format(all.linked), sep="")) @@ -198,9 +198,9 @@

Examples

#> 1 2 3 4 5 7 8 9 10 #> 11 9 4 8 4 4 4 3 1 #> 11 least connected regions: -#> with 1 link +#> 2 4 8 10 24 26 29 32 35 41 45 with 1 link #> 1 most connected region: -#> with 10 links +#> 28 with 10 links gck1 <- knn2nb(knearneigh(xy, k=1, longlat=TRUE)) (all.linked <- max(unlist(nbdists(gck1, xy, longlat=TRUE)))) #> [1] 523.5819 @@ -217,9 +217,9 @@

Examples

#> 1 2 3 4 5 6 7 8 9 10 #> 5 9 6 8 5 2 3 3 5 2 #> 5 least connected regions: -#> with 1 link +#> 2 4 8 41 45 with 1 link #> 2 most connected regions: -#> with 10 links +#> 7 28 with 10 links plot(ll.nb, xy) plot(diffnb(ll.nb, gc.nb), xy, add=TRUE, col="red", lty=2) title(main="Differences Euclidean/Great Circle") @@ -239,13 +239,13 @@

Examples

gck1b <- knn2nb(knearneigh(xy1, k=1)) system.time(o <- nbdists(gck1b, xy1)) #> user system elapsed -#> 0.007 0.000 0.006 +#> 0.006 0.000 0.006 (all.linked <- max(unlist(o))) #> [1] 522.4464 # use s2 brute-force dwithin_matrix approach for s2 <= 1.0.7 system.time(gc.nb.dwithin <- dnearneigh(xy1, 0, all.linked, use_s2=TRUE, dwithin=TRUE)) #> user system elapsed -#> 0.01 0.00 0.01 +#> 0.009 0.000 0.010 summary(gc.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -258,9 +258,9 @@

Examples

#> 1 2 3 4 5 6 7 8 9 10 #> 5 9 6 8 5 2 3 3 5 2 #> 5 least connected regions: -#> with 1 link +#> 2 4 8 41 45 with 1 link #> 2 most connected regions: -#> with 10 links +#> 7 28 with 10 links # use s2 closest_edges approach s2 > 1.0.7 if (packageVersion("s2") > "1.0.7") { (system.time(gc.nb.closest <- dnearneigh(xy1, 0, all.linked, dwithin=FALSE))) @@ -288,9 +288,9 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 10 #> 1 5 8 6 8 5 2 3 3 5 2 #> 5 least connected regions: -#> with 1 link +#> 4 8 29 41 45 with 1 link #> 2 most connected regions: -#> with 10 links +#> 7 28 with 10 links if (packageVersion("s2") > "1.0.7") { summary(gc.nb.closest, xy1, scale=0.5) } @@ -307,13 +307,13 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 10 #> 1 5 8 6 8 5 2 3 3 5 2 #> 5 least connected regions: -#> with 1 link +#> 4 8 29 41 45 with 1 link #> 2 most connected regions: -#> with 10 links +#> 7 28 with 10 links # use legacy symmetric brute-force approach system.time(gc.nb.legacy <- dnearneigh(xy1, 0, all.linked, use_s2=FALSE)) #> user system elapsed -#> 0.003 0.000 0.003 +#> 0.003 0.000 0.004 summary(gc.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -326,9 +326,9 @@

Examples

#> 1 2 3 4 5 6 7 8 9 10 #> 5 9 6 8 5 2 3 3 5 2 #> 5 least connected regions: -#> with 1 link +#> 2 4 8 41 45 with 1 link #> 2 most connected regions: -#> with 10 links +#> 7 28 with 10 links if (packageVersion("s2") > "1.0.7") all.equal(gc.nb.closest, gc.nb.dwithin, check.attributes=FALSE) #> [1] TRUE # legacy is ellipsoidal, s2 spherical, so minor differences expected diff --git a/docs/reference/edit.nb.html b/docs/reference/edit.nb.html index 44773c64..d59c98e1 100644 --- a/docs/reference/edit.nb.html +++ b/docs/reference/edit.nb.html @@ -121,12 +121,11 @@

See also

Examples

-
# \dontrun{
+    
if (FALSE) {
 columbus <- st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
 class(columbus)
-#> [1] "sf"         "data.frame"
 if (FALSE) nnb1 <- edit.nb(col.gal.nb, polys=as(columbus, "Spatial"))
-# }
+}
 
diff --git a/docs/reference/geary.mc.html b/docs/reference/geary.mc.html index 236e80b0..3164b159 100644 --- a/docs/reference/geary.mc.html +++ b/docs/reference/geary.mc.html @@ -160,12 +160,12 @@

Examples

#> alternative hypothesis: less #> mean(sim1$res) -#> [1] 1.012612 +#> [1] 0.9890232 var(sim1$res) -#> [1] 0.0119779 +#> [1] 0.01235098 summary(sim1$res) #> Min. 1st Qu. Median Mean 3rd Qu. Max. -#> 0.5299 0.9401 1.0218 1.0126 1.0906 1.2388 +#> 0.5299 0.9288 1.0029 0.9890 1.0515 1.3024 colold.lags <- nblag(COL.nb, 3) sim2 <- geary.mc(COL.OLD$CRIME, nb2listw(colold.lags[[2]], style="W"), nsim=99) @@ -177,12 +177,12 @@

Examples

#> weights: nb2listw(colold.lags[[2]], style = "W") #> number of simulations + 1: 100 #> -#> statistic = 0.81129, observed rank = 1, p-value = 0.01 +#> statistic = 0.81129, observed rank = 5, p-value = 0.05 #> alternative hypothesis: greater #> summary(sim2$res) #> Min. 1st Qu. Median Mean 3rd Qu. Max. -#> 0.8113 0.9541 1.0113 1.0014 1.0569 1.1619 +#> 0.7211 0.9490 0.9896 0.9948 1.0550 1.1807 sim3 <- geary.mc(COL.OLD$CRIME, nb2listw(colold.lags[[3]], style="W"), nsim=99) sim3 @@ -193,12 +193,12 @@

Examples

#> weights: nb2listw(colold.lags[[3]], style = "W") #> number of simulations + 1: 100 #> -#> statistic = 1.1303, observed rank = 92, p-value = 0.92 +#> statistic = 1.1303, observed rank = 95, p-value = 0.95 #> alternative hypothesis: greater #> summary(sim3$res) #> Min. 1st Qu. Median Mean 3rd Qu. Max. -#> 0.8264 0.9586 1.0079 1.0099 1.0562 1.2047 +#> 0.8034 0.9550 1.0098 1.0076 1.0474 1.2499
diff --git a/docs/reference/graphneigh.html b/docs/reference/graphneigh.html index f41bced1..008fcf4f 100644 --- a/docs/reference/graphneigh.html +++ b/docs/reference/graphneigh.html @@ -285,9 +285,9 @@

Examples

#> 0 1 2 3 4 5 #> 1 8 10 18 55 8 #> 8 least connected regions: -#> with 1 link +#> 46 47 48 49 96 97 98 99 with 1 link #> 8 most connected regions: -#> with 5 links +#> 10 15 20 25 30 35 40 45 with 5 links grd <- as.matrix(expand.grid(x=1:5, y=1:5)) #gridded data r2 <- gabrielneigh(grd) set.seed(1) diff --git a/docs/reference/grid2nb.html b/docs/reference/grid2nb.html index 27f554ac..eb1e9527 100644 --- a/docs/reference/grid2nb.html +++ b/docs/reference/grid2nb.html @@ -150,9 +150,9 @@

Examples

#> 7 11 17 26 #> 8 36 54 27 #> 8 least connected regions: -#> with 7 links +#> 1 5 21 25 101 105 121 125 with 7 links #> 27 most connected regions: -#> with 26 links +#> 32 33 34 37 38 39 42 43 44 57 58 59 62 63 64 67 68 69 82 83 84 87 88 89 92 93 94 with 26 links if (require("sp", quietly=TRUE)) { gt <- GridTopology(c(.125,.1), c(.25,.2), c(4L, 5L)) nb1 <- grid2nb(gt, queen = FALSE) diff --git a/docs/reference/include.self.html b/docs/reference/include.self.html index 1b8fad9a..287bd036 100644 --- a/docs/reference/include.self.html +++ b/docs/reference/include.self.html @@ -114,9 +114,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links summary(include.self(col.gal.nb), coords) #> Neighbour list object: #> Number of regions: 49 @@ -128,9 +128,9 @@

Examples

#> 3 4 5 6 7 8 9 10 11 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 3 links +#> 1 6 31 39 42 46 47 with 3 links #> 1 most connected region: -#> with 11 links +#> 20 with 11 links summary(remove.self(include.self(col.gal.nb)), coords) #> Neighbour list object: #> Number of regions: 49 @@ -142,9 +142,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links
diff --git a/docs/reference/joincount.multi.html b/docs/reference/joincount.multi.html index 528fbbcd..8415a202 100644 --- a/docs/reference/joincount.multi.html +++ b/docs/reference/joincount.multi.html @@ -161,95 +161,30 @@

Examples

#> high:high 52.000 28.138 18.342 5.5716 #> high:low 28.000 61.170 25.882 -6.5200 #> Jtot 28.000 61.170 33.190 -5.7577 -# \dontrun{ +if (FALSE) { data(oldcol) HICRIME <- cut(COL.OLD$CRIME, breaks=c(0,35,80), labels=c("low","high")) names(HICRIME) <- rownames(COL.OLD) joincount.multi(HICRIME, nb2listw(COL.nb, style="B")) -#> Joincount Expected Variance z-value -#> low:low 34.000 29.592 18.895 1.0141 -#> high:high 54.000 27.224 17.888 6.3307 -#> high:low 28.000 59.184 26.233 -6.0884 -#> Jtot 28.000 59.184 26.233 -6.0884 data(hopkins, package="spData") image(1:32, 1:32, hopkins[5:36,36:5], breaks=c(-0.5, 3.5, 20), col=c("white", "black")) box() - hopkins.rook.nb <- cell2nb(32, 32, type="rook") unlist(spweights.constants(nb2listw(hopkins.rook.nb, style="B"))) -#> n n1 n2 n3 nn S0 S1 S2 -#> 1024 1023 1022 1021 1048576 3968 7936 61984 hopkins.queen.nb <- cell2nb(32, 32, type="queen") hopkins.bishop.nb <- diffnb(hopkins.rook.nb, hopkins.queen.nb, verbose=FALSE) hopkins4 <- hopkins[5:36,36:5] hopkins4[which(hopkins4 > 3, arr.ind=TRUE)] <- 4 hopkins4.f <- factor(hopkins4) table(hopkins4.f) -#> hopkins4.f -#> 0 1 2 3 4 -#> 657 215 98 30 24 joincount.multi(hopkins4.f, nb2listw(hopkins.rook.nb, style="B")) -#> Joincount Expected Variance z-value -#> 0:0 864.00000 816.27273 116.05233 4.4304 -#> 1:1 94.00000 87.14015 55.25216 0.9229 -#> 2:2 18.00000 18.00379 14.81562 -0.0010 -#> 3:3 2.00000 1.64773 1.55539 0.2825 -#> 4:4 5.00000 1.04545 0.99845 3.9576 -#> 1:0 503.00000 535.05682 227.76750 -2.1241 -#> 2:0 213.00000 243.88636 97.21769 -3.1325 -#> 2:1 99.00000 79.81061 59.01930 2.4978 -#> 3:0 61.00000 74.65909 28.58592 -2.5547 -#> 3:1 28.00000 24.43182 18.99976 0.8186 -#> 3:2 15.00000 11.13636 9.82411 1.2327 -#> 4:0 40.00000 59.72727 22.78583 -4.1327 -#> 4:1 23.00000 19.54545 15.26564 0.8842 -#> 4:2 14.00000 8.90909 7.90051 1.8112 -#> 4:3 5.00000 2.72727 2.58616 1.4133 -#> Jtot 1001.00000 1059.89015 273.78610 -3.5591 cat("replicates Upton & Fingleton table 3.4 (p. 166)\n") -#> replicates Upton & Fingleton table 3.4 (p. 166) joincount.multi(hopkins4.f, nb2listw(hopkins.bishop.nb, style="B")) -#> Joincount Expected Variance z-value -#> 0:0 823.00000 790.76420 144.44877 2.6821 -#> 1:1 101.00000 84.41702 55.98143 2.2164 -#> 2:2 19.00000 17.44117 14.61542 0.4077 -#> 3:3 3.00000 1.59624 1.51444 1.1407 -#> 4:4 3.00000 1.01278 0.97111 2.0166 -#> 1:0 497.00000 518.33629 234.93545 -1.3920 -#> 2:0 216.00000 236.26491 104.42142 -1.9831 -#> 2:1 81.00000 77.31652 58.70829 0.4807 -#> 3:0 58.00000 72.32599 31.49151 -2.5529 -#> 3:1 21.00000 23.66832 18.85316 -0.6145 -#> 3:2 17.00000 10.78835 9.62487 2.0022 -#> 4:0 48.00000 57.86080 25.15973 -1.9659 -#> 4:1 21.00000 18.93466 15.14473 0.5307 -#> 4:2 10.00000 8.63068 7.73708 0.4923 -#> 4:3 4.00000 2.64205 2.51686 0.8560 -#> Jtot 973.00000 1026.76858 284.51030 -3.1877 cat("replicates Upton & Fingleton table 3.6 (p. 168)\n") -#> replicates Upton & Fingleton table 3.6 (p. 168) joincount.multi(hopkins4.f, nb2listw(hopkins.queen.nb, style="B")) -#> Joincount Expected Variance z-value -#> 0:0 1687.0000 1607.0369 303.8034 4.5877 -#> 1:1 195.0000 171.5572 114.2057 2.1936 -#> 2:2 37.0000 35.4450 29.6821 0.2854 -#> 3:3 5.0000 3.2440 3.0687 1.0024 -#> 4:4 8.0000 2.0582 1.9674 4.2361 -#> 1:0 1000.0000 1053.3931 480.6959 -2.4353 -#> 2:0 429.0000 480.1513 215.0360 -3.4882 -#> 2:1 180.0000 157.1271 119.3987 2.0932 -#> 3:0 119.0000 146.9851 65.1029 -3.4684 -#> 3:1 49.0000 48.1001 38.3268 0.1454 -#> 3:2 32.0000 21.9247 19.5237 2.2802 -#> 4:0 88.0000 117.5881 52.0312 -4.1019 -#> 4:1 44.0000 38.4801 30.7868 0.9948 -#> 4:2 24.0000 17.5398 15.6933 1.6308 -#> 4:3 9.0000 5.3693 5.0994 1.6078 -#> Jtot 1974.0000 2086.6587 582.8326 -4.6665 cat("replicates Upton & Fingleton table 3.7 (p. 169)\n") -#> replicates Upton & Fingleton table 3.7 (p. 169) -# } +} diff --git a/docs/reference/knearneigh.html b/docs/reference/knearneigh.html index f5a9e742..5f4466fa 100644 --- a/docs/reference/knearneigh.html +++ b/docs/reference/knearneigh.html @@ -161,9 +161,9 @@

Examples

#> 4 #> 48 #> 48 least connected regions: -#> with 4 links +#> 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 with 4 links #> 48 most connected regions: -#> with 4 links +#> 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 with 4 links summary(gck4.nb, xy, longlat=TRUE, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -176,9 +176,9 @@

Examples

#> 4 #> 48 #> 48 least connected regions: -#> with 4 links +#> 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 with 4 links #> 48 most connected regions: -#> with 4 links +#> 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 with 4 links #xy1 <- SpatialPoints((as.data.frame(state.center))[m50.48,], # proj4string=CRS("+proj=longlat +ellps=GRS80")) @@ -191,7 +191,7 @@

Examples

sf_use_s2(TRUE) system.time(gck4a.nb <- knn2nb(knearneigh(xy1, k=4))) #> user system elapsed -#> 0.008 0.000 0.009 +#> 0.009 0.000 0.010 summary(gck4a.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -204,14 +204,14 @@

Examples

#> 4 #> 48 #> 48 least connected regions: -#> with 4 links +#> 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 with 4 links #> 48 most connected regions: -#> with 4 links +#> 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 with 4 links sf_use_s2(FALSE) #> Spherical geometry (s2) switched off system.time(gck4a.nb <- knn2nb(knearneigh(xy1, k=4))) #> user system elapsed -#> 0.005 0.000 0.006 +#> 0.005 0.000 0.005 summary(gck4a.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -224,9 +224,9 @@

Examples

#> 4 #> 48 #> 48 least connected regions: -#> with 4 links +#> 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 with 4 links #> 48 most connected regions: -#> with 4 links +#> 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 with 4 links sf_use_s2(old_use_s2) #> Spherical geometry (s2) switched on diff --git a/docs/reference/localC.html b/docs/reference/localC.html index 1efd5e5b..03cfd45b 100644 --- a/docs/reference/localC.html +++ b/docs/reference/localC.html @@ -245,11 +245,9 @@

Examples

} #> [1] 0.985611 # pseudo-p values probably wrongly folded https://github.com/GeoDaCenter/rgeoda/issues/28 -# \dontrun{ +if (FALSE) { tmap_ok <- FALSE if (require(tmap, quietly=TRUE)) tmap_ok <- TRUE -#> Breaking News: tmap 3.x is retiring. Please test v4, e.g. with -#> remotes::install_github('r-tmap/tmap') if (run) { # doi: 10.1111/gean.12164 guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") @@ -263,25 +261,10 @@

Examples

moran(g$Infants, lw, n=nrow(g), S0=Szero(lw))$I moran(g$Suicids, lw, n=nrow(g), S0=Szero(lw))$I } -#> Reading layer `Guerry' from data source -#> `/home/rsb/lib/r_libs/rgeoda/extdata/Guerry.shp' using driver `ESRI Shapefile' -#> Simple feature collection with 85 features and 29 fields -#> Geometry type: MULTIPOLYGON -#> Dimension: XY -#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 -#> Projected CRS: NTF (Paris) / Lambert zone II -#> [1] 0.4016812 if (run) { o <- prcomp(st_drop_geometry(g), scale.=TRUE) cor(st_drop_geometry(g), o$x[,1:2])^2 #(Tab. 2) } -#> PC1 PC2 -#> Crm_prs 0.009286863 0.418851254 -#> Crm_prp 0.561825664 0.009377232 -#> Litercy 0.560570048 0.020095011 -#> Donatns 0.024138865 0.586720363 -#> Infants 0.436025658 0.012817054 -#> Suicids 0.548623327 0.152958961 if (run) { g$PC1 <- o$x[, "PC1"] brks <- c(min(g$PC1), natural_breaks(k=6, g["PC1"]), max(g$PC1)) @@ -289,7 +272,6 @@

Examples

tm_borders() # Fig. 1 else pplot(g["PC1"], breaks=brks) } - if (run) { g$PC2 <- -1*o$x[, "PC2"] # eigenvalue sign arbitrary brks <- c(min(g$PC2), natural_breaks(k=6, g["PC2"]), max(g$PC2)) @@ -297,7 +279,6 @@

Examples

tm_borders() # Fig. 2 else plot(g["PC2"], breaks=brks) } - if (run) { w <- queen_weights(g) lm_PC1 <- local_moran(w, g["PC1"], significance_cutoff=0.01, @@ -310,7 +291,6 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 3 else plot(g["lm_PC1"]) } - if (run) { set.seed(1) lm_PC1_spdep <- localmoran_perm(g$PC1, lw, nsim=9999) @@ -322,7 +302,6 @@

Examples

colorNA="gray95") + tm_borders() # rep. Fig. 3 else plot(g["lm_PC1_spdep"]) } - if (run) { lg_PC1 <- local_g(w, g["PC1"], significance_cutoff=0.01, permutations=99999) @@ -340,7 +319,6 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 4 (guess) else plot(g["lg_PC1"]) } - if (run) { lc_PC1 <- local_geary(w, g["PC1"], significance_cutoff=0.01, permutations=99999) @@ -352,14 +330,11 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 5 else plot(g["lc_PC1"]) } - if (run) { set.seed(1) system.time(lc_PC1_spdep <- localC_perm(g$PC1, lw, nsim=9999, alternative="two.sided")) } -#> user system elapsed -#> 0.376 0.001 0.377 if (run) { if (require(parallel, quietly=TRUE)) { ncpus <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L @@ -372,7 +347,6 @@

Examples

set.coresOption(cores) } } -#> [1] 1 if (run) { g$lc_PC1_spdep <- attr(lc_PC1_spdep, "cluster") is.na(g$lc_PC1_spdep) <- attr(lc_PC1_spdep, "pseudo-p")[,6] > 0.01 @@ -381,7 +355,6 @@

Examples

colorNA="gray95") + tm_borders() # rep. Fig. 5 else plot(g["lc_PC1_spdep"]) } - if (run) { g$both_PC1 <- interaction(g$lc_PC1, g$lm_PC1) g$both_PC1 <- droplevels(g$both_PC1) @@ -389,7 +362,6 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 6 else plot(g["both_PC1"]) } - if (run) { lc005_PC1 <- local_geary(w, g["PC1"], significance_cutoff=0.005, permutations=99999) @@ -401,7 +373,6 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 7 else plot(g["lc005_PC1"]) } - if (run) { g$lc005_PC1_spdep <- attr(lc_PC1_spdep, "cluster") is.na(g$lc005_PC1_spdep) <- attr(lc_PC1_spdep, "pseudo-p")[,6] > 0.005 @@ -410,7 +381,6 @@

Examples

colorNA="gray95") + tm_borders() # rep. Fig. 7 else plot(g["lc005_PC1_spdep"]) } - if (run) { lc001_PC1 <- local_geary(w, g["PC1"], significance_cutoff=0.001, permutations=99999) @@ -430,7 +400,6 @@

Examples

else plot(g["lc001_PC1_spdep"]) } } - if (run) { lc_PC2 <- local_geary(w, g["PC2"], significance_cutoff=0.01, permutations=99999) @@ -442,7 +411,6 @@

Examples

colorNA="gray95") + tm_borders() # Fig. 9 else plot(g["lc_PC2"]) } - if (run) { lmc_PC <- local_multigeary(w, g[c("PC1","PC2")], significance_cutoff=0.00247, permutations=99999) @@ -452,25 +420,19 @@

Examples

g$lmc_PC <- droplevels(g$lmc_PC) table(interaction((p.adjust(lisa_pvalues(lmc_PC), "fdr") < 0.01), g$lmc_PC)) } -#> -#> FALSE.Positive TRUE.Positive -#> 0 21 if (run) { if (tmap_ok) tm_shape(g) + tm_fill("lmc_PC", textNA="Insignificant", colorNA="gray95") + tm_borders() # Fig. 10 else plot(g["lmc_PC"]) } - if (run) { set.seed(1) lmc_PC_spdep <- localC_perm(g[c("PC1","PC2")], lw, nsim=9999, alternative="two.sided") all.equal(lisa_values(lmc_PC), c(lmc_PC_spdep)) } -#> [1] TRUE if (run) { cor(attr(lmc_PC_spdep, "pseudo-p")[,6], lisa_pvalues(lmc_PC)) } -#> [1] 0.99052 if (run) { g$lmc_PC_spdep <- attr(lmc_PC_spdep, "cluster") is.na(g$lmc_PC_spdep) <- p.adjust(attr(lmc_PC_spdep, "pseudo-p")[,6], "fdr") > 0.01 @@ -479,7 +441,6 @@

Examples

colorNA="gray95") + tm_borders() # rep. Fig. 10 else plot(g["lmc_PC_spdep"]) } - if (run) { lmc_vars <- local_multigeary(w, st_drop_geometry(g)[, 1:6], significance_cutoff=0.00247, permutations=99999) @@ -490,30 +451,22 @@

Examples

table(interaction((p.adjust(lisa_pvalues(lmc_vars), "fdr") < 0.01), g$lmc_vars)) } -#> -#> FALSE.Positive TRUE.Positive -#> 0 21 if (run) { if (tmap_ok) tm_shape(g) + tm_fill("lmc_vars", textNA="Insignificant", colorNA="gray95") + tm_borders() # Fig. 11 else plot(g["lmc_vars"]) } - if (run) { set.seed(1) system.time(lmc_vars_spdep <- localC_perm(st_drop_geometry(g)[, 1:6], lw, nsim=9999, alternative="two.sided")) } -#> user system elapsed -#> 0.824 0.002 0.828 if (run) { all.equal(lisa_values(lmc_vars), c(lmc_vars_spdep)) } -#> [1] TRUE if (run) { cor(attr(lmc_vars_spdep, "pseudo-p")[,6], lisa_pvalues(lmc_vars)) } -#> [1] 0.9938141 if (run) { if (require(parallel, quietly=TRUE)) { ncpus <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L @@ -526,15 +479,12 @@

Examples

set.coresOption(cores) } } -#> [1] 1 if (run) { all.equal(lisa_values(lmc_vars), c(lmc_vars_spdep1)) } -#> [1] TRUE if (run) { cor(attr(lmc_vars_spdep1, "pseudo-p")[,6], lisa_pvalues(lmc_vars)) } -#> [1] 0.9938141 if (run) { g$lmc_vars_spdep <- attr(lmc_vars_spdep1, "cluster") is.na(g$lmc_vars_spdep) <- p.adjust(attr(lmc_vars_spdep1, "pseudo-p")[,6], "fdr") > 0.01 @@ -543,10 +493,9 @@

Examples

colorNA="gray95") + tm_borders() # rep. Fig. 11 else plot(g["lmc_vars_spdep"]) } - -# } -# \dontrun{ +} +if (FALSE) { library(reticulate) use_python("/usr/bin/python", required = TRUE) gp <- import("geopandas") @@ -557,7 +506,6 @@

Examples

esda <- import("esda") lM <- esda$Moran_Local(x, w) all.equal(unname(localmoran(x, listw, mlvar=FALSE)[,1]), c(lM$Is)) -#> [1] TRUE # confirm x and w the same lC <- esda$Geary_Local(connectivity=w)$fit(scale(x)) # np$std missing ddof=1 @@ -566,19 +514,10 @@

Examples

# lC components probably wrongly ordered https://github.com/pysal/esda/issues/192 o <- match(round(D0, 6), round(lC$localG, 6)) all.equal(c(lC$localG)[o], D0) -#> [1] TRUE # simulation order not retained lC$p_sim[o] -#> [1] 0.278 0.460 0.112 0.019 0.121 0.038 0.330 0.412 0.147 0.001 0.113 0.141 -#> [13] 0.188 0.246 0.450 0.172 0.102 0.298 0.001 0.027 0.038 0.091 0.055 0.297 -#> [25] 0.153 0.031 0.107 0.280 0.450 0.001 0.066 0.104 0.080 0.231 0.306 0.001 -#> [37] 0.326 0.482 0.321 0.216 0.235 0.288 attr(C, "pseudo-p")[,6] -#> [1] 0.408 0.374 0.144 0.056 0.010 0.284 0.032 0.264 0.186 0.004 0.150 0.224 -#> [13] 0.022 0.150 0.438 0.084 0.126 0.184 0.002 0.238 0.126 0.100 0.068 0.372 -#> [25] 0.124 0.234 0.230 0.016 0.318 0.176 0.272 0.164 0.164 0.206 0.402 0.250 -#> [37] 0.410 0.402 0.328 0.294 0.438 0.248 -# } +} diff --git a/docs/reference/mat2listw.html b/docs/reference/mat2listw.html index 096c6e5d..656b612c 100644 --- a/docs/reference/mat2listw.html +++ b/docs/reference/mat2listw.html @@ -140,13 +140,14 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 4 11 5 8 3 9 2 2 3 2 #> 11 least connected regions: -#> with 1 link +#> 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link #> 2 most connected regions: -#> with 9 links -col005.w.mat <- nb2mat(col005, zero.policy=TRUE) -col005.w.b <- mat2listw(col005.w.mat) -#> Warning: style is M (missing); style should be set to a valid value -#> Warning: no-neighbour observations found, zero.policy set to TRUE +#> 1038 1036 with 9 links +col005.w.mat <- nb2mat(col005, style="W", zero.policy=TRUE) +try(col005.w.b <- mat2listw(col005.w.mat, style="W")) +#> Error in mat2listw(col005.w.mat, style = "W") : +#> no-neighbour observations found, set zero.policy to TRUE +col005.w.b <- mat2listw(col005.w.mat, style="W", zero.policy=TRUE) summary(col005.w.b$neighbours) #> Neighbour list object: #> Number of regions: 49 @@ -161,9 +162,9 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 4 11 5 8 3 9 2 2 3 2 #> 11 least connected regions: -#> with 1 link +#> 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link #> 2 most connected regions: -#> with 9 links +#> 1038 1036 with 9 links diffnb(col005, col005.w.b$neighbours) #> Neighbour list object: #> Number of regions: 49 @@ -177,9 +178,7 @@

Examples

#> 1029 1025 1028 1048 1015 1027 1026 #> 49 disjoint connected subgraphs col005.w.mat.3T <- kronecker(diag(3), col005.w.mat) -col005.w.b.3T <- mat2listw(col005.w.mat.3T, style="W") -#> Warning: no-neighbour observations found, zero.policy set to TRUE -#> Warning: zero sum general weights +col005.w.b.3T <- mat2listw(col005.w.mat.3T, style="W", zero.policy=TRUE) summary(col005.w.b.3T$neighbours) #> Neighbour list object: #> Number of regions: 147 @@ -194,21 +193,22 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 12 33 15 24 9 27 6 6 9 6 #> 33 least connected regions: -#> with 1 link +#> 2 5 9 10 31 34 36 39 42 46 47 51 54 58 59 80 83 85 88 91 95 96 100 103 107 108 129 132 134 137 140 144 145 with 1 link #> 6 most connected regions: -#> with 9 links +#> 11 16 60 65 109 114 with 9 links run <- FALSE if (require("spatialreg", quiet=TRUE)) run <- TRUE if (run) { W <- as(nb2listw(col005, style="W", zero.policy=TRUE), "CsparseMatrix") -col005.spM <- mat2listw(W) +try(col005.spM <- mat2listw(W)) +col005.spM <- mat2listw(W, style="W", zero.policy=TRUE) summary(col005.spM$neighbours) } #> Warning: style is M (missing); style should be set to a valid value #> Warning: style is M (missing); style should be set to a valid value #> Warning: 1005, 1006, 1008, 1043 are not origins -#> Warning: no-neighbour observations found, zero.policy set to TRUE -#> Warning: no-neighbour observations found, zero.policy set to TRUE +#> Error in sn2listw(df, style = style, zero.policy = zero.policy) : +#> no-neighbour observations found, set zero.policy to TRUE #> Neighbour list object: #> Number of regions: 49 #> Number of nonzero links: 170 @@ -222,9 +222,9 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 4 11 5 8 3 9 2 2 3 2 #> 11 least connected regions: -#> with 1 link +#> 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link #> 2 most connected regions: -#> with 9 links +#> 1038 1036 with 9 links if (run) { diffnb(col005, col005.spM$neighbours) } @@ -241,14 +241,9 @@

Examples

#> 49 disjoint connected subgraphs if (run && require("Matrix", quiet=TRUE)) { IW <- kronecker(Diagonal(3), W) -col005.spM.3T <- mat2listw(as(IW, "CsparseMatrix"), style="W") +col005.spM.3T <- mat2listw(as(IW, "CsparseMatrix"), style="W", zero.policy=TRUE) summary(col005.spM.3T$neighbours) } -#> Warning: style is M (missing); style should be set to a valid value -#> Warning: 1, 3, 6, 21, 50, 52, 55, 70, 99, 101, 104, 119 are not origins -#> Warning: no-neighbour observations found, zero.policy set to TRUE -#> Warning: no-neighbour observations found, zero.policy set to TRUE -#> Warning: zero sum general weights #> Neighbour list object: #> Number of regions: 147 #> Number of nonzero links: 510 @@ -262,9 +257,9 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 12 33 15 24 9 27 6 6 9 6 #> 33 least connected regions: -#> with 1 link +#> 2 5 9 10 31 34 36 39 42 46 47 51 54 58 59 80 83 85 88 91 95 96 100 103 107 108 129 132 134 137 140 144 145 with 1 link #> 6 most connected regions: -#> with 9 links +#> 11 16 60 65 109 114 with 9 links diff --git a/docs/reference/nb2blocknb.html b/docs/reference/nb2blocknb.html index c2276d23..460ced1b 100644 --- a/docs/reference/nb2blocknb.html +++ b/docs/reference/nb2blocknb.html @@ -127,96 +127,31 @@

See also

Examples

-
# \dontrun{
+    
if (FALSE) {
 data(boston, package="spData")
 summary(as.vector(table(boston.c$TOWN)))
-#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-#>     1.0     2.0     4.0     5.5     7.0    30.0 
 townaggr <- aggregate(boston.utm, list(town=boston.c$TOWN), mean)
 block.rel <- graph2nb(relativeneigh(as.matrix(townaggr[,2:3])),
  as.character(townaggr[,1]), sym=TRUE)
 block.rel
-#> Neighbour list object:
-#> Number of regions: 92 
-#> Number of nonzero links: 240 
-#> Percentage nonzero weights: 2.835539 
-#> Average number of links: 2.608696 
 print(is.symmetric.nb(block.rel))
-#> [1] TRUE
 plot(block.rel, as.matrix(townaggr[,2:3]))
 points(boston.utm, pch=18, col="lightgreen")
-
 block.nb <- nb2blocknb(block.rel, as.character(boston.c$TOWN))
 block.nb
-#> Neighbour list object:
-#> Number of regions: 506 
-#> Number of nonzero links: 15234 
-#> Percentage nonzero weights: 5.949945 
-#> Average number of links: 30.10672 
 print(is.symmetric.nb(block.nb))
-#> [1] TRUE
 plot(block.nb, boston.utm)
 points(boston.utm, pch=18, col="lightgreen")
-
 n.comp.nb(block.nb)$nc
-#> [1] 1
 moran.test(boston.c$CMEDV, nb2listw(boston.soi))
-#> 
-#> 	Moran I test under randomisation
-#> 
-#> data:  boston.c$CMEDV  
-#> weights: nb2listw(boston.soi)    
-#> 
-#> Moran I statistic standard deviate = 21.786, p-value < 2.2e-16
-#> alternative hypothesis: greater
-#> sample estimates:
-#> Moran I statistic       Expectation          Variance 
-#>       0.690285059      -0.001980198       0.001009685 
-#> 
 moran.test(boston.c$CMEDV, nb2listw(block.nb))
-#> 
-#> 	Moran I test under randomisation
-#> 
-#> data:  boston.c$CMEDV  
-#> weights: nb2listw(block.nb)    
-#> 
-#> Moran I statistic standard deviate = 22.455, p-value < 2.2e-16
-#> alternative hypothesis: greater
-#> sample estimates:
-#> Moran I statistic       Expectation          Variance 
-#>      0.3122905961     -0.0019801980      0.0001958827 
-#> 
 block.nb <- nb2blocknb(NULL, as.character(boston.c$TOWN))
 block.nb
-#> Neighbour list object:
-#> Number of regions: 506 
-#> Number of nonzero links: 4868 
-#> Percentage nonzero weights: 1.901295 
-#> Average number of links: 9.620553 
-#> 17 regions with no links:
-#> 1 55 56 57 58 65 196 257 284 285 286 287 342 343 348 349 354
-#> 92 disjoint connected subgraphs
 print(is.symmetric.nb(block.nb))
-#> [1] TRUE
 plot(block.nb, boston.utm)
-
 n.comp.nb(block.nb)$nc
-#> [1] 92
 moran.test(boston.c$CMEDV, nb2listw(block.nb, zero.policy=TRUE), zero.policy=TRUE)
-#> 
-#> 	Moran I test under randomisation
-#> 
-#> data:  boston.c$CMEDV  
-#> weights: nb2listw(block.nb, zero.policy = TRUE)  n reduced by no-neighbour observations
-#>   
-#> 
-#> Moran I statistic standard deviate = 21.145, p-value < 2.2e-16
-#> alternative hypothesis: greater
-#> sample estimates:
-#> Moran I statistic       Expectation          Variance 
-#>      0.6188830566     -0.0020491803      0.0008623116 
-#> 
-# }
+}
 
diff --git a/docs/reference/nb2lines.html b/docs/reference/nb2lines.html index 38b287ec..1b49a033 100644 --- a/docs/reference/nb2lines.html +++ b/docs/reference/nb2lines.html @@ -158,12 +158,12 @@

Examples

tf <- paste0(tempfile(), ".gpkg") st_write(res, dsn=tf, driver="GPKG") #> writing: substituting ENGCRS["Undefined Cartesian SRS with unknown unit"] for missing CRS -#> Writing layer `file706d874b42afe' to data source -#> `/tmp/RtmpMRGWgk/file706d874b42afe.gpkg' using driver `GPKG' +#> Writing layer `file9f36c3d2d676e' to data source +#> `/tmp/Rtmp84DoOB/file9f36c3d2d676e.gpkg' using driver `GPKG' #> Writing 230 features with 5 fields and geometry type Line String. inMap <- st_read(tf) -#> Reading layer `file706d874b42afe' from data source -#> `/tmp/RtmpMRGWgk/file706d874b42afe.gpkg' using driver `GPKG' +#> Reading layer `file9f36c3d2d676e' from data source +#> `/tmp/Rtmp84DoOB/file9f36c3d2d676e.gpkg' using driver `GPKG' #> Simple feature collection with 230 features and 5 fields #> Geometry type: LINESTRING #> Dimension: XY diff --git a/docs/reference/nb2listw.html b/docs/reference/nb2listw.html index fd9ebeee..ef19145f 100644 --- a/docs/reference/nb2listw.html +++ b/docs/reference/nb2listw.html @@ -173,9 +173,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links #> #> Weights style: minmax #> Weights constants summary: diff --git a/docs/reference/nb2listwdist.html b/docs/reference/nb2listwdist.html index a6ffbf2d..98dcafb5 100644 --- a/docs/reference/nb2listwdist.html +++ b/docs/reference/nb2listwdist.html @@ -171,43 +171,15 @@

Examples

#> Moran I statistic Expectation Variance #> 0.473883371 -0.007042254 0.029994057 #> -# \dontrun{ +if (FALSE) { # Moran's I (life expectancy) with IDW with alpha = 2, no coding scheme world_weights <- nb2listwdist(nb_world, pts, type = "idw", alpha = 2, zero.policy = TRUE) moran.test(world$lifeExp, world_weights, zero.policy = TRUE, na.action = na.pass) -#> Warning: NAs in lagged values -#> -#> Moran I test under randomisation -#> -#> data: world$lifeExp -#> weights: world_weights n reduced by no-neighbour observations -#> -#> -#> Moran I statistic standard deviate = 2.7769, p-value = 0.002744 -#> alternative hypothesis: greater -#> sample estimates: -#> Moran I statistic Expectation Variance -#> 0.473883371 -0.007042254 0.029994057 -#> # Moran's I (life expectancy), DPD, alpha = 2, dmax = 1000 km, no coding scheme world_weights <- nb2listwdist(nb_world, pts, type = "dpd", dmax = 1000000, alpha = 2, zero.policy = TRUE) moran.test(world$lifeExp, world_weights, zero.policy = TRUE, na.action = na.pass) -#> Warning: NAs in lagged values -#> -#> Moran I test under randomisation -#> -#> data: world$lifeExp -#> weights: world_weights n reduced by no-neighbour observations -#> -#> -#> Moran I statistic standard deviate = 8.8557, p-value < 2.2e-16 -#> alternative hypothesis: greater -#> sample estimates: -#> Moran I statistic Expectation Variance -#> 0.601498970 -0.007042254 0.004722063 -#> # Boston examples data(boston, package="spData") boston_coords <- data.frame(x = boston.utm[,1], y = boston.utm[,2]) @@ -217,37 +189,11 @@

Examples

boston_weights <- nb2listwdist(nb_boston, boston.geoms, type = "exp", alpha = 2, style="raw", zero.policy = TRUE) moran.test(boston.c$CRIM, boston_weights, zero.policy = TRUE, na.action = na.pass) -#> -#> Moran I test under randomisation -#> -#> data: boston.c$CRIM -#> weights: boston_weights n reduced by no-neighbour observations -#> -#> -#> Moran I statistic standard deviate = 51.34, p-value < 2.2e-16 -#> alternative hypothesis: greater -#> sample estimates: -#> Moran I statistic Expectation Variance -#> 0.8845114518 -0.0019960080 0.0002981586 -#> # Moran's I (crime) with idw weights with alpha = 2, coding scheme = W boston_weights <- nb2listwdist(nb_boston, boston.geoms, type = "idw", alpha = 2, style="W", zero.policy = TRUE) moran.test(boston.c$CRIM, boston_weights, zero.policy = TRUE, na.action = na.pass) -#> -#> Moran I test under randomisation -#> -#> data: boston.c$CRIM -#> weights: boston_weights n reduced by no-neighbour observations -#> -#> -#> Moran I statistic standard deviate = 18.976, p-value < 2.2e-16 -#> alternative hypothesis: greater -#> sample estimates: -#> Moran I statistic Expectation Variance -#> 0.4392852330 -0.0019960080 0.0005408065 -#> -# } +}
diff --git a/docs/reference/nb2mat.html b/docs/reference/nb2mat.html index 7f17e8bb..39ec4504 100644 --- a/docs/reference/nb2mat.html +++ b/docs/reference/nb2mat.html @@ -137,9 +137,9 @@

Examples

#> 0 1 2 3 4 5 6 7 8 9 #> 4 11 5 8 3 9 2 2 3 2 #> 11 least connected regions: -#> with 1 link +#> 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link #> 2 most connected regions: -#> with 9 links +#> 1038 1036 with 9 links col005.w.mat <- nb2mat(col005, style="B", zero.policy=TRUE) table(round(rowSums(col005.w.mat))) #> diff --git a/docs/reference/nblag.html b/docs/reference/nblag.html index 08180e37..bd822ea5 100644 --- a/docs/reference/nblag.html +++ b/docs/reference/nblag.html @@ -122,9 +122,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links col.lags <- nblag(col.gal.nb, 2) print(col.lags) #> [[1]] @@ -154,9 +154,9 @@

Examples

#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #> 1 2 5 4 2 3 5 4 2 3 7 3 4 1 1 1 1 #> 1 least connected region: -#> with 1 link +#> 36 with 1 link #> 1 most connected region: -#> with 17 links +#> 25 with 17 links plot(st_geometry(columbus), border="grey") plot(col.gal.nb, coords, add=TRUE) title(main="GAL order 1 (black) and 2 (red) links") diff --git a/docs/reference/poly2nb.html b/docs/reference/poly2nb.html index 1cad8008..79b13c61 100644 --- a/docs/reference/poly2nb.html +++ b/docs/reference/poly2nb.html @@ -174,10 +174,10 @@

Examples

nc.sids <- st_read(system.file("shapes/sids.shp", package="spData")[1], quiet=TRUE) system.time(xxnb <- poly2nb(nc.sids)) #> user system elapsed -#> 0.018 0.000 0.018 +#> 0.019 0.000 0.019 system.time(xxnb <- poly2nb(as(nc.sids, "Spatial"))) #> user system elapsed -#> 0.029 0.000 0.029 +#> 0.034 0.000 0.035 plot(st_geometry(nc.sids)) plot(xxnb, st_coordinates(st_centroid(nc.sids)), add=TRUE, col="blue") #> Warning: st_centroid assumes attributes are constant over geometries diff --git a/docs/reference/skater.html b/docs/reference/skater.html index aefe0190..d2b9c2e6 100644 --- a/docs/reference/skater.html +++ b/docs/reference/skater.html @@ -292,22 +292,18 @@

Examples

table(res5d$groups) #> Error in eval(expr, envir, enclos): object 'res5d' not found -# \dontrun{ +if (FALSE) { data(boston, package="spData") bh.nb <- boston.soi dpad <- data.frame(scale(boston.c[,c(7:10)])) ### calculating costs system.time(lcosts <- nbcosts(bh.nb, dpad)) -#> user system elapsed -#> 0.042 0.000 0.043 ### making listw nb.w <- nb2listw(bh.nb, lcosts, style="B") ### find a minimum spanning tree mst.bh <- mstree(nb.w,5) ### three groups with no restriction system.time(res1 <- skater(mst.bh[,1:2], dpad, 2)) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero -#> Timing stopped at: 0 0 0 library(parallel) nc <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L # set nc to 1L here @@ -321,26 +317,20 @@

Examples

} ### calculating costs system.time(plcosts <- nbcosts(bh.nb, dpad)) -#> user system elapsed -#> 0.04 0.00 0.04 all.equal(lcosts, plcosts, check.attributes=FALSE) -#> [1] TRUE ### making listw pnb.w <- nb2listw(bh.nb, plcosts, style="B") ### find a minimum spanning tree pmst.bh <- mstree(pnb.w,5) ### three groups with no restriction system.time(pres1 <- skater(pmst.bh[,1:2], dpad, 2)) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero -#> Timing stopped at: 0 0 0 if(!get.mcOption()) { set.ClusterOption(NULL) stopCluster(cl) } all.equal(res1, pres1, check.attributes=FALSE) -#> Error in h(simpleError(msg, call)): error in evaluating the argument 'target' in selecting a method for function 'all.equal': object 'res1' not found invisible(set.coresOption(coresOpt)) -# } +} diff --git a/docs/reference/summary.nb.html b/docs/reference/summary.nb.html index 79407597..674042bf 100644 --- a/docs/reference/summary.nb.html +++ b/docs/reference/summary.nb.html @@ -145,9 +145,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links col.listw <- nb2listw(col.gal.nb, style="W") col.listw #> Characteristics of weights list object: @@ -173,9 +173,9 @@

Examples

#> 2 3 4 5 6 7 8 9 10 #> 7 7 13 4 9 6 1 1 1 #> 7 least connected regions: -#> with 2 links +#> 1 6 31 39 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links #> #> Weights style: W #> Weights constants summary: @@ -199,9 +199,9 @@

Examples

#> 0 2 3 4 5 6 7 8 9 10 #> 1 5 9 12 4 10 2 4 1 1 #> 5 least connected regions: -#> with 2 links +#> 1 6 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links try(nb2listw(nb, style="W")) #> Error in nb2listw(nb, style = "W") : Empty neighbour sets found summary(nb2listw(nb, style="W", zero.policy=TRUE)) @@ -219,9 +219,9 @@

Examples

#> 0 2 3 4 5 6 7 8 9 10 #> 1 5 9 12 4 10 2 4 1 1 #> 5 least connected regions: -#> with 2 links +#> 1 6 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links #> #> Weights style: W #> Weights constants summary: @@ -242,9 +242,9 @@

Examples

#> 0 2 3 4 5 6 7 8 9 10 #> 1 5 9 12 4 10 2 4 1 1 #> 5 least connected regions: -#> with 2 links +#> 1 6 42 46 47 with 2 links #> 1 most connected region: -#> with 10 links +#> 20 with 10 links #> #> Weights style: W #> Weights constants summary: diff --git a/docs/reference/tolerance.nb.html b/docs/reference/tolerance.nb.html index 14a72c2e..e793d2ac 100644 --- a/docs/reference/tolerance.nb.html +++ b/docs/reference/tolerance.nb.html @@ -130,24 +130,18 @@

Examples

### and a maximum distance of 2 m. nb.ex<-tolerance.nb(ex.data, unit.angle = "degrees", max.dist=1, tolerance = 30) -#> Warning: style is M (missing); style should be set to a valid value -#> Warning: no-neighbour observations found, zero.policy set to TRUE ### Construct object of class nb with a tolerance angle of 30 degrees ### and a maximum distance of 2 m. The coordinates are rotated at an angle ### of 45 degrees counterclockwise. nb.ex2<-tolerance.nb(ex.data, unit.angle = "degrees", max.dist=1, tolerance = 30, rot.angle = 45) -#> Warning: style is M (missing); style should be set to a valid value -#> Warning: no-neighbour observations found, zero.policy set to TRUE ### Construct object of class nb with a tolerance angle of pi/8 radians ### and a maximum distance of 1.5 m. The coordinates are rotated at ### an angle of pi/4 radians clockwise. nb.ex3<-tolerance.nb(ex.data, unit.angle = "radians", max.dist=1.5, tolerance = pi/8, rot.angle = -pi*2/3) -#> Warning: style is M (missing); style should be set to a valid value -#> Warning: no-neighbour observations found, zero.policy set to TRUE par(mfrow=c(1,3)) plot(nb.ex,ex.data,asp=1)