Last data update: 2014.03.03

R: USCounties Contiguity Matrix
USCountiesR Documentation

USCounties Contiguity Matrix

Description

This matrix represents the contiguities of 3111 US counties using the Queen criterion of at least a single shared boundary point. The representation is as a row standardised spatial weights matrix transformed to a symmetric matrix (see Ord (1975), p. 125).

Usage

data(USCounties)

Format

A 3111 ^2 symmetric sparse matrix of class dsCMatrix with 9101 non-zero entries.

Details

The data were read into R using read.gal, and row-standardised and transformed to symmetry using nb2listw and similar.listw. This spatial weights object was converted to class dsCMatrix using as_dsTMatrix_listw and coercion.

Source

The data were retrieved from http://sal.uiuc.edu/weights/zips/usc.zip, files “usc.txt” and “usc_q.GAL”, with permission for use and distribution from Luc Anselin.

References

Ord, J. K. (1975) Estimation methods for models of spatial interaction; Journal of the American Statistical Association 70, 120–126.

Examples

data(USCounties)
(n <- ncol(USCounties))
IM <- .symDiagonal(n)
nn <- 50
set.seed(1)
rho <- runif(nn, 0, 1)
system.time(MJ <- sapply(rho, function(x)
	determinant(IM - x * USCounties, logarithm = TRUE)$modulus))

## can be done faster, by update()ing the Cholesky factor:
nWC <- -USCounties
C1 <- Cholesky(nWC, Imult = 2)
system.time(MJ1 <- n * log(rho) +
            sapply(rho, function(x)
                   2 * c(determinant(update(C1, nWC, 1/x))$modulus)))
all.equal(MJ, MJ1)


C2 <- Cholesky(nWC, super = TRUE, Imult = 2)
system.time(MJ2 <- n * log(rho) +
            sapply(rho, function(x)
                   2 * c(determinant(update(C2, nWC, 1/x))$modulus)))
all.equal(MJ, MJ2)  
system.time(MJ3 <- n * log(rho) + Matrix:::ldetL2up(C1, nWC, 1/rho))
stopifnot(all.equal(MJ, MJ3))
system.time(MJ4 <- n * log(rho) + Matrix:::ldetL2up(C2, nWC, 1/rho))
stopifnot(all.equal(MJ, MJ4))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Matrix)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Matrix/USCounties.Rd_%03d_medium.png", width=480, height=480)
> ### Name: USCounties
> ### Title: USCounties Contiguity Matrix
> ### Aliases: USCounties
> ### Keywords: datasets
> 
> ### ** Examples
> 
> data(USCounties)
> (n <- ncol(USCounties))
[1] 3111
> IM <- .symDiagonal(n)
> nn <- 50
> set.seed(1)
> rho <- runif(nn, 0, 1)
> system.time(MJ <- sapply(rho, function(x)
+ 	determinant(IM - x * USCounties, logarithm = TRUE)$modulus))
   user  system elapsed 
  0.372   0.012   0.384 
> 
> ## can be done faster, by update()ing the Cholesky factor:
> nWC <- -USCounties
> C1 <- Cholesky(nWC, Imult = 2)
> system.time(MJ1 <- n * log(rho) +
+             sapply(rho, function(x)
+                    2 * c(determinant(update(C1, nWC, 1/x))$modulus)))
   user  system elapsed 
  0.112   0.000   0.110 
> all.equal(MJ, MJ1)
[1] TRUE
> ## Don't show: 
> stopifnot( all.equal(MJ, MJ1) )
> ## End(Don't show)
> 
> C2 <- Cholesky(nWC, super = TRUE, Imult = 2)
> system.time(MJ2 <- n * log(rho) +
+             sapply(rho, function(x)
+                    2 * c(determinant(update(C2, nWC, 1/x))$modulus)))
   user  system elapsed 
  0.144   0.008   0.151 
> all.equal(MJ, MJ2)  ## Don't show: 
[1] TRUE
> stopifnot(all.equal(MJ, MJ2))
> ## End(Don't show)
> system.time(MJ3 <- n * log(rho) + Matrix:::ldetL2up(C1, nWC, 1/rho))
   user  system elapsed 
  0.068   0.000   0.067 
> stopifnot(all.equal(MJ, MJ3))
> system.time(MJ4 <- n * log(rho) + Matrix:::ldetL2up(C2, nWC, 1/rho))
   user  system elapsed 
  0.088   0.000   0.089 
> stopifnot(all.equal(MJ, MJ4))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>