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 @@
## 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
## 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 @@
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
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 @@
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
## 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 @@
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 @@## 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 @@
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 @@ ## 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 @@
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 @@ 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
# \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
-#>
-# }
+}