├── .Rbuildignore ├── .github └── workflows │ └── check-standard.yaml ├── ChangeLog ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── AAA.R ├── ME.R ├── ML_models.R ├── SLX_WX.R ├── SpatialFiltering.R ├── aple.R ├── aple.mc.R ├── apleplot.R ├── cyclical.R ├── eigenw.R ├── impacts.R ├── jacobian.R ├── jacobian_setup.R ├── kpgm_new.R ├── lextrB.R ├── lextrW.R ├── mcmcsamp.R ├── mess.R ├── predict.sarlm.R ├── s2sls.R ├── sarlm_functions.R ├── sarlm_tests.R ├── spBreg.R ├── spChkOption.R ├── sparse_mat.R ├── spautolm.R └── spautolm_functions.R ├── README.md ├── _pkgdown.yml ├── docs ├── 404.html ├── articles │ ├── SpatialFiltering.html │ ├── SpatialFiltering_files │ │ └── figure-html │ │ │ └── unnamed-chunk-6-1.png │ ├── index.html │ ├── nb_igraph.html │ ├── nb_igraph_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-13-1.png │ │ │ └── unnamed-chunk-5-1.png │ ├── sids_models.html │ └── sids_models_files │ │ └── figure-html │ │ ├── unnamed-chunk-13-1.png │ │ └── unnamed-chunk-14-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── deps │ ├── bootstrap-5.3.1 │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ └── bootstrap.min.css │ ├── bootstrap-toc-1.0.1 │ │ └── bootstrap-toc.min.js │ ├── clipboard.js-2.0.11 │ │ └── clipboard.min.js │ ├── data-deps.txt │ ├── font-awesome-6.5.2 │ │ ├── css │ │ │ ├── all.css │ │ │ ├── all.min.css │ │ │ ├── v4-shims.css │ │ │ └── v4-shims.min.css │ │ └── webfonts │ │ │ ├── fa-brands-400.ttf │ │ │ ├── fa-brands-400.woff2 │ │ │ ├── fa-regular-400.ttf │ │ │ ├── fa-regular-400.woff2 │ │ │ ├── fa-solid-900.ttf │ │ │ ├── fa-solid-900.woff2 │ │ │ ├── fa-v4compatibility.ttf │ │ │ └── fa-v4compatibility.woff2 │ ├── headroom-0.11.0 │ │ ├── headroom.min.js │ │ └── jQuery.headroom.min.js │ ├── jquery-3.6.0 │ │ ├── jquery-3.6.0.js │ │ ├── jquery-3.6.0.min.js │ │ └── jquery-3.6.0.min.map │ └── search-1.0.0 │ │ ├── autocomplete.jquery.min.js │ │ ├── fuse.min.js │ │ └── mark.min.js ├── docsearch.css ├── docsearch.js ├── index.html ├── katex-auto.js ├── lightswitch.js ├── link.svg ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── GMargminImage.html │ ├── GMerrorsar-1.png │ ├── GMerrorsar.html │ ├── HPDinterval.LagImpact.html │ ├── Hausman.test.Gmsar.html │ ├── Hausman.test.Sarlm.html │ ├── Hausman.test.html │ ├── Jacobian_W.html │ ├── LR1.Lagmess.html │ ├── LR1.Sarlm.html │ ├── LR1.Spautolm.html │ ├── LU_prepermutate_setup.html │ ├── LU_setup.html │ ├── MCMCsamp.Sarlm.html │ ├── MCMCsamp.Spautolm.html │ ├── MCMCsamp.html │ ├── ME.html │ ├── ML_models.html │ ├── Matrix_J_setup.html │ ├── Matrix_setup.html │ ├── SET_MCMC.html │ ├── SE_classic_setup.html │ ├── SE_interp_setup.html │ ├── SE_whichMin_setup.html │ ├── SLX.html │ ├── SpatialFiltering.html │ ├── Wald1.Sarlm.html │ ├── anova.Sarlm.html │ ├── aple.html │ ├── aple.mc-1.png │ ├── aple.mc.html │ ├── aple.plot-1.png │ ├── aple.plot-2.png │ ├── aple.plot-3.png │ ├── aple.plot.html │ ├── as.data.frame.Sarlm.pred.html │ ├── as_dgRMatrix_listw.html │ ├── as_dsCMatrix_I.html │ ├── as_dsCMatrix_IrW.html │ ├── as_dsTMatrix_listw.html │ ├── bptest.Sarlm.html │ ├── can.be.simmed.html │ ├── cheb_setup.html │ ├── coef.Gmsar.html │ ├── coef.Lagmess.html │ ├── coef.Sarlm.html │ ├── coef.Spautolm.html │ ├── coef.Stsls.html │ ├── coerce,listw,CsparseMatrix-method.html │ ├── coerce,listw,RsparseMatrix-method.html │ ├── coerce,listw,symmetricMatrix-method.html │ ├── create_WX.html │ ├── deviance.Gmsar.html │ ├── deviance.Lagmess.html │ ├── deviance.Sarlm.html │ ├── deviance.Spautolm.html │ ├── deviance.Stsls.html │ ├── do_ldet.html │ ├── eigen_pre_setup.html │ ├── eigen_setup.html │ ├── eigenw.html │ ├── errorsarlm.html │ ├── fitted.Gmsar.html │ ├── fitted.Lagmess.html │ ├── fitted.Me_res.html │ ├── fitted.Sarlm.html │ ├── fitted.SfResult.html │ ├── fitted.Spautolm.html │ ├── get.ClusterOption.html │ ├── get.VerboseOption.html │ ├── get.ZeroPolicyOption.html │ ├── get.coresOption.html │ ├── get.mcOption.html │ ├── gstsls-1.png │ ├── gstsls.html │ ├── impacts.Gmsar.html │ ├── impacts.Lagmess.html │ ├── impacts.MCMC_sac_G.html │ ├── impacts.MCMC_sar_G.html │ ├── impacts.MCMC_sem_G.html │ ├── impacts.Sarlm.html │ ├── impacts.SlX.html │ ├── impacts.Stsls.html │ ├── impacts.html │ ├── index.html │ ├── intImpacts.html │ ├── invIrM-1.png │ ├── invIrM.html │ ├── invIrW.html │ ├── jacobianSetup.html │ ├── l_max.html │ ├── lagmess.html │ ├── lagsarlm.html │ ├── lextrB.html │ ├── lextrS.html │ ├── lextrW.html │ ├── listw2U_Matrix.html │ ├── listw2U_spam.html │ ├── localAple.html │ ├── logLik.Lagmess.html │ ├── logLik.Sarlm.html │ ├── logLik.Spautolm.html │ ├── mcdet_setup.html │ ├── mom_calc.html │ ├── mom_calc_int2.html │ ├── moments_setup.html │ ├── plot.LagImpact.html │ ├── powerWeights.html │ ├── predict.SlX.html │ ├── predict.sarlm.html │ ├── print.Gmsar.html │ ├── print.LagImpact.html │ ├── print.Lagmess.html │ ├── print.Me_res.html │ ├── print.Sarlm.html │ ├── print.Sarlm.pred.html │ ├── print.SfResult.html │ ├── print.SlX.html │ ├── print.Spautolm.html │ ├── print.Stsls.html │ ├── print.WXimpact.html │ ├── print.summary.Gmsar.html │ ├── print.summary.LagImpact.html │ ├── print.summary.Lagmess.html │ ├── print.summary.Sarlm.html │ ├── print.summary.SlX.html │ ├── print.summary.Spautolm.html │ ├── print.summary.Stsls.html │ ├── print.summary.WXimpact.html │ ├── residuals.Gmsar.html │ ├── residuals.Lagmess.html │ ├── residuals.Sarlm.html │ ├── residuals.Spautolm.html │ ├── residuals.Stsls.html │ ├── sacsarlm.html │ ├── sarlm_tests.html │ ├── set.ClusterOption.html │ ├── set.VerboseOption.html │ ├── set.coresOption.html │ ├── set.mcOption.html │ ├── set.spChkOption.html │ ├── similar.listw.html │ ├── spBreg_err.html │ ├── spBreg_sac.html │ ├── spam_setup.html │ ├── spam_update_setup.html │ ├── sparse_mat.html │ ├── spautolm.html │ ├── stsls.html │ ├── subgraph_eigenw.html │ ├── summary.Gmsar.html │ ├── summary.LagImpact.html │ ├── summary.Lagmess.html │ ├── summary.Sarlm.html │ ├── summary.SlX.html │ ├── summary.Spautolm.html │ ├── summary.Stsls.html │ ├── summary.WXimpact.html │ ├── trW-1.png │ ├── trW.html │ └── vcov.Sarlm.html ├── search.json └── sitemap.xml ├── inst ├── CITATION ├── ChangeLog ├── README └── tinytest │ ├── test_Durbin.R │ ├── test_Durbin_factor.R │ ├── test_SLX_no_intercept.R │ ├── test_SLX_not_W.R │ └── test_TR_20_07_20.R ├── man ├── GMerrorsar.Rd ├── MCMCsamp.Rd ├── ME.Rd ├── ML_models.Rd ├── SET_MCMC.Rd ├── SLX.Rd ├── SpatialFiltering.Rd ├── aple.Rd ├── aple.mc.Rd ├── aple.plot.Rd ├── do_ldet.Rd ├── eigenw.Rd ├── gstsls.Rd ├── impacts.Rd ├── invIrM.Rd ├── lagmess.Rd ├── lextrB.Rd ├── predict.sarlm.Rd ├── sarlm_tests.Rd ├── set.mcOption.Rd ├── set.spChkOption.Rd ├── similar.listw.Rd ├── sparse_mat.Rd ├── spautolm.Rd ├── stsls.Rd └── trW.Rd ├── src ├── Makevars ├── eminmaxC.c ├── init.c ├── listw2Matrix.c ├── ml_sse.c ├── mom_calc.c └── spatialreg.h ├── tests └── tinytest.R └── vignettes ├── SpatialFiltering.Rmd ├── nb_igraph.Rmd ├── refs.bib └── sids_models.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | README.md 2 | ChangeLog 3 | ^\.travis\.yml$ 4 | ^docs$ 5 | .github 6 | .git 7 | _pkgdown.yml 8 | -------------------------------------------------------------------------------- /.github/workflows/check-standard.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | 4 | on: 5 | push: 6 | branches: [main, master] 7 | pull_request: 8 | branches: [main, master] 9 | 10 | name: R-CMD-check 11 | 12 | jobs: 13 | R-CMD-check: 14 | runs-on: ${{ matrix.config.os }} 15 | 16 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 17 | 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | config: 22 | - {os: windows-latest, r: 'release'} 23 | - {os: macOS-latest, r: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 26 | - {os: ubuntu-latest, r: 'oldrel-1'} 27 | - {os: ubuntu-latest, r: 'oldrel-2'} 28 | 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 31 | R_KEEP_PKG_SOURCE: yes 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - uses: r-lib/actions/setup-pandoc@v2 37 | 38 | - uses: r-lib/actions/setup-r@v2 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | http-user-agent: ${{ matrix.config.http-user-agent }} 42 | use-public-rspm: true 43 | 44 | - uses: r-lib/actions/setup-r-dependencies@v2 45 | with: 46 | extra-packages: any::rcmdcheck 47 | needs: check 48 | 49 | - uses: r-lib/actions/check-r-package@v2 50 | with: 51 | upload-snapshots: true 52 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: spatialreg 2 | Version: 1.3-7 3 | Date: 2025-04-25 4 | Title: Spatial Regression Analysis 5 | Encoding: UTF-8 6 | Authors@R: c(person("Roger", "Bivand", role = c("cre", "aut"), email = "Roger.Bivand@nhh.no", comment=c(ORCID="0000-0003-2392-6140")), 7 | person(given = "Gianfranco", family = "Piras", role = c("aut"), email = "gpiras@mac.com"), 8 | person("Luc", "Anselin", role = "ctb"), 9 | person("Andrew", "Bernat", role = "ctb"), 10 | person("Eric", "Blankmeyer", role = "ctb"), 11 | person("Yongwan", "Chun", role = "ctb"), 12 | person("Virgilio", "Gómez-Rubio", role = "ctb"), 13 | person("Daniel", "Griffith", role = "ctb"), 14 | person("Martin", "Gubri", role = "ctb"), 15 | person("Rein", "Halbersma", role = "ctb"), 16 | person("James", "LeSage", role = "ctb"), 17 | person("Angela", "Li", role = "ctb"), 18 | person("Hongfei", "Li", role = "ctb"), 19 | person("Jielai", "Ma", role = "ctb"), 20 | person("Abhirup", "Mallik", role = c("ctb", "trl")), 21 | person("Giovanni", "Millo", role = "ctb"), 22 | person("Kelley", "Pace", role = "ctb"), 23 | person("Josiah", "Parry", role = "ctb", comment = c(ORCID = "0000-0001-9910-865X")), 24 | person("Pedro", "Peres-Neto", role = "ctb"), 25 | person("Tobias", "Rüttenauer", role = "ctb"), 26 | person(given = "Mauricio", family = "Sarrias", role = c("ctb"), email = "mauricio.sarrias@ucn.cl"), 27 | person(given = "JuanTomas", family = "Sayago", role = c("ctb"), email = "juantomas.sayago@gmail.com"), 28 | person("Michael", "Tiefelsdorf", role = "ctb")) 29 | Depends: R (>= 3.3.0), spData (>= 2.3.1), Matrix, sf 30 | Imports: spdep (>= 1.3-11), coda, methods, MASS, boot, splines, LearnBayes, 31 | nlme, multcomp 32 | Suggests: parallel, RSpectra, tmap, foreign, spam, knitr, lmtest, expm, 33 | sandwich, rmarkdown, igraph (>= 2.0.0), tinytest 34 | Description: A collection of all the estimation functions for spatial cross-sectional models (on lattice/areal data using spatial weights matrices) contained up to now in 'spdep'. These model fitting functions include maximum likelihood methods for cross-sectional models proposed by 'Cliff' and 'Ord' (1973, ISBN:0850860369) and (1981, ISBN:0850860814), fitting methods initially described by 'Ord' (1975) . The models are further described by 'Anselin' (1988) . Spatial two stage least squares and spatial general method of moment models initially proposed by 'Kelejian' and 'Prucha' (1998) and (1999) are provided. Impact methods and MCMC fitting methods proposed by 'LeSage' and 'Pace' (2009) are implemented for the family of cross-sectional spatial regression models. Methods for fitting the log determinant term in maximum likelihood and MCMC fitting are compared by 'Bivand et al.' (2013) , and model fitting methods by 'Bivand' and 'Piras' (2015) ; both of these articles include extensive lists of references. A recent review is provided by 'Bivand', 'Millo' and 'Piras' (2021) . 'spatialreg' >= 1.1-* corresponded to 'spdep' >= 1.1-1, in which the model fitting functions were deprecated and passed through to 'spatialreg', but masked those in 'spatialreg'. From versions 1.2-*, the functions have been made defunct in 'spdep'. From version 1.3-6, add Anselin-Kelejian (1997) test to `stsls` for residual spatial autocorrelation . 35 | License: GPL-2 36 | URL: https://github.com/r-spatial/spatialreg/, https://r-spatial.github.io/spatialreg/ 37 | BugReports: https://github.com/r-spatial/spatialreg/issues/ 38 | VignetteBuilder: knitr 39 | NeedsCompilation: yes 40 | RoxygenNote: 6.1.1 41 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(spatialreg) 2 | 3 | import(spData) 4 | 5 | importFrom("stats", "lm.fit", "as.formula", "coef", "lm", "model.extract", 6 | "model.matrix", "na.fail", "napredict", "pnorm", 7 | "printCoefmat", "quantile", "residuals", "terms", 8 | "coefficients", "deviance", "nlminb", "optim", 9 | "pchisq", "summary.lm", "var", "logLik", "optimHess", 10 | "gaussian", "glm.fit", "model.offset", "model.weights", 11 | "rnorm", "sd", "predict", "AIC", "nlm", "optimize", 12 | "dbeta", "rchisq", "runif", "spline", "fitted", "formula", 13 | "model.response", "anova", "delete.response", "fitted.values", 14 | "model.frame") 15 | 16 | importFrom("spdep", "is.symmetric.glist", "lag.listw", "card", 17 | "nb2listw", "n.comp.nb", "listw2U", "listw2mat", "Szero", "listw2sn", 18 | "mat2listw", "is.symmetric.nb", "chkIDs", "get.spChkOption", 19 | "subset.listw", "spweights.constants", "have_factor_preds_mf", 20 | "warn_factor_preds") 21 | 22 | import(Matrix#, except=c("expm") 23 | ) 24 | import(sf) 25 | #importFrom(expm, expAtv, expm) 26 | importFrom(coda, as.mcmc, HPDinterval) 27 | importFrom(MASS, mvrnorm) 28 | importFrom(boot, boot) 29 | importFrom("methods", "new", "is", "slot", "as") 30 | importFrom("graphics", "plot") 31 | importFrom(splines, interpSpline) 32 | importFrom(LearnBayes, rwmetrop) 33 | importFrom(nlme, fdHess) 34 | importFrom(multcomp, glht) 35 | importFrom("utils", "packageVersion") 36 | 37 | ################## 38 | # ML SE 39 | export(errorsarlm, lagsarlm, sacsarlm) 40 | export(trW, impacts, intImpacts) 41 | export(bptest.Sarlm, LR.Sarlm, LR1.Sarlm, Wald1.Sarlm, Hausman.test) 42 | 43 | S3method(print, Sarlm) 44 | S3method(summary, Sarlm) 45 | S3method(residuals, Sarlm) 46 | S3method(deviance, Sarlm) 47 | S3method(coef, Sarlm) 48 | S3method(vcov, Sarlm) 49 | S3method(fitted, Sarlm) 50 | S3method(logLik, Sarlm) 51 | S3method(anova, Sarlm) 52 | S3method(predict, Sarlm) 53 | S3method(impacts, Sarlm) 54 | S3method(Hausman.test, Sarlm) 55 | S3method(MCMCsamp, Sarlm) 56 | 57 | S3method(print, summary.Sarlm) 58 | S3method(coef, summary.Sarlm) 59 | 60 | S3method(print, Sarlm.pred) 61 | S3method(as.data.frame, Sarlm.pred) 62 | 63 | # ML SAR/CAR/SMA 64 | export(spautolm, LR1.Spautolm) 65 | 66 | S3method(MCMCsamp, Spautolm) 67 | S3method(residuals, Spautolm) 68 | S3method(deviance, Spautolm) 69 | S3method(coef, Spautolm) 70 | S3method(fitted, Spautolm) 71 | S3method(print, Spautolm) 72 | S3method(summary, Spautolm) 73 | S3method(logLik, Spautolm) 74 | 75 | S3method(print, summary.Spautolm) 76 | S3method(coef, summary.Spautolm) 77 | 78 | # GMM SE 79 | export(stsls) 80 | 81 | S3method(residuals, Stsls) 82 | S3method(deviance, Stsls) 83 | S3method(coef, Stsls) 84 | S3method(print, Stsls) 85 | S3method(summary, Stsls) 86 | S3method(impacts, Stsls) 87 | 88 | S3method(print, summary.Stsls) 89 | S3method(coef, summary.Stsls) 90 | 91 | export(GMerrorsar, gstsls, GMargminImage) 92 | 93 | S3method(residuals, Gmsar) 94 | S3method(deviance, Gmsar) 95 | S3method(coef, Gmsar) 96 | S3method(fitted, Gmsar) 97 | S3method(print, Gmsar) 98 | S3method(summary, Gmsar) 99 | S3method(Hausman.test, Gmsar) 100 | S3method(impacts, Gmsar) 101 | 102 | S3method(coef, summary.Gmsar) 103 | S3method(print, summary.Gmsar) 104 | 105 | # ML MESS 106 | export(lagmess, LR1.Lagmess) 107 | 108 | S3method(print, Lagmess) 109 | S3method(summary, Lagmess) 110 | S3method(print, summary.Lagmess) 111 | S3method(residuals, Lagmess) 112 | S3method(deviance, Lagmess) 113 | S3method(coef, Lagmess) 114 | S3method(coef, summary.Lagmess) 115 | S3method(fitted, Lagmess) 116 | S3method(logLik, Lagmess) 117 | S3method(impacts, Lagmess) 118 | 119 | # MCMC SET 120 | export(spBreg_lag, spBreg_err, spBreg_sac) 121 | 122 | S3method(impacts, MCMC_sar_G) 123 | S3method(impacts, MCMC_sem_G) 124 | S3method(impacts, MCMC_sac_G) 125 | 126 | # SLX 127 | export(lmSLX, create_WX) 128 | 129 | S3method(impacts, SlX) 130 | S3method(predict, SlX) 131 | S3method(print, SlX) 132 | S3method(summary, SlX) 133 | S3method(print, summary.SlX) 134 | 135 | # SF/ME 136 | export(SpatialFiltering, ME) 137 | 138 | S3method(fitted, SfResult) 139 | S3method(print, SfResult) 140 | S3method(fitted, Me_res) 141 | S3method(print, Me_res) 142 | 143 | # Impacts 144 | 145 | S3method(print, LagImpact) 146 | S3method(plot, LagImpact) 147 | S3method(summary, LagImpact) 148 | S3method(HPDinterval, LagImpact) 149 | S3method(print, summary.LagImpact) 150 | 151 | S3method(print, WXimpact) 152 | S3method(summary, WXimpact) 153 | S3method(print, summary.WXimpact) 154 | 155 | exportMethods(coerce) 156 | 157 | export(as_dgRMatrix_listw, as_dsTMatrix_listw, as_dsCMatrix_I, 158 | as_dsCMatrix_IrW, Jacobian_W, listw2U_Matrix) 159 | 160 | export(powerWeights, invIrW, invIrM) 161 | 162 | export(as.spam.listw, listw2U_spam) 163 | 164 | export(lextrB, lextrW, lextrS, l_max) 165 | 166 | export(griffith_sone, subgraph_eigenw) 167 | 168 | export(mom_calc, mom_calc_int2) 169 | 170 | export(MCMCsamp) 171 | 172 | export(eigenw, jacobianSetup, can.be.simmed, similar.listw) 173 | 174 | export(do_ldet, eigen_setup, mcdet_setup, cheb_setup, spam_setup, 175 | Matrix_setup, LU_setup, Matrix_J_setup, spam_update_setup, 176 | moments_setup, SE_classic_setup, SE_whichMin_setup, SE_interp_setup, 177 | LU_prepermutate_setup, eigen_pre_setup) 178 | 179 | export(set.mcOption, get.mcOption, set.coresOption, get.coresOption, 180 | set.ClusterOption, get.ClusterOption) 181 | 182 | export(set.VerboseOption, get.VerboseOption, set.ZeroPolicyOption, 183 | get.ZeroPolicyOption) 184 | 185 | export(aple.plot, localAple, aple, aple.mc) 186 | 187 | 188 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Version 1.3-7 (development) 2 | 3 | * introduce warnings for factors (categorical variables) in Durbin models (`errorsarlm`, `lagsarlm`, `sacsarlm`, `spBreg_lag`, `spBreg_err`, `spBreg_sac` and `lm.SLX`) 4 | 5 | * convert `error` to `Rf_error` in `src/ml_sse.c` to accommodate R_NO_REMAP 6 | 7 | # Version 1.3-6 (2024-12-02) 8 | 9 | * Remove remaining `spData` ESRI shapefile use 10 | 11 | * #56 add Anselin-Kelejian (1997) test to `stsls`, reported in its summary method, analogous to the reporting in the summary method of `lagsarlm` of the Lagrange multiplier test, both for residual spatial autocorrelation 12 | 13 | * adding missing man page anchors 14 | 15 | # Version 1.3-5 (2024-08-19) 16 | 17 | * conforming with STRICT_R_HEADERS=1 18 | 19 | * Condition on forthcoming `tmap` 4 20 | 21 | * #52 subgraph updates 22 | 23 | # Version 1.3-4 (2024-06-10) 24 | 25 | * migrate from ESRI Shapefile to GeoPackage #50 26 | 27 | # Version 1.3-3 (2024-05-31) 28 | 29 | * protect `errorsarlm` against missing `Durbin=` if only intercept 30 | 31 | * fix longstanding bugs in `getVmate` in a non-default side logic branch 32 | 33 | * add `return_impacts=` to `lmSLX` to work around issues with aliased variables; impacts should be improved to handle this case when time permits 34 | 35 | * add `sqrt=TRUE` in calls to Matrix `determinant` methods in `matrix_ldet` 36 | 37 | * add `igraph (>= 2.0.0)` in DESCRIPTION for re-named `igraph` functions 38 | 39 | # Version 1.3-2 (2024-02-06) 40 | 41 | * pass through SlX formula in call 42 | 43 | * re-corrected #19 because the fitted model weights component may be NULL 44 | 45 | * suppress warning from `multcomp::glht` as the test which throws the warning is discarded 46 | 47 | # Version 1.3-1 (2023-11-23) 48 | 49 | * move `expm` from Imports to Suggests #42 50 | 51 | * added `zero.policy` pass-through to `spdep::mat2listw` calls in `predict.Sarlm` and to `spdep::sn2listw` in `sids_models.Rmd`; set `spdep` requirement to `1.3-1` 52 | 53 | * corrected #19 because the fitted model weights component is never NULL, but may have a single unique value 54 | 55 | # Version 1.2-9 (2023-05-25) 56 | 57 | * raised #39, no support for weights in SEM/SDEM/SLX #39 58 | 59 | * address #37; #38 remains (no formula Durbin support for prediction using any Sarlm object) 60 | 61 | * address #19 by not reporting `AIC` where case weights are used in `spautolm` or `errorsarlm` 62 | 63 | * address bug in `predict()` for new data, SDEM. Others in #37, #38 need work. 64 | 65 | * Further added checking for SLX/SDEM impacts and edge/corner cases; starting transition to use **multcomp** in place og **gmodels** 66 | 67 | # Version 1.2-8 (2023-03-01) 68 | 69 | * Attending to SLX/Durbin/non-W-style weights: #7, #36, #26, #35, #30 #24, #23, partly based on #13 70 | 71 | # Version 1.2-6 (2022-10-07) 72 | 73 | * make local copy of `gmodels::estimable()` for lm objects only, add authors to package contributors 74 | 75 | * -Wstrict-prototypes fixes 76 | 77 | # Version 1.2-5 (2022-08-16) 78 | 79 | * updating coercion for **Matrix** 1.4-2 80 | 81 | * updating dontrun/donttest for package split (previously unchecked, mostly in `aple`) 82 | 83 | # Version 1.2-3 (2022-04-18) 84 | 85 | * protect definition of USE_FC_LEN_T 86 | 87 | * unescape underscores in help pages 88 | 89 | # Version 1.2-1 (2021-11-11) 90 | 91 | * Add Fortran character handling USE_FC_LEN_T WRE §6.6.1 92 | 93 | * Add **spdep** split-out functionality 94 | 95 | # Version 1.1-8 (2021-05-03) 96 | 97 | * #18 standardize use of `coef()` methods for (some) fitted model summary objects 98 | 99 | * https://github.com/tidymodels/broom/issues/1003#issuecomment-798694400 changing **spatialreg** model output class names: **spdep** `sarlm` -> **spatialreg** `Sarlm`, `spautolm` -> `Spautolm`, `stsls` -> `Stsls`, `gmsar` -> `Gmsar`, `lagmess` -> `Lagmess`, `SLX` -> , `SlX`, `MCMC_s*_g` -> `MCMC_s*_G`, `SFResult` -> `SfResult`, `ME_res` -> `Me_res`, `lagImpact` -> `LagImpact`, `WXImpact` -> `WXimpact` 100 | 101 | * #16 merged coordination of impacts methods (Gianfranco Piras) 102 | 103 | * #14 merged correction to SDEM and SLX impacts when a lagged intercept is present (Tobias Rüttenauer). 104 | 105 | # Version 1.1-5 (2019-12-01) 106 | 107 | * #6, #11 na.action and precomputed eigenvalue bug 108 | 109 | * #9 Griddy Gibbs issue 110 | 111 | * #8 Predict method for SLX 112 | 113 | * #7, #13-14 Offset impacts for SDEM/SLX 114 | 115 | * #5, #10 Panel Durbin= argument 116 | 117 | 118 | # Version 1.1-3 (2019-04-01) 119 | 120 | * #2 Split spatialreg from spdep; spdep functions still present there as deprecated 121 | 122 | -------------------------------------------------------------------------------- /R/AAA.R: -------------------------------------------------------------------------------- 1 | # Copyright 2019 by Roger Bivand 2 | # 3 | 4 | .spatialregOptions <- new.env(FALSE, globalenv()) 5 | #assign("spChkID", FALSE, envir = .spatialregOptions) 6 | assign("zeroPolicy", spdep::get.ZeroPolicyOption(), envir = .spatialregOptions) 7 | assign("verbose", spdep::get.VerboseOption(), envir = .spatialregOptions) 8 | assign("mc", spdep::get.mcOption(), envir = .spatialregOptions) 9 | assign("cores", spdep::get.coresOption(), envir = .spatialregOptions) 10 | assign("cluster", spdep::get.ClusterOption(), envir = .spatialregOptions) 11 | assign("rlecuyerSeed", rep(12345, 6), envir = .spatialregOptions) 12 | #assign("listw_is_CsparseMatrix", FALSE, envir = .spatialregOptions) 13 | 14 | setOldClass(c("listw")) 15 | 16 | .onLoad <- function(lib, pkg) { 17 | options(Matrix.warnDeprecatedCoerce = 1L) 18 | } 19 | 20 | Hausman.test <- function(object, ...) 21 | UseMethod("Hausman.test") 22 | 23 | -------------------------------------------------------------------------------- /R/aple.R: -------------------------------------------------------------------------------- 1 | preAple <- function(x, listw, override_similarity_check=FALSE, useTrace=TRUE) { 2 | stopifnot(isTRUE(all.equal(mean(x), 0.0))) 3 | stopifnot(is.vector(x)) 4 | # if (!requireNamespace("spatialreg", quietly=TRUE)) 5 | # stop("install the spatialreg package") 6 | W <- as(listw, "CsparseMatrix") 7 | n <- dim(W)[1] 8 | if (useTrace) { 9 | trWW <- sum(diag(W %*% W)) 10 | } else { 11 | if (listw$style %in% c("W", "S") && !override_similarity_check) { 12 | can.sim <- can.be.simmed(listw) 13 | eig <- eigenw(similar.listw(listw)) 14 | } else { 15 | can.sim <- FALSE 16 | eig <- eigenw(listw) 17 | } 18 | if (is.complex(eig)) trWW <- Re(crossprod(eig)) 19 | else trWW <- crossprod(eig) 20 | # modified 110414 RSB 21 | # eig <- Re(eig) 22 | # trWW <- crossprod(eig) 23 | } 24 | corterm <- (trWW/n) * Diagonal(n) 25 | corterm <- as(corterm, "CsparseMatrix") 26 | WU <- ((W + t(W))/2) 27 | W2 <- crossprod(W) + corterm 28 | res <- list(W=W, corterm=corterm, W2=W2, WU=WU, n=n) 29 | res 30 | } 31 | 32 | inAple <- function(x, pre) { 33 | xwx <- crossprod(x, (pre$WU %*% x)) 34 | xwwx <- crossprod(x, (pre$W2 %*% x)) 35 | res <- c(as.matrix(xwx/xwwx)) 36 | res 37 | } 38 | 39 | aple <- function(x, listw, override_similarity_check=FALSE, useTrace=TRUE) { 40 | pre <- preAple(x=x, listw=listw, 41 | override_similarity_check=override_similarity_check, useTrace=useTrace) 42 | res <- inAple(x=x, pre=pre) 43 | res 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /R/aple.mc.R: -------------------------------------------------------------------------------- 1 | aple.mc <- function(x, listw, nsim, override_similarity_check=FALSE, 2 | useTrace=TRUE) { 3 | aple.boot <- function(var, i, ...) { 4 | var <- var[i] 5 | return(inAple(x=var, ...)) 6 | } 7 | pre <- preAple(x=x, listw=listw, 8 | override_similarity_check=override_similarity_check, useTrace=useTrace) 9 | 10 | cores <- get.coresOption() 11 | if (is.null(cores)) { 12 | parallel <- "no" 13 | } else { 14 | parallel <- ifelse (get.mcOption(), "multicore", "snow") 15 | } 16 | ncpus <- ifelse(is.null(cores), 1L, cores) 17 | cl <- NULL 18 | if (parallel == "snow") { 19 | cl <- get.ClusterOption() 20 | if (is.null(cl)) { 21 | parallel <- "no" 22 | warning("no cluster in ClusterOption, parallel set to no") 23 | } 24 | } 25 | res <- boot(x, statistic=aple.boot, R=nsim, sim="permutation", pre=pre, 26 | parallel=parallel, ncpus=ncpus, cl=cl) 27 | 28 | res 29 | } 30 | 31 | boot_wrapper_in <- function(cl, nsim) { 32 | if (requireNamespace("parallel", quietly = TRUE)) { 33 | # require(rlecuyer) 34 | rlseed <- get("rlecuyerSeed", envir = .spatialregOptions) 35 | if (storage.mode(rlseed) != "integer") rlseed <- as.integer(rlseed) 36 | if (length(rlseed) != 6L) rlseed <- rep(12345L, 6) 37 | parallel::clusterSetRNGStream(cl, iseed=rlseed) 38 | parallel::clusterEvalQ(cl, library(spdep)) 39 | nnsim <- ceiling(nsim/length(cl)) 40 | nnsim 41 | } else { 42 | stop("parallel not available") 43 | } 44 | } 45 | 46 | boot_wrapper_out <- function(lres, mcall) { 47 | res <- list() 48 | res$t0 <- lres[[1]]$t0 49 | res$t <- matrix(c(sapply(lres, function(x) x$t)), ncol=1) 50 | res$R <- sum(sapply(lres, function(x) x$R)) 51 | res$data <- lres[[1]]$data 52 | res$seed <- c(sapply(lres, function(x) x$seed)) 53 | res$statistic <- lres[[1]]$statistic 54 | res$sim <- lres[[1]]$sim 55 | res$call <- mcall 56 | res$stype <- lres[[1]]$stype 57 | res$strata <- lres[[1]]$strata 58 | class(res) <- "boot" 59 | res 60 | } 61 | -------------------------------------------------------------------------------- /R/apleplot.R: -------------------------------------------------------------------------------- 1 | aple.plot <- function(x, listw, override_similarity_check=FALSE, useTrace=TRUE, 2 | do.plot=TRUE, ...) { 3 | pre <- preAple(x=x, listw=listw, 4 | override_similarity_check=override_similarity_check, useTrace=useTrace) 5 | W2e <- eigen(pre$W2) 6 | SQRTW2 <- W2e$vectors %*% (diag(W2e$values^(0.5)) %*% t(W2e$vectors)) 7 | X <- drop(SQRTW2 %*% x) 8 | NSQRTW2 <- W2e$vectors %*% (diag(W2e$values^(-0.5)) %*% t(W2e$vectors)) 9 | Y <- drop(NSQRTW2 %*% pre$WU %*% x) 10 | if (do.plot) { 11 | plot(X, Y, ...) 12 | } 13 | list(X=X, Y=Y) 14 | } 15 | 16 | localAple <- function(x, listw, override_similarity_check=FALSE, useTrace=TRUE) { 17 | aplepl <- aple.plot(x, listw, 18 | override_similarity_check=override_similarity_check, 19 | useTrace=useTrace, do.plot=FALSE) 20 | res <- (length(aplepl$X) * aplepl$Y * aplepl$X) / c(crossprod(aplepl$X)) 21 | res 22 | } 23 | -------------------------------------------------------------------------------- /R/cyclical.R: -------------------------------------------------------------------------------- 1 | # Copyright 2012 by Roger Bivand 2 | # 3 | 4 | isCyclical <- function(nb) { 5 | stopifnot(inherits(nb, "nb")) 6 | cnb <- card(nb) 7 | if (any(cnb == 0)) stop("Neighbours must be connected") 8 | nc <- attr(nb, "ncomp") 9 | if (is.null(nc)) nc <- n.comp.nb(nb) 10 | if (nc$nc != 1) stop("Complete connection required") 11 | res <- 1L 12 | for (i in seq(along=nb)) { 13 | inbs <- nb[[i]] 14 | if (length(inbs) > 1) { 15 | for (j in 1:(length(inbs)-1)) { 16 | for (k in 2:length(inbs)) { 17 | hit <- (inbs[j] %in% nb[[inbs[k]]]) 18 | if (hit) { 19 | res <- 0L 20 | break 21 | } 22 | } 23 | if (res == 0L) break 24 | } 25 | if (res == 0L) break 26 | } 27 | } 28 | res 29 | } 30 | 31 | find_q1_q2 <- function(lw) { 32 | stopifnot(lw$style == "W") 33 | nb <- lw$neighbours 34 | nc <- attr(nb, "ncomp") 35 | if (is.null(nc)) nc <- n.comp.nb(nb) 36 | members <- tapply(1:length(nb), nc$comp.id, c) 37 | q2 <- 0L 38 | q1 <- nc$nc 39 | t1 <- table(nc$comp.id) 40 | t2 <- table(t1) 41 | if ("1" %in% names(t2)) q1 <- unname(q1 - t2["1"]) 42 | ids <- as.integer(names(t1[t1 > 1])) 43 | members1 <- members[ids] 44 | nums <- 1:length(nb) 45 | for (sub in seq(along=members1)) { 46 | subs <- members1[[sub]] 47 | nbsub <- subset(nb, (nums %in% subs)) 48 | if (length(nbsub) > 2) q2sub <- isCyclical(nbsub) 49 | else q2sub <- 1L 50 | q2 <- q2 + q2sub 51 | } 52 | c(q1, q2) 53 | } 54 | 55 | -------------------------------------------------------------------------------- /R/eigenw.R: -------------------------------------------------------------------------------- 1 | # Copyright 2002-12 by Roger Bivand 2 | # 3 | eigenw <- function(listw, quiet=NULL) 4 | { 5 | if(!inherits(listw, "listw")) stop("not a listw object") 6 | if (is.null(quiet)) quiet <- !get("verbose", envir = .spatialregOptions) 7 | stopifnot(is.logical(quiet)) 8 | 9 | w <- listw2mat(listw) 10 | sym <- all(w == t(w)) 11 | e <- eigen(w, symmetric=sym, only.values=TRUE)$values 12 | if (!quiet) { 13 | cat("Largest eigenvalue:", 14 | # modified 110414 RSB 15 | if(is.complex(e)) {max(Re(e[which(Im(e) == 0)]))} else max(e), 16 | "Sum of eigenvalues:", sum(e), "\n") 17 | } 18 | e 19 | } 20 | 21 | 22 | griffith_sone <- function(P, Q, type="rook") { 23 | stopifnot(P >= 1) 24 | stopifnot(Q >= 1) 25 | p <- seq(1:P) 26 | q <- seq(1:Q) 27 | if (type=="rook") { 28 | res0 <- outer((2*cos((pi*p)/(P+1))), (2*cos((pi*q)/(Q+1))), FUN="+") 29 | } else { 30 | e2a <- outer((cos((pi*p)/(P+1))), (cos((pi*q)/(Q+1))), FUN="+") 31 | e2b <- outer((2*cos((pi*p)/(P+1))), (cos((pi*q)/(Q+1))), FUN="*") 32 | res <- 2*(e2a+e2b) 33 | } 34 | res <- sort(c(res0), decreasing=TRUE) 35 | res 36 | } 37 | 38 | subgraph_eigenw <- function(nb, glist=NULL, style="W", zero.policy=NULL, 39 | quiet=NULL) { 40 | if(!inherits(nb, "nb")) stop("Not a neighbours list") 41 | if (is.null(quiet)) quiet <- !get("verbose", envir = .spatialregOptions) 42 | stopifnot(is.logical(quiet)) 43 | if (is.null(zero.policy)) 44 | zero.policy <- get("zeroPolicy", envir = .spatialregOptions) 45 | stopifnot(is.logical(zero.policy)) 46 | if (!(style %in% c("W", "B", "C", "S", "U", "minmax"))) 47 | stop(paste("Style", style, "invalid")) 48 | can.sim <- FALSE 49 | if (style %in% c("W", "S")) 50 | can.sim <- can.be.simmed(nb2listw(nb, glist=glist, style=style)) 51 | nc <- attr(nb, "ncomp") 52 | if (is.null(nc)) nc <- n.comp.nb(nb) 53 | t0 <- table(nc$comp.id) 54 | elist <- vector(mode="list", length=length(t0)) 55 | singleton <- names(t0)[which(t0 == 1)] 56 | if (length(singleton) > 0) elist[as.integer(singleton)] <- 0.0 57 | doubles <- names(t0)[which(t0 == 2)] 58 | if (length(doubles) > 0) { 59 | for (i in doubles) elist[[as.integer(i)]] <- c(1.0, -1.0) 60 | } 61 | rest <- which(sapply(elist, is.null)) 62 | for (i in rest) { 63 | nbi <- subset(nb, nc$comp.id == i) 64 | gli <- NULL 65 | if (!is.null(glist)) gli <- subset(glist, nc$comp.id == i) 66 | if (can.sim) { 67 | elist[[i]] <- eigenw(similar.listw(nb2listw(nbi, glist=gli, 68 | style=style))) 69 | } else { 70 | elist[[i]] <- eigenw(nb2listw(nbi, glist=gli, style=style)) 71 | } 72 | } 73 | eout <- sort(unlist(elist)) 74 | if (length(eout) != length(nb)) 75 | stop("length mismatch, eout:", length(eout)) 76 | eout 77 | } 78 | -------------------------------------------------------------------------------- /R/spChkOption.R: -------------------------------------------------------------------------------- 1 | # Copyright 2003-2015 by Roger Bivand 2 | 3 | set.listw_is_CsparseMatrix_Option <- function(check) { 4 | if (!is.logical(check)) stop ("logical argument required") 5 | res <- get("listw_is_CsparseMatrix", envir = .spatialregOptions) 6 | assign("listw_is_CsparseMatrix", check, envir = .spatialregOptions) 7 | res 8 | } 9 | 10 | get.listw_is_CsparseMatrix_Option <- function() { 11 | get("listw_is_CsparseMatrix", envir = .spatialregOptions) 12 | } 13 | 14 | set.VerboseOption <- function(check) { 15 | if (!is.logical(check)) stop ("logical argument required") 16 | res <- get("verbose", envir = .spatialregOptions) 17 | assign("verbose", check, envir = .spatialregOptions) 18 | res 19 | } 20 | 21 | get.VerboseOption <- function() { 22 | get("verbose", envir = .spatialregOptions) 23 | } 24 | 25 | set.ZeroPolicyOption <- function(check) { 26 | if (!is.logical(check)) stop ("logical argument required") 27 | res <- get("zeroPolicy", envir = .spatialregOptions) 28 | assign("zeroPolicy", check, envir = .spatialregOptions) 29 | res 30 | } 31 | 32 | get.ZeroPolicyOption <- function() { 33 | get("zeroPolicy", envir = .spatialregOptions) 34 | } 35 | 36 | set.ClusterOption <- function(cl) { 37 | if (!is.null(cl)) { 38 | if (!inherits(cl, "cluster")) stop ("cluster required") 39 | } 40 | assign("cluster", cl, envir = .spatialregOptions) 41 | invisible(NULL) 42 | } 43 | 44 | get.ClusterOption <- function() { 45 | get("cluster", envir = .spatialregOptions) 46 | } 47 | 48 | set.mcOption <- function(value) { 49 | stopifnot(is.logical(value)) 50 | stopifnot(length(value) == 1) 51 | res <- get("mc", envir = .spatialregOptions) 52 | if (.Platform$OS.type == "windows") { 53 | if (value) warning("multicore not available on Windows") 54 | } else { 55 | assign("mc", value, envir = .spatialregOptions) 56 | } 57 | res 58 | } 59 | 60 | get.mcOption <- function() { 61 | get("mc", envir = .spatialregOptions) 62 | } 63 | 64 | set.coresOption <- function(value) { 65 | res <- get("cores", envir = .spatialregOptions) 66 | if (is.null(value)) { 67 | assign("cores", value, envir = .spatialregOptions) 68 | } else { 69 | stopifnot(is.integer(value)) 70 | stopifnot(length(value) == 1) 71 | stopifnot(!is.na(value)) 72 | assign("cores", value, envir = .spatialregOptions) 73 | } 74 | res 75 | } 76 | 77 | get.coresOption <- function() { 78 | get("cores", envir = .spatialregOptions) 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /R/sparse_mat.R: -------------------------------------------------------------------------------- 1 | # Copyright 2006-14 by Roger Bivand 2 | # 3 | 4 | as.spam.listw <- function(listw) { 5 | if (requireNamespace("spam", quietly = TRUE)) { 6 | #if (!require(spam)) stop("spam not available") 7 | N <- length(listw$neighbours) 8 | W_sn <- listw2sn(listw) 9 | rpts <- as.integer(cumsum(c(1, card(listw$neighbours)))) 10 | W <- new("spam", entries=W_sn$weights, colindices=W_sn$to, 11 | rowpointers=rpts, dimension=as.integer(c(N, N))) 12 | stopifnot(spam::validate_spam(W)) 13 | return(W) 14 | } else stop("spam not available") 15 | } 16 | 17 | listw2U_spam <- function(lw) 0.5 * (lw + t(lw)) 18 | 19 | 20 | setAs("listw", "CsparseMatrix", function(from) {as(as_dgRMatrix_listw(from), "CsparseMatrix")}) 21 | setAs("listw", "RsparseMatrix", function(from) {as_dgRMatrix_listw(from)}) 22 | setAs("listw", "symmetricMatrix", function(from) {as_dsTMatrix_listw(from)}) 23 | 24 | 25 | as_dgRMatrix_listw <- function(listw) { 26 | if(!inherits(listw, "listw")) stop("not a listw object") 27 | n <- length(listw$neighbours) 28 | cardw <- card(listw$neighbours) 29 | p0 <- as.integer(c(0, cumsum(cardw))) 30 | scard <- sum(cardw) 31 | z <- .Call("listw2dgR", listw$neighbours, listw$weights, 32 | as.integer(cardw), as.integer(scard), PACKAGE="spatialreg") 33 | res <- as(new("dgRMatrix", j=z[[1]], p=p0, Dim=as.integer(c(n, n)), 34 | x=z[[2]]), "generalMatrix") 35 | colnames(res) <- attr(listw$neighbours, "region.id") 36 | rownames(res) <- colnames(res) 37 | res 38 | } 39 | 40 | as_dsTMatrix_listw <- function(listw) { 41 | if (!inherits(listw, "listw")) stop("not a listw object") 42 | if (!is.symmetric.glist(listw$neighbours, listw$weights)) 43 | stop("not a symmetric matrix") 44 | n <- length(listw$neighbours) 45 | cardw <- card(listw$neighbours) 46 | scard <- sum(cardw) 47 | if (scard %% 2 != 0) stop("odd neighbours sum") 48 | z <- .Call("listw2dsT", listw$neighbours, listw$weights, 49 | as.integer(cardw), as.integer(scard/2), PACKAGE="spatialreg") 50 | 51 | res <- as(new("dsTMatrix", i=z[[1]], j=z[[2]], Dim=as.integer(c(n, n)), 52 | x=z[[3]]), "generalMatrix") 53 | colnames(res) <- attr(listw$neighbours, "region.id") 54 | rownames(res) <- colnames(res) 55 | res 56 | } 57 | 58 | as_dsCMatrix_I <- function(n) { 59 | if (n < 1) stop("matrix must have positive dimensions") 60 | as(as(Diagonal(n), "symmetricMatrix"), "generalMatrix") 61 | } 62 | 63 | as_dsCMatrix_IrW <- function(W, rho) { 64 | stopifnot(is(W, "symmetricMatrix")) 65 | n <- dim(W)[1] 66 | as_dsCMatrix_I(n) - rho * W 67 | } 68 | 69 | Jacobian_W <- function(W, rho) { 70 | sum(2*log(diag(chol(as_dsCMatrix_IrW(W, rho))))) 71 | } 72 | 73 | 74 | listw2U_Matrix <- function(lw) 75 | as(as(0.5 * (lw + t(lw)), "symmetricMatrix"), "CsparseMatrix") 76 | 77 | 78 | powerWeights <- function(W, rho, order=250, X, tol=.Machine$double.eps^(3/5)) { 79 | timings <- list() 80 | .ptime_start <- proc.time() 81 | n <- dim(W)[1] 82 | dX <- dim(X) 83 | if (dX[1] == n) side <- "R" 84 | else if (dX[2] == n) side <- "L" 85 | else stop("W and X non-conformant") 86 | aW <- rho*W 87 | if (side == "R") last <- aW %*% X 88 | else last <- X %*% aW 89 | acc <- X + last 90 | conv <- FALSE 91 | iter <- 1 92 | series <- numeric(order) 93 | while (iter < order) { 94 | if (side == "R") { 95 | last <- aW %*% last 96 | acc <- acc + last 97 | } else { 98 | last <- last %*% aW 99 | acc <- acc + last 100 | } 101 | # abs() added 2017-02-15, bug spotted by Yongwan Chun 102 | series[iter] <- mean(abs(as(last, "matrix"))) 103 | if (series[iter] < tol) { 104 | conv <- TRUE 105 | break 106 | } 107 | iter <- iter+1 108 | } 109 | if (!conv) warning("not converged within order iterations") 110 | timings[["make_power_sum"]] <- proc.time() - .ptime_start 111 | attr(acc, "internal") <- list(series=series, order=order, 112 | tol=tol, iter=iter, conv=conv) 113 | attr(acc, "timings") <- do.call("rbind", timings)[, c(1, 3)] 114 | acc 115 | } 116 | 117 | invIrM <- function(neighbours, rho, glist=NULL, style="W", method="solve", 118 | feasible=NULL) { 119 | if(!inherits(neighbours, "nb")) stop("Not a neighbours list") 120 | invIrW(nb2listw(neighbours, glist=glist, style=style), rho=rho, 121 | method=method, feasible=feasible) 122 | } 123 | 124 | invIrW <- function(x, rho, method="solve", feasible=NULL) { 125 | if(inherits(x, "listw")) { 126 | n <- length(x$neighbours) 127 | V <- listw2mat(x) 128 | } else if (inherits(x, "Matrix") || inherits(x, "matrix")) { 129 | if (method == "chol" && all(t(x) == x)) 130 | stop("No Cholesky method for matrix or sparse matrix object") 131 | n <- dim(x)[1] 132 | V <- x 133 | } else stop("Not a weights list or a Sparse Matrix") 134 | if (is.null(feasible) || (is.logical(feasible) && !feasible)) { 135 | e <- eigen(V, only.values = TRUE)$values 136 | if (is.complex(e)) feasible <- 1/(range(Re(e))) 137 | else feasible <- 1/(range(e)) 138 | if (rho <= feasible[1] || rho >= feasible[2]) 139 | stop(paste("Rho", rho, "outside feasible range:", 140 | paste(feasible, collapse=":"))) 141 | } 142 | if (method == "chol"){ 143 | if (x$style %in% c("W", "S") && !(spatialreg::can.be.simmed(x))) 144 | stop("Cholesky method requires symmetric weights") 145 | if (x$style %in% c("B", "C", "U") && 146 | !(is.symmetric.glist(x$neighbours, x$weights))) 147 | stop("Cholesky method requires symmetric weights") 148 | if (x$style %in% c("W", "S")) { 149 | V <- listw2mat(listw2U(spatialreg::similar.listw(x))) 150 | } 151 | mat <- diag(n) - rho * V 152 | res <- chol2inv(chol(mat)) 153 | } else if (method == "solve") { 154 | mat <- diag(n) - rho * V 155 | res <- solve(mat) 156 | } else stop("unknown method") 157 | attr(res, "call") <- match.call() 158 | res 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /R/spautolm_functions.R: -------------------------------------------------------------------------------- 1 | # Copyright 2005-2012 by Roger Bivand 2 | 3 | # Simultaneous autoregressive 4 | SAR <- function(IlW, weights) { 5 | t(IlW) %*% weights %*% IlW 6 | } 7 | 8 | # Conditional autoregressive 9 | CAR <- function(IlW, weights) { 10 | IlW %*% weights 11 | } 12 | 13 | # Spatial moving average 14 | SMA <- function(IlW, weights) { 15 | IlW <- solve(IlW) 16 | t(IlW) %*% weights %*% IlW 17 | } 18 | 19 | 20 | f_spautolm_hess_nlm <- function(coefs, env) { 21 | ret <- f_spautolm_hess(coefs, env) 22 | -ret 23 | } 24 | 25 | f_spautolm_hess <- function(coefs, env) { 26 | lambda <- coefs[1] 27 | int <- get("interval", envir=env) 28 | if (lambda <= int[1] || lambda >= int[2]) return(-Inf) 29 | beta <- coefs[-1] 30 | X <- get("X", envir=env) 31 | Y <- get("Y", envir=env) 32 | fitted <- X %*% beta 33 | residuals <- Y - fitted 34 | dmmf <- eval(parse(text=get("family", envir=env))) 35 | if (get("family", envir=env) == "SMA") IlW <- dmmf((get("I", envir=env) + 36 | lambda * get("W", envir=env)), get("Sweights", envir=env)) 37 | else IlW <- dmmf((get("I", envir=env) - lambda * get("W", envir=env)), 38 | get("Sweights", envir=env)) 39 | SSE <- c(crossprod(residuals, as.matrix(IlW %*% residuals))) 40 | n <- get("n", envir=env) 41 | s2 <- SSE/n 42 | ldet <- do_ldet(lambda, env) 43 | det <- ifelse(get("family", envir=env) == "CAR", 0.5*ldet, ldet) 44 | ret <- (det + (1/2)*get("sum_lw", envir=env) - ((n/2)*log(2*pi)) - 45 | (n/2)*log(s2) - (1/(2*(s2)))*SSE) 46 | if (get("verbose", envir=env)) 47 | cat("lambda:", lambda, "function:", ret, "Jacobian", ldet, "SSE", 48 | SSE, "\n") 49 | if (!is.finite(ret)) return(-Inf) 50 | ret 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![R-CMD-check](https://github.com/r-spatial/spatialreg/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/r-spatial/spatialreg/actions/workflows/check-standard.yaml) 3 | [![CRAN](http://www.r-pkg.org/badges/version/spatialreg)](https://cran.r-project.org/package=spatialreg) 4 | 5 | 6 | # spatialreg 7 | 8 | ### spatialreg: spatial models estimation and testing 9 | 10 | A collection of all the estimation functions for spatial cross-sectional models (on lattice/areal data using spatial weights matrices) contained up to now in **spdep**. These model fitting functions include maximum likelihood methods for cross-sectional models proposed by Cliff and Ord (1973, ISBN: 0850860369) and (1981, ISBN: 0850860814), fitting methods initially described by Ord (1975) https://doi.org/10.1080/01621459.1975.10480272. The models are further described by Anselin (1988) https://doi.org/10.1007/978-94-015-7799-1. Spatial two stage least squares and spatial general method of moment models initially proposed by Kelejian and Prucha (1998) https://doi.org/10.1023/A:1007707430416 and (1999) https://doi.org/10.1111/1468-2354.00027 are provided. Impact methods and MCMC fitting methods proposed by LeSage and Pace (2009) https://doi.org/10.1201/9781420064254 are implemented for the family of cross-sectional spatial regression models. Methods for fitting the log determinant term in maximum likelihood and MCMC fitting are compared by Bivand et al. (2013) https://doi.org/10.1111/gean.12008, and model fitting methods by Bivand and Piras (2015) https://doi.org/10.18637/jss.v063.i18; both of these articles include extensive lists of references. A recent review is provided by Bivand, Millo and Piras (2021) https://doi.org/10.3390/math9111276. **spatialreg** >= 1.1-1 corresponds to **spdep** = 1.1-1, in which the model fitting functions are deprecated and pass through to **spatialreg**, but will mask those in **spatialreg**. From versions 1.2-1, the functions have been made defunct in **spdep**. From version 1.3-6, add Anselin-Kelejian (1997) test to `stsls` for residual spatial autocorrelation https://doi.org/10.1177/016001769702000109. 11 | 12 | Default branch now `main`. 13 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | template: 2 | bootstrap: 5 3 | url: https://r-spatial.github.io/spatialreg/ 4 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • spatialreg 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Skip to contents 17 | 18 | 19 |
54 |
55 |
60 | 61 | Content not found. Please use links in the navbar. 62 | 63 |
64 |
65 | 66 | 67 |
70 | 71 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/articles/SpatialFiltering_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/articles/SpatialFiltering_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • spatialreg 3 | Skip to contents 4 | 5 | 6 |
34 |
35 |
39 | 40 | 51 |
52 | 53 | 54 |
57 | 58 | 61 | 62 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /docs/articles/nb_igraph_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/articles/nb_igraph_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/articles/nb_igraph_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/articles/nb_igraph_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/sids_models_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/articles/sids_models_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/articles/sids_models_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/articles/sids_models_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | !function(a){"use strict";window.Toc={helpers:{findOrFilter:function(e,t){var n=e.find(t);return e.filter(t).add(n).filter(":not([data-toc-skip])")},generateUniqueIdBase:function(e){return a(e).text().trim().replace(/\'/gi,"").replace(/[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v]/g,"-").replace(/-{2,}/g,"-").substring(0,64).replace(/^-+|-+$/gm,"").toLowerCase()||e.tagName.toLowerCase()},generateUniqueId:function(e){for(var t=this.generateUniqueIdBase(e),n=0;;n++){var r=t;if(0')},createChildNavList:function(e){var t=this.createNavList();return e.append(t),t},generateNavEl:function(e,t){var n=a('');n.attr("href","#"+e),n.text(t);var r=a("
  • ");return r.append(n),r},generateNavItem:function(e){var t=this.generateAnchor(e),n=a(e),r=n.data("toc-text")||n.text();return this.generateNavEl(t,r)},getTopLevel:function(e){for(var t=1;t<=6;t++){if(1 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-v4compatibility.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-v4compatibility.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.5.2/webfonts/fa-v4compatibility.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/deps/font-awesome-6.5.2/webfonts/fa-v4compatibility.woff2 -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.11.0 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2020 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Headroom=n()}(this,function(){"use strict";function t(){return"undefined"!=typeof window}function d(t){return function(t){return t&&t.document&&function(t){return 9===t.nodeType}(t.document)}(t)?function(t){var n=t.document,o=n.body,s=n.documentElement;return{scrollHeight:function(){return Math.max(o.scrollHeight,s.scrollHeight,o.offsetHeight,s.offsetHeight,o.clientHeight,s.clientHeight)},height:function(){return t.innerHeight||s.clientHeight||o.clientHeight},scrollY:function(){return void 0!==t.pageYOffset?t.pageYOffset:(s||o.parentNode||o).scrollTop}}}(t):function(t){return{scrollHeight:function(){return Math.max(t.scrollHeight,t.offsetHeight,t.clientHeight)},height:function(){return Math.max(t.offsetHeight,t.clientHeight)},scrollY:function(){return t.scrollTop}}}(t)}function n(t,s,e){var n,o=function(){var n=!1;try{var t={get passive(){n=!0}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){n=!1}return n}(),i=!1,r=d(t),l=r.scrollY(),a={};function c(){var t=Math.round(r.scrollY()),n=r.height(),o=r.scrollHeight();a.scrollY=t,a.lastScrollY=l,a.direction=ls.tolerance[a.direction],e(a),l=t,i=!1}function h(){i||(i=!0,n=requestAnimationFrame(c))}var u=!!o&&{passive:!0,capture:!1};return t.addEventListener("scroll",h,u),c(),{destroy:function(){cancelAnimationFrame(n),t.removeEventListener("scroll",h,u)}}}function o(t,n){n=n||{},Object.assign(this,o.options,n),this.classes=Object.assign({},o.options.classes,n.classes),this.elem=t,this.tolerance=function(t){return t===Object(t)?t:{down:t,up:t}}(this.tolerance),this.initialised=!1,this.frozen=!1}return o.prototype={constructor:o,init:function(){return o.cutsTheMustard&&!this.initialised&&(this.addClass("initial"),this.initialised=!0,setTimeout(function(t){t.scrollTracker=n(t.scroller,{offset:t.offset,tolerance:t.tolerance},t.update.bind(t))},100,this)),this},destroy:function(){this.initialised=!1,Object.keys(this.classes).forEach(this.removeClass,this),this.scrollTracker.destroy()},unpin:function(){!this.hasClass("pinned")&&this.hasClass("unpinned")||(this.addClass("unpinned"),this.removeClass("pinned"),this.onUnpin&&this.onUnpin.call(this))},pin:function(){this.hasClass("unpinned")&&(this.addClass("pinned"),this.removeClass("unpinned"),this.onPin&&this.onPin.call(this))},freeze:function(){this.frozen=!0,this.addClass("frozen")},unfreeze:function(){this.frozen=!1,this.removeClass("frozen")},top:function(){this.hasClass("top")||(this.addClass("top"),this.removeClass("notTop"),this.onTop&&this.onTop.call(this))},notTop:function(){this.hasClass("notTop")||(this.addClass("notTop"),this.removeClass("top"),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){this.hasClass("bottom")||(this.addClass("bottom"),this.removeClass("notBottom"),this.onBottom&&this.onBottom.call(this))},notBottom:function(){this.hasClass("notBottom")||(this.addClass("notBottom"),this.removeClass("bottom"),this.onNotBottom&&this.onNotBottom.call(this))},shouldUnpin:function(t){return"down"===t.direction&&!t.top&&t.toleranceExceeded},shouldPin:function(t){return"up"===t.direction&&t.toleranceExceeded||t.top},addClass:function(t){this.elem.classList.add.apply(this.elem.classList,this.classes[t].split(" "))},removeClass:function(t){this.elem.classList.remove.apply(this.elem.classList,this.classes[t].split(" "))},hasClass:function(t){return this.classes[t].split(" ").every(function(t){return this.classList.contains(t)},this.elem)},update:function(t){t.isOutOfBounds||!0!==this.frozen&&(t.top?this.top():this.notTop(),t.bottom?this.bottom():this.notBottom(),this.shouldUnpin(t)?this.unpin():this.shouldPin(t)&&this.pin())}},o.options={tolerance:{up:0,down:0},offset:0,scroller:t()?window:null,classes:{frozen:"headroom--frozen",pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},o.cutsTheMustard=!!(t()&&function(){}.bind&&"classList"in document.documentElement&&Object.assign&&Object.keys&&requestAnimationFrame),o}); -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/jQuery.headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(a){a&&(a.fn.headroom=function(b){return this.each(function(){var c=a(this),d=c.data("headroom"),e="object"==typeof b&&b;e=a.extend(!0,{},Headroom.options,e),d||(d=new Headroom(this,e),d.init(),c.data("headroom",d)),"string"==typeof b&&(d[b](),"destroy"===b&&c.removeData("headroom"))})},a("[data-headroom]").each(function(){var b=a(this);b.headroom(b.data())}))}(window.Zepto||window.jQuery); -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/katex-auto.js: -------------------------------------------------------------------------------- 1 | // https://github.com/jgm/pandoc/blob/29fa97ab96b8e2d62d48326e1b949a71dc41f47a/src/Text/Pandoc/Writers/HTML.hs#L332-L345 2 | document.addEventListener("DOMContentLoaded", function () { 3 | var mathElements = document.getElementsByClassName("math"); 4 | var macros = []; 5 | for (var i = 0; i < mathElements.length; i++) { 6 | var texText = mathElements[i].firstChild; 7 | if (mathElements[i].tagName == "SPAN") { 8 | katex.render(texText.data, mathElements[i], { 9 | displayMode: mathElements[i].classList.contains("display"), 10 | throwOnError: false, 11 | macros: macros, 12 | fleqn: false 13 | }); 14 | }}}); 15 | -------------------------------------------------------------------------------- /docs/lightswitch.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) 4 | * Copyright 2011-2023 The Bootstrap Authors 5 | * Licensed under the Creative Commons Attribution 3.0 Unported License. 6 | * Updates for {pkgdown} by the {bslib} authors, also licensed under CC-BY-3.0. 7 | */ 8 | 9 | const getStoredTheme = () => localStorage.getItem('theme') 10 | const setStoredTheme = theme => localStorage.setItem('theme', theme) 11 | 12 | const getPreferredTheme = () => { 13 | const storedTheme = getStoredTheme() 14 | if (storedTheme) { 15 | return storedTheme 16 | } 17 | 18 | return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' 19 | } 20 | 21 | const setTheme = theme => { 22 | if (theme === 'auto') { 23 | document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) 24 | } else { 25 | document.documentElement.setAttribute('data-bs-theme', theme) 26 | } 27 | } 28 | 29 | function bsSetupThemeToggle () { 30 | 'use strict' 31 | 32 | const showActiveTheme = (theme, focus = false) => { 33 | var activeLabel, activeIcon; 34 | 35 | document.querySelectorAll('[data-bs-theme-value]').forEach(element => { 36 | const buttonTheme = element.getAttribute('data-bs-theme-value') 37 | const isActive = buttonTheme == theme 38 | 39 | element.classList.toggle('active', isActive) 40 | element.setAttribute('aria-pressed', isActive) 41 | 42 | if (isActive) { 43 | activeLabel = element.textContent; 44 | activeIcon = element.querySelector('span').classList.value; 45 | } 46 | }) 47 | 48 | const themeSwitcher = document.querySelector('#dropdown-lightswitch') 49 | if (!themeSwitcher) { 50 | return 51 | } 52 | 53 | themeSwitcher.setAttribute('aria-label', activeLabel) 54 | themeSwitcher.querySelector('span').classList.value = activeIcon; 55 | 56 | if (focus) { 57 | themeSwitcher.focus() 58 | } 59 | } 60 | 61 | window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { 62 | const storedTheme = getStoredTheme() 63 | if (storedTheme !== 'light' && storedTheme !== 'dark') { 64 | setTheme(getPreferredTheme()) 65 | } 66 | }) 67 | 68 | window.addEventListener('DOMContentLoaded', () => { 69 | showActiveTheme(getPreferredTheme()) 70 | 71 | document 72 | .querySelectorAll('[data-bs-theme-value]') 73 | .forEach(toggle => { 74 | toggle.addEventListener('click', () => { 75 | const theme = toggle.getAttribute('data-bs-theme-value') 76 | setTheme(theme) 77 | setStoredTheme(theme) 78 | showActiveTheme(theme, true) 79 | }) 80 | }) 81 | }) 82 | } 83 | 84 | setTheme(getPreferredTheme()); 85 | bsSetupThemeToggle(); 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('nav.navbar').headroom(); 6 | 7 | Toc.init({ 8 | $nav: $("#toc"), 9 | $scope: $("main h2, main h3, main h4, main h5, main h6") 10 | }); 11 | 12 | if ($('#toc').length) { 13 | $('body').scrollspy({ 14 | target: '#toc', 15 | offset: $("nav.navbar").outerHeight() + 1 16 | }); 17 | } 18 | 19 | // Activate popovers 20 | $('[data-bs-toggle="popover"]').popover({ 21 | container: 'body', 22 | html: true, 23 | trigger: 'focus', 24 | placement: "top", 25 | sanitize: false, 26 | }); 27 | 28 | $('[data-bs-toggle="tooltip"]').tooltip(); 29 | 30 | /* Clipboard --------------------------*/ 31 | 32 | function changeTooltipMessage(element, msg) { 33 | var tooltipOriginalTitle=element.getAttribute('data-bs-original-title'); 34 | element.setAttribute('data-bs-original-title', msg); 35 | $(element).tooltip('show'); 36 | element.setAttribute('data-bs-original-title', tooltipOriginalTitle); 37 | } 38 | 39 | if(ClipboardJS.isSupported()) { 40 | $(document).ready(function() { 41 | var copyButton = ""; 42 | 43 | $("div.sourceCode").addClass("hasCopyButton"); 44 | 45 | // Insert copy buttons: 46 | $(copyButton).prependTo(".hasCopyButton"); 47 | 48 | // Initialize tooltips: 49 | $('.btn-copy-ex').tooltip({container: 'body'}); 50 | 51 | // Initialize clipboard: 52 | var clipboard = new ClipboardJS('[data-clipboard-copy]', { 53 | text: function(trigger) { 54 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 55 | } 56 | }); 57 | 58 | clipboard.on('success', function(e) { 59 | changeTooltipMessage(e.trigger, 'Copied!'); 60 | e.clearSelection(); 61 | }); 62 | 63 | clipboard.on('error', function(e) { 64 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 65 | }); 66 | 67 | }); 68 | } 69 | 70 | /* Search marking --------------------------*/ 71 | var url = new URL(window.location.href); 72 | var toMark = url.searchParams.get("q"); 73 | var mark = new Mark("main#main"); 74 | if (toMark) { 75 | mark.mark(toMark, { 76 | accuracy: { 77 | value: "complementary", 78 | limiters: [",", ".", ":", "/"], 79 | } 80 | }); 81 | } 82 | 83 | /* Search --------------------------*/ 84 | /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ 85 | // Initialise search index on focus 86 | var fuse; 87 | $("#search-input").focus(async function(e) { 88 | if (fuse) { 89 | return; 90 | } 91 | 92 | $(e.target).addClass("loading"); 93 | var response = await fetch($("#search-input").data("search-index")); 94 | var data = await response.json(); 95 | 96 | var options = { 97 | keys: ["what", "text", "code"], 98 | ignoreLocation: true, 99 | threshold: 0.1, 100 | includeMatches: true, 101 | includeScore: true, 102 | }; 103 | fuse = new Fuse(data, options); 104 | 105 | $(e.target).removeClass("loading"); 106 | }); 107 | 108 | // Use algolia autocomplete 109 | var options = { 110 | autoselect: true, 111 | debug: true, 112 | hint: false, 113 | minLength: 2, 114 | }; 115 | var q; 116 | async function searchFuse(query, callback) { 117 | await fuse; 118 | 119 | var items; 120 | if (!fuse) { 121 | items = []; 122 | } else { 123 | q = query; 124 | var results = fuse.search(query, { limit: 20 }); 125 | items = results 126 | .filter((x) => x.score <= 0.75) 127 | .map((x) => x.item); 128 | if (items.length === 0) { 129 | items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; 130 | } 131 | } 132 | callback(items); 133 | } 134 | $("#search-input").autocomplete(options, [ 135 | { 136 | name: "content", 137 | source: searchFuse, 138 | templates: { 139 | suggestion: (s) => { 140 | if (s.title == s.what) { 141 | return `${s.dir} >
    ${s.title}
    `; 142 | } else if (s.previous_headings == "") { 143 | return `${s.dir} >
    ${s.title}
    > ${s.what}`; 144 | } else { 145 | return `${s.dir} >
    ${s.title}
    > ${s.previous_headings} > ${s.what}`; 146 | } 147 | }, 148 | }, 149 | }, 150 | ]).on('autocomplete:selected', function(event, s) { 151 | window.location.href = s.path + "?q=" + q + "#" + s.id; 152 | }); 153 | }); 154 | })(window.jQuery || window.$) 155 | 156 | document.addEventListener('keydown', function(event) { 157 | // Check if the pressed key is '/' 158 | if (event.key === '/') { 159 | event.preventDefault(); // Prevent any default action associated with the '/' key 160 | document.getElementById('search-input').focus(); // Set focus to the search input 161 | } 162 | }); 163 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 3.1.11.1 2 | pkgdown: 2.1.1 3 | pkgdown_sha: ~ 4 | articles: 5 | nb_igraph: nb_igraph.html 6 | sids_models: sids_models.html 7 | SpatialFiltering: SpatialFiltering.html 8 | last_built: 2024-12-02T10:09Z 9 | urls: 10 | reference: https://r-spatial.github.io/spatialreg/reference 11 | article: https://r-spatial.github.io/spatialreg/articles 12 | -------------------------------------------------------------------------------- /docs/reference/GMargminImage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/GMerrorsar-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/GMerrorsar-1.png -------------------------------------------------------------------------------- /docs/reference/HPDinterval.LagImpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Hausman.test.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Hausman.test.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Hausman.test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Jacobian_W.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/LR1.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/LR1.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/LR1.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/LU_prepermutate_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/LU_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/MCMCsamp.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/MCMCsamp.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Matrix_J_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Matrix_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/SE_classic_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/SE_interp_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/SE_whichMin_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Wald1.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/anova.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/aple.mc-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/aple.mc-1.png -------------------------------------------------------------------------------- /docs/reference/aple.plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/aple.plot-1.png -------------------------------------------------------------------------------- /docs/reference/aple.plot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/aple.plot-2.png -------------------------------------------------------------------------------- /docs/reference/aple.plot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/aple.plot-3.png -------------------------------------------------------------------------------- /docs/reference/as.data.frame.Sarlm.pred.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/as_dgRMatrix_listw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/as_dsCMatrix_I.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/as_dsCMatrix_IrW.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/as_dsTMatrix_listw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/bptest.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/can.be.simmed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/cheb_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coef.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coef.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coef.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coef.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coef.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coerce,listw,CsparseMatrix-method.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coerce,listw,RsparseMatrix-method.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/coerce,listw,symmetricMatrix-method.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/create_WX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/deviance.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/deviance.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/deviance.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/deviance.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/deviance.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/eigen_pre_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/eigen_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/errorsarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.Me_res.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.SfResult.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/fitted.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get.ClusterOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get.VerboseOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get.ZeroPolicyOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get.coresOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get.mcOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/gstsls-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/gstsls-1.png -------------------------------------------------------------------------------- /docs/reference/impacts.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.MCMC_sac_G.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.MCMC_sar_G.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.MCMC_sem_G.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.SlX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/impacts.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/intImpacts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/invIrM-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/invIrM-1.png -------------------------------------------------------------------------------- /docs/reference/invIrW.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/jacobianSetup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/l_max.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/lagsarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/lextrS.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/lextrW.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/listw2U_Matrix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/listw2U_spam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/localAple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/logLik.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/logLik.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/logLik.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/mcdet_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/mom_calc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/mom_calc_int2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/moments_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/plot.LagImpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/powerWeights.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/predict.SlX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.LagImpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Me_res.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Sarlm.pred.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.SfResult.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.SlX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.WXimpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.LagImpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.SlX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/print.summary.WXimpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/residuals.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/residuals.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/residuals.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/residuals.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/residuals.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/sacsarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/set.ClusterOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/set.VerboseOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/set.coresOption.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/spBreg_err.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/spBreg_sac.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/spam_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/spam_update_setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/subgraph_eigenw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.Gmsar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.LagImpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.Lagmess.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.SlX.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.Spautolm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.Stsls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/summary.WXimpact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/trW-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-spatial/spatialreg/8ce139cb51b133a2ea69b8ca5b4e94cfccc1b3bf/docs/reference/trW-1.png -------------------------------------------------------------------------------- /docs/reference/vcov.Sarlm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | https://r-spatial.github.io/spatialreg/404.html 3 | https://r-spatial.github.io/spatialreg/articles/SpatialFiltering.html 4 | https://r-spatial.github.io/spatialreg/articles/index.html 5 | https://r-spatial.github.io/spatialreg/articles/nb_igraph.html 6 | https://r-spatial.github.io/spatialreg/articles/sids_models.html 7 | https://r-spatial.github.io/spatialreg/authors.html 8 | https://r-spatial.github.io/spatialreg/index.html 9 | https://r-spatial.github.io/spatialreg/news/index.html 10 | https://r-spatial.github.io/spatialreg/reference/GMerrorsar.html 11 | https://r-spatial.github.io/spatialreg/reference/MCMCsamp.html 12 | https://r-spatial.github.io/spatialreg/reference/ME.html 13 | https://r-spatial.github.io/spatialreg/reference/ML_models.html 14 | https://r-spatial.github.io/spatialreg/reference/SET_MCMC.html 15 | https://r-spatial.github.io/spatialreg/reference/SLX.html 16 | https://r-spatial.github.io/spatialreg/reference/SpatialFiltering.html 17 | https://r-spatial.github.io/spatialreg/reference/aple.html 18 | https://r-spatial.github.io/spatialreg/reference/aple.mc.html 19 | https://r-spatial.github.io/spatialreg/reference/aple.plot.html 20 | https://r-spatial.github.io/spatialreg/reference/do_ldet.html 21 | https://r-spatial.github.io/spatialreg/reference/eigenw.html 22 | https://r-spatial.github.io/spatialreg/reference/gstsls.html 23 | https://r-spatial.github.io/spatialreg/reference/impacts.html 24 | https://r-spatial.github.io/spatialreg/reference/index.html 25 | https://r-spatial.github.io/spatialreg/reference/invIrM.html 26 | https://r-spatial.github.io/spatialreg/reference/lagmess.html 27 | https://r-spatial.github.io/spatialreg/reference/lextrB.html 28 | https://r-spatial.github.io/spatialreg/reference/predict.sarlm.html 29 | https://r-spatial.github.io/spatialreg/reference/sarlm_tests.html 30 | https://r-spatial.github.io/spatialreg/reference/set.mcOption.html 31 | https://r-spatial.github.io/spatialreg/reference/set.spChkOption.html 32 | https://r-spatial.github.io/spatialreg/reference/similar.listw.html 33 | https://r-spatial.github.io/spatialreg/reference/sparse_mat.html 34 | https://r-spatial.github.io/spatialreg/reference/spautolm.html 35 | https://r-spatial.github.io/spatialreg/reference/stsls.html 36 | https://r-spatial.github.io/spatialreg/reference/trW.html 37 | 38 | 39 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite spatialreg in publications use one or more of the following as appropriate:") 2 | 3 | bibentry(bibtype="Article", 4 | title="A Review of Software for Spatial Econometrics in {R}", 5 | author=c(person(c("Roger"), "Bivand"), 6 | person(c("Giovanni"), "Millo"), 7 | person(c("Gianfranco"), "Piras")), 8 | journal="Mathematics", 9 | year="2021", 10 | volume="9", 11 | number="11", 12 | url="https://www.mdpi.com/2227-7390/9/11/1276", 13 | doi="10.3390/math9111276" 14 | ) 15 | 16 | bibentry(bibtype = "Article", 17 | title = "Comparing Implementations of Estimation Methods for Spatial Econometrics", 18 | author = c(person(c("Roger"), "Bivand"), 19 | person(c("Gianfranco"), "Piras")), 20 | journal = "Journal of Statistical Software", 21 | year = "2015", 22 | volume = "63", 23 | number = "18", 24 | pages = "1--36", 25 | doi = "10.18637/jss.v063.i18" 26 | ) 27 | 28 | bibentry(bibtype = "Article", 29 | title = "Computing the Jacobian in Gaussian spatial autoregressive models: An illustrated comparison of available methods", 30 | author = c(person(c("Roger"), "Bivand"), 31 | person(c("Jan"), "Hauke"), 32 | person(c("Tomasz"), "Kossowski")), 33 | journal = "Geographical Analysis", 34 | year = "2013", 35 | volume = "45", 36 | number = "2", 37 | pages = "150--179", 38 | doi = "10.1111/gean.12008" 39 | ) 40 | bibentry(bibtype="book", 41 | author = c(person(c("Roger S."), "Bivand"), person(c("Edzer"), "Pebesma"), person(c("Virgilio"), c("Gómez-Rubio"))), 42 | title = "Applied spatial data analysis with {R}, Second edition", 43 | year = "2013", 44 | publisher = "Springer, NY", 45 | url = "https://asdar-book.org/" 46 | ) 47 | 48 | bibentry(bibtype="book", 49 | author = c(person(c("Edzer"), "Pebesma"), person(c("Roger S."), "Bivand")), 50 | title = "Spatial Data Science With Applications in {R}", 51 | year = "2023", 52 | publisher = "Chapman & Hall", 53 | url = "https://r-spatial.org/book/" 54 | ) 55 | 56 | -------------------------------------------------------------------------------- /inst/README: -------------------------------------------------------------------------------- 1 | Spatial Regression Analysis 2 | 3 | A collection of functions for estimating spatial simultaneous 4 | autoregressive (SAR) lag and error models, weighted and unweighted 5 | SAR and CAR spatial regression models, and GM SAR error models. 6 | 7 | This file is intended to clarify ownership and copyright: where 8 | possible individual files also carry brief copyright notices. 9 | 10 | Copyrights 11 | ========== 12 | 13 | File: R/lag.spsarlm.R is copyright (c) 1998-2002 by Roger Bivand and Andrew 14 | Bernat, and is subject to the licence at the foot of this file. 15 | 16 | File: R/kpgm_new.R is copyright (c) 2005 by Luc Anselin and Roger Bivand, 17 | and is subject to the licence at the foot of this file. 18 | 19 | File: R/SpatialFiltering.R is copyright (c) 2005 by Yongwan Chun, Michael 20 | Tiefelsdorf and Roger Bivand, and is subject to the licence at the foot 21 | of this file. 22 | 23 | File R/SpBreg.R is copyright (c) 2011-2019 by Abhirup Mallik, 24 | Virgilio Gómez-Rubio and Roger Bivand, and is subject to the licence 25 | at the foot of this file. It is based on translated Matlab code from the 26 | Spatial Econometrics toolbox by James LeSage and R. Kelley Pace 27 | (http://www.spatial-econometrics.com/). 28 | 29 | All other files are copyright (c) 1998-2019 Roger S. Bivand and 30 | are subject to the licence at the foot of this file. 31 | 32 | Licence 33 | ======= 34 | 35 | This is free software; you can redistribute it and/or modify 36 | it under the terms of the GNU General Public License as published by 37 | the Free Software Foundation; either version 2 of the License, or 38 | (at your option) any later version. 39 | 40 | This program is distributed in the hope that it will be useful, 41 | but WITHOUT ANY WARRANTY; without even the implied warranty of 42 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 43 | GNU General Public License for more details. 44 | 45 | You should have received a copy of the GNU General Public License 46 | along with this program; if not, write to the Free Software 47 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 48 | 49 | 50 | The file COPYING in the R top-level directory is a copy of the "GNU 51 | General Public License". 52 | 53 | Roger.Bivand@nhh.no 54 | 55 | -------------------------------------------------------------------------------- /inst/tinytest/test_Durbin.R: -------------------------------------------------------------------------------- 1 | library(spatialreg) 2 | data(oldcol, package="spdep") 3 | lw <- spdep::nb2listw(COL.nb) 4 | f <- formula(CRIME ~ INC + HOVAL) 5 | COL.SLX <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=TRUE) 6 | p0 <- predict(COL.SLX, newdata=COL.OLD, listw=lw) 7 | COL.SLX.f <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=~ INC) 8 | p0f <- predict(COL.SLX.f, newdata=COL.OLD, listw=lw) 9 | COL.mix.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=TRUE) 10 | p1 <- predict(COL.mix.eig) 11 | p2 <- predict(COL.mix.eig, newdata=COL.OLD, listw=lw, pred.type = "TS", 12 | legacy.mixed = TRUE) 13 | p3 <- predict(COL.mix.eig, newdata=COL.OLD, listw=lw, pred.type = "TS", 14 | legacy=FALSE, legacy.mixed = TRUE) 15 | expect_true(isTRUE(all.equal(p2, p3, check.attributes=FALSE))) 16 | COL.mix.eig.f <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=~ INC) 17 | p2f <- predict(COL.mix.eig.f, newdata=COL.OLD, listw=lw, pred.type = "TS", legacy.mixed = TRUE) 18 | p3f <- predict(COL.mix.eig.f, newdata=COL.OLD, listw=lw, pred.type = "TS", legacy=FALSE, legacy.mixed = TRUE) 19 | expect_true(isTRUE(all.equal(p2f, p3f, check.attributes=FALSE))) 20 | COL.SDerr.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=TRUE) 21 | p1 <- predict(COL.SDerr.eig) 22 | p2 <- predict(COL.SDerr.eig, newdata=COL.OLD, listw=lw, pred.type = "TS", 23 | legacy.mixed = TRUE) 24 | p3 <- predict(COL.SDerr.eig, newdata=COL.OLD, listw=lw, pred.type = "TS", 25 | legacy=FALSE, legacy.mixed = TRUE) 26 | expect_true(isTRUE(all.equal(p2, p3, check.attributes=FALSE))) 27 | COL.SDerr.eig.f <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Durbin=~ INC) 28 | p2f <- predict(COL.SDerr.eig.f, newdata=COL.OLD, listw=lw, pred.type = "TS", legacy.mixed = TRUE) 29 | p3f <- predict(COL.SDerr.eig.f, newdata=COL.OLD, listw=lw, pred.type = "TS", legacy=FALSE, legacy.mixed = TRUE) 30 | expect_true(isTRUE(all.equal(p2f, p3f, check.attributes=FALSE))) 31 | set.seed(1) 32 | drops <- match(sample(row.names(COL.OLD), size=9L), row.names(COL.OLD)) 33 | COL_40 <- COL.OLD[-drops,] 34 | nd <- COL.OLD[drops,] 35 | lw_40 <- subset(lw, !(attr(lw, "region.id") %in% attr(lw, "region.id")[drops]), zero.policy=TRUE) 36 | nd_COL.SLX <- lmSLX(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=TRUE, zero.policy=TRUE) 37 | nd_p0 <- predict(nd_COL.SLX, newdata=nd, listw=lw) 38 | nd_COL.SLX.f <- lmSLX(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=~ INC, zero.policy=TRUE) 39 | nd_p0f <- predict(nd_COL.SLX.f, newdata=nd, listw=lw) 40 | nd_COL.mix.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=TRUE, zero.policy=TRUE) 41 | nd_p1 <- predict(nd_COL.mix.eig) 42 | nd_p2 <- predict(nd_COL.mix.eig, newdata=nd, listw=lw, pred.type = "TS", legacy = TRUE, zero.policy=TRUE) 43 | nd_p3 <- predict(nd_COL.mix.eig, newdata=nd, listw=lw, pred.type = "TS", legacy=FALSE, zero.policy=TRUE) 44 | expect_true(isTRUE(all.equal(nd_p2, nd_p3, check.attributes=FALSE))) 45 | nd_COL.mix.eig.f <- lagsarlm(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=~ INC, zero.policy=TRUE) 46 | expect_error(nd_p2f <- predict(nd_COL.mix.eig.f, newdata=nd, listw=lw, pred.type = "TS", legacy=TRUE)) # https://github.com/r-spatial/spatialreg/issues/38 47 | expect_error(nd_p3f <- predict(nd_COL.mix.eig.f, newdata=nd, listw=lw, pred.type = "TS", legacy=FALSE)) # https://github.com/r-spatial/spatialreg/issues/38 48 | #expect_true(isTRUE(all.equal(nd_p2f, nd_p3f, check.attributes=FALSE))) 49 | nd_COL.SDerr.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=TRUE, zero.policy=TRUE) 50 | nd_p1 <- predict(nd_COL.SDerr.eig) 51 | nd_p2 <- predict(nd_COL.SDerr.eig, newdata=nd, listw=lw, pred.type = "TS", 52 | legacy.mixed = TRUE, zero.policy=TRUE) 53 | nd_p3 <- predict(nd_COL.SDerr.eig, newdata=nd, listw=lw, pred.type = "TS", 54 | legacy=FALSE, legacy.mixed = TRUE, zero.policy=TRUE) 55 | expect_true(isTRUE(all.equal(nd_p2, nd_p3, check.attributes=FALSE))) 56 | nd_COL.SDerr.eig.f <- errorsarlm(CRIME ~ INC + HOVAL, data=COL_40, lw_40, Durbin=~ INC, zero.policy=TRUE) 57 | expect_error(nd_p2f <- predict(nd_COL.SDerr.eig.f, newdata=nd, listw=lw, pred.type = "TS", legacy=TRUE, zero.policy=TRUE)) # https://github.com/r-spatial/spatialreg/issues/38 58 | expect_error(nd_p3f <- predict(nd_COL.SDerr.eig.f, newdata=nd, listw=lw, pred.type = "TS", legacy=FALSE, zero.policy=TRUE)) # https://github.com/r-spatial/spatialreg/issues/38 59 | #expect_true(isTRUE(all.equal(nd_p2f, nd_p3f, check.attributes=FALSE))) 60 | 61 | 62 | -------------------------------------------------------------------------------- /inst/tinytest/test_Durbin_factor.R: -------------------------------------------------------------------------------- 1 | library(spatialreg) 2 | data(oldcol, package="spdep") 3 | lw <- spdep::nb2listw(COL.nb) 4 | COL.OLD$fEW <- factor(COL.OLD$EW) 5 | COL.OLD$fDISCBD <- ordered(cut(COL.OLD$DISCBD, c(0, 1.5, 3, 4.5, 6))) 6 | f <- formula(CRIME ~ INC + HOVAL + fDISCBD*fEW) 7 | expect_warning(COL.SLX0 <- lmSLX(f, data=COL.OLD, lw, Durbin=TRUE)) 8 | expect_warning(COL.SLX1 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 9 | expect_warning(COL.SLX2 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fEW)) 10 | expect_silent(COL.SLX3 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 11 | expect_warning(COL.err0 <- errorsarlm(f, data=COL.OLD, lw, Durbin=TRUE)) 12 | expect_warning(COL.err1 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 13 | expect_warning(COL.err2 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 14 | expect_silent(COL.err3 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 15 | expect_warning(COL.lag0 <- lagsarlm(f, data=COL.OLD, lw, Durbin=TRUE)) 16 | expect_warning(COL.lag1 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 17 | expect_warning(COL.lag2 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 18 | expect_silent(COL.lag3 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 19 | expect_warning(COL.sac0 <- sacsarlm(f, data=COL.OLD, lw, Durbin=TRUE)) 20 | expect_warning(COL.sac1 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 21 | expect_warning(COL.sac2 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 22 | expect_silent(COL.sac3 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 23 | expect_warning(COL.lag0 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=TRUE)) 24 | expect_warning(COL.lag1 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 25 | expect_warning(COL.lag2 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 26 | expect_silent(COL.lag3 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 27 | expect_warning(COL.err0 <- spBreg_err(f, data=COL.OLD, lw, Durbin=TRUE)) 28 | expect_warning(COL.err1 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 29 | expect_warning(COL.err2 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 30 | expect_silent(COL.err3 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 31 | expect_warning(COL.sac0 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=TRUE)) 32 | expect_warning(COL.sac1 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW)) 33 | expect_warning(COL.sac2 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD)) 34 | expect_silent(COL.sac3 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL)) 35 | 36 | -------------------------------------------------------------------------------- /inst/tinytest/test_SLX_no_intercept.R: -------------------------------------------------------------------------------- 1 | library(spatialreg) 2 | # https://github.com/r-spatial/spatialreg/issues/7 3 | data(oldcol, package="spdep") 4 | W <- spdep::nb2listw(COL.nb, style="W") 5 | expect_silent(slx <- lmSLX(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = W, Durbin=TRUE)) 6 | expect_silent(slx1 <- lmSLX(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = W, Durbin=~ 0 + INC)) 7 | summary(impacts(slx1)) 8 | expect_silent(sem <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = W)) 9 | expect_error(impacts(sem)) 10 | expect_silent(sdem <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = W, Durbin=TRUE)) 11 | summary(impacts(sdem)) 12 | expect_silent(sdem1 <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = W, Durbin=~ 0 + INC)) 13 | summary(impacts(sdem1)) 14 | B <- spdep::nb2listw(COL.nb, style="B") 15 | expect_silent(slxB <- lmSLX(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = B, Durbin=TRUE)) 16 | summary(impacts(slxB)) 17 | expect_silent(slx1B <- lmSLX(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = B, Durbin=~ 0 + INC)) 18 | summary(impacts(slx1B)) 19 | expect_silent(semB <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = B)) 20 | expect_error(impacts(semB)) 21 | expect_silent(sdemB <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = B, Durbin=TRUE)) 22 | summary(impacts(sdemB)) 23 | expect_silent(sdem1B <- errorsarlm(CRIME ~ 0 + INC + HOVAL, data = COL.OLD, listw = B, Durbin=~ 0 + INC)) 24 | summary(impacts(sdem1B)) 25 | 26 | -------------------------------------------------------------------------------- /inst/tinytest/test_SLX_not_W.R: -------------------------------------------------------------------------------- 1 | library(spatialreg) 2 | data(oldcol, package="spdep") 3 | lwB <- spdep::nb2listw(COL.nb, style="B") 4 | expect_silent(mod0 <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, listw=lwB)) 5 | coef(mod0) 6 | INCB <- spdep::lag.listw(lwB, COL.OLD$INC) 7 | HOVALB <- spdep::lag.listw(lwB, COL.OLD$HOVAL) 8 | INTERCEPTB <- spdep::card(lwB$neighbours) 9 | mod1 <- lm(CRIME ~ INC + HOVAL + INTERCEPTB + INCB + HOVALB, data=COL.OLD) 10 | expect_true(isTRUE(all.equal(unname(coef(mod0)), unname(coef(mod1))))) 11 | expect_silent(modx <- lmSLX(CRIME ~ INC + HOVAL + 0, data=COL.OLD, listw=lwB)) 12 | mod1x <- lm(CRIME ~ INC + HOVAL + 0 + INCB + HOVALB, data=COL.OLD) 13 | expect_true(isTRUE(all.equal(unname(coef(modx)), unname(coef(mod1x))))) 14 | expect_error(mod0_no_x <- lmSLX(CRIME ~ 1, data=COL.OLD, listw=lwB, Durbin=TRUE)) 15 | expect_error(mod0_no_x <- lmSLX(CRIME ~ 1, data=COL.OLD, listw=lwB, Durbin= ~ INC)) 16 | expect_warning(mod0_no_x <- errorsarlm(CRIME ~ 1, data=COL.OLD, listw=lwB, Durbin=TRUE)) 17 | expect_warning(mod0_no_x <- errorsarlm(CRIME ~ 1, data=COL.OLD, listw=lwB, Durbin= ~ INC)) 18 | 19 | -------------------------------------------------------------------------------- /man/MCMCsamp.Rd: -------------------------------------------------------------------------------- 1 | \name{MCMCsamp} 2 | \alias{MCMCsamp} 3 | \alias{MCMCsamp.Spautolm} 4 | \alias{MCMCsamp.Sarlm} 5 | %- Also NEED an '\alias' for EACH other topic documented here. 6 | \title{MCMC sample from fitted spatial regression} 7 | \description{The \code{MCMCsamp} method uses \code{\link[LearnBayes]{rwmetrop}}, a random walk Metropolis algorithm, from \pkg{LearnBayes} to make MCMC samples from fitted maximum likelihood spatial regression models.} 8 | \usage{ 9 | MCMCsamp(object, mcmc = 1L, verbose = NULL, ...) 10 | \method{MCMCsamp}{Spautolm}(object, mcmc = 1L, verbose = NULL, ..., 11 | burnin = 0L, scale=1, listw, control = list()) 12 | \method{MCMCsamp}{Sarlm}(object, mcmc = 1L, verbose = NULL, ..., 13 | burnin=0L, scale=1, listw, listw2=NULL, control=list())} 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{object}{A spatial regression model object fitted by maximum likelihood with \code{\link{spautolm}}} 17 | \item{mcmc}{The number of MCMC iterations after burnin} 18 | \item{verbose}{default NULL, use global option value; if TRUE, reports progress} 19 | \item{\dots}{Arguments passed through} 20 | \item{burnin}{The number of burn-in iterations for the sampler} 21 | \item{scale}{a positive scale parameter} 22 | \item{listw, listw2}{\code{listw} objects created for example by \code{nb2listw}; should be the same object(s) used for fitting the model} 23 | \item{control}{list of extra control arguments - see \code{\link{spautolm}}} 24 | } 25 | \value{An object of class \dQuote{mcmc} suited to \pkg{coda}, with attributes: \dQuote{accept} acceptance rate; \dQuote{type} input ML fitted model type \dQuote{SAR}, \dQuote{CAR}, \dQuote{SMA}, \dQuote{lag}, \dQuote{mixed}, \dQuote{error}, \dQuote{sac}, \dQuote{sacmixed}; \dQuote{timings} run times} 26 | \note{If the acceptance rate is below 0.05, a warning will be issued; consider increasing mcmc.} 27 | \references{Jim Albert (2007) Bayesian Computation with R, Springer, New York, pp. 104-105.} 28 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 29 | 30 | \seealso{\code{\link[LearnBayes]{rwmetrop}}, \code{\link{spautolm}}, \code{\link{lagsarlm}}, \code{\link{errorsarlm}}, \code{\link{sacsarlm}}} 31 | \examples{ 32 | require("sf", quietly=TRUE) 33 | nydata <- st_read(system.file("shapes/NY8_bna_utm18.gpkg", package="spData")[1], quiet=TRUE) 34 | suppressMessages(nyadjmat <- as.matrix(foreign::read.dbf(system.file( 35 | "misc/nyadjwts.dbf", package="spData")[1])[-1])) 36 | suppressMessages(ID <- as.character(names(foreign::read.dbf(system.file( 37 | "misc/nyadjwts.dbf", package="spData")[1]))[-1])) 38 | identical(substring(ID, 2, 10), substring(as.character(nydata$AREAKEY), 2, 10)) 39 | #require("spdep", quietly=TRUE) 40 | listw_NY <- spdep::mat2listw(nyadjmat, as.character(nydata$AREAKEY), style="B") 41 | esar1f <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 42 | listw=listw_NY, family="SAR", method="eigen") 43 | summary(esar1f) 44 | res <- MCMCsamp(esar1f, mcmc=1000, burnin=200, listw=listw_NY) 45 | summary(res) 46 | \dontrun{ 47 | esar1fw <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 48 | listw=listw_NY, weights=POP8, family="SAR", method="eigen") 49 | summary(esar1fw) 50 | res <- MCMCsamp(esar1fw, mcmc=5000, burnin=500, listw=listw_NY) 51 | summary(res) 52 | ecar1f <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 53 | listw=listw_NY, family="CAR", method="eigen") 54 | summary(ecar1f) 55 | res <- MCMCsamp(ecar1f, mcmc=5000, burnin=500, listw=listw_NY) 56 | summary(res) 57 | esar1fw <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 58 | listw=listw_NY, weights=POP8, family="SAR", method="eigen") 59 | summary(esar1fw) 60 | res <- MCMCsamp(esar1fw, mcmc=5000, burnin=500, listw=listw_NY) 61 | summary(res) 62 | ecar1fw <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 63 | listw=listw_NY, weights=POP8, family="CAR", method="eigen") 64 | summary(ecar1fw) 65 | res <- MCMCsamp(ecar1fw, mcmc=5000, burnin=500, listw=listw_NY) 66 | summary(res) 67 | } 68 | esar0 <- errorsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 69 | listw=listw_NY) 70 | summary(esar0) 71 | res <- MCMCsamp(esar0, mcmc=1000, burnin=200, listw=listw_NY) 72 | summary(res) 73 | \dontrun{ 74 | esar0w <- errorsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 75 | listw=listw_NY, weights=POP8) 76 | summary(esar0) 77 | res <- MCMCsamp(esar0w, mcmc=5000, burnin=500, listw=listw_NY) 78 | summary(res) 79 | esar1 <- errorsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 80 | listw=listw_NY, etype="emixed") 81 | summary(esar1) 82 | res <- MCMCsamp(esar1, mcmc=5000, burnin=500, listw=listw_NY) 83 | summary(res) 84 | lsar0 <- lagsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 85 | listw=listw_NY) 86 | summary(lsar0) 87 | res <- MCMCsamp(lsar0, mcmc=5000, burnin=500, listw=listw_NY) 88 | summary(res) 89 | lsar1 <- lagsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 90 | listw=listw_NY, type="mixed") 91 | summary(lsar1) 92 | res <- MCMCsamp(lsar1, mcmc=5000, burnin=500, listw=listw_NY) 93 | summary(res) 94 | ssar0 <- sacsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 95 | listw=listw_NY) 96 | summary(ssar0) 97 | res <- MCMCsamp(ssar0, mcmc=5000, burnin=500, listw=listw_NY) 98 | summary(res) 99 | ssar1 <- sacsarlm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME, data=nydata, 100 | listw=listw_NY, type="sacmixed") 101 | summary(ssar1) 102 | res <- MCMCsamp(ssar1, mcmc=5000, burnin=500, listw=listw_NY) 103 | summary(res) 104 | } 105 | } 106 | % Add one or more standard keywords, see file 'KEYWORDS' in the 107 | % R documentation directory. 108 | \keyword{spatial} 109 | -------------------------------------------------------------------------------- /man/SpatialFiltering.Rd: -------------------------------------------------------------------------------- 1 | \name{SpatialFiltering} 2 | \alias{SpatialFiltering} 3 | \alias{print.SfResult} 4 | \alias{fitted.SfResult} 5 | %- Also NEED an '\alias' for EACH other topic documented here. 6 | \title{Semi-parametric spatial filtering} 7 | \description{ 8 | The function selects eigenvectors in a semi-parametric spatial filtering approach to removing spatial dependence from linear models. Selection is by brute force by finding the single eigenvector reducing the standard variate of Moran's I for regression residuals most, and continuing until no candidate eigenvector reduces the value by more than \code{tol}. It returns a summary table from the selection process and a matrix of selected eigenvectors for the specified model. 9 | } 10 | \usage{ 11 | SpatialFiltering(formula, lagformula=NULL, data=list(), na.action=na.fail, 12 | nb=NULL, glist = NULL, 13 | style = "C", zero.policy = NULL, tol = 0.1, zerovalue = 1e-04, 14 | ExactEV = FALSE, symmetric = TRUE, alpha=NULL, alternative="two.sided", 15 | verbose=NULL) 16 | } 17 | %- maybe also 'usage' for other objects documented here. 18 | \arguments{ 19 | \item{formula}{a symbolic description of the model to be fit, assuming a spatial error representation; when lagformula is given, it should include only the response and the intercept term} 20 | \item{lagformula}{An extra one-sided formula to be used when a spatial lag representation is desired; the intercept is excluded within the function if present because it is part of the formula argument, but excluding it explicitly in the lagformula argument in the presence of factors generates a collinear model matrix} 21 | \item{data}{an optional data frame containing the variables in the model} 22 | \item{nb}{an object of class \code{nb}} 23 | \item{glist}{list of general weights corresponding to neighbours} 24 | \item{style}{\code{style} can take values W, B, C, U, and S} 25 | \item{na.action}{a function (default \code{options("na.action")}), can also be \code{na.omit} or \code{na.exclude} with consequences for residuals and fitted values - in these cases the spatial weights list will be subsetted to remove NAs in the data. It may be necessary to set zero.policy to TRUE because this subsetting may create no-neighbour observations. Note that only weights lists created without using the glist argument to \code{nb2listw} may be subsetted.} 26 | \item{zero.policy}{default NULL, use global option value; if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zero-length weights vectors} 27 | \item{tol}{tolerance value for convergence of spatial filtering} 28 | \item{zerovalue}{eigenvectors with eigenvalues of an absolute value smaller than zerovalue will be excluded in eigenvector search} 29 | \item{ExactEV}{Set ExactEV=TRUE to use exact expectations and variances rather than the expectation and variance of Moran's I from the previous iteration, default FALSE} 30 | \item{symmetric}{Should the spatial weights matrix be forced to symmetry, default TRUE} 31 | \item{alpha}{if not NULL, used instead of the tol= argument as a stopping rule to choose all eigenvectors up to and including the one with a probability value exceeding alpha.} 32 | \item{alternative}{a character string specifying the alternative hypothesis, must be one of greater, less or two.sided (default).} 33 | \item{verbose}{default NULL, use global option value; if TRUE report eigenvectors selected} 34 | } 35 | \value{ 36 | An \code{SfResult} object, with: 37 | \item{selection}{a matrix summarising the selection of eigenvectors for inclusion, with columns: 38 | \describe{ 39 | \item{Step}{Step counter of the selection procedure} 40 | \item{SelEvec}{number of selected eigenvector (sorted descending)} 41 | \item{Eval}{its associated eigenvalue} 42 | \item{MinMi}{value Moran's I for residual autocorrelation} 43 | \item{ZMinMi}{standardized value of Moran's I assuming a normal approximation} 44 | \item{pr(ZI)}{probability value of the permutation-based standardized deviate for the given value of the alternative argument} 45 | \item{R2}{R^2 of the model including exogenous variables and eigenvectors} 46 | \item{gamma}{regression coefficient of selected eigenvector in fit} 47 | } 48 | The first row is the value at the start of the search 49 | } 50 | \item{dataset}{a matrix of the selected eigenvectors in order of selection} 51 | } 52 | \references{Tiefelsdorf M, Griffith DA. (2007) Semiparametric Filtering of Spatial Autocorrelation: The Eigenvector Approach. Environment and Planning A, 39 (5) 1193 - 1221.} 53 | \author{Yongwan Chun, Michael Tiefelsdorf, Roger Bivand} 54 | 55 | \seealso{\code{\link[stats]{lm}}, \code{\link[base]{eigen}}, \code{\link[spdep]{nb2listw}}, \code{\link[spdep]{listw2U}}} 56 | \examples{ 57 | require("sf", quietly=TRUE) 58 | columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) 59 | #require("spdep", quietly=TRUE) 60 | col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) 61 | lmbase <- lm(CRIME ~ INC + HOVAL, data=columbus) 62 | sarcol <- SpatialFiltering(CRIME ~ INC + HOVAL, data=columbus, 63 | nb=col.gal.nb, style="W", ExactEV=TRUE) 64 | sarcol 65 | lmsar <- lm(CRIME ~ INC + HOVAL + fitted(sarcol), data=columbus) 66 | (x <- summary(lmsar)) 67 | coef(x) 68 | anova(lmbase, lmsar) 69 | spdep::lm.morantest(lmsar, spdep::nb2listw(col.gal.nb)) 70 | lagcol <- SpatialFiltering(CRIME ~ 1, ~ INC + HOVAL - 1, data=columbus, 71 | nb=col.gal.nb, style="W") 72 | lagcol 73 | lmlag <- lm(CRIME ~ INC + HOVAL + fitted(lagcol), data=columbus) 74 | lmlag 75 | anova(lmbase, lmlag) 76 | spdep::lm.morantest(lmlag, spdep::nb2listw(col.gal.nb)) 77 | NA.columbus <- columbus 78 | NA.columbus$CRIME[20:25] <- NA 79 | COL.SF.NA <- SpatialFiltering(CRIME ~ INC + HOVAL, data=NA.columbus, 80 | nb=col.gal.nb, style="W", na.action=na.exclude) 81 | COL.SF.NA$na.action 82 | summary(lm(CRIME ~ INC + HOVAL + fitted(COL.SF.NA), data=NA.columbus, 83 | na.action=na.exclude)) 84 | } 85 | \keyword{spatial} 86 | 87 | -------------------------------------------------------------------------------- /man/aple.Rd: -------------------------------------------------------------------------------- 1 | \name{aple} 2 | \alias{aple} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Approximate profile-likelihood estimator (APLE)} 5 | \description{ 6 | The Approximate profile-likelihood estimator (APLE) of the simultaneous autoregressive model's spatial dependence parameter was introduced in Li et al. (2007). It employs a correction term using the eigenvalues of the spatial weights matrix, and consequently should not be used for large numbers of observations. It also requires that the variable has a mean of zero, and it is assumed that it has been detrended. The spatial weights object is assumed to be row-standardised, that is using default \code{style="W"} in \code{nb2listw}. 7 | } 8 | \usage{ 9 | aple(x, listw, override_similarity_check=FALSE, useTrace=TRUE) 10 | } 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{x}{a zero-mean detrended continuous variable} 14 | \item{listw}{a \code{listw} object from for example \code{spdep::nb2listw}} 15 | \item{override_similarity_check}{default FALSE, if TRUE - typically for row-standardised weights with asymmetric underlying general weights - similarity is not checked} 16 | \item{useTrace}{default TRUE, use trace of sparse matrix \code{W \%*\% W} (Li et al. (2010)), if FALSE, use crossproduct of eigenvalues of \code{W} as in Li et al. (2007)} 17 | } 18 | \details{ 19 | This implementation has been checked with Hongfei Li's own implementation using her data; her help was very valuable. 20 | } 21 | \value{ 22 | A scalar APLE value. 23 | } 24 | \references{Li, H, Calder, C. A. and Cressie N. A. C. (2007) Beyond Moran's I: testing for spatial dependence based on the spatial autoregressive model. Geographical Analysis 39, 357-375; Li, H, Calder, C. A. and Cressie N. A. C. (2012) One-step estimation of spatial dependence parameters: Properties and extensions of the APLE statistic, Journal of Multivariate Analysis 105, 68-84.} 25 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 26 | 27 | \seealso{\code{\link[spdep]{nb2listw}}, \code{\link{aple.mc}}, \code{\link{aple.plot}} 28 | } 29 | \examples{ 30 | wheat <- st_read(system.file("shapes/wheat.gpkg", package="spData")[1], quiet=TRUE) 31 | library(spdep) 32 | nbr1 <- spdep::poly2nb(wheat, queen=FALSE) 33 | nbrl <- spdep::nblag(nbr1, 2) 34 | nbr12 <- spdep::nblag_cumul(nbrl) 35 | cms0 <- with(as.data.frame(wheat), tapply(yield, c, median)) 36 | cms1 <- c(model.matrix(~ factor(c) -1, data=wheat) \%*\% cms0) 37 | wheat$yield_detrend <- wheat$yield - cms1 38 | isTRUE(all.equal(c(with(as.data.frame(wheat), 39 | tapply(yield_detrend, c, median))), rep(0.0, 25), 40 | check.attributes=FALSE)) 41 | spdep::moran.test(wheat$yield_detrend, spdep::nb2listw(nbr12, style="W")) 42 | aple(as.vector(scale(wheat$yield_detrend, scale=FALSE)), spdep::nb2listw(nbr12, style="W")) 43 | \dontrun{ 44 | errorsarlm(yield_detrend ~ 1, wheat, spdep::nb2listw(nbr12, style="W")) 45 | } 46 | } 47 | % Add one or more standard keywords, see file 'KEYWORDS' in the 48 | % R documentation directory. 49 | \keyword{spatial} 50 | 51 | -------------------------------------------------------------------------------- /man/aple.mc.Rd: -------------------------------------------------------------------------------- 1 | \name{aple.mc} 2 | \alias{aple.mc} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Approximate profile-likelihood estimator (APLE) permutation test} 5 | \description{ 6 | A permutation bootstrap test for the approximate profile-likelihood estimator (APLE). 7 | } 8 | \usage{ 9 | aple.mc(x, listw, nsim, override_similarity_check=FALSE, useTrace=TRUE) 10 | } 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{x}{a zero-mean detrended continuous variable} 14 | \item{listw}{a \code{listw} object from for example \code{spdep::nb2listw}} 15 | \item{nsim}{number of simulations} 16 | \item{override_similarity_check}{default FALSE, if TRUE - typically for row-standardised weights with asymmetric underlying general weights - similarity is not checked} 17 | \item{useTrace}{default TRUE, use trace of sparse matrix \code{W \%*\% W} (Li et al. (2010)), if FALSE, use crossproduct of eigenvalues of \code{W} as in Li et al. (2007)} 18 | } 19 | 20 | \value{ 21 | A \code{boot} object as returned by the \code{boot} function. 22 | } 23 | \references{Li, H, Calder, C. A. and Cressie N. A. C. (2007) Beyond Moran's I: testing for spatial dependence based on the spatial autoregressive model. Geographical Analysis 39, 357-375; Li, H, Calder, C. A. and Cressie N. A. C. (2012) One-step estimation of spatial dependence parameters: Properties and extensions of the APLE statistic, Journal of Multivariate Analysis 105, 68-84.} 24 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 25 | 26 | \seealso{\code{\link{aple}}, \code{\link[boot]{boot}}} 27 | \examples{ 28 | \dontrun{ 29 | wheat <- st_read(system.file("shapes/wheat.gpkg", package="spData")[1], quiet=TRUE) 30 | nbr1 <- spdep::poly2nb(wheat, queen=FALSE) 31 | nbrl <- spdep::nblag(nbr1, 2) 32 | nbr12 <- spdep::nblag_cumul(nbrl) 33 | wheat_g <- wheat 34 | st_geometry(wheat_g) <- NULL 35 | cms0 <- with(wheat_g, tapply(yield, c, median)) 36 | cms1 <- c(model.matrix(~ factor(c) -1, data=wheat) \%*\% cms0) 37 | wheat$yield_detrend <- wheat$yield - cms1 38 | oldRNG <- RNGkind() 39 | RNGkind("L'Ecuyer-CMRG") 40 | set.seed(1L) 41 | boot_out_ser <- aple.mc(as.vector(scale(wheat$yield_detrend, scale=FALSE)), 42 | spdep::nb2listw(nbr12, style="W"), nsim=500) 43 | plot(boot_out_ser) 44 | boot_out_ser 45 | library(parallel) 46 | oldCores <- set.coresOption(NULL) 47 | nc <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L 48 | # set nc to 1L here 49 | if (nc > 1L) nc <- 1L 50 | invisible(set.coresOption(nc)) 51 | set.seed(1L) 52 | if (!get.mcOption()) { 53 | cl <- makeCluster(nc) 54 | set.ClusterOption(cl) 55 | } else{ 56 | mc.reset.stream() 57 | } 58 | boot_out_par <- aple.mc(as.vector(scale(wheat$yield_detrend, scale=FALSE)), 59 | spdep::nb2listw(nbr12, style="W"), nsim=500) 60 | if (!get.mcOption()) { 61 | set.ClusterOption(NULL) 62 | stopCluster(cl) 63 | } 64 | boot_out_par 65 | invisible(set.coresOption(oldCores)) 66 | RNGkind(oldRNG[1], oldRNG[2]) 67 | } 68 | } 69 | % Add one or more standard keywords, see file 'KEYWORDS' in the 70 | % R documentation directory. 71 | \keyword{spatial} 72 | 73 | -------------------------------------------------------------------------------- /man/aple.plot.Rd: -------------------------------------------------------------------------------- 1 | \name{aple.plot} 2 | \alias{aple.plot} 3 | \alias{localAple} 4 | %- Also NEED an '\alias' for EACH other topic documented here. 5 | \title{Approximate profile-likelihood estimator (APLE) scatterplot} 6 | \description{ 7 | A scatterplot decomposition of the approximate profile-likelihood estimator, and a local APLE based on the list of vectors returned by the scatterplot function. 8 | } 9 | \usage{ 10 | aple.plot(x, listw, override_similarity_check=FALSE, useTrace=TRUE, do.plot=TRUE, ...) 11 | localAple(x, listw, override_similarity_check=FALSE, useTrace=TRUE) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{a zero-mean detrended continuous variable} 16 | \item{listw}{a \code{listw} object from for example \code{spdep::nb2listw}} 17 | \item{override_similarity_check}{default FALSE, if TRUE - typically for row-standardised weights with asymmetric underlying general weights - similarity is not checked} 18 | \item{useTrace}{default TRUE, use trace of sparse matrix \code{W \%*\% W} (Li et al. (2010)), if FALSE, use crossproduct of eigenvalues of \code{W} as in Li et al. (2007)} 19 | \item{do.plot}{default TRUE: should a scatterplot be drawn} 20 | \item{\dots}{other arguments to be passed to \code{plot}} 21 | } 22 | \details{ 23 | The function solves a secondary eigenproblem of size n internally, so constructing the values for the scatterplot is quite compute and memory intensive, and is not suitable for very large n. 24 | } 25 | \value{ 26 | \code{aple.plot} returns list with components: 27 | \item{X}{A vector as described in Li et al. (2007), p. 366.} 28 | \item{Y}{A vector as described in Li et al. (2007), p. 367.} 29 | 30 | \code{localAple} returns a vector of local APLE values. 31 | } 32 | \references{Li, H, Calder, C. A. and Cressie N. A. C. (2007) Beyond Moran's I: testing for spatial dependence based on the spatial autoregressive model. Geographical Analysis 39, pp. 357-375; Li, H, Calder, C. A. and Cressie N. A. C. (2012) One-step estimation of spatial dependence parameters: Properties and extensions of the APLE statistic, Journal of Multivariate Analysis 105, 68-84.} 33 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 34 | 35 | \seealso{\code{\link{aple}}} 36 | \examples{ 37 | \dontrun{ 38 | wheat <- st_read(system.file("shapes/wheat.gpkg", package="spData")[1], quiet=TRUE) 39 | nbr1 <- spdep::poly2nb(wheat, queen=FALSE) 40 | nbrl <- spdep::nblag(nbr1, 2) 41 | nbr12 <- spdep::nblag_cumul(nbrl) 42 | cms0 <- with(as.data.frame(wheat), tapply(yield, c, median)) 43 | cms1 <- c(model.matrix(~ factor(c) -1, data=wheat) \%*\% cms0) 44 | wheat$yield_detrend <- wheat$yield - cms1 45 | plt_out <- aple.plot(as.vector(scale(wheat$yield_detrend, scale=FALSE)), 46 | spdep::nb2listw(nbr12, style="W"), cex=0.6) 47 | lm_obj <- lm(Y ~ X, plt_out) 48 | abline(lm_obj) 49 | abline(v=0, h=0, lty=2) 50 | zz <- summary(influence.measures(lm_obj)) 51 | infl <- as.integer(rownames(zz)) 52 | points(plt_out$X[infl], plt_out$Y[infl], pch=3, cex=0.6, col="red") 53 | crossprod(plt_out$Y, plt_out$X)/crossprod(plt_out$X) 54 | wheat$localAple <- localAple(as.vector(scale(wheat$yield_detrend, scale=FALSE)), 55 | spdep::nb2listw(nbr12, style="W")) 56 | mean(wheat$localAple) 57 | hist(wheat$localAple) 58 | opar <- par(no.readonly=TRUE) 59 | plot(wheat[,"localAple"], reset=FALSE) 60 | text(st_coordinates(st_centroid(st_geometry(wheat)))[infl,], labels=rep("*", length(infl))) 61 | par(opar) 62 | } 63 | } 64 | % Add one or more standard keywords, see file 'KEYWORDS' in the 65 | % R documentation directory. 66 | \keyword{spatial} 67 | 68 | -------------------------------------------------------------------------------- /man/lextrB.Rd: -------------------------------------------------------------------------------- 1 | \name{lextrB} 2 | \alias{lextrB} 3 | \alias{lextrW} 4 | \alias{lextrS} 5 | \alias{l_max} 6 | %- Also NEED an '\alias' for EACH other topic documented here. 7 | \title{Find extreme eigenvalues of binary symmetric spatial weights} 8 | \description{The functions find extreme eigenvalues of binary symmetric spatial weights, when these form planar graphs; general weights are not permiited. \code{l_max} finds the largest eigenvalue using Rayleigh quotient methods of any \dQuote{listw} object. \code{lextrB} first calls \code{l_max}, and uses its output to find the smallest eigenvalue in addition for binary symmetric spatial weights. \code{lextrW} extends these to find the smallest eigenvalue for intrinsically symmetric row-standardized binary weights matrices (transformed to symmetric through similarity internally). \code{lextrS} does the same for variance-stabilized (\dQuote{S} style) intrinsically symmetric binary weights matrices (transformed to symmetric through similarity internally).} 9 | \usage{ 10 | lextrB(lw, zero.policy = TRUE, control = list()) 11 | lextrW(lw, zero.policy=TRUE, control=list()) 12 | lextrS(lw, zero.policy=TRUE, control=list()) 13 | l_max(lw, zero.policy=TRUE, control=list()) 14 | } 15 | %- maybe also 'usage' for other objects documented here. 16 | \arguments{ 17 | \item{lw}{a binary symmetric \code{listw} object from, for example, \code{nb2listw} with style \dQuote{B} for \code{lextrB}, style \dQuote{W} for \code{lextrW} and style \dQuote{S} for \code{lextrS}; for \code{l_max}, the object may be asymmetric and does not have to be binary} 18 | \item{zero.policy}{default NULL, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE assign NA} 19 | \item{control}{a list of control arguments} 20 | } 21 | \section{Control arguments}{ 22 | \describe{ 23 | \item{trace}{report values in while loops, default NULL assuming FALSE; logical} 24 | \item{tol}{tolerance for breaking while loops, default \code{.Machine$double.eps^(1/2)}; numeric} 25 | \item{maxiter}{maximum number of iterations in while loops, default \code{6 * (length(lw$neighbours) - 2}; integer} 26 | \item{useC}{use C code, default TRUE, logical (not in \code{l_max})} 27 | } 28 | } 29 | \value{ 30 | The functions return approximations to the extreme eigenvalues with the eigenvectors returned as attributes of this object. 31 | } 32 | \references{Griffith, D. A. (2004). Extreme eigenfunctions of adjacency matrices for planar graphs employed in spatial analyses. \emph{Linear Algebra and its Applications}, 388:201--219.} 33 | \author{Roger Bivand, Yongwan Chun, Daniel Griffith} 34 | 35 | \note{It may be necessary to modify control arguments if warnings about lack of convergence are seen.} 36 | 37 | \examples{ 38 | data(boston, package="spData") 39 | #require(spdep, quietly=TRUE) 40 | ab.listb <- spdep::nb2listw(boston.soi, style="B") 41 | er <- range(eigenw(ab.listb)) 42 | er 43 | res_1 <- lextrB(ab.listb) 44 | c(res_1) 45 | run <- FALSE 46 | if (require("RSpectra", quietly=TRUE)) run <- TRUE 47 | if (run) { 48 | B <- as(ab.listb, "CsparseMatrix") 49 | eigs(B, k=1, which="SR")$values 50 | } 51 | if (run) { 52 | eigs(B, k=1, which="LR")$values 53 | } 54 | k5 <- spdep::knn2nb(spdep::knearneigh(boston.utm, k=5)) 55 | c(l_max(spdep::nb2listw(k5, style="B"))) 56 | max(Re(eigenw(spdep::nb2listw(k5, style="B")))) 57 | c(l_max(spdep::nb2listw(k5, style="C"))) 58 | max(Re(eigenw(spdep::nb2listw(k5, style="C")))) 59 | ab.listw <- spdep::nb2listw(boston.soi, style="W") 60 | er <- range(eigenw(similar.listw(ab.listw))) 61 | er 62 | res_1 <- lextrW(ab.listw) 63 | c(res_1) 64 | if (run) { 65 | B <- as(similar.listw(ab.listw), "CsparseMatrix") 66 | eigs(B, k=1, which="SR")$values 67 | } 68 | if (run) { 69 | eigs(B, k=1, which="LR")$values 70 | } 71 | \dontrun{ 72 | ab.listw <- spdep::nb2listw(boston.soi, style="S") 73 | er <- range(eigenw(similar.listw(ab.listw))) 74 | er 75 | res_1 <- lextrS(ab.listw) 76 | c(res_1) 77 | } 78 | if (run) { 79 | B <- as(similar.listw(ab.listw), "CsparseMatrix") 80 | eigs(B, k=1, which="SR")$values 81 | } 82 | if (run) { 83 | eigs(B, k=1, which="LR")$values 84 | } 85 | } 86 | % Add one or more standard keywords, see file 'KEYWORDS' in the 87 | % R documentation directory. 88 | \keyword{spatial} 89 | -------------------------------------------------------------------------------- /man/sarlm_tests.Rd: -------------------------------------------------------------------------------- 1 | % Copyright 2002-9 by Roger S. Bivand 2 | \name{LR.Sarlm} 3 | \alias{LR.Sarlm} 4 | \alias{LR1.Sarlm} 5 | \alias{Wald1.Sarlm} 6 | \alias{Hausman.test} 7 | \alias{Hausman.test.Sarlm} 8 | \alias{logLik.Sarlm} 9 | \alias{anova.Sarlm} 10 | \alias{bptest.Sarlm} 11 | \alias{impacts.Sarlm} 12 | 13 | %- Also NEED an `\alias' for EACH other topic documented here. 14 | \title{Likelihood ratio test} 15 | \description{ 16 | The \code{LR.Sarlm()} function provides a likelihood ratio test for objects for which a \code{logLik()} function exists for their class, or for objects of class \code{logLik}. \code{LR1.Sarlm()} and \code{Wald1.Sarlm()} are used internally in \code{summary.Sarlm()}, but may be accessed directly; they report the values respectively of LR and Wald tests for the absence of spatial dependence in spatial lag or error models. The spatial Hausman test is available for models fitted with \code{errorSarlm} and \code{GMerrorsar}. 17 | } 18 | \usage{ 19 | LR.Sarlm(x, y) 20 | \method{logLik}{Sarlm}(object, ...) 21 | LR1.Sarlm(object) 22 | Wald1.Sarlm(object) 23 | \method{Hausman.test}{Sarlm}(object, ..., tol=NULL) 24 | \method{anova}{Sarlm}(object, ...) 25 | bptest.Sarlm(object, varformula=NULL, studentize = TRUE, data=list()) 26 | \method{impacts}{Sarlm}(obj, \dots, tr, R = NULL, listw = NULL, evalues=NULL, 27 | useHESS = NULL, tol = 1e-06, empirical = FALSE, Q=NULL) 28 | } 29 | %- maybe also `usage' for other objects documented here. 30 | \arguments{ 31 | \item{x}{a \code{logLik} object or an object for which a \code{logLik()} function exists} 32 | \item{y}{a \code{logLik} object or an object for which a \code{logLik()} function exists} 33 | \item{object, obj}{a \code{Sarlm} object} 34 | \item{\dots}{further arguments passed to or from other methods} 35 | % \item{tol}{\code{tol} argument passed to \code{solve}, default NULL} 36 | \item{varformula}{a formula describing only the potential explanatory variables for the variance (no dependent variable needed). By default the same explanatory variables are taken as in the main regression model} 37 | \item{studentize}{logical. If set to \code{TRUE} Koenker's studentized 38 | version of the test statistic will be used.} 39 | \item{data}{an optional data frame containing the variables in the varformula} \item{tr}{A vector of traces of powers of the spatial weights matrix created using \code{trW}, for approximate impact measures; if not given, \code{listw} must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression, and must be row-standardised} 40 | \item{listw}{If \code{tr} is not given, a spatial weights object as created by \code{nb2listw}; they must be the same spatial weights as were used in fitting the spatial regression, but do not have to be row-standardised} 41 | \item{evalues}{vector of eigenvalues of spatial weights matrix for impacts calculations} 42 | \item{R}{If given, simulations are used to compute distributions for the impact measures, returned as \code{mcmc} objects; the objects are used for convenience but are not output by an MCMC process} 43 | \item{useHESS}{Use the Hessian approximation (if available) even if the asymptotic coefficient covariance matrix is available; used for comparing methods} 44 | \item{tol}{Argument passed to \code{mvrnorm} and \code{solve}: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix} 45 | \item{empirical}{Argument passed to \code{mvrnorm} (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix} 46 | \item{Q}{default NULL, else an integer number of cumulative power series impacts to calculate if \code{tr} is given} 47 | } 48 | \value{ 49 | The tests return objects of class \code{htest} with: 50 | \item{statistic}{value of statistic} 51 | \item{parameter}{degrees of freedom} 52 | \item{p.value}{Probability value} 53 | \item{estimate}{varies with test} 54 | \item{method}{description of test method} 55 | 56 | \code{logLik.Sarlm()} returns an object of class \code{logLik} 57 | \code{LR1.Sarlm}, \code{Hausman.Sarlm} and \code{Wald1.Sarlm} returm objects of class \code{htest} 58 | } 59 | 60 | \note{The numbers of degrees of freedom returned by \code{logLik.Sarlm()} include nuisance parameters, that is the number of regression coefficients, plus sigma, plus spatial parameter esitmate(s).} 61 | 62 | \references{LeSage J and RK Pace (2009) Introduction to Spatial Econometrics. CRC Press, Boca Raton, pp. 61--63; Pace RK and LeSage J (2008) A spatial Hausman test. \emph{Economics Letters} 101, 282--284. 63 | T.S. Breusch & A.R. Pagan (1979), 64 | A Simple Test for Heteroscedasticity and Random Coefficient Variation. 65 | \emph{Econometrica} \bold{47}, 1287--1294 66 | 67 | W. Krämer & H. Sonnberger (1986), 68 | \emph{The Linear Regression Model under Test}. Heidelberg: Physica. 69 | 70 | L. Anselin (1988) \emph{Spatial econometrics: methods and models.} 71 | Dordrecht: Kluwer, pp. 121--122. 72 | } 73 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}, \code{bptest}: Torsten Hothorn and Achim Zeileis, modified by Roger Bivand} 74 | 75 | \seealso{\code{\link{logLik.lm}}, \code{\link{anova.Sarlm}}} 76 | 77 | \examples{ 78 | require("sf", quietly=TRUE) 79 | columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) 80 | #require("spdep", quietly=TRUE) 81 | col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) 82 | lm.mod <- lm(CRIME ~ HOVAL + INC, data=columbus) 83 | lag <- lagsarlm(CRIME ~ HOVAL + INC, data=columbus, spdep::nb2listw(col.gal.nb)) 84 | mixed <- lagsarlm(CRIME ~ HOVAL + INC, data=columbus, spdep::nb2listw(col.gal.nb), type="mixed") 85 | error <- errorsarlm(CRIME ~ HOVAL + INC, data=columbus, spdep::nb2listw(col.gal.nb)) 86 | Hausman.test(error) 87 | LR.Sarlm(mixed, error) 88 | anova(lag, lm.mod) 89 | anova(lag, error, mixed) 90 | AIC(lag, error, mixed) 91 | bptest.Sarlm(error) 92 | bptest.Sarlm(error, studentize=FALSE) 93 | } 94 | 95 | \keyword{spatial} 96 | -------------------------------------------------------------------------------- /man/set.mcOption.Rd: -------------------------------------------------------------------------------- 1 | \name{set.mcOption} 2 | \alias{set.ClusterOption} 3 | \alias{get.ClusterOption} 4 | \alias{set.mcOption} 5 | \alias{get.coresOption} 6 | \alias{set.coresOption} 7 | \alias{get.mcOption} 8 | %- Also NEED an `\alias' for EACH other topic documented here. 9 | \title{Options for parallel support} 10 | \description{ 11 | Provides support for the use of parallel computation in the parallel package. 12 | } 13 | \usage{ 14 | set.mcOption(value) 15 | get.mcOption() 16 | set.coresOption(value) 17 | get.coresOption() 18 | set.ClusterOption(cl) 19 | get.ClusterOption() 20 | } 21 | %- maybe also `usage' for other objects documented here. 22 | \arguments{ 23 | \item{value}{valid replacement value} 24 | \item{cl}{a cluster object created by \code{makeCluster} in \pkg{parallel}} 25 | } 26 | \details{ 27 | Options in the spatialreg package are held in an environment local to the package namespace and not exported. Option values are set and retrieved with pairs of access functions, get and set. The \code{mc} option is set by default to FALSE on Windows systems, as they cannot fork the R session; by default it is TRUE on other systems, but may be set FALSE. If \code{mc} is FALSE, the \code{Cluster} option is used: if \code{mc} is FALSE and the \code{Cluster} option is NULL no parallel computing is done, or the \code{Cluster} option is passed a \dQuote{cluster} object created by the parallel or snow package for access without being passed as an argument. The \code{cores} option is set to NULL by default, and can be used to store the number of cores to use as an integer. If \code{cores} is NULL, facilities from the parallel package will not be used. 28 | } 29 | \value{ 30 | The option access functions return their current settings, the assignment functions usually return the previous value of the option. 31 | } 32 | \note{An extended example is shown in the documentation of \code{\link{mom_calc}}, including treatment of seeding of RNG for multicore/cluster.} 33 | 34 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 35 | 36 | 37 | \examples{ 38 | ls(envir=spatialreg:::.spatialregOptions) 39 | library(parallel) 40 | nc <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L 41 | nc 42 | # set nc to 1L here 43 | if (nc > 1L) nc <- 1L 44 | #nc <- ifelse(nc > 2L, 2L, nc) 45 | coresOpt <- get.coresOption() 46 | coresOpt 47 | if (!is.na(nc)) { 48 | invisible(set.coresOption(nc)) 49 | print(exists("mom_calc")) 50 | if(.Platform$OS.type == "windows") { 51 | # forking not permitted on Windows - start cluster 52 | # removed for Github actions 210502 53 | \dontrun{ 54 | print(get.mcOption()) 55 | cl <- makeCluster(get.coresOption()) 56 | print(clusterEvalQ(cl, exists("mom_calc"))) 57 | set.ClusterOption(cl) 58 | clusterEvalQ(get.ClusterOption(), library(spatialreg)) 59 | print(clusterEvalQ(cl, exists("mom_calc"))) 60 | clusterEvalQ(get.ClusterOption(), detach(package:spatialreg)) 61 | set.ClusterOption(NULL) 62 | print(clusterEvalQ(cl, exists("mom_calc"))) 63 | stopCluster(cl) 64 | } 65 | } else { 66 | mcOpt <- get.mcOption() 67 | print(mcOpt) 68 | print(mclapply(1:get.coresOption(), function(i) exists("mom_calc"), 69 | mc.cores=get.coresOption())) 70 | invisible(set.mcOption(FALSE)) 71 | cl <- makeCluster(nc) 72 | print(clusterEvalQ(cl, exists("mom_calc"))) 73 | set.ClusterOption(cl) 74 | clusterEvalQ(get.ClusterOption(), library(spatialreg)) 75 | print(clusterEvalQ(cl, exists("mom_calc"))) 76 | clusterEvalQ(get.ClusterOption(), detach(package:spatialreg)) 77 | set.ClusterOption(NULL) 78 | print(clusterEvalQ(cl, exists("mom_calc"))) 79 | stopCluster(cl) 80 | invisible(set.mcOption(mcOpt)) 81 | } 82 | invisible(set.coresOption(coresOpt)) 83 | } 84 | } 85 | \keyword{ spatial } 86 | -------------------------------------------------------------------------------- /man/set.spChkOption.Rd: -------------------------------------------------------------------------------- 1 | \name{set.ZeroPolicyOption} 2 | \alias{set.VerboseOption} 3 | \alias{get.VerboseOption} 4 | \alias{set.ZeroPolicyOption} 5 | \alias{get.ZeroPolicyOption} 6 | %\alias{set.listw_is_CsparseMatrix_Option} 7 | %\alias{get.listw_is_CsparseMatrix_Option} 8 | %- Also NEED an `\alias' for EACH other topic documented here. 9 | \title{Control checking of spatial object IDs} 10 | \description{ 11 | Provides support for checking the mutual integrity of spatial neighbour weights and spatial data; similar mechanisms are used for passing global verbose and zero.policy options, and for providing access to a running cluster for embarrassingly parallel tasks. 12 | } 13 | \usage{ 14 | set.VerboseOption(check) 15 | get.VerboseOption() 16 | set.ZeroPolicyOption(check) 17 | get.ZeroPolicyOption() 18 | #set.listw_is_CsparseMatrix_Option(check) 19 | #get.listw_is_CsparseMatrix_Option() 20 | } 21 | %- maybe also `usage' for other objects documented here. 22 | \arguments{ 23 | \item{check}{a logical value, TRUE or FALSE} 24 | } 25 | \details{ 26 | Analysis functions will have an spChk argument by default set to NULL, and will call \code{get.spChkOption()} to get the global spatial option for whether to check or not --- this is initialised to FALSE, and consequently should not break anything. It can be changed to TRUE using \code{set.spChkOption(TRUE)}, or the spChk argument can be assigned in analysis functions. \code{spNamedVec()} is provided to ensure that rownames are passed on to single columns taken from two-dimensional arrays and data frames. 27 | } 28 | \value{ 29 | \code{set.spChkOption()} returns the old logical value, \code{get.spChkOption()} returns the current logical value, and \code{chkIDs()} returns a logical value for the test lack of difference. \code{spNamedVec()} returns the selected column with the names set to the row names of the object from which it has been extracted. 30 | } 31 | 32 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 33 | 34 | \examples{ 35 | get.VerboseOption() 36 | get.ZeroPolicyOption() 37 | } 38 | 39 | \keyword{ spatial } 40 | -------------------------------------------------------------------------------- /man/similar.listw.Rd: -------------------------------------------------------------------------------- 1 | \name{similar.listw} 2 | \alias{similar.listw} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Create symmetric similar weights lists} 5 | \description{ 6 | From Ord's 1975 paper, it is known that the Jacobian for SAR models may be found by "symmetrizing" by similarity (the eigenvalues of similar matrices are identical, so the Jacobian is too). This applies only to styles "W" and "S" with underlying symmetric binary neighbour relations or symmetric general neighbour relations (so no k-nearest neighbour relations). The function is invoked automatically within the SAR fitting functions, to call \code{eigen} on a symmetric matrix for the default eigen method, or to make it possible to use the Matrix method on weights that can be "symmetrized" in this way. 7 | } 8 | \usage{ 9 | similar.listw(listw) 10 | } 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{listw}{a \code{listw} object created for example by \code{spdep::nb2listw}} 14 | } 15 | 16 | \value{ 17 | a \code{listw} object 18 | } 19 | \references{Ord, J. K. 1975 Estimation methods for models of spatial interaction, \emph{Journal of the American Statistical Association}, 70, 120-126} 20 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 21 | 22 | \seealso{\code{\link{lagsarlm}}, \code{\link{errorsarlm}}} 23 | \examples{ 24 | #require("spdep", quietly=TRUE) 25 | data(oldcol, package="spdep") 26 | COL.W <- spdep::nb2listw(COL.nb, style="W") 27 | COL.S <- spdep::nb2listw(COL.nb, style="S") 28 | sum(log(1 - 0.5 * eigenw(COL.W))) 29 | sum(log(1 - 0.5 * eigenw(similar.listw(COL.W)))) 30 | W_J <- as(as_dsTMatrix_listw(similar.listw(COL.W)), "CsparseMatrix") 31 | I <- as_dsCMatrix_I(dim(W_J)[1]) 32 | c(determinant(I - 0.5 * W_J, logarithm=TRUE)$modulus) 33 | sum(log(1 - 0.5 * eigenw(COL.S))) 34 | sum(log(1 - 0.5 * eigenw(similar.listw(COL.S)))) 35 | W_J <- as(as_dsTMatrix_listw(similar.listw(COL.S)), "CsparseMatrix") 36 | c(determinant(I - 0.5 * W_J, logarithm=TRUE)$modulus) 37 | } 38 | \keyword{spatial} 39 | -------------------------------------------------------------------------------- /man/sparse_mat.Rd: -------------------------------------------------------------------------------- 1 | % Copyright 2001-3 by Roger S. Bivand 2 | \name{as.spam.listw} 3 | \alias{as.spam.listw} 4 | \alias{listw2U_spam} 5 | \alias{as_dgRMatrix_listw} 6 | \alias{as_dsTMatrix_listw} 7 | \alias{as_dsCMatrix_I} 8 | \alias{as_dsCMatrix_IrW} 9 | \alias{listw2U_Matrix} 10 | \alias{Jacobian_W} 11 | \alias{coerce,listw,CsparseMatrix-method} 12 | \alias{coerce,listw,RsparseMatrix-method} 13 | \alias{coerce,listw,symmetricMatrix-method} 14 | \alias{powerWeights} 15 | \title{Spatial neighbour sparse representation} 16 | \description{ 17 | Interface between Matrix class objects and weights lists. The \code{as.spam.listw} method converts a \code{"listw"} object to a sparse matrix as defined in the \pkg{spam} package. 18 | } 19 | \usage{ 20 | as.spam.listw(listw) 21 | listw2U_spam(lw) 22 | listw2U_Matrix(lw) 23 | as_dgRMatrix_listw(listw) 24 | as_dsTMatrix_listw(listw) 25 | as_dsCMatrix_I(n) 26 | as_dsCMatrix_IrW(W, rho) 27 | Jacobian_W(W, rho) 28 | powerWeights(W, rho, order=250, X, tol=.Machine$double.eps^(3/5)) 29 | } 30 | \arguments{ 31 | \item{listw, lw}{a \code{listw} object from for example \code{nb2listw}} 32 | \item{W}{a \code{dsTMatrix} object created using \code{as_dsTMatrix_listw} from a symmetric \code{listw} object} 33 | \item{rho}{spatial regression coefficient} 34 | \item{n}{length of diagonal for identity matrix} 35 | \item{order}{Power series maximum limit} 36 | \item{X}{A numerical matrix} 37 | \item{tol}{Tolerance for convergence of power series} 38 | } 39 | 40 | 41 | 42 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 43 | 44 | \seealso{\code{\link[spdep]{nb2listw}}} 45 | 46 | \examples{ 47 | \dontrun{ 48 | require(sf, quietly=TRUE) 49 | columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) 50 | #require(spdep, quietly=TRUE) 51 | col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) 52 | col.listw <- spdep::nb2listw(col.gal.nb) 53 | if (require("spam", quietly=TRUE)) { 54 | col.sp <- as.spam.listw(col.listw) 55 | str(col.sp) 56 | } 57 | suppressMessages(nyadjmat <- as.matrix(foreign::read.dbf(system.file( 58 | "misc/nyadjwts.dbf", package="spData")[1])[-1])) 59 | nyadjlw <- spdep::mat2listw(nyadjmat) 60 | listw_NY <- spdep::nb2listw(nyadjlw$neighbours, style="B") 61 | W_C <- as(listw_NY, "CsparseMatrix") 62 | W_R <- as(listw_NY, "RsparseMatrix") 63 | W_S <- as(listw_NY, "symmetricMatrix") 64 | n <- nrow(W_S) 65 | I <- Diagonal(n) 66 | rho <- 0.1 67 | c(determinant(I - rho * W_S, logarithm=TRUE)$modulus) 68 | sum(log(1 - rho * eigenw(listw_NY))) 69 | nW <- - W_S 70 | nChol <- Cholesky(nW, Imult=8) 71 | n * log(rho) + (2 * c(determinant(update(nChol, nW, 1/rho))$modulus)) 72 | } 73 | nb7rt <- spdep::cell2nb(7, 7, torus=TRUE) 74 | x <- matrix(sample(rnorm(500*length(nb7rt))), nrow=length(nb7rt)) 75 | lw <- spdep::nb2listw(nb7rt) 76 | if (FALSE) { 77 | # Only needed in some simulation settings where the input and 78 | # output distributions must agree in all but autocorrelation 79 | e <- eigenw(lw) 80 | x <- apply(x, 2, scale) 81 | st <- apply(x, 2, function(x) shapiro.test(x)$p.value) 82 | x <- x[, (st > 0.2 & st < 0.8)] 83 | x <- apply(x, 2, function(v) residuals(spautolm(v ~ 1, listw=lw, 84 | method="eigen", control=list(pre_eig=e, fdHess=FALSE)))) 85 | x <- apply(x, 2, scale) 86 | } 87 | W <- as(lw, "CsparseMatrix") 88 | system.time(e <- invIrM(nb7rt, rho=0.98, method="solve", feasible=NULL) \%*\% x) 89 | system.time(ee <- powerWeights(W, rho=0.98, X=x)) 90 | str(attr(ee, "internal")) 91 | all.equal(e, as(ee, "matrix"), check.attributes=FALSE) 92 | \dontrun{ 93 | system.time(ee <- powerWeights(W, rho=0.9, X=x)) 94 | system.time(ee <- powerWeights(W, rho=0.98, order=1000, X=x)) 95 | all.equal(e, as(ee, "matrix"), check.attributes=FALSE) 96 | nb60rt <- spdep::cell2nb(60, 60, torus=TRUE) 97 | W <- as(spdep::nb2listw(nb60rt), "CsparseMatrix") 98 | set.seed(1) 99 | x <- matrix(rnorm(dim(W)[1]), ncol=1) 100 | system.time(ee <- powerWeights(W, rho=0.3, X=x)) 101 | str(as(ee, "matrix")) 102 | obj <- errorsarlm(as(ee, "matrix")[,1] ~ 1, listw=spdep::nb2listw(nb60rt), method="Matrix") 103 | coefficients(obj) 104 | } 105 | } 106 | \keyword{spatial} 107 | -------------------------------------------------------------------------------- /man/trW.Rd: -------------------------------------------------------------------------------- 1 | \name{trW} 2 | \Rdversion{1.1} 3 | \alias{trW} 4 | \alias{mom_calc} 5 | \alias{mom_calc_int2} 6 | %- Also NEED an '\alias' for EACH other topic documented here. 7 | \title{Spatial weights matrix powers traces} 8 | \description{The function is used to prepare a vector of traces of powers of a spatial weights matrix} 9 | \usage{ 10 | trW(W=NULL, m = 30, p = 16, type = "mult", listw=NULL, momentsSymmetry=TRUE) 11 | mom_calc(lw, m) 12 | mom_calc_int2(is, m, nb, weights, Card) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{W}{A spatial weights matrix in CsparseMatrix form} 17 | \item{m}{The number of powers; must be an even number for \sQuote{type}=\dQuote{moments} (default changed from 100 to 30 (2010-11-17))} 18 | \item{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))} 19 | \item{type}{Either \dQuote{mult} (default) for powering a sparse matrix (with moderate or larger N, the matrix becomes dense, and may lead to swapping), or \dQuote{MC} for Monte Carlo simulation of the traces (the first two simulated traces are replaced by their analytical equivalents), or \dQuote{moments} to use the looping space saving algorithm proposed by Smirnov and Anselin (2009) - for \dQuote{moments}, \code{W} must be symmetric, for row-standardised weights through a similarity transformation} 20 | \item{listw, lw}{a listw object, which should either be fully symmetric, or be constructed as similar to symmetric from intrinsically symmetric neighbours using \code{\link{similar.listw}}, used with \sQuote{type}=\dQuote{moments}} 21 | \item{momentsSymmetry}{default TRUE; assert Smirnov/Anselin symmetry assumption} 22 | \item{is}{(used internally only in \code{mom_calc_int2} for \sQuote{type}=\dQuote{moments} on a cluster)} 23 | \item{nb}{(used internally only in \code{mom_calc_int2} for \sQuote{type}=\dQuote{moments} on a cluster)} 24 | \item{weights}{(used internally only in \code{mom_calc_int2} for \sQuote{type}=\dQuote{moments} on a cluster)} 25 | \item{Card}{(used internally only in \code{mom_calc_int2} for \sQuote{type}=\dQuote{moments} on a cluster)} 26 | } 27 | 28 | \value{ 29 | A numeric vector of \code{m} traces, with \dQuote{timings} and \dQuote{type} attributes; the \sQuote{type}=\dQuote{MC} also returns the standard deviation of the p-vector V divided by the square root of p as a measure of spread for the trace estimates. 30 | } 31 | \note{\code{mom_calc} and \code{mom_calc_int2} are for internal use only} 32 | \references{LeSage J and RK Pace (2009) \emph{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. \emph{Computational Statistics and Data Analysis} 53 (2009) 2983--2984.} 33 | \author{Roger Bivand \email{Roger.Bivand@nhh.no}} 34 | 35 | 36 | \seealso{ 37 | \code{\link{as_dgRMatrix_listw}}, \code{\link[spdep]{nb2listw}} 38 | } 39 | \examples{ 40 | require("sf", quietly=TRUE) 41 | columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) 42 | #require(spdep, quietly=TRUE) 43 | col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) 44 | listw <- spdep::nb2listw(col.gal.nb) 45 | W <- as(listw, "CsparseMatrix") 46 | system.time(trMat <- trW(W, type="mult")) 47 | str(trMat) 48 | set.seed(1100) 49 | system.time(trMC <- trW(W, type="MC")) 50 | str(trMC) 51 | plot(trMat, trMC) 52 | abline(a=0, b=1) 53 | for(i in 3:length(trMC)) { 54 | segments(trMat[i], trMC[i]-2*attr(trMC, "sd")[i], trMat[i], 55 | trMC[i]+2*attr(trMC, "sd")[i]) 56 | } 57 | listwS <- similar.listw(listw) 58 | W <- forceSymmetric(as(listwS, "CsparseMatrix")) 59 | system.time(trmom <- trW(listw=listwS, m=24, type="moments")) 60 | str(trmom) 61 | all.equal(trMat[1:24], trmom, check.attributes=FALSE) 62 | system.time(trMat <- trW(W, m=24, type="mult")) 63 | str(trMat) 64 | all.equal(trMat, trmom, check.attributes=FALSE) 65 | set.seed(1) 66 | system.time(trMC <- trW(W, m=24, type="MC")) 67 | str(trMC) 68 | \dontrun{ 69 | data(boston, package="spData") 70 | listw <- spdep::nb2listw(boston.soi) 71 | listwS <- similar.listw(listw) 72 | system.time(trmom <- trW(listw=listwS, m=24, type="moments")) 73 | str(trmom) 74 | library(parallel) 75 | nc <- max(2L, detectCores(logical=FALSE), na.rm = TRUE)-1L 76 | # set nc to 1L here 77 | if (nc > 1L) nc <- 1L 78 | coresOpt <- get.coresOption() 79 | invisible(set.coresOption(nc)) 80 | if(!get.mcOption()) { 81 | cl <- makeCluster(get.coresOption()) 82 | set.ClusterOption(cl) 83 | } 84 | system.time(trmomp <- trW(listw=listwS, m=24, type="moments")) 85 | if(!get.mcOption()) { 86 | set.ClusterOption(NULL) 87 | stopCluster(cl) 88 | } 89 | all.equal(trmom, trmomp, check.attributes=FALSE) 90 | invisible(set.coresOption(coresOpt)) 91 | } 92 | } 93 | \keyword{spatial} 94 | 95 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 2 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 by Roger S. Bivand. */ 2 | 3 | #include "spatialreg.h" 4 | #include 5 | #include 6 | 7 | /*static const R_CMethodDef CEntries[] = { 8 | {NULL, NULL, 0} 9 | };*/ 10 | 11 | 12 | static R_CallMethodDef CallEntries[] = { 13 | {"lmin21", (DL_FUNC) &lmin21, 4}, 14 | {"lmin22", (DL_FUNC) &lmin22, 5}, 15 | {"lmin23", (DL_FUNC) &lmin23, 6}, 16 | {"lmin3", (DL_FUNC) &lmin3, 6}, 17 | {"lmin3S", (DL_FUNC) &lmin3S, 7}, 18 | {"mom_calc_int2", (DL_FUNC) &mom_calc_int2, 5}, 19 | {"listw2dsT", (DL_FUNC) &listw2dsT, 4}, 20 | {"listw2dgR", (DL_FUNC) &listw2dgR, 4}, 21 | {"opt_error_free", (DL_FUNC) &opt_error_free, 1}, 22 | {"hess_error_free", (DL_FUNC) &hess_error_free, 1}, 23 | {"hess_lag_free", (DL_FUNC) &hess_lag_free, 1}, 24 | {"opt_error_init", (DL_FUNC) &opt_error_init, 0}, 25 | {"hess_error_init", (DL_FUNC) &hess_error_init, 0}, 26 | {"hess_lag_init", (DL_FUNC) &hess_lag_init, 0}, 27 | {"R_ml_sse_env", (DL_FUNC) &R_ml_sse_env, 2}, 28 | {"R_ml1_sse_env", (DL_FUNC) &R_ml1_sse_env, 3}, 29 | {"R_ml2_sse_env", (DL_FUNC) &R_ml2_sse_env, 3}, 30 | {NULL, NULL, 0} 31 | }; 32 | 33 | 34 | void 35 | #ifdef HAVE_VISIBILITY_ATTRIBUTE 36 | __attribute__ ((visibility ("default"))) 37 | #endif 38 | R_init_spdep(DllInfo *dll) 39 | { 40 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 41 | R_useDynamicSymbols(dll, FALSE); 42 | 43 | } 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/listw2Matrix.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2006 by Roger S. Bivand. */ 2 | 3 | #include "spatialreg.h" 4 | 5 | SEXP listw2dsT(SEXP nbs, SEXP wts, SEXP card, SEXP ncard2) 6 | { 7 | int i, ii, j, jj, n, pc=0; 8 | SEXP ans; 9 | /* double *card; */ 10 | 11 | n = LENGTH(nbs); 12 | PROTECT(ans = NEW_LIST(3)); pc++; 13 | SET_VECTOR_ELT(ans, 0, NEW_INTEGER(INTEGER_POINTER(ncard2)[0])); 14 | SET_VECTOR_ELT(ans, 1, NEW_INTEGER(INTEGER_POINTER(ncard2)[0])); 15 | SET_VECTOR_ELT(ans, 2, NEW_NUMERIC(INTEGER_POINTER(ncard2)[0])); 16 | 17 | for (i=0, ii=0; i < n; i++) { 18 | for (j=0; j < INTEGER_POINTER(card)[i]; j++) { 19 | jj = INTEGER_POINTER(VECTOR_ELT(nbs, i))[j]; 20 | if (jj > i) { 21 | INTEGER_POINTER(VECTOR_ELT(ans, 0))[ii] = i; 22 | INTEGER_POINTER(VECTOR_ELT(ans, 1))[ii] = jj-1; 23 | NUMERIC_POINTER(VECTOR_ELT(ans, 2))[ii] = 24 | NUMERIC_POINTER(VECTOR_ELT(wts, i))[j]; 25 | if (ii >= INTEGER_POINTER(ncard2)[0]) 26 | Rf_error("ncard2 incorrectly given"); 27 | ii++; 28 | } 29 | } 30 | } 31 | UNPROTECT(pc); 32 | return(ans); 33 | } 34 | 35 | SEXP listw2dgR(SEXP nbs, SEXP wts, SEXP card, SEXP ncard) 36 | { 37 | int i, ii, j, jj, n, pc=0; 38 | SEXP ans; 39 | /* double *card; */ 40 | 41 | n = LENGTH(nbs); 42 | PROTECT(ans = NEW_LIST(2)); pc++; 43 | SET_VECTOR_ELT(ans, 0, NEW_INTEGER(INTEGER_POINTER(ncard)[0])); 44 | SET_VECTOR_ELT(ans, 1, NEW_NUMERIC(INTEGER_POINTER(ncard)[0])); 45 | 46 | for (i=0, ii=0; i < n; i++) { 47 | for (j=0; j < INTEGER_POINTER(card)[i]; j++) { 48 | jj = INTEGER_POINTER(VECTOR_ELT(nbs, i))[j]; 49 | INTEGER_POINTER(VECTOR_ELT(ans, 0))[ii] = jj-1; 50 | NUMERIC_POINTER(VECTOR_ELT(ans, 1))[ii] = 51 | NUMERIC_POINTER(VECTOR_ELT(wts, i))[j]; 52 | if (ii >= INTEGER_POINTER(ncard)[0]) 53 | Rf_error("ncard incorrectly given"); 54 | ii++; 55 | } 56 | } 57 | UNPROTECT(pc); 58 | return(ans); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/mom_calc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-24 by Roger S. Bivand. */ 2 | 3 | #include "spatialreg.h" 4 | 5 | static int c__1 = 1; 6 | 7 | SEXP mom_calc_int2(SEXP is, SEXP m, SEXP nb, SEXP weights, SEXP card) { 8 | SEXP Omega; 9 | int hm = INTEGER_POINTER(m)[0]; 10 | int n = Rf_length(card); 11 | double *eta, *zeta, *omega, sum, res; 12 | int i, ii, j, k1, k2, k3; 13 | int iis = Rf_length(is); 14 | 15 | omega = (double *) R_alloc((size_t) hm, sizeof(double)); 16 | eta = (double *) R_alloc((size_t) n, sizeof(double)); 17 | zeta = (double *) R_alloc((size_t) n, sizeof(double)); 18 | for (j=0; j 10 | #include 11 | #include 12 | #include 13 | #include 14 | #ifndef FCONE 15 | # define FCONE 16 | #endif 17 | #include 18 | /* #include */ 19 | #include 20 | #define ROFFSET 1 21 | 22 | SEXP lmin21(SEXP nb, SEXP y, SEXP cy, SEXP card); 23 | SEXP lmin22(SEXP nb, SEXP y, SEXP cy, SEXP card, SEXP beta); 24 | SEXP lmin23(SEXP nb, SEXP y, SEXP cy, SEXP card, SEXP beta, SEXP tol); 25 | SEXP lmin3(SEXP nb, SEXP ev1, SEXP ev1_lag, SEXP n_nei, SEXP beta, SEXP tol); 26 | SEXP lmin3S(SEXP nb, SEXP ev1, SEXP ev1_lag, SEXP n_nei, SEXP card, SEXP beta, SEXP tol); 27 | SEXP mom_calc_int2(SEXP is, SEXP m, SEXP nb, SEXP weights, SEXP card); 28 | SEXP listw2dsT(SEXP nbs, SEXP wts, SEXP card, SEXP ncard2); 29 | SEXP listw2dgR(SEXP nbs, SEXP wts, SEXP card, SEXP ncard); 30 | 31 | SEXP opt_error_free(SEXP ptr); 32 | SEXP hess_error_free(SEXP ptr); 33 | SEXP hess_lag_free(SEXP ptr); 34 | SEXP opt_error_init(void); /* -Wstrict-prototypes */ 35 | SEXP hess_error_init(void); /* -Wstrict-prototypes */ 36 | SEXP hess_lag_init(void); /* -Wstrict-prototypes */ 37 | SEXP R_ml_sse_env(SEXP env, SEXP coef); 38 | SEXP R_ml1_sse_env(SEXP env, SEXP lambda, SEXP beta); 39 | SEXP R_ml2_sse_env(SEXP env, SEXP rho, SEXP beta); 40 | SEXP mom_calc_int2(SEXP is, SEXP m, SEXP nb, SEXP weights, SEXP card); 41 | 42 | void opt_error_set(SEXP env); 43 | void hess_error_set(SEXP env); 44 | void hess_lag_set(SEXP env); 45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/tinytest.R: -------------------------------------------------------------------------------- 1 | if ( requireNamespace("tinytest", quietly=TRUE) ){ 2 | tinytest::test_package("spatialreg") 3 | } 4 | -------------------------------------------------------------------------------- /vignettes/SpatialFiltering.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Moran Eigenvectors" 3 | author: "Roger Bivand" 4 | output: 5 | html_document: 6 | toc: true 7 | toc_float: 8 | collapsed: false 9 | smooth_scroll: false 10 | toc_depth: 2 11 | bibliography: refs.bib 12 | link-citations: yes 13 | vignette: > 14 | %\VignetteIndexEntry{Moran Eigenvectors} 15 | %\VignetteEngine{knitr::rmarkdown} 16 | %\VignetteEncoding{UTF-8} 17 | --- 18 | 19 | ```{r setup, include=FALSE} 20 | knitr::opts_chunk$set(message = FALSE, warning = FALSE) 21 | ``` 22 | 23 | ## Introduction [^1] 24 | 25 | [^1]: This vignette formed pp. 302–305 of the first edition of Bivand, R. S., Pebesma, E. and Gómez-Rubio V. (2008) Applied Spatial Data Analysis with R, Springer-Verlag, New York. It was retired from the second edition (2013) to accommodate material on other topics, and is made available in this form with the understanding of the publishers. 26 | 27 | The Moran eigenvector approach 28 | [@dray+legendre+peres-neto:06; @griffith+peres-neto:06] involved the 29 | spatial patterns represented by maps of eigenvectors; by choosing 30 | suitable orthogonal patterns and adding them to a linear or generalised 31 | linear model, the spatial dependence present in the residuals can be 32 | moved into the model. 33 | 34 | It uses brute force to search the set of eigenvectors of the matrix 35 | $\mathbf{M W M}$, where 36 | 37 | $$\mathbf{M} = \mathbf{I} - \mathbf{X}(\mathbf{X}^{\rm T} 38 | \mathbf{X})^{-1}\mathbf{X}^{\rm T}$$ is a symmetric and idempotent 39 | projection matrix and $\mathbf{W}$ are the spatial weights. In the 40 | spatial lag form of [`SpatialFiltering`]{} and in the GLM [`ME`]{} form 41 | below, $\mathbf{X}$ is an $n$-vector of ones, that is the intercept 42 | only. 43 | 44 | In its general form, [`SpatialFiltering`]{} chooses the subset of the 45 | $n$ eigenvectors that reduce the residual spatial autocorrelation in the 46 | error of the model with covariates. The lag form adds the covariates in 47 | assessment of which eigenvectors to choose, but does not use them in 48 | constructing the eigenvectors. [`SpatialFiltering`]{} was implemented 49 | and contributed by Yongwan Chun and Michael Tiefelsdorf, and is 50 | presented in @tiefelsdorf+griffith:07; [`ME`]{} is based on Matlab code 51 | by Pedro Peres-Neto and is discussed in @dray+legendre+peres-neto:06 and 52 | @griffith+peres-neto:06. 53 | 54 | ```{r echo=TRUE} 55 | library(spdep) 56 | require("sf", quietly=TRUE) 57 | if (packageVersion("spData") >= "2.3.2") { 58 | NY8 <- sf::st_read(system.file("shapes/NY8_utm18.gpkg", package="spData")) 59 | } else { 60 | NY8 <- sf::st_read(system.file("shapes/NY8_bna_utm18.gpkg", package="spData")) 61 | sf::st_crs(NY8) <- "EPSG:32618" 62 | NY8$Cases <- NY8$TRACTCAS 63 | } 64 | NY_nb <- read.gal(system.file("weights/NY_nb.gal", package="spData"), override.id=TRUE) 65 | ``` 66 | 67 | ```{r, echo=TRUE} 68 | library(spatialreg) 69 | nySFE <- SpatialFiltering(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME, data=NY8, nb=NY_nb, style="W", verbose=FALSE) 70 | nylmSFE <- lm(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME+fitted(nySFE), data=NY8) 71 | summary(nylmSFE) 72 | nylm <- lm(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME, data=NY8) 73 | anova(nylm, nylmSFE) 74 | ``` 75 | 76 | Since the [`SpatialFiltering`]{} approach does not allow weights to be 77 | used, we see that the residual autocorrelation of the original linear 78 | model is absorbed, or ‘whitened’ by the inclusion of selected 79 | eigenvectors in the model, but that the covariate coefficients change 80 | little. The addition of these eigenvectors – each representing an 81 | independent spatial pattern – relieves the residual autocorrelation, but 82 | otherwise makes few changes in the substantive coefficient values. 83 | 84 | The [`ME`]{} function also searches for eigenvectors from the spatial 85 | lag variant of the underlying model, but in a GLM framework. The 86 | criterion is a permutation bootstrap test on Moran’s $I$ for regression 87 | residuals, and in this case, because of the very limited remaining 88 | spatial autocorrelation, is set at $\alpha = 0.5$. Even with this very 89 | generous stopping rule, only few eigenvectors are chosen; their combined 90 | contribution only just improves the fit of the GLM model. 91 | 92 | ```{r, echo=TRUE} 93 | NYlistwW <- nb2listw(NY_nb, style = "W") 94 | set.seed(111) 95 | ``` 96 | 97 | ```{r, echo=TRUE} 98 | nyME <- ME(Cases~PEXPOSURE+PCTAGE65P+PCTOWNHOME, data=NY8, offset=log(POP8), family="poisson", listw=NYlistwW, alpha=0.46) 99 | ``` 100 | 101 | ```{r, echo=TRUE} 102 | nyME 103 | NY8$eigen_1 <- fitted(nyME)[,1] 104 | NY8$eigen_2 <- fitted(nyME)[,2] 105 | ``` 106 | 107 | ```{r, echo=TRUE} 108 | #gry <- brewer.pal(9, "Greys")[-1] 109 | plot(NY8[,c("eigen_1", "eigen_2")]) 110 | ``` 111 | 112 | ```{r, echo=TRUE} 113 | nyglmME <- glm(Cases~PEXPOSURE+PCTAGE65P+PCTOWNHOME+offset(log(POP8))+fitted(nyME), data=NY8, family="poisson") 114 | summary(nyglmME) 115 | nyGLMp <- glm(Cases~PEXPOSURE+PCTAGE65P+PCTOWNHOME+offset(log(POP8)), data=NY8,family="poisson") 116 | anova(nyGLMp, nyglmME, test="Chisq") 117 | ``` 118 | 119 | Figure \[fig:geigen2\] shows the spatial patterns chosen to match the 120 | very small amount of spatial autocorrelation remaining in the model. As 121 | with the other Poisson regressions, the closeness to TCE sites is highly 122 | significant. Since, however, many TCE sites are also in or close to more 123 | densely populated urban areas with the possible presence of both 124 | point-source and non-point-source pollution, it would be premature to 125 | take such results simply at their face value. There is, however, a 126 | potentially useful contrast between the cities of Binghamton in the 127 | south of the study area with several sites in its vicinity, and Syracuse 128 | in the north without TCE sites in this data set. 129 | 130 | ## References 131 | 132 | 133 | --------------------------------------------------------------------------------