diff --git a/docs/404.html b/docs/404.html index 927893dc..7fe2f533 100644 --- a/docs/404.html +++ b/docs/404.html @@ -60,6 +60,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • diff --git a/docs/articles/CO69.html b/docs/articles/CO69.html index ae51666f..833be0f8 100644 --- a/docs/articles/CO69.html +++ b/docs/articles/CO69.html @@ -60,6 +60,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • @@ -576,7 +579,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.110   0.000   0.111
    +## 0.122 0.000 0.123
     res <- sapply(c("MoranN", "MoranR", "GearyN", "GearyR", "Prop_unstdN", "Prop_unstdR", "Prop_stdN", "Prop_stdR"), function(x) sapply(get(x), "[[", "statistic"))
     rownames(res) <- vars
    @@ -808,7 +811,7 @@ 

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

    ##    user  system elapsed 
    -##   0.063   0.000   0.064
    +## 0.073 0.000 0.073
     res <- sapply(c("MoranSad", "Prop_unstdSad", "Prop_stdSad"), function(x) sapply(get(x), "[[", "statistic"))
     rownames(res) <- vars
    @@ -871,7 +874,7 @@

    Simulating measures of s Prop_stdEx <- lapply(lm_objs, function(x) lm.morantest.exact(x, listw=lw_std)) })
    ##    user  system elapsed 
    -##   0.079   0.000   0.080
    +## 0.089 0.000 0.090
     res <- sapply(c("MoranEx", "Prop_unstdEx", "Prop_stdEx"), function(x) sapply(get(x), "[[", "statistic"))
     rownames(res) <- vars
    @@ -954,12 +957,6 @@

    Simulating measures of s ## radiopcap 0.0083 0.1376 ## retailpcap 0.6376 0.5307 ## psinglem30_34 0.4094 0.4889 -
    -Three contrasted spatial weights definitions

    -Three contrasted spatial weights definitions -

    -
    -

    Odds and ends diff --git a/docs/articles/index.html b/docs/articles/index.html index eb3e2f2c..79698e07 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -77,6 +80,8 @@

    All vignettes

    Introduction to the North Carolina SIDS data set (re-revised)
    +
    No-neighbour observation and subgraph handling
    +
    diff --git a/docs/articles/nb.html b/docs/articles/nb.html index a9f10eef..df1e27c6 100644 --- a/docs/articles/nb.html +++ b/docs/articles/nb.html @@ -60,6 +60,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • @@ -132,7 +135,7 @@

    Introductionlibrary(spdep)
    ## Loading required package: spData
    ## Loading required package: sf
    -
    ## Linking to GEOS 3.13.0beta1, GDAL 3.9.2, PROJ 9.4.1; sf_use_s2() is TRUE
    +
    ## Linking to GEOS 3.13.0, GDAL 3.9.2, PROJ 9.4.1; sf_use_s2() is TRUE
     if (packageVersion("spData") >= "2.3.2") {
         NY8a <- sf::st_read(system.file("shapes/NY8_utm18.gpkg", package="spData"))
    @@ -220,16 +223,9 @@ 

    Creating Contiguity Neighboursplot(Syracuse, border="grey60") plot(Sy0_nb, coordinates(Syracuse), add=TRUE, pch=19, cex=0.6) plot(diffnb(Sy0_nb, Sy2_nb, verbose=FALSE), coordinates(Syracuse), - add=TRUE, pch=".", cex=0.6, lwd=2, col="orange")

    -
    ## Warning in diffnb(Sy0_nb, Sy2_nb, verbose = FALSE): region.id differ; using ids
    -## of first list
    -
    ## Warning in diffnb(Sy0_nb, Sy2_nb, verbose = FALSE): neighbour object has 44
    -## sub-graphs
    -
    -text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="b)", cex=0.8)
    -

    -
    -par(oopar)
    + add=TRUE, pch=".", cex=0.6, lwd=2, col="orange") +text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="b)", cex=0.8) +par(oopar)

    a: Queen-style census tract contiguities, Syracuse; b: Rook-style contiguity differences shown as thicker orange lines

    If we have access to a GIS such as GRASS or ArcGIS, we can export the @@ -250,7 +246,7 @@

    Creating Contiguity Neighbours
    +
     library(rgrass)
     v <- terra::vect(sf::st_as_sf(Syracuse))
     SG <- terra::rast(terra::ext(v), crs=terra::crs(v))
    @@ -298,7 +294,7 @@ 

    Creating Graph-Based Neighbours(Avis and Horton 1985). Functions for graph-based neighbours were kindly contributed by Nicholas Lewin-Koh.

    -
    +
     coords <- coordinates(Syracuse)
     IDs <- row.names(as(Syracuse, "data.frame"))
     #FIXME library(tripack)
    @@ -311,10 +307,10 @@ 

    Creating Graph-Based Neighbours## The following object is masked from 'package:stats': ## ## as.dendrogram

    -
    +
     Sy6_nb <- graph2nb(gabrielneigh(coords), row.names=IDs)
     Sy7_nb <- graph2nb(relativeneigh(coords), row.names=IDs)
    -
    +
     oopar <- par(mfrow=c(2,2), mar=c(1,1,1,1)+0.1)
     plot(Syracuse, border="grey60")
     plot(Sy4_nb, coords, add=TRUE, pch=".")
    @@ -329,10 +325,8 @@ 

    Creating Graph-Based Neighbourstext(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="c)", cex=0.8) plot(Syracuse, border="grey60") plot(Sy7_nb, coords, add=TRUE, pch=".") -text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="d)", cex=0.8)

    -

    -
    -par(oopar)
    +text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="d)", cex=0.8) +par(oopar)

    a: Delauney triangulation neighbours; b: Sphere of influence neighbours (if available); c: Gabriel graph neighbours; d: Relative graph neighbours

    @@ -362,14 +356,14 @@

    Creating Graph-Based Neighbours -
    +
     nb_l <- list(Triangulation=Sy4_nb, Gabriel=Sy6_nb,
       Relative=Sy7_nb)
     if (!is.null(Sy5_nb)) nb_l <- c(nb_l, list(SOI=Sy5_nb))
     sapply(nb_l, function(x) is.symmetric.nb(x, verbose=FALSE, force=TRUE))
    ## Triangulation       Gabriel      Relative           SOI 
     ##          TRUE         FALSE         FALSE          TRUE
    -
    +
     sapply(nb_l, function(x) n.comp.nb(x)$nc)
    ## Triangulation       Gabriel      Relative           SOI 
     ##             1             1             1             1
    @@ -388,22 +382,22 @@

    Distance-Based Neighboursnb object by knn2nb(); knearneigh() can also take a longlat= argument to handle geographical coordinates.

    -
    +
     Sy8_nb <- knn2nb(knearneigh(coords, k=1), row.names=IDs)
    ## Warning in knn2nb(knearneigh(coords, k = 1), row.names = IDs): neighbour object
     ## has 15 sub-graphs
    -
    +
     Sy9_nb <- knn2nb(knearneigh(coords, k=2), row.names=IDs)
     Sy10_nb <- knn2nb(knearneigh(coords, k=4), row.names=IDs)
     nb_l <- list(k1=Sy8_nb, k2=Sy9_nb, k4=Sy10_nb)
     sapply(nb_l, function(x) is.symmetric.nb(x, verbose=FALSE, force=TRUE))
    ##    k1    k2    k4 
     ## FALSE FALSE FALSE
    -
    +
     sapply(nb_l, function(x) n.comp.nb(x)$nc)
    ## k1 k2 k4 
     ## 15  1  1
    -
    +
     oopar <- par(mfrow=c(1,3), mar=c(1,1,1,1)+0.1)
     plot(Syracuse, border="grey60")
     plot(Sy8_nb, coords, add=TRUE, pch=".")
    @@ -413,10 +407,8 @@ 

    Distance-Based Neighbourstext(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="b)", cex=0.8) plot(Syracuse, border="grey60") plot(Sy10_nb, coords, add=TRUE, pch=".") -text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="c)", cex=0.8)

    -

    -
    -par(oopar)
    +text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="c)", cex=0.8) +par(oopar)

    a: k=1k=1 neighbours; b: @@ -443,31 +435,31 @@

    Distance-Based Neighboursd1 and d2 setting the lower and upper distance bounds; it can also take a longlat argument to handle geographical coordinates.

    -
    +
     dsts <- unlist(nbdists(Sy8_nb, coords))
     summary(dsts)
    ##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
     ##   395.7   587.3   700.1   760.4   906.1  1544.6
    -
    +
     max_1nn <- max(dsts)
     max_1nn
    ## [1] 1544.615
    -
    +
     Sy11_nb <- dnearneigh(coords, d1=0, d2=0.75*max_1nn, row.names=IDs)
    ## Warning in dnearneigh(coords, d1 = 0, d2 = 0.75 * max_1nn, row.names = IDs):
     ## neighbour object has 4 sub-graphs
    -
    +
     Sy12_nb <- dnearneigh(coords, d1=0, d2=1*max_1nn, row.names=IDs)
     Sy13_nb <- dnearneigh(coords, d1=0, d2=1.5*max_1nn, row.names=IDs)
     nb_l <- list(d1=Sy11_nb, d2=Sy12_nb, d3=Sy13_nb)
     sapply(nb_l, function(x) is.symmetric.nb(x, verbose=FALSE, force=TRUE))
    ##   d1   d2   d3 
     ## TRUE TRUE TRUE
    -
    +
     sapply(nb_l, function(x) n.comp.nb(x)$nc)
    ## d1 d2 d3 
     ##  4  1  1
    -
    +
     oopar <- par(mfrow=c(1,3), mar=c(1,1,1,1)+0.1)
     plot(Syracuse, border="grey60")
     plot(Sy11_nb, coords, add=TRUE, pch=".")
    @@ -477,10 +469,8 @@ 

    Distance-Based Neighbourstext(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="b)", cex=0.8) plot(Syracuse, border="grey60") plot(Sy13_nb, coords, add=TRUE, pch=".") -text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="c)", cex=0.8)

    -

    -
    -par(oopar)
    +text(bbox(Syracuse)[1,1], bbox(Syracuse)[2,2], labels="c)", cex=0.8) +par(oopar)

    a: Neighbours within 1,158m; b: neighbours within 1,545m; c: neighbours within 2,317m

    The figure shows how the numbers of distance-based neighbours @@ -494,7 +484,7 @@

    Distance-Based Neighbours -
    +
     dS <- c(0.75, 1, 1.5)*max_1nn
     res <- sapply(nb_l, function(x) table(card(x)))
     mx <- max(card(Sy13_nb))
    @@ -517,7 +507,7 @@ 

    Distance-Based Neighbours -
    +
     
    ##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    @@ -551,13 +541,13 @@ 

    Higher-Order Neighboursnblag() function takes an existing neighbour list and returns a list of lists, from first to maxlag= order neighbours.

    -
    +
     Sy0_nb_lags <- nblag(Sy0_nb, maxlag=9)
    ## Warning in nblag(Sy0_nb, maxlag = 9): lag 6 neighbour object has 7 sub-graphs
    ## Warning in nblag(Sy0_nb, maxlag = 9): lag 7 neighbour object has 22 sub-graphs
    ## Warning in nblag(Sy0_nb, maxlag = 9): lag 8 neighbour object has 52 sub-graphs
    ## Warning in nblag(Sy0_nb, maxlag = 9): lag 9 neighbour object has 63 sub-graphs
    -
    +
     names(Sy0_nb_lags) <- c("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth")
     res <- sapply(Sy0_nb_lags, function(x) table(card(x)))
     mx <- max(unlist(sapply(Sy0_nb_lags, function(x) card(x))))
    @@ -595,14 +585,14 @@ 

    Grid Neighbours -
    +
     cell2nb(7, 7, type="rook", torus=TRUE)
    ## Neighbour list object:
     ## Number of regions: 49 
     ## Number of nonzero links: 196 
     ## Percentage nonzero weights: 8.163265 
     ## Average number of links: 4
    -
    +
     cell2nb(7, 7, type="rook", torus=FALSE)
    ## Neighbour list object:
     ## Number of regions: 49 
    @@ -626,7 +616,7 @@ 

    Grid Neighbours103×3103 \times 3,103 matrix.

    -
    +
     data(meuse.grid)
     coordinates(meuse.grid) <- c("x", "y")
     gridded(meuse.grid) <- TRUE
    @@ -638,7 +628,7 @@ 

    Grid Neighbours## Number of nonzero links: 12022 ## Percentage nonzero weights: 0.1248571 ## Average number of links: 3.874315

    -
    +
     table(card(mg_nb))
    ## 
     ##    1    2    3    4 
    diff --git a/docs/articles/nb_sf.html b/docs/articles/nb_sf.html
    index ccc9923d..db6b00c6 100644
    --- a/docs/articles/nb_sf.html
    +++ b/docs/articles/nb_sf.html
    @@ -60,6 +60,9 @@
         
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • @@ -228,7 +231,7 @@

    Comparison of sp and sf approaches} if (dothis) sf_extSoftVersion()
    ##           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
    -##  "3.13.0beta1"        "3.9.2"        "9.4.1"         "true"         "true" 
    +##       "3.13.0"        "3.9.2"        "9.4.1"         "true"         "true" 
     ##           PROJ 
     ##        "9.4.1"

    Let us read the GPKG file with valid geometries in to ‘sf’ and ‘sp’ @@ -257,7 +260,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.1662  0.0095  0.1764
    +## 0.1832 0.0096 0.1937

    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 @@ -326,32 +329,29 @@

    Contiguity neighbours from ## [5] "Component 260: Numeric: lengths (8, 9) differ"

    Using st_make_valid() to make the geometries valid:

    -NY8_sf_old_val <- st_make_valid(NY8_sf_old, dist=0)
    -
    ## Warning in compareVersion(CPL_geos_version(), "3.8.0"): NAs introduced by
    -## coercion
    -
    -table(st_is_valid(NY8_sf_old_val))
    +NY8_sf_old_val <- st_make_valid(NY8_sf_old, dist=0) +table(st_is_valid(NY8_sf_old_val))
    ## 
     ## TRUE 
     ##  281

    we also see that the geometry type of the geometry column changes:

    -
    +
     class(st_geometry(NY8_sf_old))
    ## [1] "sfc_POLYGON" "sfc"
    -
    +
     class(st_geometry(NY8_sf_old_val))
    ## [1] "sfc_GEOMETRY" "sfc"

    and checking the "sfg" objects, two now have objects of different topological dimensions.

    -
    +
     table(sapply(st_geometry(NY8_sf_old_val), function(x) class(x)[[2]]))
    ## 
     ## MULTIPOLYGON      POLYGON 
     ##            3          278

    This can be remedied using st_collection_extract() to get the polygon objects:

    -
    +
     NY8_sf_old_val <- st_collection_extract(NY8_sf_old_val, "POLYGON")
     table(sapply(st_geometry(NY8_sf_old_val), function(x) class(x)[[2]]))
    ## 
    @@ -360,7 +360,7 @@ 

    Contiguity neighbours from

    However, in making the geometries valid, we change the geometries, so the new sets of neighbours still differ from those made with the valid geometries in the same ways as before imposing validity:

    -
    +
     try(NY8_sf_old_1_nb_val <- poly2nb(NY8_sf_old_val), silent = TRUE)
     all.equal(NY8_sf_old_1_nb_val, NY8_sf_1_nb, check.attributes=FALSE)
    ## [1] "Component 57: Numeric: lengths (4, 5) differ" 
    @@ -370,7 +370,7 @@ 

    Contiguity neighbours from ## [5] "Component 260: Numeric: lengths (8, 9) differ"

    The neighbour sets are the same for the old boundaries with or without imposing validity:

    -
    +
     all.equal(NY8_sf_old_1_nb_val, NY8_sf_old_1_nb, check.attributes=FALSE)
    ## [1] TRUE
    @@ -387,20 +387,20 @@

    Finding points for polygon objectsof_largest_polygon=TRUE argument to make sure that the centroid is that of the largest polygon id the observation is made up of more than one external ring:

    -
    +
     NY8_ct_sf <- st_centroid(st_geometry(NY8_sf), of_largest_polygon=TRUE)

    or st_point_on_surface() which guarantees that the point will fall on the surface of a member polygon:

    -
    +
     NY8_pos_sf <- st_point_on_surface(st_geometry(NY8_sf))

    or indeed taking the centre of the largest inscribed circle (the function returns a radius line segment, so we choose the central point, not the point on the circle):

    -
    +
     if (unname(sf_extSoftVersion()["GEOS"] >= "3.9.0")) 
         NY8_cic_sf <- st_cast(st_inscribed_circle(st_geometry(NY8_sf), nQuadSegs=0), "POINT")[(1:(2*nrow(NY8_sf)) %% 2) != 0]

    We need to check whether coordinates are planar or not:

    -
    +
     st_is_longlat(NY8_ct_sf)
    ## [1] FALSE
    @@ -409,7 +409,7 @@

    Graph-based neighbours

    From this, we can check the graph-based neighbours (planar coordinates only):

    -
    +
     suppressPackageStartupMessages(require(deldir))
     NY84_nb <- tri2nb(NY8_ct_sf)
     if (require(dbscan, quietly=TRUE)) {
    @@ -422,7 +422,7 @@ 

    Graph-based neighbours## as.dendrogram

    ## Warning in graph2nb(soi.graph(NY84_nb, NY8_ct_sf)): neighbour object has 2
     ## sub-graphs
    -
    +
     NY86_nb <- graph2nb(gabrielneigh(NY8_ct_sf))
     NY87_nb <- graph2nb(relativeneigh(NY8_ct_sf))
    @@ -433,44 +433,44 @@

    K-nearest neighboursdbscan::kNN() in 2D or 3D building a kd-tree is used:

    -
    +
     system.time(for (i in 1:reps) suppressWarnings(NY88_nb_sf <- knn2nb(knearneigh(NY8_ct_sf, k=1))))/reps
    ##    user  system elapsed 
    -##  0.0222  0.0005  0.0228
    +## 0.0239 0.0017 0.0257

    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.0224  0.0007  0.0231
    +## 0.0259 0.0015 0.0275

    Distance neighbours

    Distance neighbours need a threshold - nbdists shows the maximum distance to first nearest neighbour:

    -
    +
     dsts <- unlist(nbdists(NY88_nb_sf, NY8_ct_sf))
     summary(dsts)
    ##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
     ##    82.85   912.85  1801.11  3441.04  4461.26 17033.11
    -
    +
     max_1nn <- max(dsts)

    dnearneigh can also handle Great Circle distances, but this is not demonstrated here, as the data set used is planar:

    -
    +
     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.0576  0.0009  0.0587
    +## 0.0636 0.0015 0.0654

    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 computation a little by reverting to legacy code not building a kd-tree first, but in general the differences are so small that the user will not notice:

    -
    +
     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.0431  0.0009  0.0442
    +## 0.0462 0.0013 0.0477
    @@ -481,7 +481,7 @@

    Spherical point-based neighbourssf 1.0-0 to use s2 by default has opened up new opportunities where spatial indexing on the sphere may help.

    -
    +
     pts_ll <- st_transform(NY8_ct_sf, "OGC:CRS84")
     st_is_longlat(pts_ll)
    ## [1] TRUE
    @@ -492,45 +492,45 @@

    K-nearest neighbourssf_use_s2() is TRUE, knearneigh() will use spatially indexed points and s2::s2_closest_edges() (see https://github.com/r-spatial/s2/issues/125#issuecomment-860107442)

    -
    +
     (old_use_s2 <- sf_use_s2())
    ## [1] TRUE

    and performs well with also with larger data sets:

    -
    +
     sf_use_s2(TRUE)
     system.time(for (i in 1:reps) pts_ll1_nb <- knn2nb(knearneigh(pts_ll, k=6)))/reps
    ##    user  system elapsed 
    -##  0.0312  0.0000  0.0312
    +## 0.0338 0.0002 0.0342

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

    -
    +
     sf_use_s2(FALSE)
    ## Spherical geometry (s2) switched off
    -
    +
     system.time(for (i in 1:reps) pts_ll2_nb <- knn2nb(knearneigh(pts_ll, k=6)))/reps
    ##    user  system elapsed 
    -##  0.0267  0.0000  0.0268
    +## 0.0299 0.0000 0.0300

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

    -
    +
     all.equal(pts_ll1_nb, pts_ll2_nb, check.attributes=FALSE)
    ## [1] "Component 52: Mean relative difference: 1.466667"  
     ## [2] "Component 124: Mean relative difference: 0.0251046"
    -
    +
     pts_ll1_nb[[52]]
    ## [1] 15 38 48 49 50 53
    -
    +
     pts_ll2_nb[[52]]
    ## [1] 37 38 48 49 50 53
    -
    +
     pts_ll1_nb[[124]]
    ## [1] 117 122 123 125 133 134
    -
    +
     pts_ll2_nb[[124]]
    ## [1] 116 117 123 125 133 134
    -
    +
     sf_use_s2(old_use_s2)
    ## Spherical geometry (s2) switched on
    @@ -546,11 +546,11 @@

    Distance neighbours.

    -
    +
     
    ## Warning in knn2nb(knearneigh(pts_ll, k = 1)): neighbour object has 62
     ## sub-graphs
    -
    +
     args(dnearneigh)
    ## function (x, d1, d2, row.names = NULL, longlat = NULL, bounds = c("GE", 
     ##     "LE"), use_kd_tree = TRUE, symtest = FALSE, use_s2 = packageVersion("s2") > 
    @@ -559,57 +559,57 @@ 

    Distance neighbourss2::s2_dwithin_matrix() is run:

    -
    +
     if (packageVersion("s2") > "1.0.7") {
       system.time(for (i in 1:(reps/5)) suppressWarnings(pts_ll3_nb <- dnearneigh(pts_ll, d1=0,
           d2=0.75*max_1nn_ll)))/(reps/5)
     }
    ##    user  system elapsed 
    -##  0.0645  0.0000  0.0645
    +## 0.068 0.000 0.068

    Alternatively, spherical distances can be used with dwithin=FALSE and s2::s2_closest_edges(); although running in similar time, s2::s2_closest_edges() depends on the additional k= argument, which, if mis-set, may miss valid neighbours:

    -
    +
     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.0505  0.0000  0.0510
    -
    +##  0.0545  0.0000  0.0555
    +
     if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3_nb, pts_ll5_nb, check.attributes=FALSE)
    ## [1] TRUE

    Using s2::s2_closest_edges() respects d1 > 0 without requiring a second pass in R, so is faster than s2::s2_dwithin_matrix():

    -
    +
     if (packageVersion("s2") > "1.0.7") {
       system.time(for (i in 1:(reps/5)) suppressWarnings(pts_ll3a_nb <- dnearneigh(pts_ll, d1=5,
           d2=0.75*max_1nn_ll, dwithin=FALSE)))/(reps/5)
     }
    ##    user  system elapsed 
    -##  0.0425  0.0000  0.0425
    +## 0.0475 0.0000 0.0475

    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:

    -
    +
     if (packageVersion("s2") > "1.0.7") {
         system.time(for (i in 1:(reps/5)) suppressWarnings(pts_ll5a_nb <- dnearneigh(pts_ll, d1=5,
             d2=0.75*max_1nn_ll)))/(reps/5)
     }
    ##    user  system elapsed 
    -##  0.0855  0.0000  0.0855
    -
    +##   0.094   0.000   0.095
    +
     if (packageVersion("s2") > "1.0.7") all.equal(pts_ll3a_nb, pts_ll5a_nb, check.attributes=FALSE)
    ## [1] TRUE

    Setting use_s2=FALSE falls back to the legacy version, which uses symmetry to reduce time:

    -
    +
     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.0350  0.0001  0.0352
    +## 0.0425 0.0001 0.0428

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

    -
    +
     all.equal(pts_ll5_nb, pts_ll6_nb, check.attributes=FALSE)
    ##  [1] "Component 20: Numeric: lengths (6, 5) differ"     
     ##  [2] "Component 28: Numeric: lengths (7, 6) differ"     
    @@ -633,11 +633,11 @@ 

    Distance neighbours## [20] "Component 235: Numeric: lengths (40, 39) differ" ## [21] "Component 237: Numeric: lengths (14, 15) differ" ## [22] "Component 245: Numeric: lengths (16, 15) differ"

    -
    +
     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.0275  0.0000  0.0277
    -
    +##  0.0324  0.0000  0.0326
    +
     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"       
     ##  [2] "Component 28: Numeric: lengths (7, 6) differ"       
    @@ -676,7 +676,7 @@ 

    Contiguity neighbours for spherical polygon supports2 spatial indexing functionality is accessed in finding candidate neighbours in intersecting geometries.

    -
    +
     NY8_sf_ll <- st_transform(NY8_sf, "OGC:CRS84")
     st_is_longlat(NY8_sf_ll)
    ## [1] TRUE
    @@ -684,12 +684,12 @@

    Contiguity neighbours for spherical polygon supports2_intersects_matrix(), but the results are the same, and because spatial indexing is used, this scales well for larger data sets:

    -
    +
     sf_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.1522  0.0016  0.1542
    -
    +##  0.1703  0.0019  0.1729
    +
     all.equal(NY8_sf_1_nb, NY8_sf_1_nb_ll, check.attributes=FALSE)
    ## [1] TRUE
    diff --git a/docs/articles/sids.html b/docs/articles/sids.html index 11e97a93..fa8d121b 100644 --- a/docs/articles/sids.html +++ b/docs/articles/sids.html @@ -60,6 +60,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • @@ -154,7 +157,6 @@

    Getting the data into Rsf_use_s2(TRUE) plot(st_geometry(nc), axes=TRUE) text(st_coordinates(st_centroid(st_geometry(nc), of_largest_polygon=TRUE)), label=nc$FIPSNO, cex=0.5) -

    We can examine the names of the columns of the data frame to see what it contains — in fact some of the same columns that we will be examining below, and some others which will be useful in cleaning the data @@ -397,12 +399,11 @@

    Getting the data into R## Percentage nonzero weights: 3.94 ## Average number of links: 3.94 ## 2 regions with no links: -## 37055 37095 +## 37055, 37095 ## 3 disjoint connected subgraphs
     plot(st_geometry(nc), border="grey")
     plot(ncCC89, st_centroid(st_geometry(nc), of_largest_polygon), add=TRUE, col="blue")
    -

    Printing the neighbour object shows that it is a neighbour list object, with a very sparse structure — if displayed as a matrix, only 3.94% of cells would be filled. Objects of class diff --git a/docs/articles/subgraphs.html b/docs/articles/subgraphs.html new file mode 100644 index 00000000..893d76a1 --- /dev/null +++ b/docs/articles/subgraphs.html @@ -0,0 +1,702 @@ + + + + + + + +No-neighbour observation and subgraph handling • spdep + + + + + + + + + + + +

    +
    + + + + +
    +
    + + + + +
    +

    Introduction +

    +

    The spdep package has always been careful about +disconnected graphs, especially where the disconnected observations are +graph nodes with no neighbours, that is no incoming or outgoing edges. +In nb neighbour objects, they are encoded as integer +vectors of length 1 containing integer 0, which is an +invalid index on +[1,N][1, N], +where +NN +is the observation count. Functions taking neighbour objects as +arguments use the zero.policy argument to guide how to +handle no-neighbour observations.

    +

    spdep has also had n.comp.nb to find the +number of disjoint connected subgraphs in an nb object, +contributed by Nicholas Lewin-Koh in 2001 and using depth-first search +for symmetric neighbours, showing in addition which observations belong +to which subgraph. Obviously, no-neighbour observations are singleton +graph nodes, but subgraphs are also troubling for spatial analysis, +because there is no connection between the spatial processes in those +subgraphs. The ripples in one pond cannot cross into a separate pond if +they are not connected.

    +

    From spdep 1.3-1, steps began to raise awareness of the +possibility that neighbour objects might be created that are +disconnected in some way, mostly through warnings, and through the +computation of subgraph measures by default. This vignette is intended +to provide some background to these steps.

    +
    +
    +

    No-neighbour observations +

    +

    From the start, nb objects have recorded no-neighbour +observations as an integer vector of unit length and value +0, where neighbours are recorded as ID values between +1 and N, where N is the +observation count. print and summary methods +have always reported the presence of no-neighbour observations, and +listed their IDs (or region.id values). If an +nb object contains no-neighbour observations, the user has +to decide whether to drop those observations, or if retained, what value +to give its weights. The zero.policy argument uses zero as +the value if TRUE, but if FALSE causes nb2listw to fail. +The value of zero.policy in a call to functions like +nb2listw, subset.listw or +mat2listw creating listw objects representing +sparse spatial weights matrices is added to the created object as an +attribute, and used subsequently to pass through that choice to other +functions. For example, moran.test takes the value of this +attribute as default for its zero.policy argument:

    + +
    ## Loading required package: spData
    +
    ## Loading required package: sf
    +
    ## Linking to GEOS 3.13.0, GDAL 3.9.2, PROJ 9.4.1; sf_use_s2() is TRUE
    +
    +args(moran.test)
    +
    ## function (x, listw, randomisation = TRUE, zero.policy = attr(listw, 
    +##     "zero.policy"), alternative = "greater", rank = FALSE, na.action = na.fail, 
    +##     spChk = NULL, adjust.n = TRUE, drop.EI2 = FALSE) 
    +## NULL
    +

    If observation +ii +has no neighbours, its weights sum +j=1Nwij=0\sum_{j=1}^N w_{ij} = 0, +as +wij=0,jw_{ij} = 0, \forall j +(see discussion in Bivand and Portnov +(2004)). Its eigenvalue will also be zero, with consequences for +analytical inference:

    +
    +eigen(0)$values
    +
    ## [1] 0
    +

    The adjust.n argument to measures of spatial +autocorrelation is by default TRUE, and subtracts the count of singleton +nodes from +NN +in an attempt to acknowledge the reduction in information available.

    +

    This discussion will address problems arising when analysing +areal/lattice data, and neighbours are defined as polygon features with +contiguous boundaries. One way in which no-neighbour observations may +occur is when they are islands. This is clearly the case in Freni-Sterrantino, Ventrucci, and Rue (2018), +where Capraia and Giglio Isles are singleton nodes. Here we take +Westminster constituencies for Wales used in the July 2024 UK general +election.

    +
    +run <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0"
    +

    The boundaries are taken from the Ordnance Survey Boundary-Line site, +https://osdatahub.os.uk/downloads/open/BoundaryLine, +choosing the 2024 Westminster constituencies (https://www.os.uk/opendata/licence), simplified using a +tolerance of 50m to reduce object size, and merged with selected voting +outcomes for constituencies in Great Britain https://electionresults.parliament.uk/countries/1, (https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/). +Here, the subset for Wales is useful as we will see:

    +
    +w50m <- st_read(system.file("etc/shapes/GB_2024_Wales_50m.gpkg.zip", package="spdep"))
    +
    ## Reading layer `GB_2024_Wales_50m' from data source 
    +##   `/tmp/RtmpYdUOF1/temp_libpathbff31ae05681/spdep/etc/shapes/GB_2024_Wales_50m.gpkg.zip' 
    +##   using driver `GPKG'
    +## Simple feature collection with 32 features and 19 fields
    +## Geometry type: MULTIPOLYGON
    +## Dimension:     XY
    +## Bounding box:  xmin: 146597.1 ymin: 164536.5 xmax: 355287 ymax: 395993.5
    +## Projected CRS: OSGB36 / British National Grid
    +
    +(w50m |> poly2nb(row.names=as.character(w50m$Constituency)) -> nb_W_50m)
    +
    ## Warning in poly2nb(w50m, row.names = as.character(w50m$Constituency)): some observations have no neighbours;
    +## if this seems unexpected, try increasing the snap argument.
    +
    ## Warning in poly2nb(w50m, row.names = as.character(w50m$Constituency)): neighbour object has 2 sub-graphs;
    +## if this sub-graph count seems unexpected, try increasing the snap argument.
    +
    ## Neighbour list object:
    +## Number of regions: 32 
    +## Number of nonzero links: 136 
    +## Percentage nonzero weights: 13.28125 
    +## Average number of links: 4.25 
    +## 1 region with no links:
    +## Ynys Môn
    +## 2 disjoint connected subgraphs
    +

    The two subgraphs are the singleton Ynys Môn and all the other 31 +constituencies:

    +
    +attr(nb_W_50m, "ncomp")$comp.id |>table() |> table()
    +
    ## 
    +##  1 31 
    +##  1  1
    +

    The left map shows that Ynys Môn can be shown selecting by name, as a +black border, and by the zero cardinality of its neighbour set, using +card, filling the polygon. The right map shows the location +of the island, known in English as Anglesey, north-west of the Welsh +mainland, and with no neighbour links:

    +
    +ynys_mon <- w50m$Constituency == "Ynys Môn"
    +pts <- st_point_on_surface(st_geometry(w50m))
    +opar <- par(mfrow=c(1, 2))
    +plot(st_geometry(w50m), border="grey75")
    +plot(st_geometry(w50m)[ynys_mon], add=TRUE)
    +plot(st_geometry(w50m)[card(nb_W_50m) == 0L], add=TRUE, border="transparent", col="wheat1")
    +plot(st_geometry(w50m), border="grey75")
    +plot(nb_W_50m, pts, add=TRUE)
    +

    +
    +par(opar)
    +

    From the maps, we can see that the island is close to two +constituencies across the Afon Menai (Menai Strait in English), the +three simplified polygons being less than 280m apart, measured between +polygon boundaries:

    +
    +dists <- st_distance(w50m)
    +dym <- dists[ynys_mon,]
    +sort(dym)
    +
    ## Units: [m]
    +##  [1]      0.0000    123.4132    277.5414  16658.7265  37985.7086  54096.7729
    +##  [7]  58146.4320  65550.2491  67696.3323  93741.9873 113007.3659 137858.1826
    +## [13] 143263.1054 152082.3317 153252.5905 155549.0216 155714.7682 161193.8054
    +## [19] 161827.5282 164019.9370 165112.6409 169101.7883 170104.8336 170945.5304
    +## [25] 175795.2033 179502.3290 187020.3546 188242.8514 188376.2837 188697.2020
    +## [31] 194162.9221 196578.9512
    +

    Using a snap distance of 280m, we can join the island to +its two obvious proximate neighbours:

    +
    +(nb_W_50m_snap <- poly2nb(w50m, row.names=as.character(w50m$Constituency), snap=280))
    +
    ## Neighbour list object:
    +## Number of regions: 32 
    +## Number of nonzero links: 140 
    +## Percentage nonzero weights: 13.67188 
    +## Average number of links: 4.375
    +
    +plot(st_geometry(w50m), border="grey75")
    +plot(nb_W_50m_snap, pts, add=TRUE)
    +

    +

    In this case, increasing snap from its default of 10mm +(or close equivalents for geometries with known metrics; previously +sqrt(.Machine$double.eps) in all cases) helps. The +symmetric links added are to:

    +
    +attr(nb_W_50m_snap, "region.id")[nb_W_50m_snap[[which(ynys_mon)]]]
    +
    ## [1] "Bangor Aberconwy"   "Dwyfor Meirionnydd"
    +

    This is not always going to be the case, but here the strait is +narrow. If islands are much further offshore, other steps may be +required, because a large snap distance will draw in extra +neighbours for already connected observations. It is also possible that +increasing the snap distance may fail to link islands if +they are not considered candidate neighbours, that is if their extents +(bounding boxes), buffered out by the snap value, do not +intersect.

    +

    We can also use the distances to pick out those neighbour candidates +that meet our criterion of 280m, taking care not to lose the ordering +needed to identify the correct observations:

    +
    +(meet_criterion <- sum(dym <= units::set_units(280, "m")))
    +
    ## [1] 3
    +

    These candidates are the island itself, and the two neighbours across +the Menai Strait:

    +
    +(cands <- attr(nb_W_50m, "region.id")[order(dym)[1:meet_criterion]])
    +
    ## [1] "Ynys Môn"           "Bangor Aberconwy"   "Dwyfor Meirionnydd"
    +

    The addlinks1 function can be used to add both the links +from Ynys Môn to its neighbours, and by symmetry from them to Ynys Môn. +This approach means that each island should be treated separately (or +scripted in sequence), but does not risk adding spurious neighbours in +denser parts of the study area.

    +
    +(nb_W_50m_add <- addlinks1(nb_W_50m, from = cands[1], to = cands[2:meet_criterion]))
    +
    ## Neighbour list object:
    +## Number of regions: 32 
    +## Number of nonzero links: 140 
    +## Percentage nonzero weights: 13.67188 
    +## Average number of links: 4.375
    +
    +all.equal(nb_W_50m_add, nb_W_50m_snap, check.attributes=FALSE)
    +
    ## [1] TRUE
    +

    Since these constituency observations have areal support, it is not +surprising that changing support to points and using +kk-nearest +neighbours does not work adequately, because the distance measurements +are between the points representing the polygons rather than as above +between the areal unit boundaries:

    +
    +k2 <- knn2nb(knearneigh(pts, k=2), row.names=as.character(w50m$Constituency), sym=TRUE)
    +
    ## Warning in knn2nb(knearneigh(pts, k = 2), row.names =
    +## as.character(w50m$Constituency), : neighbour object has 2 sub-graphs
    +
    +attr(k2, "region.id")[k2[[which(ynys_mon)]]]
    +
    ## [1] "Bangor Aberconwy" "Clwyd North"
    +

    Here, Clwyd North, east of Bangor Aberconwy, is given as a neighbour +of Ynys Môn but Dwyfor Meirionnydd, west of Bangor Aberconwy, is not. In +addition, there are two subgraphs, which still remain up to +k=6k=6.

    +
    +
    +

    Subgraphs +

    +

    Subgraphs may be found when no-neighbour observations are present, +but also when the graph is split between two blocks of observations with +no path from any observation in a block to any in another block, across +the low population density constituencies in mid-Wales:

    +
    +(k6 <- knn2nb(knearneigh(pts, k=6), row.names=as.character(w50m$Constituency), sym=TRUE))
    +
    ## Warning in knn2nb(knearneigh(pts, k = 6), row.names =
    +## as.character(w50m$Constituency), : neighbour object has 2 sub-graphs
    +
    ## Neighbour list object:
    +## Number of regions: 32 
    +## Number of nonzero links: 238 
    +## Percentage nonzero weights: 23.24219 
    +## Average number of links: 7.4375 
    +## 2 disjoint connected subgraphs
    +
    +plot(st_geometry(w50m), border="grey75")
    +plot(k6, pts, add=TRUE)
    +

    +We can show the block structure by displaying the binary spatial weights +matrix:

    +
    +o <- order(attr(k6, "ncomp")$comp.id)
    +image(t(nb2mat(k6, style="B")[o, rev(o)]), axes=FALSE, asp=1)
    +

    +

    This occurs frequently with point support, but may also occur with +areal support, as Freni-Sterrantino, Ventrucci, +and Rue (2018) find for the eight municipalities on the island of +Elba.

    +

    From spdep 1.3-6, if the igraph and +spatialreg packages are available, n.comp.nb +uses igraph::components to compute the graph components, +also using depth-first search. The original implementation is as fast, +but for directed (asymmetric) graphs converts first to symmetry, while +igraph::components can handle directed graphs without such +conversion (see https://github.com/r-spatial/spdep/issues/160 for +details).

    +
    +(k6a <- knn2nb(knearneigh(pts, k=6), row.names=as.character(w50m$Constituency)))
    +
    ## Warning in knn2nb(knearneigh(pts, k = 6), row.names =
    +## as.character(w50m$Constituency)): neighbour object has 2 sub-graphs
    +
    ## Neighbour list object:
    +## Number of regions: 32 
    +## Number of nonzero links: 192 
    +## Percentage nonzero weights: 18.75 
    +## Average number of links: 6 
    +## 2 disjoint connected subgraphs
    +## Non-symmetric neighbours list
    +

    Another case demonstrates how cyclical subgraphs may appear; this is +again taken from constituencies in the 2024 UK general election, +subsetted to those in England south of London.

    +
    +sc50m <- st_read(system.file("etc/shapes/GB_2024_southcoast_50m.gpkg.zip", package="spdep"))
    +
    ## Reading layer `GB_2024_southcoast_50m' from data source 
    +##   `/tmp/RtmpYdUOF1/temp_libpathbff31ae05681/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
    +
    +(nb_sc_50m <- poly2nb(sc50m, row.names=as.character(sc50m$Constituency)))
    +
    ## Warning in poly2nb(sc50m, row.names = as.character(sc50m$Constituency)): neighbour object has 2 sub-graphs;
    +## if this sub-graph count seems unexpected, try increasing the snap argument.
    +
    ## Neighbour list object:
    +## Number of regions: 119 
    +## Number of nonzero links: 530 
    +## Percentage nonzero weights: 3.742674 
    +## Average number of links: 4.453782 
    +## 2 disjoint connected subgraphs
    +

    The second subgraph only has two members, who are each others’ only +neighbours, known as a cyclical component.

    +
    +nc <- attr(nb_sc_50m, "ncomp")$comp.id
    +table(nc)
    +
    ## nc
    +##   1   2 
    +## 117   2
    +

    Both constituencies are on the Isle of Wight:

    +
    +(sub2 <- attr(nb_sc_50m, "region.id")[nc == 2L])
    +
    ## [1] "Isle of Wight East" "Isle of Wight West"
    +
    +pts <- st_point_on_surface(st_geometry(sc50m))
    +plot(st_geometry(sc50m), border="grey75")
    +plot(st_geometry(sc50m)[nc == 2L], border="orange", lwd=2, add=TRUE)
    +plot(nb_sc_50m, pts, add=TRUE)
    +

    +

    This has consequences for the eigenvalues of the spatial weights +matrix, pointed out by Smirnov and Anselin +(2009) and Bivand, Hauke, and Kossowski +(2013). With row-standardised weights, the eigenvalues of this +component are:

    +
    +1/range(eigen(cbind(c(0, 1), c(1, 0)))$values)
    +
    ## [1] -1  1
    +
    +1/range(eigen(nb2mat(subset(nb_sc_50m, nc == 2L), style="W"))$values)
    +
    ## [1] -1  1
    +

    This “takes over” the lower domain boundary, which for the whole data +set is now the same:

    +
    +1/range(eigen(nb2mat(nb_sc_50m, style="W"))$values)
    +
    ## [1] -1  1
    +

    compared to the lower domain boundary for the remainder of the study +area:

    +
    +1/range(eigen(nb2mat(subset(nb_sc_50m, nc == 1L), style="W"))$values)
    +
    ## [1] -1.094637  1.000000
    +

    This subgraph may be added to the remainder as shown above:

    +
    +dists <- st_distance(sc50m)
    +iowe <- match(sub2[1], attr(nb_sc_50m, "region.id"))
    +ioww <- match(sub2[2], attr(nb_sc_50m, "region.id"))
    +diowe <- dists[iowe,]
    +sort(diowe)
    +
    ## Units: [m]
    +##   [1]      0.000      0.000   1886.833   3509.366   6693.575   6943.672
    +##   [7]   7678.999   8576.454  10579.530  12163.332  16875.920  17161.786
    +##  [13]  17324.011  18281.711  18662.054  20696.880  23112.456  24554.956
    +##  [19]  25503.226  30161.222  33990.533  35806.417  37611.567  41619.391
    +##  [25]  42554.444  44136.902  45464.639  46455.579  46637.710  47011.024
    +##  [31]  49420.024  49594.304  49675.443  49783.155  49849.256  56116.494
    +##  [37]  59155.588  61057.479  61151.719  61698.519  62455.496  63499.103
    +##  [43]  65047.234  67015.524  67054.611  68212.030  68414.647  68885.668
    +##  [49]  68972.461  69312.018  69510.876  69632.911  72062.461  72454.844
    +##  [55]  73402.955  77684.394  80124.607  80197.831  80743.227  81651.023
    +##  [61]  82775.170  84499.162  87118.777  88294.869  89740.840  90055.204
    +##  [67]  90742.141  92053.188  92087.364  96024.323  96317.975  97143.689
    +##  [73]  97267.821  97378.956  97389.283  99105.304 100681.013 101284.496
    +##  [79] 101711.895 105866.317 111693.308 115215.248 115491.111 119039.687
    +##  [85] 119233.755 119427.415 119860.449 119948.460 123691.303 124034.062
    +##  [91] 124409.479 127543.054 132027.159 133614.738 133968.895 134153.093
    +##  [97] 135701.794 141207.606 141930.729 151946.630 152377.224 154637.521
    +## [103] 156357.811 156931.995 158266.815 164138.776 165663.544 166570.798
    +## [109] 181352.328 183040.609 184094.367 200018.283 200793.802 206439.076
    +## [115] 211775.372 240001.776 251151.081 273124.685 275889.761
    +
    +dioww <- dists[ioww,]
    +sort(dioww)
    +
    ## Units: [m]
    +##   [1]      0.000      0.000   1232.724   2541.318   5746.764   5770.602
    +##   [7]   8902.579   9747.265  10529.540  10909.845  12250.564  12379.871
    +##  [13]  15216.730  15524.385  16135.738  16765.383  18911.995  20106.050
    +##  [19]  21646.981  21756.596  22487.653  23447.594  25706.044  28206.439
    +##  [25]  28270.733  30160.375  35816.047  41511.678  46416.990  47237.169
    +##  [31]  47691.458  48990.595  50833.901  51600.226  53300.127  57034.842
    +##  [37]  57876.216  59841.242  62115.159  63586.637  63636.192  64993.376
    +##  [43]  65946.268  66071.726  68504.036  69015.186  70004.373  71064.630
    +##  [49]  71125.541  71620.708  73527.836  74182.552  75164.623  76015.617
    +##  [55]  77700.898  78314.460  79008.282  80729.974  82239.380  86551.567
    +##  [61]  86805.101  87432.343  88107.435  88958.052  90739.834  90957.614
    +##  [67]  92544.780  93344.700  96274.996  96443.039  97868.074  98969.789
    +##  [73] 100309.681 100439.701 100657.788 100734.520 103010.342 104458.721
    +##  [79] 104709.930 106122.320 106242.946 106798.348 107973.005 108438.430
    +##  [85] 112194.112 112839.433 116168.516 117985.874 122405.074 124317.947
    +##  [91] 127935.566 128067.594 129244.951 129534.665 131969.390 132618.144
    +##  [97] 133665.970 134668.862 136168.693 137113.422 142446.528 144061.374
    +## [103] 144266.056 144658.126 151303.101 160064.669 161362.417 163954.851
    +## [109] 173663.287 174702.325 178279.403 179218.513 184112.268 189187.890
    +## [115] 192234.794 218331.070 229918.445 251395.553 255554.022
    +

    Using 5km as a cutoff seems prudent, but would not work as a +snap value. Taking Isle of Wight East first, there are four +constituencies with boundaries within 5km:

    +
    +(meet_criterion <- sum(diowe <= units::set_units(5000, "m")))
    +
    ## [1] 4
    +

    Obviously the contiguous neighbour is among them with zero distance, +and needs to be dropped, although addlinks1 would drop the +duplicate:

    +
    +(cands <- attr(nb_sc_50m, "region.id")[order(diowe)[1:meet_criterion]])
    +
    ## [1] "Isle of Wight East" "Isle of Wight West" "Portsmouth South"  
    +## [4] "Gosport"
    +
    +(nb_sc_50m_iowe <- addlinks1(nb_sc_50m, from = cands[1], to = cands[3:meet_criterion]))
    +
    ## Neighbour list object:
    +## Number of regions: 119 
    +## Number of nonzero links: 534 
    +## Percentage nonzero weights: 3.77092 
    +## Average number of links: 4.487395
    +

    Although all constituencies are now linked, we should see whether +using the 5km criterion brings in extra neighbours for Isle of Wight +West:

    +
    +(meet_criterion <- sum(dioww <= units::set_units(5000, "m")))
    +
    ## [1] 4
    +

    It, does, but we need to beware of the sorting order of the zero +self-distance and contiguous neighbour distance, where from +is now in the second position:

    +
    +(cands <- attr(nb_sc_50m, "region.id")[order(dioww)[1:meet_criterion]])
    +
    ## [1] "Isle of Wight East" "Isle of Wight West" "New Forest West"   
    +## [4] "New Forest East"
    +

    This then yields links to the north-west:

    +
    +(nb_sc_50m_iow <- addlinks1(nb_sc_50m_iowe, from = cands[2], to = cands[3:meet_criterion]))
    +
    ## Neighbour list object:
    +## Number of regions: 119 
    +## Number of nonzero links: 538 
    +## Percentage nonzero weights: 3.799167 
    +## Average number of links: 4.521008
    +
    +pts <- st_point_on_surface(st_geometry(sc50m))
    +plot(st_geometry(sc50m), border="grey75")
    +plot(st_geometry(sc50m)[nc == 2L], border="orange", lwd=2, add=TRUE)
    +plot(nb_sc_50m_iow, pts, add=TRUE)
    +

    +

    It remains to add a suitable generalisation of addlinks1 +to handle a from vector argument and a to +argument taking a list of vectors.

    +
    +
    +

    Unintentional disconnected graphs +

    +

    Sometimes apparently sensible polygons turn out to be represented in +such a way that disconnected graphs are generated when extracting +contiguities. One such case was raised in https://github.com/r-spatial/spdep/issues/162, for +subdivisions of Tokyo.

    +
    +tokyo <- st_read(system.file("etc/shapes/tokyo.gpkg.zip", package="spdep"))
    +
    ## Reading layer `tokyo' from data source 
    +##   `/tmp/RtmpYdUOF1/temp_libpathbff31ae05681/spdep/etc/shapes/tokyo.gpkg.zip' 
    +##   using driver `GPKG'
    +## Simple feature collection with 262 features and 1 field
    +## Geometry type: MULTIPOLYGON
    +## Dimension:     XY
    +## Bounding box:  xmin: 266206.6 ymin: -90932.11 xmax: 411400.3 ymax: 37142.75
    +## Projected CRS: Tokyo / Japan Plane Rectangular CS VI
    +

    After correcting invalid polygons:

    +
    +all(st_is_valid(tokyo))
    +
    ## [1] FALSE
    +
    +tokyo <- st_make_valid(tokyo)
    +

    applying poly2nb with the legacy default snap value +produced numerous singleton observations as well as many +multiple-observation subgraphs:

    +
    +(nb_t0 <- poly2nb(tokyo, snap=sqrt(.Machine$double.eps)))
    +
    ## Warning in poly2nb(tokyo, snap = sqrt(.Machine$double.eps)): some observations have no neighbours;
    +## if this seems unexpected, try increasing the snap argument.
    +
    ## Warning in poly2nb(tokyo, snap = sqrt(.Machine$double.eps)): neighbour object has 23 sub-graphs;
    +## if this sub-graph count seems unexpected, try increasing the snap argument.
    +
    ## Neighbour list object:
    +## Number of regions: 262 
    +## Number of nonzero links: 946 
    +## Percentage nonzero weights: 1.378125 
    +## Average number of links: 3.610687 
    +## 10 regions with no links:
    +## 101, 127, 134, 135, 152, 154, 167, 237, 242, 243
    +## 23 disjoint connected subgraphs
    +

    The legacy default snap value when the coordinates are +measured in metres was 15 nanometres, which effectively assumed that the +coordinates making up polygon boundaries were identical:

    +
    +units::set_units(units::set_units(attr(nb_t0, "snap"), "m"), "nm")
    +
    ## 14.90116 [nm]
    +

    Stepping out a little to 2mm, the lack of contact ceased to be a +problem.

    +
    +(nb_t1 <- poly2nb(tokyo, snap=0.002))
    +
    ## Neighbour list object:
    +## Number of regions: 262 
    +## Number of nonzero links: 1390 
    +## Percentage nonzero weights: 2.02494 
    +## Average number of links: 5.305344
    +
    +units::set_units(units::set_units(attr(nb_t1, "snap"), "m"), "mm")
    +
    ## 2 [mm]
    +

    On that basis, the default was changed from spdep 1.3-6 +to 10mm for projected polygons, and the snap value used was returned as +an attribute of the neighbour object:

    +
    +(nb_t2 <- poly2nb(tokyo))
    +
    ## Neighbour list object:
    +## Number of regions: 262 
    +## Number of nonzero links: 1390 
    +## Percentage nonzero weights: 2.02494 
    +## Average number of links: 5.305344
    +
    +units::set_units(units::set_units(attr(nb_t2, "snap"), "m"), "mm")
    +
    ## 10 [mm]
    +

    Where the polygons are represented by geographical (spherical) +coordinates, the new default from spdep 1.3-6 is set to a +value mimicking 10mm:

    +
    +(nb_t3 <- poly2nb(st_transform(tokyo, "OGC:CRS84")))
    +
    ## Neighbour list object:
    +## Number of regions: 262 
    +## Number of nonzero links: 1338 
    +## Percentage nonzero weights: 1.949187 
    +## Average number of links: 5.10687
    +

    The default snap value used in poly2nb when +the polygons are expressed in decimal degrees is:

    +
    +attr(nb_t3, "snap")
    +
    ## [1] 9e-08
    +

    This was set based on the apparent “size” of 10mm in decimal +degrees:

    +
    +(180 * 0.01) / (pi * 6378137)
    +
    ## [1] 8.983153e-08
    +
    +
    +

    References +

    +
    +
    +Bivand, Roger, Jan Hauke, and Tomasz Kossowski. 2013. “Computing +the Jacobian in Gaussian Spatial +Autoregressive Models: An Illustrated Comparison of Available +Methods.” Geographical Analysis 45 (2): 150–79. https://doi.org/10.1111/gean.12008. +
    +
    +Bivand, Roger, and B. A. Portnov. 2004. “Exploring Spatial Data +Analysis Techniques Using R: The Case of Observations with +No Neighbours.” In Advances in Spatial Econometrics: +Methodology, Tools, Applications, edited by Luc Anselin, Raymond J. +G. M. Florax, and S. J. Rey, 121–42. Berlin: Springer. https://doi.org/10.1007/978-3-662-05617-2_6. +
    +
    +Freni-Sterrantino, Anna, Massimo Ventrucci, and Håvard Rue. 2018. +“A Note on Intrinsic Conditional Autoregressive Models for +Disconnected Graphs.” Spatial and Spatio-Temporal +Epidemiology 26: 25–34. https://doi.org/10.1016/j.sste.2018.04.002. +
    +
    +Smirnov, O., and L. Anselin. 2009. “An O(N) Parallel +Method of Computing the Log-Jacobian of the +Variable Transformation for Models with Spatial Interaction on a +Lattice.” Computational Statistics & Data Analysis +53 (8): 2980–88. https://doi.org/10.1016/j.csda.2008.10.010. +
    +
    +
    +
    + + + +
    + + + +
    + +
    +

    +

    Site built with pkgdown 2.1.0.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 00000000..73eb45c3 Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-18-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-18-1.png new file mode 100644 index 00000000..7b01a6ee Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-19-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-19-1.png new file mode 100644 index 00000000..07bac2a9 Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-19-1.png differ diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-25-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-25-1.png new file mode 100644 index 00000000..7f173b24 Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-25-1.png differ diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-37-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-37-1.png new file mode 100644 index 00000000..630e9f07 Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-37-1.png differ diff --git a/docs/articles/subgraphs_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 00000000..536af3e3 Binary files /dev/null and b/docs/articles/subgraphs_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/authors.html b/docs/authors.html index 382ff10a..d188f3f1 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/index.html b/docs/index.html index 482fe46d..2e438b9c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -61,6 +61,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • diff --git a/docs/news/index.html b/docs/news/index.html index 958f8c5a..7f83d220 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 5b899b71..c093c23c 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -6,4 +6,5 @@ articles: nb_sf: nb_sf.html nb: nb.html sids: sids.html -last_built: 2024-09-02T15:07Z + subgraphs: subgraphs.html +last_built: 2024-09-07T16:32Z diff --git a/docs/reference/COL.OLD.html b/docs/reference/COL.OLD.html index 7d1f01fd..fada7ecc 100644 --- a/docs/reference/COL.OLD.html +++ b/docs/reference/COL.OLD.html @@ -48,6 +48,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/EBImoran.mc.html b/docs/reference/EBImoran.mc.html index bbd96ac1..81dcccd0 100644 --- a/docs/reference/EBImoran.mc.html +++ b/docs/reference/EBImoran.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/EBest.html b/docs/reference/EBest.html index 88be280c..f484383b 100644 --- a/docs/reference/EBest.html +++ b/docs/reference/EBest.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/EBlocal.html b/docs/reference/EBlocal.html index 38574e22..d82ded1d 100644 --- a/docs/reference/EBlocal.html +++ b/docs/reference/EBlocal.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/LOSH.cs.html b/docs/reference/LOSH.cs.html index 118aa999..7f598e63 100644 --- a/docs/reference/LOSH.cs.html +++ b/docs/reference/LOSH.cs.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/LOSH.html b/docs/reference/LOSH.html index a9f8d050..06389ca3 100644 --- a/docs/reference/LOSH.html +++ b/docs/reference/LOSH.html @@ -45,6 +45,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/LOSH.mc.html b/docs/reference/LOSH.mc.html index 321bc04a..eeaa6b05 100644 --- a/docs/reference/LOSH.mc.html +++ b/docs/reference/LOSH.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/SD.RStests.html b/docs/reference/SD.RStests.html index cfd578f9..0cabc245 100644 --- a/docs/reference/SD.RStests.html +++ b/docs/reference/SD.RStests.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/aggregate.nb.html b/docs/reference/aggregate.nb.html index 3c1ee890..86512669 100644 --- a/docs/reference/aggregate.nb.html +++ b/docs/reference/aggregate.nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/airdist.html b/docs/reference/airdist.html index 5fa0c09e..e148b683 100644 --- a/docs/reference/airdist.html +++ b/docs/reference/airdist.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/autocov_dist.html b/docs/reference/autocov_dist.html index 4997e1db..405ff0f1 100644 --- a/docs/reference/autocov_dist.html +++ b/docs/reference/autocov_dist.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/bhicv.html b/docs/reference/bhicv.html index a6efd195..c44774ee 100644 --- a/docs/reference/bhicv.html +++ b/docs/reference/bhicv.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -102,10 +105,12 @@

    Format

    Examples

    -
    bh <- st_read(system.file("etc/shapes/bhicv.gpkg",
    +    
    if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
    +bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
           package="spdep")[1])
    +}
     #> Reading layer `bhicv' from data source 
    -#>   `/tmp/Rtmput1Tax/temp_libpath71c612b87ba64/spdep/etc/shapes/bhicv.gpkg' 
    +#>   `/tmp/RtmpYdUOF1/temp_libpathbff31ae05681/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/card.html b/docs/reference/card.html
    index 184dfbe4..45f05a18 100644
    --- a/docs/reference/card.html
    +++ b/docs/reference/card.html
    @@ -44,6 +44,9 @@
         
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/cell2nb.html b/docs/reference/cell2nb.html index 62ab399a..47194cbd 100644 --- a/docs/reference/cell2nb.html +++ b/docs/reference/cell2nb.html @@ -47,6 +47,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/choynowski.html b/docs/reference/choynowski.html index 47dcfd39..9fba0278 100644 --- a/docs/reference/choynowski.html +++ b/docs/reference/choynowski.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/columbus.html b/docs/reference/columbus.html index beb1691c..99d1b589 100644 --- a/docs/reference/columbus.html +++ b/docs/reference/columbus.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/compon.html b/docs/reference/compon.html index 477d5018..1c621424 100644 --- a/docs/reference/compon.html +++ b/docs/reference/compon.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -113,6 +116,7 @@

    Examples

    coords <- st_coordinates(st_centroid(st_geometry(columbus))) plot(col.gal.nb, coords, col="grey") col2 <- droplinks(col.gal.nb, 21) +#> Warning: some observations have no neighbours #> Warning: neighbour object has 3 sub-graphs res <- n.comp.nb(col2) table(res$comp.id) @@ -213,12 +217,12 @@

    Examples

    system.time(udir <- n.comp.nb(make.sym.nb(k6))) } #> user system elapsed -#> 2.238 0.000 2.252 +#> 2.435 0.000 2.457 if (run) { system.time(dir <- n.comp.nb(k6)) } #> user system elapsed -#> 0.719 0.002 0.724 +#> 0.806 0.002 0.812 if (run) { udir$nc } diff --git a/docs/reference/diffnb.html b/docs/reference/diffnb.html index b890c31f..3eb94951 100644 --- a/docs/reference/diffnb.html +++ b/docs/reference/diffnb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/dnearneigh.html b/docs/reference/dnearneigh.html index 9550bf74..90436874 100644 --- a/docs/reference/dnearneigh.html +++ b/docs/reference/dnearneigh.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -247,14 +250,14 @@

    Examples

    #> Warning: neighbour object has 11 sub-graphs system.time(o <- nbdists(gck1b, xy1)) #> user system elapsed -#> 0.006 0.000 0.006 +#> 0.007 0.000 0.007 (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.012 +#> 0.013 0.000 0.014 summary(gc.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -276,13 +279,13 @@

    Examples

    } #> Warning: neighbour object has 3 sub-graphs #> user system elapsed -#> 0.01 0.00 0.01 +#> 0.012 0.000 0.011 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.011 0.000 0.011 +#> 0.013 0.000 0.013 if (packageVersion("s2") > "1.0.7") { summary(gc.nb.dwithin, xy1, scale=0.5) } @@ -325,7 +328,7 @@

    Examples

    system.time(gc.nb.legacy <- dnearneigh(xy1, 0, all.linked, use_s2=FALSE)) #> Warning: neighbour object has 3 sub-graphs #> user system elapsed -#> 0.006 0.000 0.006 +#> 0.007 0.000 0.007 summary(gc.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 diff --git a/docs/reference/droplinks.html b/docs/reference/droplinks.html index 2a7ce5f2..a346d1b8 100644 --- a/docs/reference/droplinks.html +++ b/docs/reference/droplinks.html @@ -1,5 +1,5 @@ -Drop links in a neighbours list — droplinks • spdepDrop and add links in a neighbours list — droplinks • spdep @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -62,17 +65,18 @@
    -

    Drops links to and from or just to a region from a neighbours list. The example corresponds to Fingleton's Table 1, p. 6, for lattices 5 to 19.

    +

    droplinks drops links to and from or just to a region from a neighbours list. The example corresponds to Fingleton's Table 1, (1999) p. 6, for lattices 5 to 19. addlinks1 adds links from a single region to specified regions.

    -
    droplinks(nb, drop, sym=TRUE)
    +
    droplinks(nb, drop, sym=TRUE)
    +addlinks1(nb, from, to, sym=TRUE)
    @@ -85,7 +89,13 @@

    Arguments

    either a logical vector the length of nb, or a character vector of named regions corresponding to nb's region.id attribute, or an integer vector of region numbers

    sym
    -

    TRUE for removal of both "row" and "column" links, FALSE for only "row" links

    +

    TRUE for removal of both "row" and "column" links, FALSE for only "row" links; when adding links, inserts links to the from region from the to regions

    + +
    from
    +

    single from region for adding links, either a character vector of length 1 of the named from region corresponding to nb's region.id attribute, or an integer vector of length 1 holding a region number

    + +
    to
    +

    to regions, either a character vector of named from regions corresponding to nb's region.id attribute, or an integer vector of region numbers

    @@ -128,6 +138,14 @@

    Examples

    mxs[i,j] <- max(res) } } +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours +#> Warning: some observations have no neighbours print(mns) #> 0.2 0.5 0.95 0.999 1 #> 5 1.038271 1.312627 9.486051 30.81487 32.04915 diff --git a/docs/reference/edit.nb.html b/docs/reference/edit.nb.html index 7f2a69f7..a174c1ac 100644 --- a/docs/reference/edit.nb.html +++ b/docs/reference/edit.nb.html @@ -48,6 +48,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/eire.html b/docs/reference/eire.html index a02c4eff..d75991a3 100644 --- a/docs/reference/eire.html +++ b/docs/reference/eire.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/geary.html b/docs/reference/geary.html index 033df528..03f0e030 100644 --- a/docs/reference/geary.html +++ b/docs/reference/geary.html @@ -48,6 +48,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/geary.mc.html b/docs/reference/geary.mc.html index 60418e81..eca3a921 100644 --- a/docs/reference/geary.mc.html +++ b/docs/reference/geary.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/geary.test.html b/docs/reference/geary.test.html index 3ef20e0c..a83cb509 100644 --- a/docs/reference/geary.test.html +++ b/docs/reference/geary.test.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/globalG.test.html b/docs/reference/globalG.test.html index 901dbcb9..cb73522d 100644 --- a/docs/reference/globalG.test.html +++ b/docs/reference/globalG.test.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/graphneigh.html b/docs/reference/graphneigh.html index 993980a3..fa7052a9 100644 --- a/docs/reference/graphneigh.html +++ b/docs/reference/graphneigh.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -305,7 +308,8 @@

    Examples

    #> Percentage nonzero weights: 1.79 #> Average number of links: 1.79 #> 23 regions with no links: -#> 22 39 43 53 58 61 66 70 71 73 76 78 81 88 90 93 94 95 96 97 98 99 100 +#> 22, 39, 43, 53, 58, 61, 66, 70, 71, 73, 76, 78, 81, 88, 90, 93, 94, 95, +#> 96, 97, 98, 99, 100 #> Non-symmetric neighbours list graph2nb(relativeneigh(coords)) #> Neighbour list object: @@ -314,8 +318,8 @@

    Examples

    #> Percentage nonzero weights: 1.17 #> Average number of links: 1.17 #> 31 regions with no links: -#> 22 29 33 39 41 42 43 44 53 58 61 64 65 66 70 71 73 75 76 78 81 88 90 93 -#> 94 95 96 97 98 99 100 +#> 22, 29, 33, 39, 41, 42, 43, 44, 53, 58, 61, 64, 65, 66, 70, 71, 73, 75, +#> 76, 78, 81, 88, 90, 93, 94, 95, 96, 97, 98, 99, 100 #> Non-symmetric neighbours list
    diff --git a/docs/reference/grid2nb.html b/docs/reference/grid2nb.html index 078d68f6..71cd7daa 100644 --- a/docs/reference/grid2nb.html +++ b/docs/reference/grid2nb.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/hotspotmap.html b/docs/reference/hotspotmap.html index 747677ef..d766ce16 100644 --- a/docs/reference/hotspotmap.html +++ b/docs/reference/hotspotmap.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/include.self.html b/docs/reference/include.self.html index 369f6fe0..3b6ee1bd 100644 --- a/docs/reference/include.self.html +++ b/docs/reference/include.self.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/index.html b/docs/reference/index.html index 728c70bf..59a3c0af 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -146,9 +149,9 @@

    All functions

    Neighbourhood contiguity by distance

    -

    droplinks()

    +

    droplinks() addlinks1()

    -

    Drop links in a neighbours list

    +

    Drop and add links in a neighbours list

    edit(<nb>)

    diff --git a/docs/reference/joincount.mc.html b/docs/reference/joincount.mc.html index 7379e4f5..95e1a395 100644 --- a/docs/reference/joincount.mc.html +++ b/docs/reference/joincount.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/joincount.multi.html b/docs/reference/joincount.multi.html index 69de1b74..75d40915 100644 --- a/docs/reference/joincount.multi.html +++ b/docs/reference/joincount.multi.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/joincount.test.html b/docs/reference/joincount.test.html index e0de4db0..aea73e40 100644 --- a/docs/reference/joincount.test.html +++ b/docs/reference/joincount.test.html @@ -49,6 +49,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/knearneigh.html b/docs/reference/knearneigh.html index c16149c9..40be89ab 100644 --- a/docs/reference/knearneigh.html +++ b/docs/reference/knearneigh.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -191,7 +194,7 @@

    Examples

    sf_use_s2(TRUE) system.time(gck4a.nb <- knn2nb(knearneigh(xy1, k=4))) #> user system elapsed -#> 0.011 0.000 0.010 +#> 0.012 0.001 0.013 summary(gck4a.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 @@ -211,7 +214,7 @@

    Examples

    #> Spherical geometry (s2) switched off system.time(gck4a.nb <- knn2nb(knearneigh(xy1, k=4))) #> user system elapsed -#> 0.007 0.000 0.008 +#> 0.009 0.000 0.010 summary(gck4a.nb, xy1, scale=0.5) #> Neighbour list object: #> Number of regions: 48 diff --git a/docs/reference/knn2nb.html b/docs/reference/knn2nb.html index 333990e8..9ac50d51 100644 --- a/docs/reference/knn2nb.html +++ b/docs/reference/knn2nb.html @@ -45,6 +45,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lag.listw.html b/docs/reference/lag.listw.html index cba53314..77ed6d67 100644 --- a/docs/reference/lag.listw.html +++ b/docs/reference/lag.listw.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lee.html b/docs/reference/lee.html index ff49bf1c..5d0d48c5 100644 --- a/docs/reference/lee.html +++ b/docs/reference/lee.html @@ -47,6 +47,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lee.mc.html b/docs/reference/lee.mc.html index 7e7dc384..71451089 100644 --- a/docs/reference/lee.mc.html +++ b/docs/reference/lee.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lee.test.html b/docs/reference/lee.test.html index 65a4e276..17b6bf85 100644 --- a/docs/reference/lee.test.html +++ b/docs/reference/lee.test.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/licd_multi.html b/docs/reference/licd_multi.html index 1b66f5ac..ee0414c6 100644 --- a/docs/reference/licd_multi.html +++ b/docs/reference/licd_multi.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/listw2sn.html b/docs/reference/listw2sn.html index 11eae231..58a21b8b 100644 --- a/docs/reference/listw2sn.html +++ b/docs/reference/listw2sn.html @@ -45,6 +45,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lm.RStests.html b/docs/reference/lm.RStests.html index 23379cd3..adf242f5 100644 --- a/docs/reference/lm.RStests.html +++ b/docs/reference/lm.RStests.html @@ -50,6 +50,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lm.morantest.exact.html b/docs/reference/lm.morantest.exact.html index 9e98bb1a..ed504b89 100644 --- a/docs/reference/lm.morantest.exact.html +++ b/docs/reference/lm.morantest.exact.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lm.morantest.html b/docs/reference/lm.morantest.html index f588cbb7..d57ba666 100644 --- a/docs/reference/lm.morantest.html +++ b/docs/reference/lm.morantest.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/lm.morantest.sad.html b/docs/reference/lm.morantest.sad.html index 764e5012..31391928 100644 --- a/docs/reference/lm.morantest.sad.html +++ b/docs/reference/lm.morantest.sad.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localC.html b/docs/reference/localC.html index 101f31f9..7c8abb06 100644 --- a/docs/reference/localC.html +++ b/docs/reference/localC.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -203,6 +206,7 @@

    Examples

    #> [31] 2.54591475 3.85570655 2.99413462 0.96084992 0.80678832 1.56869350 #> [37] 0.86422915 0.38817470 0.23425755 1.26191610 1.34455327 1.80707481 listw1 <- nb2listw(droplinks(sym.attr.nb(orig), 3, sym=TRUE), zero.policy=TRUE) +#> Warning: some observations have no neighbours #> Warning: neighbour object has 2 sub-graphs (A1 <- localC(x, listw1, zero.policy=FALSE)) #> [1] 0.39025457 0.57491918 NA 2.90814878 3.40006901 0.17103368 @@ -437,7 +441,7 @@

    Examples

    alternative="two.sided")) } #> user system elapsed -#> 0.352 0.006 0.359 +#> 0.368 0.011 0.382 if (run) { if (require(parallel, quietly=TRUE)) { ncpus <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L @@ -691,7 +695,7 @@

    Examples

    nsim=9999, alternative="two.sided")) } #> user system elapsed -#> 0.564 0.008 0.575 +#> 0.670 0.001 0.674 if (run) { all.equal(lisa_values(lmc_vars), c(lmc_vars_spdep)) } diff --git a/docs/reference/localG.html b/docs/reference/localG.html index bf893cf6..28995f98 100644 --- a/docs/reference/localG.html +++ b/docs/reference/localG.html @@ -49,6 +49,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localGS.html b/docs/reference/localGS.html index 99ea5069..e8c53bb6 100644 --- a/docs/reference/localGS.html +++ b/docs/reference/localGS.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/local_joincount_bv.html b/docs/reference/local_joincount_bv.html index da2fbb70..b43b907f 100644 --- a/docs/reference/local_joincount_bv.html +++ b/docs/reference/local_joincount_bv.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/local_joincount_uni.html b/docs/reference/local_joincount_uni.html index c3d811dc..dfbe9c31 100644 --- a/docs/reference/local_joincount_uni.html +++ b/docs/reference/local_joincount_uni.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localmoran.exact.html b/docs/reference/localmoran.exact.html index b250bfd8..9b1cc40d 100644 --- a/docs/reference/localmoran.exact.html +++ b/docs/reference/localmoran.exact.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localmoran.html b/docs/reference/localmoran.html index d969bdfb..e72f6a20 100644 --- a/docs/reference/localmoran.html +++ b/docs/reference/localmoran.html @@ -47,6 +47,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localmoran.sad.html b/docs/reference/localmoran.sad.html index 09e56efa..f8030bf6 100644 --- a/docs/reference/localmoran.sad.html +++ b/docs/reference/localmoran.sad.html @@ -51,6 +51,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/localmoran_bv.html b/docs/reference/localmoran_bv.html index 873ac5c9..98dde876 100644 --- a/docs/reference/localmoran_bv.html +++ b/docs/reference/localmoran_bv.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/mat2listw.html b/docs/reference/mat2listw.html index a6e4038d..029df18b 100644 --- a/docs/reference/mat2listw.html +++ b/docs/reference/mat2listw.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -133,7 +136,7 @@

    Examples

    #> Percentage nonzero weights: 7.080383 #> Average number of links: 3.469388 #> 4 regions with no links: -#> 1005 1006 1008 1043 +#> 1005, 1006, 1008, 1043 #> 8 disjoint connected subgraphs #> Link number distribution: #> @@ -159,7 +162,7 @@

    Examples

    #> Percentage nonzero weights: 7.080383 #> Average number of links: 3.469388 #> 4 regions with no links: -#> 1005 1006 1008 1043 +#> 1005, 1006, 1008, 1043 #> 8 disjoint connected subgraphs #> Link number distribution: #> @@ -177,10 +180,11 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no links: -#> 1005 1001 1006 1002 1007 1008 1004 1003 1018 1010 1038 1037 1039 1040 -#> 1009 1036 1011 1042 1041 1017 1043 1019 1012 1035 1032 1020 1021 1031 -#> 1033 1034 1045 1013 1022 1044 1023 1046 1030 1024 1047 1016 1014 1049 -#> 1029 1025 1028 1048 1015 1027 1026 +#> 1005, 1001, 1006, 1002, 1007, 1008, 1004, 1003, 1018, 1010, 1038, 1037, +#> 1039, 1040, 1009, 1036, 1011, 1042, 1041, 1017, 1043, 1019, 1012, 1035, +#> 1032, 1020, 1021, 1031, 1033, 1034, 1045, 1013, 1022, 1044, 1023, 1046, +#> 1030, 1024, 1047, 1016, 1014, 1049, 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", zero.policy=TRUE) @@ -192,7 +196,7 @@

    Examples

    #> Percentage nonzero weights: 2.360128 #> Average number of links: 3.469388 #> 12 regions with no links: -#> 1 3 6 21 50 52 55 70 99 101 104 119 +#> 1, 3, 6, 21, 50, 52, 55, 70, 99, 101, 104, 119 #> 24 disjoint connected subgraphs #> Link number distribution: #> @@ -229,7 +233,7 @@

    Examples

    #> Percentage nonzero weights: 7.080383 #> Average number of links: 3.469388 #> 4 regions with no links: -#> 1005 1006 1008 1043 +#> 1005, 1006, 1008, 1043 #> 8 disjoint connected subgraphs #> Link number distribution: #> @@ -249,10 +253,11 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no links: -#> 1005 1001 1006 1002 1007 1008 1004 1003 1018 1010 1038 1037 1039 1040 -#> 1009 1036 1011 1042 1041 1017 1043 1019 1012 1035 1032 1020 1021 1031 -#> 1033 1034 1045 1013 1022 1044 1023 1046 1030 1024 1047 1016 1014 1049 -#> 1029 1025 1028 1048 1015 1027 1026 +#> 1005, 1001, 1006, 1002, 1007, 1008, 1004, 1003, 1018, 1010, 1038, 1037, +#> 1039, 1040, 1009, 1036, 1011, 1042, 1041, 1017, 1043, 1019, 1012, 1035, +#> 1032, 1020, 1021, 1031, 1033, 1034, 1045, 1013, 1022, 1044, 1023, 1046, +#> 1030, 1024, 1047, 1016, 1014, 1049, 1029, 1025, 1028, 1048, 1015, 1027, +#> 1026 #> 49 disjoint connected subgraphs if (run && require("Matrix", quiet=TRUE)) { IW <- kronecker(Diagonal(3), W) @@ -269,7 +274,7 @@

    Examples

    #> Percentage nonzero weights: 2.360128 #> Average number of links: 3.469388 #> 12 regions with no links: -#> 1 3 6 21 50 52 55 70 99 101 104 119 +#> 1, 3, 6, 21, 50, 52, 55, 70, 99, 101, 104, 119 #> 24 disjoint connected subgraphs #> Link number distribution: #> diff --git a/docs/reference/moran.html b/docs/reference/moran.html index 0f28acd8..4f0d3967 100644 --- a/docs/reference/moran.html +++ b/docs/reference/moran.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/moran.mc.html b/docs/reference/moran.mc.html index d1289fb1..154f26e3 100644 --- a/docs/reference/moran.mc.html +++ b/docs/reference/moran.mc.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/moran.plot.html b/docs/reference/moran.plot.html index 45707fb0..c4a613c5 100644 --- a/docs/reference/moran.plot.html +++ b/docs/reference/moran.plot.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/moran.test.html b/docs/reference/moran.test.html index 65205b62..7c9dc86d 100644 --- a/docs/reference/moran.test.html +++ b/docs/reference/moran.test.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/moran_bv.html b/docs/reference/moran_bv.html index 395ba460..8896f3be 100644 --- a/docs/reference/moran_bv.html +++ b/docs/reference/moran_bv.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/mstree.html b/docs/reference/mstree.html index 47d9cde5..d72e5e23 100644 --- a/docs/reference/mstree.html +++ b/docs/reference/mstree.html @@ -47,6 +47,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -123,7 +126,8 @@

    Author

    Examples

    ### loading data
    -bh <- st_read(system.file("etc/shapes/bhicv.gpkg",
    +if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
    +bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
           package="spdep")[1], quiet=TRUE)
     ### data padronized
     dpad <- data.frame(scale(as.data.frame(bh)[,5:8]))
    @@ -139,31 +143,15 @@ 

    Examples

    ### find a minimum spanning tree system.time(mst.bh <- mstree(nb.w,5)) -#> user system elapsed -#> 0.003 0.000 0.003 dim(mst.bh) -#> [1] 97 3 head(mst.bh) -#> [,1] [,2] [,3] -#> [1,] 5 12 1.2951120 -#> [2,] 12 13 0.6141101 -#> [3,] 13 11 0.7913745 -#> [4,] 13 6 0.9775650 -#> [5,] 11 31 0.9965625 -#> [6,] 31 39 0.6915158 tail(mst.bh) -#> [,1] [,2] [,3] -#> [92,] 89 90 2.5743702 -#> [93,] 26 56 2.6235317 -#> [94,] 86 87 2.6471303 -#> [95,] 87 72 0.7874461 -#> [96,] 49 36 2.8743677 -#> [97,] 24 25 3.4675168 ### the mstree plot par(mar=c(0,0,0,0)) plot(st_geometry(bh), border=gray(.5)) plot(mst.bh, st_coordinates(st_centroid(bh)), col=2, cex.lab=.6, cex.circles=0.035, fg="blue", add=TRUE) +} #> Warning: st_centroid assumes attributes are constant over geometries
    diff --git a/docs/reference/nb2INLA.html b/docs/reference/nb2INLA.html index d0c777e3..d8770bc2 100644 --- a/docs/reference/nb2INLA.html +++ b/docs/reference/nb2INLA.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nb2WB.html b/docs/reference/nb2WB.html index 32e4a230..6e393390 100644 --- a/docs/reference/nb2WB.html +++ b/docs/reference/nb2WB.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nb2blocknb.html b/docs/reference/nb2blocknb.html index 10ff14d4..89dc4b0d 100644 --- a/docs/reference/nb2blocknb.html +++ b/docs/reference/nb2blocknb.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -194,7 +197,8 @@

    Examples

    #> 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 +#> 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 diff --git a/docs/reference/nb2lines.html b/docs/reference/nb2lines.html index 8761c1e9..bce7834f 100644 --- a/docs/reference/nb2lines.html +++ b/docs/reference/nb2lines.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -157,12 +160,12 @@

    Examples

    #> Max. :0.5000 tf <- paste0(tempfile(), ".gpkg") st_write(res, dsn=tf, driver="GPKG") -#> Writing layer `file71d532de9e00d' to data source -#> `/tmp/Rtmp6barmj/file71d532de9e00d.gpkg' using driver `GPKG' +#> Writing layer `filec1856d3811f' to data source +#> `/tmp/Rtmp3CAEPn/filec1856d3811f.gpkg' using driver `GPKG' #> Writing 230 features with 5 fields and geometry type Line String. inMap <- st_read(tf) -#> Reading layer `file71d532de9e00d' from data source -#> `/tmp/Rtmp6barmj/file71d532de9e00d.gpkg' using driver `GPKG' +#> Reading layer `filec1856d3811f' from data source +#> `/tmp/Rtmp3CAEPn/filec1856d3811f.gpkg' using driver `GPKG' #> Simple feature collection with 230 features and 5 fields #> Geometry type: LINESTRING #> Dimension: XY @@ -192,8 +195,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs res1 <- listw2lines(nb2listw(col.gal.nb), as(columbus, "Spatial")) summary(res1) diff --git a/docs/reference/nb2listw.html b/docs/reference/nb2listw.html index 4331d3cb..523e2e33 100644 --- a/docs/reference/nb2listw.html +++ b/docs/reference/nb2listw.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nb2listwdist.html b/docs/reference/nb2listwdist.html index 2d567d40..fa3accfe 100644 --- a/docs/reference/nb2listwdist.html +++ b/docs/reference/nb2listwdist.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nb2mat.html b/docs/reference/nb2mat.html index 61e8d634..582ec184 100644 --- a/docs/reference/nb2mat.html +++ b/docs/reference/nb2mat.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -130,7 +133,7 @@

    Examples

    #> Percentage nonzero weights: 7.080383 #> Average number of links: 3.469388 #> 4 regions with no links: -#> 1005 1006 1008 1043 +#> 1005, 1006, 1008, 1043 #> 8 disjoint connected subgraphs #> Link number distribution: #> diff --git a/docs/reference/nbcosts.html b/docs/reference/nbcosts.html index 0b97ecd7..e30ceb2b 100644 --- a/docs/reference/nbcosts.html +++ b/docs/reference/nbcosts.html @@ -45,6 +45,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nbdists.html b/docs/reference/nbdists.html index 66f41147..c96ebaff 100644 --- a/docs/reference/nbdists.html +++ b/docs/reference/nbdists.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nblag.html b/docs/reference/nblag.html index c48f2015..210eb241 100644 --- a/docs/reference/nblag.html +++ b/docs/reference/nblag.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/nboperations.html b/docs/reference/nboperations.html index 9f655abf..181140e4 100644 --- a/docs/reference/nboperations.html +++ b/docs/reference/nboperations.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -138,6 +141,7 @@

    Examples

    par(mfrow=c(2,2)) col2 <- droplinks(col.gal.nb, 21) +#> Warning: some observations have no neighbours #> Warning: neighbour object has 3 sub-graphs plot(intersect.nb(col.gal.nb, col2), coords) #> Warning: neighbour object has 3 sub-graphs diff --git a/docs/reference/p.adjustSP.html b/docs/reference/p.adjustSP.html index 1f520cba..b1e4a119 100644 --- a/docs/reference/p.adjustSP.html +++ b/docs/reference/p.adjustSP.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/plot.mst.html b/docs/reference/plot.mst.html index 1abe422b..5a96dbfa 100644 --- a/docs/reference/plot.mst.html +++ b/docs/reference/plot.mst.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/plot.nb.html b/docs/reference/plot.nb.html index 00de3b30..3831d6cf 100644 --- a/docs/reference/plot.nb.html +++ b/docs/reference/plot.nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/plot.skater.html b/docs/reference/plot.skater.html index 1bff553a..5f9e6b0b 100644 --- a/docs/reference/plot.skater.html +++ b/docs/reference/plot.skater.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/poly2nb.html b/docs/reference/poly2nb.html index c037eb68..9f6cfaba 100644 --- a/docs/reference/poly2nb.html +++ b/docs/reference/poly2nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -140,8 +143,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs sfc_xx <- poly2nb(st_geometry(columbus)) diffnb(sfc_xx, xx) @@ -152,8 +156,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs xxx <- poly2nb(as(columbus, "Spatial"), queen=FALSE) dxxx <- diffnb(xxx, col.gal.nb) @@ -176,10 +181,10 @@

    Examples

    nc.sids <- st_read(system.file("shapes/sids.gpkg", package="spData")[1], quiet=TRUE) system.time(xxnb <- poly2nb(nc.sids)) #> user system elapsed -#> 0.039 0.000 0.040 +#> 0.040 0.000 0.041 system.time(xxnb <- poly2nb(as(nc.sids, "Spatial"))) #> user system elapsed -#> 0.053 0.000 0.054 +#> 0.057 0.000 0.056 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 @@ -189,7 +194,7 @@

    Examples

    sq3 <- sq + c(1,0) sq4 <- sq + c(1,1) gm <- st_sfc(list(sq, sq2, sq3, sq4)) -df <- st_as_sf(gm, id=1:4) +df <- st_as_sf(data.frame(gm, id=1:4)) plot(st_geometry(df)) text(st_coordinates(st_centroid(gm)), as.character(df$id)) diff --git a/docs/reference/probmap.html b/docs/reference/probmap.html index 89f865df..b1348a10 100644 --- a/docs/reference/probmap.html +++ b/docs/reference/probmap.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/prunecost.html b/docs/reference/prunecost.html index aa503686..81b038ab 100644 --- a/docs/reference/prunecost.html +++ b/docs/reference/prunecost.html @@ -48,6 +48,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/prunemst.html b/docs/reference/prunemst.html index 58a7711c..2acb5629 100644 --- a/docs/reference/prunemst.html +++ b/docs/reference/prunemst.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/read.gal.html b/docs/reference/read.gal.html index 7e55194c..01a45829 100644 --- a/docs/reference/read.gal.html +++ b/docs/reference/read.gal.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/read.gwt2nb.html b/docs/reference/read.gwt2nb.html index b5724e7f..de54424c 100644 --- a/docs/reference/read.gwt2nb.html +++ b/docs/reference/read.gwt2nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -159,17 +162,20 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 211 regions with no 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 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 +#> 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 #> 211 disjoint connected subgraphs data(oldcol) tmpMAT <- tempfile() @@ -186,8 +192,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs listwmat2 <- read.dat2listw(system.file("etc/weights/wmat.dat", package="spdep")[1]) @@ -200,8 +207,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs if (require("foreign", quietly=TRUE)) { nc_sf <- sf::st_read(system.file("gpkg/nc.gpkg", package="sf")[1]) @@ -220,7 +228,8 @@

    Examples

    style="B", zero.policy=TRUE) nc1ia all.equal(nc1i, nc1ia) -cal <- st_read(system.file("etc/shapes/california.gpkg", package="spdep")[1]) +if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") { +cal <- st_read(system.file("etc/shapes/california.gpkg.zip", package="spdep")[1]) fn <- system.file("etc/misc/contiguity_myid.dbf", package="spdep")[1] cal1 <- read.swmdbf2listw(fn, style="B") cal1a <- read.swmdbf2listw(fn, region.id=as.character(cal$MYID), style="B") @@ -248,6 +257,7 @@

    Examples

    all(isTRUE(all.equal(cal1a_1n$neighbours, cal1_1n_rt$neighbours))) all(isTRUE(all.equal(cal1a_1n$weights, cal1_1n_rt$weights))) } +} #> Reading layer `nc.gpkg' from data source `/home/rsb/lib/r_libs/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON @@ -263,7 +273,7 @@

    Examples

    #> #> Warning: region.id not given, c(MYID, NID) range is 1:100 #> Reading layer `california' from data source -#> `/tmp/Rtmput1Tax/temp_libpath71c612b87ba64/spdep/etc/shapes/california.gpkg' +#> `/tmp/RtmpYdUOF1/temp_libpathbff31ae05681/spdep/etc/shapes/california.gpkg.zip' #> using driver `GPKG' #> Simple feature collection with 58 features and 2 fields #> Geometry type: MULTIPOLYGON @@ -279,6 +289,7 @@

    Examples

    #> no-neighbour observations found, set zero.policy to TRUE #> #> Warning: region.id not given, c(MYID, NID) range is 1:58 +#> Warning: some observations have no neighbours #> Warning: neighbour object has 4 sub-graphs #> Warning: neighbour object has 4 sub-graphs #> Warning: region.id not given, c(MYID, NID) range is 159:214 diff --git a/docs/reference/rotation.html b/docs/reference/rotation.html index 011f8013..9a4b652c 100644 --- a/docs/reference/rotation.html +++ b/docs/reference/rotation.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/set.mcOption.html b/docs/reference/set.mcOption.html index ce4f6b99..197f06c7 100644 --- a/docs/reference/set.mcOption.html +++ b/docs/reference/set.mcOption.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -165,12 +168,7 @@

    Examples

    #> [[1]] #> [1] FALSE #> -#> [[1]] -#> [1] TRUE -#> -#> [[1]] -#> [1] FALSE -#> +#> Error in checkForRemoteErrors(lapply(cl, recvResult)): one node produced an error: there is no package called 'spdep'
    diff --git a/docs/reference/set.spChkOption.html b/docs/reference/set.spChkOption.html index 9fcbb401..f2140be6 100644 --- a/docs/reference/set.spChkOption.html +++ b/docs/reference/set.spChkOption.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/skater.html b/docs/reference/skater.html index 673ad86e..fd0dff65 100644 --- a/docs/reference/skater.html +++ b/docs/reference/skater.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -178,7 +181,8 @@

    See also

    Examples

    ### loading data
    -bh <- st_read(system.file("etc/shapes/bhicv.gpkg",
    +if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
    +bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
           package="spdep")[1], quiet=TRUE)
     ### data standardized 
     dpad <- data.frame(scale(as.data.frame(bh)[,5:8]))
    @@ -199,97 +203,70 @@ 

    Examples

    par(mar=c(0,0,0,0)) plot(st_geometry(bh), border=gray(.5)) pts <- st_coordinates(st_centroid(bh)) -#> Warning: st_centroid assumes attributes are constant over geometries plot(mst.bh, pts, col=2, cex.lab=.6, cex.circles=0.035, fg="blue", add=TRUE) - ### three groups with no restriction 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 ### groups size table(res1$groups) -#> Error in eval(expr, envir, enclos): object 'res1' not found ### the skater plot opar <- par(mar=c(0,0,0,0)) plot(res1, pts, cex.circles=0.035, cex.lab=.7) -#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'res1' not found ### the skater plot, using other colors plot(res1, pts, cex.circles=0.035, cex.lab=.7, groups.colors=heat.colors(length(res1$ed))) -#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'res1' not found ### the Spatial Polygons plot plot(st_geometry(bh), col=heat.colors(length(res1$edg))[res1$groups]) -#> Error in eval(expr, envir, enclos): object 'res1' not found - par(opar) ### EXPERT OPTIONS ### more one partition res1b <- skater(res1, dpad, 1) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero ### length groups frequency table(res1$groups) -#> Error in eval(expr, envir, enclos): object 'res1' not found table(res1b$groups) -#> Error in eval(expr, envir, enclos): object 'res1b' not found ### thee groups with minimum population res2 <- skater(mst.bh[,1:2], dpad, 2, 200000, bh$Pop) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res2$groups) -#> Error in eval(expr, envir, enclos): object 'res2' not found ### thee groups with minimun number of areas res3 <- skater(mst.bh[,1:2], dpad, 2, 3, rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res3$groups) -#> Error in eval(expr, envir, enclos): object 'res3' not found ### thee groups with minimun and maximun number of areas res4 <- skater(mst.bh[,1:2], dpad, 2, c(20,50), rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res4$groups) -#> Error in eval(expr, envir, enclos): object 'res4' not found ### if I want to get groups with 20 to 40 elements res5 <- skater(mst.bh[,1:2], dpad, 2, c(20,40), rep(1,nrow(bh))) ## DON'T MAKE DIVISIONS -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res5$groups) -#> Error in eval(expr, envir, enclos): object 'res5' not found ### In this MST don't have groups with this restrictions ### In this case, first I do one division ### with the minimun criteria res5a <- skater(mst.bh[,1:2], dpad, 1, 20, rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res5a$groups) -#> Error in eval(expr, envir, enclos): object 'res5a' not found ### and do more one division with the full criteria res5b <- skater(res5a, dpad, 1, c(20, 40), rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res5b$groups) -#> Error in eval(expr, envir, enclos): object 'res5b' not found ### and do more one division with the full criteria res5c <- skater(res5b, dpad, 1, c(20, 40), rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res5c$groups) -#> Error in eval(expr, envir, enclos): object 'res5c' not found ### It don't have another divison with this criteria res5d <- skater(res5c, dpad, 1, c(20, 40), rep(1,nrow(bh))) -#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero table(res5d$groups) -#> Error in eval(expr, envir, enclos): object 'res5d' not found # \dontrun{ data(boston, package="spData") @@ -297,16 +274,12 @@

    Examples

    dpad <- data.frame(scale(boston.c[,c(7:10)])) ### calculating costs system.time(lcosts <- nbcosts(bh.nb, dpad)) -#> user system elapsed -#> 0.055 0.000 0.055 ### 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 @@ -320,26 +293,24 @@

    Examples

    } ### calculating costs system.time(plcosts <- nbcosts(bh.nb, dpad)) -#> user system elapsed -#> 0.043 0.000 0.044 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)) # } +} +#> Warning: st_centroid assumes attributes are constant over geometries +#> Error in if (w$num_obs < 1) { stop("The weights is not valid.")}: argument is of length zero +
    diff --git a/docs/reference/sp.correlogram.html b/docs/reference/sp.correlogram.html index b5c64ca3..e4de3ad0 100644 --- a/docs/reference/sp.correlogram.html +++ b/docs/reference/sp.correlogram.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/sp.mantel.mc.html b/docs/reference/sp.mantel.mc.html index 695b4cdd..e5d1f8bc 100644 --- a/docs/reference/sp.mantel.mc.html +++ b/docs/reference/sp.mantel.mc.html @@ -49,6 +49,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/spdep-defunct.html b/docs/reference/spdep-defunct.html index 0a9fe7e8..a8f8cd1c 100644 --- a/docs/reference/spdep-defunct.html +++ b/docs/reference/spdep-defunct.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/spdep.html b/docs/reference/spdep.html index 8e70ac5c..e863e367 100644 --- a/docs/reference/spdep.html +++ b/docs/reference/spdep.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/spweights.constants.html b/docs/reference/spweights.constants.html index 83f0980d..5279d8a9 100644 --- a/docs/reference/spweights.constants.html +++ b/docs/reference/spweights.constants.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/ssw.html b/docs/reference/ssw.html index 2528aaac..74faa385 100644 --- a/docs/reference/ssw.html +++ b/docs/reference/ssw.html @@ -44,6 +44,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/subset.listw.html b/docs/reference/subset.listw.html index e82f2ddd..ae2bd2c3 100644 --- a/docs/reference/subset.listw.html +++ b/docs/reference/subset.listw.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/subset.nb.html b/docs/reference/subset.nb.html index 9c83dab2..ca7bf762 100644 --- a/docs/reference/subset.nb.html +++ b/docs/reference/subset.nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/summary.nb.html b/docs/reference/summary.nb.html index 1f05d770..82b3ea13 100644 --- a/docs/reference/summary.nb.html +++ b/docs/reference/summary.nb.html @@ -45,6 +45,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/testnb.html b/docs/reference/testnb.html index 38b21ed0..eb8af4f1 100644 --- a/docs/reference/testnb.html +++ b/docs/reference/testnb.html @@ -47,6 +47,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/tolerance.nb.html b/docs/reference/tolerance.nb.html index a431b6b7..e142e9dc 100644 --- a/docs/reference/tolerance.nb.html +++ b/docs/reference/tolerance.nb.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/tri2nb.html b/docs/reference/tri2nb.html index db1ae209..864187a8 100644 --- a/docs/reference/tri2nb.html +++ b/docs/reference/tri2nb.html @@ -46,6 +46,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog diff --git a/docs/reference/write.nb.gal.html b/docs/reference/write.nb.gal.html index 5ed7e8be..8e61e571 100644 --- a/docs/reference/write.nb.gal.html +++ b/docs/reference/write.nb.gal.html @@ -43,6 +43,9 @@
  • Introduction to the North Carolina SIDS data set (re-revised)
  • +
  • + No-neighbour observation and subgraph handling +
  • Changelog @@ -117,8 +120,9 @@

    Examples

    #> Percentage nonzero weights: 0 #> Average number of links: 0 #> 49 regions with no 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 49 +#> 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 #> 49 disjoint connected subgraphs #> Link number distribution: #> diff --git a/docs/sitemap.xml b/docs/sitemap.xml index dd3433d1..a0ad5ec6 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -5,6 +5,7 @@ /articles/nb.html /articles/nb_sf.html /articles/sids.html +/articles/subgraphs.html /authors.html /index.html /news/index.html