R/getAmat.R

Defines functions getAmat

Documented in getAmat

#' Extract adjacency matrix from the map 
#' 
#' @param geo SpatialPolygonsDataFrame of the map
#' @param names  character vector of region ids to be added to the neighbours list
#' 
#' @return Spatial djacency matrix.
#' @author Zehang Richard Li 
#' @examples
#' \dontrun{
#' data(DemoMap) 
#' mat <- getAmat(geo = DemoMap$geo, names = DemoMap$geo$REGNAME)
#' mat
#' DemoMap$Amat
#' } 
#' @export


getAmat <- function(geo, names){
	nb.r <- spdep::poly2nb(geo, queen=F, row.names = names)
	mat <- spdep::nb2mat(nb.r, style="B",zero.policy=TRUE)
	regions <- colnames(mat) <- rownames(mat) 
	mat <- as.matrix(mat[1:dim(mat)[1], 1:dim(mat)[1]])
	return(mat)
}

Try the SUMMER package in your browser

Any scripts or data that you put into this service are public.

SUMMER documentation built on July 8, 2022, 9:05 a.m.