do_ldet {spdep} | R Documentation |
These functions are made available in the package namespace for other developers, and are not intended for users. They provide a shared infrastructure for setting up data for Jacobian computation, and then for caclulating the Jacobian, either exactly or approximately, in maximum likelihood fitting of spatial regression models. The techniques used are the exact eigenvalue, Cholesky decompositions (Matrix, spam), and LU ones, with Chebyshev and Monte Carlo approximations; moments use the methods due to Martin and Smirnov/Anselin.
do_ldet(coef, env, which=1) cheb_setup(env, q=5, which=1) mcdet_setup(env, p=16, m=30, which=1) eigen_setup(env, which=1) spam_setup(env, pivot="MMD", which=1) spam_update_setup(env, in_coef=0.1, pivot="MMD", which=1) Matrix_setup(env, Imult, super=as.logical(NA), which=1) Matrix_J_setup(env, super=FALSE, which=1) LU_setup(env, which=1) moments_setup(env, trs=NULL, m, p, type="MC", correct=TRUE, trunc=TRUE, which=1)
coef |
spatial coefficient value |
env |
environment containing pre-computed objects, fixed after assignment in setup functions |
which |
default 1; if 2, use second listw object |
q |
Chebyshev approximation order; default in calling spdep functions is 5, here it cannot be missing and does not have a default |
p |
Monte Carlo approximation number of random normal variables; default calling spdep functions is 16, here it cannot be missing and does not have a default |
m |
Monte Carlo approximation number of series terms; default in calling spdep functions is 30, here it cannot be missing and does not have a default; |
pivot |
default “MMD”, may also be “RCM” for Cholesky decompisition using spam |
in_coef |
fill-in initiation coefficient value, default 0.1 |
Imult |
see |
super |
see |
trs |
A numeric vector of |
type |
moments trace type, see |
correct |
default TRUE: use Smirnov correction term, see |
trunc |
default TRUE: truncate Smirnov correction term, see |
Since environments are containers in the R workspace passed by reference rather than by value, they are useful for passing objects to functions called in numerical optimisation, here for the maximum likelihood estimation of spatial regression models. This technique can save a little time on each function call, balanced against the need to access the objects in the environment inside the function. The environment should contain a family
string object either “SAR”, “CAR” or “SMA” (used in do_ldet
to choose spatial moving average in spautolm
, and these specific objects before calling the set-up functions:
Classical Ord eigenvalue computations:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
logical scalar: legacy report print control, for historical reasons only
and assigns to the environment:
a vector of eigenvalues
the search interval for the spatial coefficient
string: “eigen”
Sparse matrix pre-computed Cholesky decomposition with fast updating:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
and assigns to the environment:
Standard Cholesky decomposition without updating:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
number of spatial objects
and assigns to the environment:
sparse spatial weights matrix
sparse identity matrix
the value of the super
argument
string: “Matrix_J”
Standard Cholesky decomposition without updating:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
number of spatial objects
and assigns to the environment:
sparse spatial weights matrix
sparse identity matrix
string — pivot method
string: “spam”
Pre-computed Cholesky decomposition with updating:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
number of spatial objects
and assigns to the environment:
sparse spatial weights matrix
sparse identity matrix
A Cholesky decomposition for updating
string: “spam”
Standard LU decomposition without updating:
A listw spatial weights object
number of spatial objects
and assigns to the environment:
sparse spatial weights matrix
sparse identity matrix
string: “LU”
Monte Carlo approximation:
A listw spatial weights object
and assigns to the environment:
list of Monte Carlo approximation terms (the first two simulated traces are replaced by their analytical equivalents)
sparse spatial weights matrix
string: “MC”
Chebyshev approximation:
A listw spatial weights object
and assigns to the environment:
vector of Chebyshev approximation terms
sparse spatial weights matrix
string: “Chebyshev”
moments approximation:
A listw spatial weights object
logical scalar: can the spatial weights be made symmetric by similarity
and assigns to the environment:
vector of traces, possibly approximated
logical scalar: use Smirnov correction term
logical scalar: truncate Smirnov correction term
string: “moments”
Some set-up functions may also assign similar
to the environment if the weights were made symmetric by similarity.
do_ldet
returns the value of the Jacobian for the calculation method recorded in the environment argument, and for the Monte Carlo approximation, returns a measure of the spread of the approximation as an “sd” attribute; the remaining functions modify the environment in place as a side effect and return nothing.
Roger Bivand Roger.Bivand@nhh.no
LeSage J and RK Pace (2009) Introduction to Spatial Econometrics. CRC Press, Boca Raton, pp. 77–110
spautolm
, lagsarlm
, errorsarlm
, Cholesky
data(boston) lw <- nb2listw(boston.soi) can.sim <- spdep:::can.be.simmed(lw) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("can.sim", can.sim, envir=env) assign("similar", FALSE, envir=env) assign("verbose", FALSE, envir=env) assign("family", "SAR", envir=env) eigen_setup(env) get("similar", envir=env) do_ldet(0.5, env) rm(env) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("can.sim", can.sim, envir=env) assign("similar", FALSE, envir=env) assign("family", "SAR", envir=env) assign("n", length(boston.soi), envir=env) Matrix_setup(env, Imult=2, super=FALSE) get("similar", envir=env) do_ldet(0.5, env) rm(env) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("n", length(boston.soi), envir=env) assign("can.sim", can.sim, envir=env) assign("similar", FALSE, envir=env) assign("family", "SAR", envir=env) spam_setup(env) get("similar", envir=env) do_ldet(0.5, env) rm(env) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("n", length(boston.soi), envir=env) assign("similar", FALSE, envir=env) assign("family", "SAR", envir=env) LU_setup(env) get("similar", envir=env) do_ldet(0.5, env) rm(env) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("similar", FALSE, envir=env) assign("family", "SAR", envir=env) cheb_setup(env, q=5) get("similar", envir=env) do_ldet(0.5, env) rm(env) env <- new.env(parent=globalenv()) assign("listw", lw, envir=env) assign("n", length(boston.soi), envir=env) assign("similar", FALSE, envir=env) assign("family", "SAR", envir=env) set.seed(12345) mcdet_setup(env, p=16, m=30) get("similar", envir=env) do_ldet(0.5, env) rm(env)