Skip to content

Commit

Permalink
Merge pull request #53 from r-spatial/n_comp
Browse files Browse the repository at this point in the history
N comp
  • Loading branch information
rsbivand authored Jun 16, 2024
2 parents bfb1ebe + 29095b5 commit d0ce698
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment=c(ORCID="0000-0003-2392-6140")),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 5 additions & 2 deletions R/cyclical.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/eigenw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion man/eigenw.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion vignettes/nb_igraph.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0ce698

Please sign in to comment.