wrld_1deg.RdThis matrix gives the contiguities of 15260 one-degree grid cells of world land areas, using a criterion based on the great-circle distance between centers.
data(wrld_1deg)A \(15260 \times 15260\) sparse, symmetric
matrix of class dsCMatrix, with 55973
nonzero entries.
Shoreline data were read into R from the GSHHS database
using function Rgshhs from package maptools.
Antarctica was excluded. An approximately one-degree grid
was generated using function Sobj_SpatialGrid, also
from maptools. Grid cells with centers on land
were identified using the over method for classes
SpatialPolygons and SpatialGrid, defined in
package sp. Neighbours of these were identified
by passing the resulting SpatialPixels object to
function dnearneigh from package spdep,
using as a cut-off a great-circle distance of sqrt(2)
kilometers between centers.
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(wrld_1deg, package = "Matrix")
(n <- ncol(wrld_1deg))
#> [1] 15260
I <- .symDiagonal(n)
doExtras <- interactive() || nzchar(Sys.getenv("R_MATRIX_CHECK_EXTRA"))
set.seed(1)
r <- if(doExtras) 20L else 3L
rho <- 1 / runif(r, 0, 0.5)
system.time(MJ0 <- sapply(rho, function(mult)
determinant(wrld_1deg + mult * I, logarithm = TRUE)$modulus))
#> user system elapsed
#> 0.092 0.000 0.092
## Can be done faster by updating the Cholesky factor:
C1 <- Cholesky(wrld_1deg, Imult = 2)
system.time(MJ1 <- sapply(rho, function(mult)
determinant(update(C1, wrld_1deg, mult), sqrt = FALSE)$modulus))
#> user system elapsed
#> 0.041 0.000 0.042
stopifnot(all.equal(MJ0, MJ1))
C2 <- Cholesky(wrld_1deg, 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 813 is not positive
system.time(MJ2 <- sapply(rho, function(mult)
determinant(update(C2, wrld_1deg, 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.001 0 0.001
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