USCounties.RdThis matrix gives the contiguities of 3111 U.S. counties, using the queen criterion of at least one shared vertex or edge.
data(USCounties)A \(3111 \times 3111\) sparse, symmetric
matrix of class dsCMatrix, with 9101
nonzero entries.
GAL lattice file usc_q.GAL
(retrieved in 2008 from
http://sal.uiuc.edu/weights/zips/usc.zip
with permission from Luc Anselin for use and distribution)
was read into R using function read.gal
from package spdep.
Neighbour lists were augmented with row-standardized
(and then symmetrized) spatial weights, using functions
nb2listw and similar.listw from packages
spdep and spatialreg.
The resulting listw object was coerced to class
dsTMatrix
using as_dsTMatrix_listw from spatialreg,
and subsequently to class dsCMatrix.
Ord, J. K. (1975). Estimation methods for models of spatial interaction. Journal of the American Statistical Association, 70(349), 120-126. doi:10.2307/2285387
data(USCounties, package = "Matrix")
(n <- ncol(USCounties))
#> [1] 3111
I <- .symDiagonal(n)
set.seed(1)
r <- 50L
rho <- 1 / runif(r, 0, 0.5)
system.time(MJ0 <- sapply(rho, function(mult)
determinant(USCounties + mult * I, logarithm = TRUE)$modulus))
#> user system elapsed
#> 0.255 0.020 0.276
## Can be done faster by updating the Cholesky factor:
C1 <- Cholesky(USCounties, Imult = 2)
system.time(MJ1 <- sapply(rho, function(mult)
determinant(update(C1, USCounties, mult), sqrt = FALSE)$modulus))
#> user system elapsed
#> 0.078 0.000 0.077
stopifnot(all.equal(MJ0, MJ1))
C2 <- Cholesky(USCounties, super = TRUE, Imult = 2)
#> Warning: CHOLMOD warning 'matrix not positive definite' at file 'Supernodal/t_cholmod_super_numeric_worker.c', line 1114
#> Error in .local(A, ...): leading principal minor of order 1550 is not positive
system.time(MJ2 <- sapply(rho, function(mult)
determinant(update(C2, USCounties, mult), sqrt = FALSE)$modulus))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'determinant': error in evaluating the argument 'object' in selecting a method for function 'update': object 'C2' not found
#> Timing stopped at: 0 0 0
stopifnot(all.equal(MJ0, MJ2))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'current' in selecting a method for function 'all.equal': object 'MJ2' not found