From da75b6962305cc81607d27d6bd0867252590b4cf Mon Sep 17 00:00:00 2001 From: Roger Bivand Date: Fri, 14 Jun 2024 22:01:50 +0200 Subject: [PATCH 1/2] start n.comp.nb update --- vignettes/nb_igraph.Rmd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vignettes/nb_igraph.Rmd b/vignettes/nb_igraph.Rmd index c1dbcf8..e9d7699 100644 --- a/vignettes/nb_igraph.Rmd +++ b/vignettes/nb_igraph.Rmd @@ -232,13 +232,16 @@ First we'll see how to get from sparse matrices to graphs. The mode of a symmetr class(B) object.size(B) if (!require("igraph", quietly=FALSE)) dothis <- FALSE +``` + +```{r, echo=dothis, eval=dothis} g1 <- graph_from_adjacency_matrix(B, mode="undirected") class(g1) object.size(g1) ``` ### Converting from graph to symmetric adjacency matrix -We can also convert this graph pack to the same matrix, but note that `get.adjacency` chooses a particular class of sparse matrix to be returned, so that the conversion process typically leads many matrices to fewer graph types, and back to fewer matrix types: +We can also convert this graph back to the same matrix, but note that `as_adjacency_matrix` chooses a particular class of sparse matrix to be returned, so that the conversion process typically leads many matrices to fewer graph types, and back to fewer matrix types: ```{r, echo=dothis, eval=dothis} # Matrix 1.4-2 vulnerability work-around From 29095b59142b8172f31b5158fea5bb3e7d3fdac5 Mon Sep 17 00:00:00 2001 From: Roger Bivand Date: Fri, 14 Jun 2024 22:24:56 +0200 Subject: [PATCH 2/2] addressing #52 --- DESCRIPTION | 4 ++-- NEWS.md | 6 +++++- R/cyclical.R | 7 +++++-- R/eigenw.R | 3 ++- man/eigenw.Rd | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6207cf9..d43b01f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: spatialreg -Version: 1.3-4 -Date: 2024-06-10 +Version: 1.3-5 +Date: 2024-06-14 Title: Spatial Regression Analysis Encoding: UTF-8 Authors@R: c(person("Roger", "Bivand", role = c("cre", "aut"), email = "Roger.Bivand@nhh.no", comment=c(ORCID="0000-0003-2392-6140")), diff --git a/NEWS.md b/NEWS.md index 5510430..b77ab81 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# Version 1.3-4 (development) +# Version 1.3-5 (development) + +* #52 subgraph updates + +# Version 1.3-4 (2024-06-10) * migrate from ESRI Shapefile to GeoPackage #50 diff --git a/R/cyclical.R b/R/cyclical.R index 578362c..efbbce8 100644 --- a/R/cyclical.R +++ b/R/cyclical.R @@ -5,7 +5,9 @@ isCyclical <- function(nb) { stopifnot(inherits(nb, "nb")) cnb <- card(nb) if (any(cnb == 0)) stop("Neighbours must be connected") - if (n.comp.nb(nb)$nc != 1) stop("Complete connection required") + nc <- attr(nb, "ncomp") + if (is.null(nc)) nc <- n.comp.nb(nb) + if (nc$nc != 1) stop("Complete connection required") res <- 1L for (i in seq(along=nb)) { inbs <- nb[[i]] @@ -29,7 +31,8 @@ isCyclical <- function(nb) { find_q1_q2 <- function(lw) { stopifnot(lw$style == "W") nb <- lw$neighbours - nc <- n.comp.nb(nb) + nc <- attr(nb, "ncomp") + if (is.null(nc)) nc <- n.comp.nb(nb) members <- tapply(1:length(nb), nc$comp.id, c) q2 <- 0L q1 <- nc$nc diff --git a/R/eigenw.R b/R/eigenw.R index e825e06..1517f60 100644 --- a/R/eigenw.R +++ b/R/eigenw.R @@ -48,7 +48,8 @@ subgraph_eigenw <- function(nb, glist=NULL, style="W", zero.policy=NULL, can.sim <- FALSE if (style %in% c("W", "S")) can.sim <- can.be.simmed(nb2listw(nb, glist=glist, style=style)) - nc <- n.comp.nb(nb) + nc <- attr(nb, "ncomp") + if (is.null(nc)) nc <- n.comp.nb(nb) t0 <- table(nc$comp.id) elist <- vector(mode="list", length=length(t0)) singleton <- names(t0)[which(t0 == 1)] diff --git a/man/eigenw.Rd b/man/eigenw.Rd index f6a1d0e..91a206a 100644 --- a/man/eigenw.Rd +++ b/man/eigenw.Rd @@ -69,7 +69,8 @@ Jc <- sum(log(1 - rho * k3eig)) # complex eigenvalue Jacobian Jc # subgraphs -nc <- spdep::n.comp.nb(k3) +nc <- attr(k3, "ncomp") +if (is.null(nc)) nc <- spdep::n.comp.nb(k3) nc$nc table(nc$comp.id) k3eigSG <- subgraph_eigenw(k3, style="W")