diff --git a/docs/articles/CO69.html b/docs/articles/CO69.html index f89106aa..ed42e027 100644 --- a/docs/articles/CO69.html +++ b/docs/articles/CO69.html @@ -548,7 +548,7 @@
## user system elapsed
-## 0.12 0.00 0.12
+## 0.112 0.001 0.113
res <- sapply(c("MoranN", "MoranR", "GearyN", "GearyR", "Prop_unstdN", "Prop_unstdR", "Prop_stdN", "Prop_stdR"), function(x) sapply(get(x), "[[", "statistic"))
rownames(res) <- vars
@@ -780,7 +780,7 @@ Simulating measures of s
Prop_stdSad <- lapply(lm_objs, function(x) lm.morantest.sad(x, listw=lw_std))
})
## user system elapsed
-## 0.066 0.000 0.066
+## 0.065 0.000 0.066
res <- sapply(c("MoranSad", "Prop_unstdSad", "Prop_stdSad"), function(x) sapply(get(x), "[[", "statistic"))
rownames(res) <- vars
## user system elapsed
-## 0.082 0.000 0.082
+## 0.083 0.000 0.084
res <- sapply(c("MoranEx", "Prop_unstdEx", "Prop_stdEx"), function(x) sapply(get(x), "[[", "statistic"))
rownames(res) <- vars
## user system elapsed
-## 0.1853 0.0094 0.1960
+## 0.2036 0.0089 0.2136
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 @@ -406,12 +406,12 @@
system.time(for (i in 1:reps) suppressWarnings(NY88_nb_sf <- knn2nb(knearneigh(NY8_ct_sf, k=1))))/reps
## user system elapsed
-## 0.0271 0.0013 0.0286
+## 0.0232 0.0007 0.0240
Legacy code may be used omitting the kd-tree:
system.time(for (i in 1:reps) suppressWarnings(NY89_nb_sf <- knn2nb(knearneigh(NY8_ct_sf, k=1, use_kd_tree=FALSE))))/reps
## user system elapsed
-## 0.0263 0.0019 0.0284
+## 0.0233 0.0012 0.0246
system.time(for (i in 1:reps) suppressWarnings(NY810_nb <- dnearneigh(NY8_ct_sf, d1=0, d2=0.75*max_1nn)))/reps
## user system elapsed
-## 0.0619 0.0013 0.0634
+## 0.0606 0.0012 0.0621
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
@@ -440,7 +440,7 @@
system.time(for (i in 1:reps) suppressWarnings(NY811_nb <- dnearneigh(NY8_ct_sf, d1=0, d2=0.75*max_1nn, use_kd_tree=FALSE)))/reps
## user system elapsed
-## 0.0469 0.0008 0.0479
+## 0.0445 0.0013 0.0459
## user system elapsed
-## 0.0331 0.0001 0.0332
+## 0.0325 0.0000 0.0327
For this smaller data set, the legacy approach without spatial indexing is adequate, but slows down as the number of observations increases:
@@ -480,7 +480,7 @@
system.time(for (i in 1:reps) pts_ll2_nb <- knn2nb(knearneigh(pts_ll, k=6)))/reps
## user system elapsed
-## 0.0287 0.0001 0.0289
+## 0.0281 0.0001 0.0282
The WGS84 ellipsoid Great Circle distances differ a very little from the s2 spherical distances, yielding output that here diverges for two tract centroids:
@@ -535,7 +535,7 @@## user system elapsed
-## 0.068 0.000 0.068
+## 0.0665 0.0000 0.0665
Alternatively, spherical distances can be used with
dwithin=FALSE
and s2::s2_closest_edges()
;
although running in similar time, s2::s2_closest_edges()
@@ -544,7 +544,7 @@
system.time(for (i in 1:(reps/5)) suppressWarnings(pts_ll5_nb <- dnearneigh(pts_ll, d1=0, d2=0.75*max_1nn_ll, dwithin=FALSE)))/(reps/5)
## user system elapsed
-## 0.054 0.000 0.054
+## 0.0535 0.0000 0.0540
if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3_nb, pts_ll5_nb, check.attributes=FALSE)
## [1] TRUE
@@ -557,7 +557,7 @@ ## user system elapsed
-## 0.048 0.000 0.048
+## 0.044 0.000 0.044
Using s2::s2_dwithin_matrix()
requires a second pass,
one for the lower bound, another for the upper bound, and a set
difference operation to find neighbours in the distance band:
## user system elapsed
-## 0.0895 0.0005 0.0905
+## 0.0865 0.0000 0.0865
if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3a_nb, pts_ll5a_nb, check.attributes=FALSE)
## [1] TRUE
@@ -576,7 +576,7 @@
system.time(for (i in 1:reps) suppressWarnings(pts_ll6_nb <- dnearneigh(pts_ll, d1=0, d2=0.75*max_1nn_ll, use_s2=FALSE)))/reps
## user system elapsed
-## 0.0376 0.0000 0.0377
+## 0.0367 0.0000 0.0368
Minor differences may occur between the legacy ellipsoid and s2 spherical approaches:
@@ -606,7 +606,7 @@Distance neighbours
system.time(for (i in 1:reps) suppressWarnings(pts_ll6a_nb <- dnearneigh(pts_ll, d1=5, d2=0.75*max_1nn_ll, use_s2=FALSE)))/reps
## user system elapsed
-## 0.0314 0.0001 0.0318
+## 0.0286 0.0001 0.0288
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"
@@ -658,7 +658,7 @@ Contiguity neighbours for spherical polygon supportsf_use_s2(TRUE)
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.1660 0.0016 0.1682
+## 0.1569 0.0024 0.1599
all.equal(NY8_sf_1_nb, NY8_sf_1_nb_ll, check.attributes=FALSE)
## [1] TRUE
diff --git a/docs/articles/subgraphs.html b/docs/articles/subgraphs.html
index 91d90574..5c815182 100644
--- a/docs/articles/subgraphs.html
+++ b/docs/articles/subgraphs.html
@@ -179,7 +179,7 @@ ## Reading layer `GB_2024_Wales_50m' from data source
-## `/tmp/RtmpPpr0yz/temp_libpathafa452560f839/spdep/etc/shapes/GB_2024_Wales_50m.gpkg.zip'
+## `/tmp/RtmpcuVtwS/temp_libpathba7861ea38876/spdep/etc/shapes/GB_2024_Wales_50m.gpkg.zip'
## using driver `GPKG'
## Simple feature collection with 32 features and 19 fields
## Geometry type: MULTIPOLYGON
@@ -371,7 +371,7 @@ Subgraphssc50m <- st_read(target)
}
## Reading layer `GB_2024_southcoast_50m' from data source
-## `/tmp/RtmpPpr0yz/temp_libpathafa452560f839/spdep/etc/shapes/GB_2024_southcoast_50m.gpkg.zip'
+## `/tmp/RtmpcuVtwS/temp_libpathba7861ea38876/spdep/etc/shapes/GB_2024_southcoast_50m.gpkg.zip'
## using driver `GPKG'
## Simple feature collection with 119 features and 19 fields
## Geometry type: MULTIPOLYGON
@@ -654,7 +654,7 @@ Unintentional disconnected graphs tokyo <- st_read(target)
}
## Reading layer `tokyo' from data source
-## `/tmp/RtmpPpr0yz/temp_libpathafa452560f839/spdep/etc/shapes/tokyo.gpkg.zip'
+## `/tmp/RtmpcuVtwS/temp_libpathba7861ea38876/spdep/etc/shapes/tokyo.gpkg.zip'
## using driver `GPKG'
## Simple feature collection with 262 features and 3 fields
## Geometry type: MULTIPOLYGON
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index a91fa60a..8f9c3992 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -7,7 +7,7 @@ articles:
nb: nb.html
sids: sids.html
subgraphs: subgraphs.html
-last_built: 2024-09-10T08:34Z
+last_built: 2024-09-10T14:30Z
urls:
reference: https://r-spatial.github.io/spdep/reference
article: https://r-spatial.github.io/spdep/articles
diff --git a/docs/reference/bhicv.html b/docs/reference/bhicv.html
index e0475f4f..e5a01bb0 100644
--- a/docs/reference/bhicv.html
+++ b/docs/reference/bhicv.html
@@ -90,7 +90,7 @@ Examples bh <- st_read(target)
}
#> Reading layer `bhicv' from data source
-#> `/tmp/RtmpPpr0yz/temp_libpathafa452560f839/spdep/etc/shapes/bhicv.gpkg.zip'
+#> `/tmp/RtmpcuVtwS/temp_libpathba7861ea38876/spdep/etc/shapes/bhicv.gpkg.zip'
#> using driver `GPKG'
#> Simple feature collection with 98 features and 8 fields
#> Geometry type: POLYGON
diff --git a/docs/reference/compon.html b/docs/reference/compon.html
index 28873812..1b378eb2 100644
--- a/docs/reference/compon.html
+++ b/docs/reference/compon.html
@@ -189,12 +189,12 @@ Examplessystem.time(udir <- n.comp.nb(make.sym.nb(k6)))
}
#> user system elapsed
-#> 2.104 0.000 2.111
+#> 2.076 0.000 2.087
if (run) {
system.time(dir <- n.comp.nb(k6))
}
#> user system elapsed
-#> 0.701 0.003 0.707
+#> 0.680 0.002 0.685
if (run) {
udir$nc
}
diff --git a/docs/reference/dnearneigh.html b/docs/reference/dnearneigh.html
index c226d66f..df95f316 100644
--- a/docs/reference/dnearneigh.html
+++ b/docs/reference/dnearneigh.html
@@ -222,14 +222,14 @@ Examples#> Warning: neighbour object has 11 sub-graphs
system.time(o <- nbdists(gck1b, xy1))
#> user system elapsed
-#> 0.007 0.000 0.007
+#> 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))
#> Warning: neighbour object has 3 sub-graphs
#> user system elapsed
-#> 0.012 0.000 0.011
+#> 0.011 0.001 0.012
summary(gc.nb, xy1, scale=0.5)
#> Neighbour list object:
#> Number of regions: 48
@@ -251,13 +251,13 @@ Examples}
#> Warning: neighbour object has 3 sub-graphs
#> user system elapsed
-#> 0.01 0.00 0.01
+#> 0.010 0.000 0.009
if (packageVersion("s2") > "1.0.7") {
system.time(gc.nb.dwithin <- dnearneigh(xy1, 0, all.linked, use_s2=TRUE, dwithin=TRUE))
}
#> Warning: neighbour object has 3 sub-graphs
#> user system elapsed
-#> 0.012 0.000 0.012
+#> 0.012 0.000 0.011
if (packageVersion("s2") > "1.0.7") {
summary(gc.nb.dwithin, xy1, scale=0.5)
}
@@ -300,7 +300,7 @@ Examplessystem.time(gc.nb.legacy <- dnearneigh(xy1, 0, all.linked, use_s2=FALSE))
#> Warning: neighbour object has 3 sub-graphs
#> user system elapsed
-#> 0.007 0.000 0.006
+#> 0.006 0.000 0.006
summary(gc.nb, xy1, scale=0.5)
#> Neighbour list object:
#> Number of regions: 48
diff --git a/docs/reference/joincount.multi.html b/docs/reference/joincount.multi.html
index 53c169cc..3c028905 100644
--- a/docs/reference/joincount.multi.html
+++ b/docs/reference/joincount.multi.html
@@ -229,6 +229,56 @@ Examplescat("replicates Upton & Fingleton table 3.7 (p. 169)\n")
#> replicates Upton & Fingleton table 3.7 (p. 169)
# }
+GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0"
+file <- "etc/shapes/GB_2024_southcoast_50m.gpkg.zip"
+zipfile <- system.file(file, package="spdep")
+if (GDAL37) {
+ sc50m <- st_read(zipfile)
+} else {
+ td <- tempdir()
+ bn <- sub(".zip", "", basename(file), fixed=TRUE)
+ target <- unzip(zipfile, files=bn, exdir=td)
+ sc50m <- st_read(target)
+}
+#> Reading layer `GB_2024_southcoast_50m' from data source
+#> `/tmp/RtmpcuVtwS/temp_libpathba7861ea38876/spdep/etc/shapes/GB_2024_southcoast_50m.gpkg.zip'
+#> using driver `GPKG'
+#> Simple feature collection with 119 features and 19 fields
+#> Geometry type: MULTIPOLYGON
+#> Dimension: XY
+#> Bounding box: xmin: 82643.12 ymin: 5342.9 xmax: 640301.6 ymax: 187226.2
+#> Projected CRS: OSGB36 / British National Grid
+plot(sc50m[,"Winner"], pal=c("#2297E6", "#61D04F", "#DF536B", "#F5C710"))
+
+nb_sc_50m <- poly2nb(sc50m, row.names=as.character(sc50m$Constituency))
+#> Warning: neighbour object has 2 sub-graphs;
+#> if this sub-graph count seems unexpected, try increasing the snap argument.
+sub2 <- attr(nb_sc_50m, "region.id")[attr(nb_sc_50m, "ncomp")$comp.id == 2L]
+iowe <- match(sub2[1], attr(nb_sc_50m, "region.id"))
+diowe <- c(st_distance(sc50m[iowe,], sc50m))
+meet_criterion <- sum(diowe <= units::set_units(5000, "m"))
+cands <- attr(nb_sc_50m, "region.id")[order(diowe)[1:meet_criterion]]
+nb_sc_50m_iowe <- addlinks1(nb_sc_50m, from = cands[1],
+ to = cands[3:meet_criterion])
+ioww <- match(sub2[2], attr(nb_sc_50m, "region.id"))
+dioww <- c(st_distance(sc50m[ioww,], sc50m))
+meet_criterion <- sum(dioww <= units::set_units(5000, "m"))
+cands <- attr(nb_sc_50m, "region.id")[order(dioww)[1:meet_criterion]]
+nb_sc_50m_iow <- addlinks1(nb_sc_50m_iowe, from = cands[2], to = cands[3:meet_criterion])
+nb_sc_1_2 <- nblag_cumul(nblag(nb_sc_50m_iow, 2))
+joincount.multi(factor(sc50m$Winner), nb2listw(nb_sc_1_2, style="B"))
+#> Joincount Expected Variance z-value
+#> Con:Con 146.0000 84.4324 116.3530 5.7077
+#> Green:Green 0.0000 0.0000 0.0000 NaN
+#> LD:LD 100.0000 75.8866 103.9440 2.3651
+#> Lab:Lab 63.0000 98.1057 136.0379 -3.0099
+#> Green:Con 4.0000 4.4438 5.8532 -0.1834
+#> LD:Con 198.0000 164.4210 166.3583 2.6034
+#> LD:Green 4.0000 4.2159 5.4573 -0.0924
+#> Lab:Con 184.0000 186.6401 180.9233 -0.1963
+#> Lab:Green 3.0000 4.7856 6.4663 -0.7022
+#> Lab:LD 98.0000 177.0688 175.2035 -5.9736
+#> Jtot 491.0000 541.5753 153.6123 -4.0806