Learn R Programming

spdep (version 0.5-33)

trW: Spatial weights matrix powers traces

Description

The function is used to prepare a vector of traces of pwers of a spatial weights matrix

Usage

trW(W=NULL, m = 30, p = 16, type = "mult", listw=NULL)

Arguments

W
A spatial weights matrix in CsparseMatrix form
m
The number of powers; must be an even number for type=moments (default changed from 100 to 30 (2010-11-17))
p
The number of samples used in Monte Carlo simulation of the traces if type is MC (default changed from 50 to 16 (2010-11-17))
type
Either mult (default) for powering a sparse matrix (with moderate or larger N, the matrix becomes dense, and may lead to swapping), or MC for Monte Carlo simulation of the traces, or moments to use the lo
listw
a listw object, which should either be fully symmetric, or be constructed as similar to symmetric from intrinsically symmetric neighbours using similar.listw, used with type=m

Value

  • A numeric vector of m traces.

References

LeSage J and RK Pace (2009) Introduction to Spatial Econometrics. CRC Press, Boca Raton, pp. 96--105; Smirnov O and L Anselin (2009) An O(N) parallel method of computing the Log-Jacobian of the variable transformation for models with spatial interaction on a lattice. Computational Statistics and Data Analysis 53 (2009) 2983--2984.

See Also

as_dgRMatrix_listw, nb2listw

Examples

Run this code
example(columbus)
listw <- nb2listw(col.gal.nb)
W <- as(as_dgRMatrix_listw(listw), "CsparseMatrix")
system.time(trMat <- trW(W, type="mult"))
str(trMat)
set.seed(1)
system.time(trMC <- trW(W, type="MC"))
str(trMC)
plot(trMat, trMC)
listwS <- similar.listw(listw)
W <- as(as(as_dgRMatrix_listw(listwS), "CsparseMatrix"), "symmetricMatrix")
system.time(trmom <- trW(W, m=24, type="moments"))
str(trmom)
all.equal(trMat[1:24], trmom, check.attributes=FALSE)
system.time(trMat <- trW(W, m=24, type="mult"))
str(trMat)
all.equal(trMat, trmom, check.attributes=FALSE)
set.seed(1)
system.time(trMC <- trW(W, m=24, type="MC"))
str(trMC)

Run the code above in your browser using DataLab