├── DESCRIPTION ├── MD5 ├── NAMESPACE ├── R ├── BootstrapGWR.r ├── GeneralizedGWR.r ├── LocalsummaryStatistics.r ├── Model.selection.r ├── MontCarlo.r ├── RcppExports.R ├── bw.ggwr.r ├── bw.gtwr.R ├── bw.gwda.r ├── bw.gwss.average.R ├── bw.sel.r ├── collinearity.r ├── gtwr.R ├── gw.average.cv.R ├── gw.average.cv.contrib.R ├── gw.dist.r ├── gw.weight.r ├── gwda.r ├── gwpca.mc.r ├── gwpca.r ├── gwpca.visualization.r ├── gwr.basic.r ├── gwr.collin.diagno.r ├── gwr.hetero.r ├── gwr.mixed.r ├── gwr.multiscale.R ├── gwr.predict.r ├── gwr.robust.r ├── gwr.scalable.r ├── gwr.t.adjust.r ├── mink.pvals.R ├── minkovski.approach.r ├── writeGWR.r └── zzz.r ├── build └── partial.rdb ├── cleanup ├── configure ├── configure.ac ├── data ├── DubVoter.rda ├── EWHP.rda ├── EWOutline.rda ├── Georgia.rda ├── GeorgiaCounties.rda ├── LondonBorough.rda ├── LondonHP.rda ├── USelect.rda └── datalist ├── inst └── CITATION ├── man ├── DubVoter.rd ├── EWHP.Rd ├── EWOutline.rd ├── GWmodel-package.Rd ├── Georgia.Rd ├── GeorgiaCounties.rd ├── LondonBorough.rd ├── LondonHP.Rd ├── USelect.rd ├── bw.ggwr.Rd ├── bw.gtwr.Rd ├── bw.gwda.rd ├── bw.gwpca.rd ├── bw.gwr.Rd ├── bw.gwr.lcr.rd ├── bw.gwss.average.Rd ├── ggwr.basic.Rd ├── ggwr.cv.Rd ├── ggwr.cv.contrib.Rd ├── gtwr.Rd ├── gw.dist.Rd ├── gw.pcplot.rd ├── gw.weight.Rd ├── gwda.rd ├── gwpca.check.components.rd ├── gwpca.cv.Rd ├── gwpca.cv.contrib.Rd ├── gwpca.glyph.plot.rd ├── gwpca.montecarlo.1.rd ├── gwpca.montecarlo.2.rd ├── gwpca.rd ├── gwr.basic.rd ├── gwr.bootstrap.rd ├── gwr.collin.diagno.Rd ├── gwr.cv.Rd ├── gwr.cv.contrib.Rd ├── gwr.hetero.rd ├── gwr.lcr.cv.Rd ├── gwr.lcr.cv.contrib.Rd ├── gwr.lcr.rd ├── gwr.mink.approach.rd ├── gwr.mink.matrixview.rd ├── gwr.mink.pval.rd ├── gwr.mixed.rd ├── gwr.model.selection.Rd ├── gwr.model.sort.Rd ├── gwr.model.view.rd ├── gwr.montecarlo.Rd ├── gwr.multiscale.rd ├── gwr.predict.Rd ├── gwr.robust.Rd ├── gwr.scalable.rd ├── gwr.t.adjust.rd ├── gwr.write.Rd ├── gwss.montecarlo.Rd ├── gwss.rd └── st.dist.Rd └── src ├── GWmodel.cpp ├── GWmodelCUDA ├── CGWmodelCUDA.cpp ├── CGWmodelCUDA.h ├── CMakeLists.txt ├── GWmodelKernel.cu ├── GWmodelKernel.h ├── IGWmodelCUDA.cpp ├── IGWmodelCUDA.h ├── cmake │ └── FindcuBLAS.cmake └── helper.h ├── Makevars.in ├── Makevars.win ├── RcppExports.cpp └── init.c /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: GWmodel 2 | Type: Package 3 | Version: 2.4-1 4 | Date: 2024-09-07 5 | Title: Geographically-Weighted Models 6 | Depends: R (>= 3.0.0), robustbase,sp (> 1.4-0), Rcpp (>= 1.0.12) 7 | Imports: methods, sf, grDevices, spacetime,spdep,spatialreg,FNN 8 | LinkingTo: Rcpp, RcppArmadillo, RcppEigen 9 | Suggests: mvoutlier, RColorBrewer, gstat,spData 10 | Description: Techniques from a particular branch of spatial statistics,termed geographically-weighted (GW) models. GW models suit situations when data are not described well by some global model, but where there are spatial regions where a suitably localised calibration provides a better description. 'GWmodel' includes functions to calibrate: GW summary statistics (Brunsdon et al., 2002), GW principal components analysis (Harris et al., 2011), GW discriminant analysis (Brunsdon et al., 2007) and various forms of GW regression (Brunsdon et al., 1996); some of which are provided in basic and robust (outlier resistant) forms. 11 | Authors@R: c(person(given = "Binbin", 12 | family = "Lu", 13 | role = c("aut", "cre"), 14 | email = "binbinlu@whu.edu.cn"), 15 | person(given = "Paul", 16 | family = "Harris", 17 | role = "aut"), 18 | person(given = "Martin", 19 | family = "Charlton", 20 | role = "aut"), 21 | person(given = "Chris", 22 | family = "Brunsdon", 23 | role = "aut"), 24 | person(given = "Tomoki", 25 | family = "Nakaya", 26 | role = "aut"), 27 | person(given = "Daisuke", 28 | family = "Murakami", 29 | role = "ctb"), 30 | person(given = "Yigong", 31 | family = "Hu", 32 | role = "ctb"), 33 | person(given = c("Fiona", "H"), 34 | family = "Evans", 35 | role = "ctb"), 36 | person(given = "Hjalmar", 37 | family = "Hglund", 38 | role = "ctb")) 39 | Maintainer: Binbin Lu 40 | License: GPL (>= 2) 41 | Repository: CRAN 42 | URL: http://gwr.nuim.ie/ 43 | NeedsCompilation: yes 44 | SystemRequirements: GNU make 45 | Packaged: 2024-09-07 07:50:13 UTC; Lenovo 46 | Author: Binbin Lu [aut, cre], 47 | Paul Harris [aut], 48 | Martin Charlton [aut], 49 | Chris Brunsdon [aut], 50 | Tomoki Nakaya [aut], 51 | Daisuke Murakami [ctb], 52 | Yigong Hu [ctb], 53 | Fiona H Evans [ctb], 54 | Hjalmar Hglund [ctb] 55 | Date/Publication: 2024-09-07 11:00:02 UTC 56 | -------------------------------------------------------------------------------- /MD5: -------------------------------------------------------------------------------- 1 | d34b791316d9520c43961da439c7e354 *DESCRIPTION 2 | ad4a248df556d055e68c632b25bc205e *NAMESPACE 3 | bb0a47b99e5ca788b1a639e2ad2eed5a *R/BootstrapGWR.r 4 | 261c4362f5a7ec4f5f3aa4ff64ddde3f *R/GeneralizedGWR.r 5 | 7c5870d7c3b84cd149d5017c7c4406bc *R/LocalsummaryStatistics.r 6 | 3f3c0abdb858db90d49a45c67a3e1e49 *R/Model.selection.r 7 | c112944592afb0fb664f055170cd9b25 *R/MontCarlo.r 8 | a19b92d02865e5f1af264dce4f70b5e8 *R/RcppExports.R 9 | b26d14e38ef6c67b422e6e7fe0eada66 *R/bw.ggwr.r 10 | 85af2881a847054a2fc018aff27c19c3 *R/bw.gtwr.R 11 | 971bd94990dd762f40aa57a3cba90e76 *R/bw.gwda.r 12 | 0418a683ebfdb05150d372d805b3338d *R/bw.gwss.average.R 13 | 358fbc20c777da5eef6c847af684b492 *R/bw.sel.r 14 | 0a6a3e92577868919ec3f417f546daa0 *R/collinearity.r 15 | 5c3b5423816aea6e78964f98fc3fa1e7 *R/gtwr.R 16 | 6fe93e3e5f89699fbcb03308cd04ac70 *R/gw.average.cv.R 17 | 0a9409a1a77dfbb5d039b7555f348a68 *R/gw.average.cv.contrib.R 18 | ddc3df6c3e2cb04235180a02bc566b6c *R/gw.dist.r 19 | b2d462291068a01c1afd5d8b44a87f5e *R/gw.weight.r 20 | 30fa64ddcc290c600c36e0875acda006 *R/gwda.r 21 | f2a95937dd1fa885d5a5e6de7ffcc339 *R/gwpca.mc.r 22 | e3d38f2e5df4697f0f89359762dc0c4e *R/gwpca.r 23 | f171984367215ea784130c88096c18be *R/gwpca.visualization.r 24 | 1911455469615b66dd1be86dbef3e2ed *R/gwr.basic.r 25 | df1fa341d82ef80a63e637dd55e831bf *R/gwr.collin.diagno.r 26 | 16faa8a18f3a1a4554c8bb5e04ef0247 *R/gwr.hetero.r 27 | c4d17a9cf6fe5d10ef6ee8380d3b3565 *R/gwr.mixed.r 28 | 0c7281c12cf7c2fd7bb4f80e707bf445 *R/gwr.multiscale.R 29 | 7ad494007f286b7315999943661fb26d *R/gwr.predict.r 30 | 25c19217c88e14a59699c2e94a1a1ed7 *R/gwr.robust.r 31 | bc2ff02710967cd7572c8597f97c7099 *R/gwr.scalable.r 32 | d7325b59bcb0e1ec6f5f7d0bcc3781c7 *R/gwr.t.adjust.r 33 | cc91ed43d6ddd9905c11a6cec56e3df3 *R/mink.pvals.R 34 | f50aba340c089559db7e4de36f7aeae8 *R/minkovski.approach.r 35 | e3d12441f983fe10cd38fced1bb918c8 *R/writeGWR.r 36 | 7f95fea716e4a1cfd4b6f7d8ba171a61 *R/zzz.r 37 | d155cc7210d33ea564457f73b896eeab *build/partial.rdb 38 | b33959749e71fb18bd292de23cdd4366 *cleanup 39 | 3031667ebd88b3c0d3e880e8052ca03b *configure 40 | d48782cdb1a2cc00aefb86336f8c46bb *configure.ac 41 | fad011ea3383c650e1e0174e39c7de99 *data/DubVoter.rda 42 | 995fa662c41ffd3afd86fdcd55cdfeaa *data/EWHP.rda 43 | 81a3e0fc73a8ecf7ff7de5eae43b42f0 *data/EWOutline.rda 44 | 9a7953173706ceaeb546c3ea002d56fd *data/Georgia.rda 45 | 0c352651c36fe498b01430e632389722 *data/GeorgiaCounties.rda 46 | 28a2cc38b3d444eecfb2cc2aaef51bd6 *data/LondonBorough.rda 47 | da0b0351e8bf7aa8343de1934a674056 *data/LondonHP.rda 48 | d1841e224383498b2d3e701dbe2f0c08 *data/USelect.rda 49 | 360c6074f98e66f2a6746d347c035cf0 *data/datalist 50 | 05f6717a93eb86840ef775eae30f031e *inst/CITATION 51 | c88bf1ad118dcadb0e804e246196ae22 *man/DubVoter.rd 52 | 153427d2d7c2c0f819150ff3e223a29a *man/EWHP.Rd 53 | dbbef722403d8acd64fe7973d29a861b *man/EWOutline.rd 54 | 3c35d26aa42b1652bbebd28cbc2d2ccd *man/GWmodel-package.Rd 55 | 9dc5b8a9a66126e3b506832b7eac69a9 *man/Georgia.Rd 56 | ff8b836ed2d644536b21e44fdf7b9c28 *man/GeorgiaCounties.rd 57 | c41673fda549370c0907d47e1bed65ed *man/LondonBorough.rd 58 | a775b26ac81b5991dd442c4c59713a15 *man/LondonHP.Rd 59 | 797dfb4fdc6ac972c7c2999c020887c5 *man/USelect.rd 60 | b89257a8f1994a710ad64fc56d94ea7c *man/bw.ggwr.Rd 61 | a729f32eba98f2ec146f1ec64fe0cf86 *man/bw.gtwr.Rd 62 | 3c8e537c31d99631a98fe9868fec52c8 *man/bw.gwda.rd 63 | fa08fcfd63eb5137471220e5fdcbff4a *man/bw.gwpca.rd 64 | c2b4b697af374cf7e29ca9adbf2d12be *man/bw.gwr.Rd 65 | 3a5e74a9cd3db710b7f5a1522cd8cbe3 *man/bw.gwr.lcr.rd 66 | 6aecb01cfde02091fcf4dc703d9a3435 *man/bw.gwss.average.Rd 67 | 54c1c8f057c68a134133c832697e1295 *man/ggwr.basic.Rd 68 | 474607373025824715b927ce215fe28a *man/ggwr.cv.Rd 69 | 62518615df78246391575b2999bfa3d9 *man/ggwr.cv.contrib.Rd 70 | 1a68e80ec90ca57cae554cb39083bc20 *man/gtwr.Rd 71 | f76c3c5347c0d01ce220ea2c252ffc93 *man/gw.dist.Rd 72 | a5ef36e3ad666fb157181176625400fa *man/gw.pcplot.rd 73 | e733fa7afe2efbf81ae477e1a909bd1f *man/gw.weight.Rd 74 | 96e76f682176173cfb9815c6ae6d1c8b *man/gwda.rd 75 | 75ce561863fb9016b3732b42e8a304b1 *man/gwpca.check.components.rd 76 | 00f8e8cace9b00a03afdb588863c742a *man/gwpca.cv.Rd 77 | a49e26853d1ac80b726c180e0e726605 *man/gwpca.cv.contrib.Rd 78 | 53f5000543b97784c0a8e232f7362075 *man/gwpca.glyph.plot.rd 79 | fad1d5134a4c895fea794e4d9dc126fb *man/gwpca.montecarlo.1.rd 80 | ea6cf5e957ddae6781c6813fbd847022 *man/gwpca.montecarlo.2.rd 81 | bd32998f96e26d40e5a3d65276af908a *man/gwpca.rd 82 | f1e1168e342fc2ea77cbed8e8a00b97a *man/gwr.basic.rd 83 | cc09f3ed250f1427ab23d543fbabb992 *man/gwr.bootstrap.rd 84 | 233a851d80e6084fb2e2b8901e0d412f *man/gwr.collin.diagno.Rd 85 | 081c4434efed61ef74c27de76ac2ed57 *man/gwr.cv.Rd 86 | 8e5270dab08e95f5651fc64090350396 *man/gwr.cv.contrib.Rd 87 | ac4659d270f358027507c709820f92f7 *man/gwr.hetero.rd 88 | ac4bc71308f8ba06489134fda9a16bce *man/gwr.lcr.cv.Rd 89 | 0991e3e6b7f7c3b1547bafc2df6fdac2 *man/gwr.lcr.cv.contrib.Rd 90 | 83cc0c6e4f62543463ca5660dd05666f *man/gwr.lcr.rd 91 | 0f433a3708dcd779bd3054273b6d8b92 *man/gwr.mink.approach.rd 92 | 3f124c5d79b0be7849f6b14b16d5479a *man/gwr.mink.matrixview.rd 93 | cdbf98cad6dded53a7f1658e9cedd26a *man/gwr.mink.pval.rd 94 | f2327b0963a7921346272310b3eb1030 *man/gwr.mixed.rd 95 | 0f7e1203cd5bc99de773aa73c1069109 *man/gwr.model.selection.Rd 96 | 2550eb83610381c836b33cd03254eaa4 *man/gwr.model.sort.Rd 97 | d4cb146b6f5b4456b2d1dcd5713a12f7 *man/gwr.model.view.rd 98 | 5e335b5305bdf7c04a233357bbe5dffa *man/gwr.montecarlo.Rd 99 | d931959059fe030aa7bbf4fed22c1276 *man/gwr.multiscale.rd 100 | db857fe7142aecf01eb14fbb3fd50216 *man/gwr.predict.Rd 101 | c6fe95d0cbdfce3c78136ba3119080cf *man/gwr.robust.Rd 102 | b69403892779777c8652d823322d5841 *man/gwr.scalable.rd 103 | be977e2632d90c36bd41bb12254ce1ba *man/gwr.t.adjust.rd 104 | 26756bd92f087062c7f53d6fcc618916 *man/gwr.write.Rd 105 | 9e7eba3da5e2ea9f522b94ab66fd1b20 *man/gwss.montecarlo.Rd 106 | e2397c697ac46c1f3ffb6c4cd38f444e *man/gwss.rd 107 | 9c47f62bb72b3292a15acf550b764e15 *man/st.dist.Rd 108 | 65e6c2a73cc6de6545222e1b696578bc *src/GWmodel.cpp 109 | b35981ee522aae72b3663648521bdcbe *src/GWmodelCUDA/CGWmodelCUDA.cpp 110 | e5f9ee14c1656101d56e11d263298c35 *src/GWmodelCUDA/CGWmodelCUDA.h 111 | e00f5dee790a84460b6679b03a626aac *src/GWmodelCUDA/CMakeLists.txt 112 | 571d739e6595d5708bbbeea1d953a123 *src/GWmodelCUDA/GWmodelKernel.cu 113 | bafe96482f72aad73a049ac685864967 *src/GWmodelCUDA/GWmodelKernel.h 114 | c1190e62d421c19ad364cfb46a6b987c *src/GWmodelCUDA/IGWmodelCUDA.cpp 115 | 49e3bd0fbf1fe11325081ffb6756dae1 *src/GWmodelCUDA/IGWmodelCUDA.h 116 | d85547674b5aae04a975e19f6202ce85 *src/GWmodelCUDA/cmake/FindcuBLAS.cmake 117 | 6485a1dbfd02d019f32c097cd6770af0 *src/GWmodelCUDA/helper.h 118 | 6dfac6dd0bcf3848bcb8bacab76474f0 *src/Makevars.in 119 | 1c0a70f94ad598754dbaaf51f6f4ebce *src/Makevars.win 120 | 4bc7a38cfa2ffd8a71cf0136081b9be4 *src/RcppExports.cpp 121 | fe9aac58a87341f83789ed6f61b96ee3 *src/init.c 122 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(GWmodel) 2 | import(Rcpp) 3 | import(sf) 4 | import(robustbase) 5 | import(sp) 6 | import(stats) 7 | import(spacetime) 8 | import(parallel) 9 | importFrom(FNN, get.knn) 10 | importFrom(Rcpp, evalCpp) 11 | importFrom("grDevices", "grey", "rainbow", "rgb") 12 | importFrom("methods", "as", "is", "slot") 13 | importFrom("graphics", "abline", "axis", "hist", "identify", "legend", 14 | "lines", "points", "rect", "text") 15 | importFrom("spdep", "knearneigh", "poly2nb", "nb2listw","listw2mat","knn2nb") 16 | importFrom("sf", "st_write", "st_as_sf") 17 | importFrom("spatialreg", "errorsarlm", "spautolm","lagsarlm") 18 | export(gwr.scalable,gwr.scalable.loocv,AICc1, gwr_diag1,scgwr_loocv,scgwr_pre,scgwr_reg,bw.gtwr, gtwr.aic, gtwr, ti.distv, ti.distm,ti.dist, st.dist, gwr.bootstrap,generate.lm.data,parametric.bs,parametric.bs.local,se.bs,bias.bs,ci.bs,pval.bs,gwrtvar,gwrt.mlr,gwrt.lag,gwrt.err,gwrt.sma,bw.gwr3,gwr.multiscale,gwr.backfit,gwr.q2, confusion.matrix,gwss.montecarlo,gwda,print.gwda,grouping.xy,wqda,wlda,splitx,wmean,wvarcov,wprior,bw.gwda,wqda.cr,wlda.cr,gwr.hetero,gwr.mixed,gwr.mixed.2,gwr.mixed.trace.fast, gwr.mixed.trace, gwr.mixed.trace.fast,print.mgwr,gwr.q,gwr.collin.diagno,plot.mcsims,bw.gwr, gwr.cv,gwr.cv.contrib, gwr.aic, gold, gw.dist, gw.weight, gwr.basic, F1234.test,extract.mat,Generate.formula,gwr.generalised,gwr.poisson,gwr.binomial,gwss,bw.ggwr,ggwr.basic,ggwr.cv,ggwr.cv.contrib,ggwr.aic,gwr.poisson.wt,gwr.binomial.wt,wpca,robustSvd,wt.median,rwpca,gwpca,bw.gwpca,gwpca.cv,gwpca.cv.contrib,gwr.lcr,ridge.lm,bw.gwr.lcr,gwr.lcr.cv,gwr.lcr.cv.contrib,gwr.t.adjust,gwr.predict,gwr.robust,gw.pcplot,bw.gwr1,gwr.aic1,gwr.cv1,plot.pvlas,gw_reg,gw.fitted,ehat,rss,gwr_diag,AICc,AICc_rss,Ci_mat,gwss.montecarlo,gwpca.montecarlo.1,gwpca.montecarlo.2,gwr.model.selection,gwr.model.view,gwr.model.sort,gwr.montecarlo,gwr.write,gwr.write.shp,gwpca.glyph.plot,gwpca.check.components,gwr.mink.approach,gwr.mink.matrixview,gwr.mink.pval,gwr.mink.pval.forward,gwr.mink.pval.backward,gw.mean.cv,gw.median.cv,gw.average.cv,gw.average.cv.contrib,bw.gwss.average,montecarlo.gwss,montecarlo.gwpca.1,montecarlo.gwpca.2,model.selection.gwr,model.view.gwr,model.sort.gwr,montecarlo.gwr,writeGWR,writeGWR.shp,glyph.plot,check.components,mink.approach,mink.matrixview,gwr_q,gwr_mixed_trace, gwr_mixed_2,gw_dist,gw_weight, gw_weight_vec, gw_weight_mat, gw_reg, gw_reg_1, trhat2, gw_fitted, ehat, rss, gwr_diag, gwr_diag1, AICc, AICc1, AICc_rss, AICc_rss1, Ci_mat, gw_local_r2, gw_BIC, gw_reg_2, gwr_q, scgwr_pre, scgwr_reg, scgwr_loocv, gw_reg_all, gw_reg_all_omp, gw_reg_all_cuda, gw_cv_all, gw_cv_all_omp, gw_cv_all_cuda, e_vec, gwr_mixed_trace, gwr_mixed_2, new_multiscale) 19 | useDynLib(GWmodel, .registration = TRUE) 20 | 21 | S3method(print, mcsims) 22 | S3method(print, gwrm) 23 | S3method(print, ggwrm) 24 | S3method(print, gwss) 25 | S3method(print, gwrlcr) 26 | S3method(print, gwrm.pred) 27 | S3method(plot, mcsims) 28 | S3method(plot, pvlas) 29 | S3method(print, gwda) 30 | S3method(print, mgwr) 31 | S3method(print, gwrbsm) 32 | S3method(print, multiscalegwr) 33 | S3method(print, gtwrm) 34 | S3method(print, gwpca) 35 | S3method(print, scgwrm) -------------------------------------------------------------------------------- /R/bw.gwda.r: -------------------------------------------------------------------------------- 1 | ################################################### 2 | #Bandwidth selection using cross-validation 3 | bw.gwda <- function(formula, data, COV.gw = T, prior.gw = T, mean.gw = T, 4 | prior = NULL, wqda = F, kernel = "bisquare", adaptive 5 | = FALSE, p = 2, theta = 0, longlat = F, dMat) 6 | { 7 | #data must be given as training data 8 | if(inherits(data, "Spatial")) 9 | { 10 | if (is(data, "Spatial")) 11 | { 12 | dp.locat<-coordinates(data) 13 | data <- as(data, "data.frame") 14 | } 15 | } 16 | else if(inherits(data, "sf")) 17 | { 18 | if(any((st_geometry_type(data)=="POLYGON")) | any(st_geometry_type(data)=="MULTIPOLYGON")) 19 | dp.locat <- st_coordinates(st_centroid(st_geometry(data))) 20 | else 21 | dp.locat <- st_coordinates(st_geometry(data)) 22 | } 23 | else 24 | stop("Given training data must be a Spatial*DataFrame or data.frame object") 25 | ######## variables from formula 26 | vars <- all.vars(formula) 27 | grouping.nm <- vars[1] 28 | expl.vars <- vars[-1] 29 | m <- length(expl.vars) 30 | if (m < 2) 31 | stop("Two or more variables shoule be specfied for analysis") 32 | #x, y from training data 33 | res1 <- grouping.xy(data, grouping.nm, expl.vars) 34 | x<- res1$x 35 | grouping <- res1$y 36 | lev <- levels(grouping) 37 | dp.n<-nrow(data) 38 | if (missing(dMat)) 39 | { 40 | dMat <- gw.dist(dp.locat=dp.locat, p=p, theta=theta, longlat=longlat) 41 | } 42 | else 43 | { 44 | dim.dMat<-dim(dMat) 45 | if (dim.dMat[1]!=dp.n||dim.dMat[2]!=dp.n) 46 | stop ("Dimensions of dMat are not correct") 47 | } 48 | if(adaptive) 49 | { 50 | upper<-dp.n 51 | lower<-20 52 | } 53 | else 54 | { 55 | upper<-range(dMat)[2] 56 | lower<-upper/5000 57 | } 58 | bw<-NA 59 | if(wqda) 60 | bw <- optimize(wqda.cr,lower=lower,upper=upper,maximum=T, 61 | x=x, grouping=grouping, dMat=dMat, COV.gw=COV.gw, 62 | mean.gw=mean.gw, prior.gw=prior.gw, prior=prior, 63 | kernel = kernel, adaptive =adaptive) 64 | else 65 | bw <- optimize(wlda.cr,lower=lower,upper=upper,maximum=T, 66 | x=x, grouping=grouping, dMat=dMat, COV.gw=COV.gw, 67 | mean.gw=mean.gw, prior.gw=prior.gw, prior=prior, 68 | kernel = kernel, adaptive =adaptive) 69 | if(adaptive) 70 | bw <- round(bw$maximum) 71 | else 72 | bw <- bw$maximum 73 | bw 74 | } 75 | 76 | ###Correct ratio 77 | wqda.cr <- function(bw, x, grouping, dMat, COV.gw=T, 78 | mean.gw=T, prior.gw=T, prior=NULL, 79 | kernel = "bisquare", adaptive = FALSE) 80 | { 81 | if(adaptive) bw <- round(bw) 82 | wt <- gw.weight(dMat,bw,kernel,adaptive) 83 | diag(wt) <- 0 84 | res.df <- try(wqda(x, grouping, x, wt, COV.gw, 85 | mean.gw, prior.gw, prior)) 86 | if(!inherits(res.df, "try-error")) 87 | { 88 | n.correct <- length(which(grouping == res.df[,"group.predicted"])) 89 | correct.ratio <- n.correct/nrow(x) 90 | } 91 | else 92 | correct.ratio <- 0 93 | if(adaptive) 94 | cat("Adaptive bandwidth:", bw, "Correctly predicted proportion:", correct.ratio, "\n") 95 | else 96 | cat("Fixed bandwidth:", bw, "Correctly predicted proportion:", correct.ratio, "\n") 97 | correct.ratio 98 | } 99 | 100 | wlda.cr <- function(bw, x, grouping, dMat, COV.gw=T, 101 | mean.gw=T, prior.gw=T, prior=NULL,kernel = "bisquare", adaptive = FALSE) 102 | { 103 | if(adaptive) bw <- round(bw) 104 | wt <- gw.weight(dMat,bw,kernel,adaptive) 105 | diag(wt) <- 0 106 | res.df <- try(wlda(x, grouping, x, wt, COV.gw, 107 | mean.gw, prior.gw, prior)) 108 | if(!inherits(res.df, "try-error")) 109 | { 110 | n.correct <- length(which(grouping == res.df[,"group.predicted"])) 111 | correct.ratio <- n.correct/nrow(x) 112 | } 113 | else 114 | correct.ratio <- 0 115 | if(adaptive) 116 | cat("Adaptive bandwidth:", bw, "Correctly predicted proportion:", correct.ratio, "\n") 117 | else 118 | cat("Fixed bandwidth:", bw, "Correctly predicted proportion:", correct.ratio, "\n") 119 | correct.ratio 120 | } 121 | -------------------------------------------------------------------------------- /R/bw.gwss.average.R: -------------------------------------------------------------------------------- 1 | bw.gwss.average<- function (data, summary.locat, vars, kernel = "bisquare", adaptive = FALSE, p = 2, theta = 0, longlat = F, dMat) 2 | { 3 | if (is(data, "Spatial")) 4 | { 5 | p4s <- proj4string(data) 6 | dp.locat <- coordinates(data) 7 | } 8 | else if (is(data, "data.frame") && (!missing(dMat))) 9 | data <- data 10 | else 11 | stop("Given data must be a Spatial*DataFrame or data.frame object") 12 | if (missing(summary.locat)) 13 | { 14 | sp.given <- FALSE 15 | summary.locat <- data 16 | sp.locat <- coordinates(summary.locat) 17 | } 18 | else 19 | { 20 | sp.given <- T 21 | if (is(summary.locat, "Spatial")) 22 | sp.locat <- coordinates(summary.locat) 23 | else 24 | { 25 | warning("Output loactions are not packed in a Spatial object,and it has to be a two-column numeric vector") 26 | summary.locat <- sp.locat 27 | } 28 | } 29 | data <- as(data, "data.frame") 30 | dp.n <- nrow(data) 31 | sp.n <- nrow(sp.locat) 32 | if (missing(dMat)) 33 | DM.given <- F 34 | else { 35 | DM.given <- T 36 | dim.dMat <- dim(dMat) 37 | if (dim.dMat[1] != dp.n || dim.dMat[2] != sp.n) 38 | stop("Dimensions of dMat are not correct") 39 | } 40 | if (missing(vars)) 41 | stop("Variables input error") 42 | 43 | if (missing(dMat)) { 44 | DM.given <- F 45 | if (dp.n + dp.n <= 10000) { 46 | dMat <- gw.dist(dp.locat = dp.locat, rp.locat = dp.locat, 47 | p = p, theta = theta, longlat = longlat) 48 | DM.given <- T 49 | } 50 | } 51 | else { 52 | DM.given <- T 53 | dim.dMat <- dim(dMat) 54 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 55 | stop("Dimensions of dMat are not correct") 56 | } 57 | if (adaptive) { 58 | upper <- dp.n 59 | lower <- 20 60 | } 61 | else { 62 | if (DM.given) { 63 | upper <- range(dMat)[2] 64 | lower <- upper/5000 65 | } 66 | else { 67 | dMat <- NULL 68 | if (p == 2) { 69 | b.box <- bbox(dp.locat) 70 | upper <- sqrt((b.box[1, 2] - b.box[1, 1])^2 + 71 | (b.box[2, 2] - b.box[2, 1])^2) 72 | lower <- upper/5000 73 | } 74 | else { 75 | upper <- 0 76 | for (i in 1:dp.n) { 77 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 78 | p = p, theta = theta, longlat = longlat) 79 | upper <- max(upper, range(dist.vi)[2]) 80 | } 81 | lower <- upper/5000 82 | } 83 | } 84 | } 85 | 86 | col.nm <- colnames(data) 87 | var.idx <- match(vars, col.nm)[!is.na(match(vars, col.nm))] 88 | if (length(var.idx) == 0) 89 | stop("Variables input doesn't match with data") 90 | X <- data[, var.idx] 91 | X <- as.matrix(X) 92 | colnames(X)<-vars 93 | var.n <- length(vars) 94 | bws<-matrix(numeric(2*var.n),nrow=2) 95 | rownames(bws)<-c('Local Mean bw','Local Median bw') 96 | colnames(bws) <- colnames(X) 97 | for(k in 1:var.n) 98 | { 99 | bws[1,k] <- gold(gw.mean.cv, lower, upper, adapt.bw = adaptive, 100 | X[,k], kernel, adaptive, dp.locat, p, theta, longlat, dMat) 101 | bws[2,k] <- gold(gw.median.cv, lower, upper, adapt.bw = adaptive, 102 | X[,k], kernel, adaptive, dp.locat, p, theta, longlat, dMat) 103 | } 104 | bws 105 | } -------------------------------------------------------------------------------- /R/gw.average.cv.R: -------------------------------------------------------------------------------- 1 | #Calculate the cv score for each column, not the whole X of all the variables 2 | gw.mean.cv <- function (bw, x, kernel, adaptive, dp.locat, p, theta, longlat, 3 | dMat) 4 | { 5 | dp.n <- length(dp.locat[, 1]) 6 | if (is.null(dMat)) 7 | DM.given <- F 8 | else { 9 | DM.given <- T 10 | dim.dMat <- dim(dMat) 11 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 12 | stop("Dimensions of dMat are not correct") 13 | } 14 | CV.mean <- numeric(dp.n) 15 | for (i in 1:dp.n) 16 | { 17 | if (DM.given) 18 | dist.vi <- dMat[, i] 19 | else 20 | { 21 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 22 | p = p, theta = theta, longlat = longlat) 23 | } 24 | W.i <- gw.weight(dist.vi, bw, kernel, adaptive) 25 | sum.w <- sum(W.i) 26 | Wi <- W.i/sum.w 27 | l.mean<-sum(Wi*x) 28 | W.i[i] <- 0 29 | W.i<-W.i/sum(W.i) 30 | l.mean.resi <- try(sum(W.i*x)) 31 | if (!inherits(l.mean.resi, "try-error")) { 32 | CV.mean[i] <- l.mean - l.mean.resi 33 | } 34 | else { 35 | CV.mean[i] <- Inf 36 | break 37 | } 38 | 39 | } 40 | if (!any(is.infinite(CV.mean))) 41 | CV.mean.score <- t(CV.mean) %*% CV.mean 42 | else { 43 | CV.mean.score <- Inf 44 | } 45 | 46 | CV.mean.score 47 | } 48 | 49 | gw.median.cv <- function (bw, X, kernel, adaptive, dp.locat, p, theta, longlat, dMat) 50 | { 51 | findmedian <- function(x, w) { 52 | lw <- length(w) 53 | xo <- sort(x) 54 | wo <- w[order(x)] 55 | 56 | cond <- max({ cumsum(wo) <= 0.5} * seq(1:lw)) 57 | if (cond == 0) 58 | cond <- 1 59 | xo[cond] 60 | } 61 | dp.n <- length(dp.locat[, 1]) 62 | if (is.null(dMat)) 63 | DM.given <- F 64 | else 65 | { 66 | DM.given <- T 67 | dim.dMat <- dim(dMat) 68 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 69 | stop("Dimensions of dMat are not correct") 70 | } 71 | CV.median <- numeric(dp.n) 72 | for (i in 1:dp.n) { 73 | if (DM.given) 74 | dist.vi <- dMat[, i] 75 | else { 76 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 77 | p = p, theta = theta, longlat = longlat) 78 | } 79 | W.i <- gw.weight(dist.vi, bw, kernel, adaptive) 80 | sum.w <- sum(W.i) 81 | Wi <- W.i/sum.w 82 | l.median<- findmedian(X, w = Wi) 83 | Wi <- Wi[-i] 84 | Wi<-Wi/sum(Wi) 85 | l.median.resi<- try(findmedian(X[-i], w = Wi)) 86 | if (!inherits(l.median.resi, "try-error")) { 87 | CV.median[i] <- l.median - l.median.resi 88 | } 89 | else { 90 | CV.median[i] <- Inf 91 | break 92 | } 93 | 94 | } 95 | if (!any(is.infinite(CV.median))) 96 | CV.median.score <- t(CV.median) %*% CV.median 97 | else { 98 | CV.median.score <- Inf 99 | } 100 | 101 | CV.median.score 102 | 103 | } 104 | 105 | # bws should be a matrix of 2*var.n, variable specific 106 | gw.average.cv <- function (bws, X, kernel, adaptive, dp.locat, p, theta, longlat, 107 | dMat) 108 | { 109 | findmedian <- function(x, w) { 110 | lw <- length(w) 111 | xo <- sort(x) 112 | wo <- w[order(x)] 113 | 114 | cond <- max({ cumsum(wo) <= 0.5} * seq(1:lw)) 115 | if (cond == 0) 116 | cond <- 1 117 | xo[cond] 118 | } 119 | 120 | 121 | dp.n <- length(dp.locat[, 1]) 122 | if (is.null(dMat)) 123 | DM.given <- F 124 | else 125 | { 126 | DM.given <- T 127 | dim.dMat <- dim(dMat) 128 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 129 | stop("Dimensions of dMat are not correct") 130 | } 131 | 132 | vars<-colnames(X) 133 | var.n <- length(vars) 134 | if(dim(bws)[1]!=2||dim(bws)[2]!=var.n) 135 | stop("Dimensions of bws are not correct (see the mannual for tips)!") 136 | CV.mean <- matrix(numeric(dp.n*var.n),ncol=var.n) 137 | CV.median <- matrix(numeric(dp.n*var.n),ncol=var.n) 138 | CV.mean.score <- numeric(var.n) 139 | CV.median.score <- numeric(var.n) 140 | for(k in 1:var.n) 141 | { 142 | x <- X[,k] 143 | for (i in 1:dp.n) 144 | { 145 | if (DM.given) 146 | dist.vi <- dMat[, i] 147 | else { 148 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 149 | p = p, theta = theta, longlat = longlat) 150 | } 151 | W.i <- gw.weight(dist.vi, bws[1,k], kernel, adaptive) 152 | sum.w <- sum(W.i) 153 | Wi <- W.i/sum.w 154 | l.mean<-sum(Wi*x) 155 | W.i[i] <- 0 156 | W.i<-W.i/sum(W.i) 157 | l.mean.resi <- try(sum(W.i*x)) 158 | if (!inherits(l.mean.resi, "try-error")) { 159 | CV.mean[i,k] <- l.mean - l.mean.resi 160 | } 161 | else 162 | { 163 | CV.mean[i,k] <- Inf 164 | break 165 | } 166 | W.i <- gw.weight(dist.vi, bws[2,k], kernel, adaptive) 167 | sum.w <- sum(W.i) 168 | Wi <- W.i/sum.w 169 | l.median<- findmedian(x, w = Wi) 170 | Wi <- Wi[-i] 171 | Wi <- Wi/sum(Wi) 172 | l.median.resi<- try(findmedian(X[-i], w = Wi)) 173 | if (!inherits(l.median.resi, "try-error")) 174 | { 175 | CV.median[i,k] <- l.median - l.median.resi 176 | } 177 | else { 178 | CV.median[i,k] <- Inf 179 | break 180 | } 181 | } 182 | if (!any(is.infinite(CV.mean[,k]))) 183 | CV.mean.score[k] <- diag(t(CV.mean[,k]) %*% CV.mean[,k]) 184 | else 185 | CV.mean.score[k] <- Inf 186 | 187 | if (!any(is.infinite(CV.median[,k]))) 188 | CV.median.score[k] <- t(CV.median[,k]) %*% CV.median[,k] 189 | else 190 | CV.median.score[k] <- Inf 191 | } 192 | CV.score<-list(CV.mean.score=CV.mean.score,CV.mean=CV.mean,CV.median.score=CV.median.score,CV.median=CV.median) 193 | 194 | CV.score 195 | } -------------------------------------------------------------------------------- /R/gw.average.cv.contrib.R: -------------------------------------------------------------------------------- 1 | gw.average.cv.contrib<- function(bw, X, kernel, adaptive, dp.locat, p, theta, longlat, dMat) 2 | { 3 | findmedian <- function(x, w) { 4 | lw <- length(w) 5 | xo <- sort(x) 6 | wo <- w[order(x)] 7 | 8 | cond <- max({ cumsum(wo) <= 0.5} * seq(1:lw)) 9 | if (cond == 0) 10 | cond <- 1 11 | xo[cond] 12 | } 13 | 14 | dp.n <- length(dp.locat[, 1]) 15 | if (is.null(dMat)) 16 | DM.given <- F 17 | else { 18 | DM.given <- T 19 | dim.dMat <- dim(dMat) 20 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 21 | stop("Dimensions of dMat are not correct") 22 | } 23 | CV.mean <- numeric(dp.n) 24 | CV.median <- numeric(dp.n) 25 | for (i in 1:dp.n) { 26 | if (DM.given) 27 | dist.vi <- dMat[, i] 28 | else { 29 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 30 | p = p, theta = theta, longlat = longlat) 31 | } 32 | W.i <- matrix(gw.weight(dist.vi, bw, kernel, adaptive),nrow=1) 33 | sum.w <- sum(W.i) 34 | Wi <- W.i/sum.w 35 | l.mean<-Wi%*%X 36 | l.median<- findmedian(X, w = c(Wi)) 37 | Wi <- Wi[-i] 38 | Wi<-Wi/sum(Wi) 39 | l.mean.resi <- try(sum(Wi*X[-i])) 40 | l.median.resi<- try(findmedian(X[-i], w = Wi)) 41 | 42 | if (!inherits(l.mean.resi, "try-error")) { 43 | CV.mean[i] <- l.mean - l.mean.resi 44 | } 45 | else { 46 | CV.mean[i] <- Inf 47 | break 48 | } 49 | 50 | if (!inherits(l.median.resi, "try-error")) { 51 | CV.median[i] <- l.median - l.median.resi 52 | } 53 | else { 54 | CV.median[i] <- Inf 55 | break 56 | } 57 | } 58 | CV<-cbind(CV.mean,CV.median) 59 | colnames(CV)<-c('Local Mean','Local Median') 60 | CV 61 | } -------------------------------------------------------------------------------- /R/gw.dist.r: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # gw.dist: caculate a distance vector or distance matrix between (a) regression point and data points 3 | # dp.locat: numeric vector of two colunms, coordinates of data points 4 | # rp.locat: numeric vector of two colunms, coordinates of regression points 5 | # focus: an integer, indexing to the current regression point, if focus=0, all the distances between all the regression points and data points will be calculated and a distance matrix will be returned; 6 | # if 0 length(rp.locat[,1])) 22 | stop("No regression point is fixed") 23 | dists <- gw_dist(dp.locat, rp.locat, focus - 1, ifelse(is.infinite(p), -1, p), theta, longlat, T) 24 | } 25 | else dists <- gw_dist(dp.locat, dp.locat, focus - 1, ifelse(is.infinite(p), -1, p), theta, longlat, F) 26 | dists 27 | } 28 | -------------------------------------------------------------------------------- /R/gw.weight.r: -------------------------------------------------------------------------------- 1 | ################## NAME: gw.weight ################### 2 | ## ARGUMENTS IN: 3 | #### vdist: numeric vector or matrix of distances (from gw.dist.r) 4 | #### bw: scalar, bandwidth or number of nearest neighbours 5 | #### kernel: text vector of function chosen 6 | ########## boxcar: wgt=1 if dist < bw, wgt=0 otherwise 7 | ########## gaussian: wgt = exp(-.5*(vdist/bw)^2) 8 | ########## bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise 9 | ########## tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise 10 | ########## adaptive: if TRUE calulate the adaptive kernel, and bw correspond to the number of nearest neighbour 11 | #### 12 | ## ARGUMENTS OUT: 13 | #### if vdist is a vector the output is a vector of weights of the length of vdist 14 | #### if vdist is a matrix the output is a matrix of weights of the dim of vdist, containing in column i the weights for observation i 15 | ## REFERENCES: Book pg 56-57 16 | ######################## 17 | ####C++ code embeded at 31/01/2021 18 | 19 | # MAIN FUNCTION 20 | 21 | gw.weight <-function(vdist,bw,kernel,adaptive=FALSE){ 22 | if (is.matrix(vdist)) 23 | { 24 | wgt <- gw_weight_mat(vdist,bw,kernel,adaptive) 25 | } 26 | else 27 | { 28 | wgt <- as.vector(gw_weight_vec(vdist,bw,kernel,adaptive)) 29 | } 30 | 31 | wgt 32 | } 33 | -------------------------------------------------------------------------------- /R/gwr.collin.diagno.r: -------------------------------------------------------------------------------- 1 | #local collinearity diagnostic function for GWR 2 | gwr.collin.diagno <- function(formula, data, bw, kernel="bisquare", 3 | adaptive=FALSE, p=2, theta=0, longlat=F,dMat) 4 | { 5 | ##Record the start time 6 | timings <- list() 7 | timings[["start"]] <- Sys.time() 8 | ###################################macth the variables 9 | this.call <- match.call() 10 | p4s <- as.character(NA) 11 | #####Check the given data frame and regression points 12 | ##Data points{ 13 | polygons <- NULL 14 | griddedObj <- F 15 | spdf <- FALSE 16 | if (inherits(data, "Spatial")) 17 | { 18 | p4s <- proj4string(data) 19 | spdf <- TRUE 20 | if (is(data, "SpatialPolygonsDataFrame")) 21 | { 22 | polygons <- polygons(data) 23 | dp.locat<-coordinates(data) 24 | } 25 | else 26 | { 27 | dp.locat<-coordinates(data) 28 | griddedObj <- gridded(data) 29 | } 30 | data <- as(data, "data.frame") 31 | } 32 | else if(inherits(data, "sf")) { 33 | if(any((st_geometry_type(data)=="POLYGON")) | any(st_geometry_type(data)=="MULTIPOLYGON")) 34 | dp.locat <- st_coordinates(st_centroid(st_geometry(data))) 35 | else 36 | dp.locat <- st_coordinates(st_geometry(data)) 37 | } 38 | else 39 | { 40 | stop("Given regression data must be Spatial*DataFrame") 41 | } 42 | 43 | #################### 44 | ######Extract the data frame 45 | ####Refer to the function lm 46 | mf <- match.call(expand.dots = FALSE) 47 | m <- match(c("formula", "data"), names(mf), 0L) 48 | 49 | mf <- mf[c(1L, m)] 50 | mf$drop.unused.levels <- TRUE 51 | mf[[1L]] <- as.name("model.frame") 52 | mf <- eval(mf, parent.frame()) 53 | mt <- attr(mf, "terms") 54 | y <- model.extract(mf, "response") 55 | x <- model.matrix(mt, mf) 56 | idx1 <- match("(Intercept)", colnames(x)) 57 | var.n<-ncol(x) 58 | if(!is.na(idx1)) 59 | { 60 | colnames(x)[idx1]<-"Intercept" 61 | x1<-x[,-1] 62 | } 63 | else 64 | { 65 | x1 <- x 66 | } 67 | var.nms <- colnames(x) 68 | if (var.n<=1) 69 | stop("The number of independent variables must be larger than one") 70 | dp.n<-nrow(data) 71 | if (missing(dMat)) 72 | { 73 | DM.given<-F 74 | DM1.given<-F 75 | if(dp.n <= 5000) 76 | { 77 | dMat <- gw.dist(dp.locat=dp.locat, p=p, theta=theta, longlat=longlat) 78 | DM.given<-T 79 | } 80 | } 81 | else 82 | { 83 | DM.given<-T 84 | DM1.given<-T 85 | dim.dMat<-dim(dMat) 86 | if (dim.dMat[1]!=dp.n||dim.dMat[2]!=dp.n) 87 | stop("Dimensions of dMat are not correct") 88 | } 89 | ###############local correlation 90 | # cov.nms <- c() 91 | corr.nms <- c() 92 | #cov.mat <- matrix(numeric((var.n - 1) * var.n * dp.n/2), 93 | # nrow = dp.n) 94 | corr.mat <- matrix(numeric((var.n - 1) * var.n * dp.n/2), 95 | nrow = dp.n) 96 | vifs.mat <- matrix(numeric((var.n-1) * dp.n), 97 | nrow = dp.n) 98 | vdp.idx <- matrix(numeric(var.n * dp.n), 99 | nrow = dp.n) # condition index, the same as condition number 100 | vdp.pi <- array(0, dim=c(dp.n,var.n,var.n)) # VDPs 101 | 102 | for (i in 1:dp.n) 103 | { 104 | if (DM.given) 105 | dist.vi <- dMat[, i] 106 | else 107 | { 108 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 109 | p = p, theta = theta, longlat = longlat) 110 | } 111 | W.i <- matrix(gw.weight(dist.vi, bw, kernel, adaptive), 112 | nrow = 1) 113 | sum.w <- sum(W.i) 114 | Wi <- W.i/sum.w 115 | tag <- 0 116 | for (j in 1:(var.n - 1)) 117 | for (k in (j + 1):var.n) 118 | { 119 | tag <- tag + 1 120 | #cov.mat[i,tag] <- cov.wt(cbind(x[, j],x[, k]), wt=Wi[1,])$cov[1,2] # Replace the old code for something faster 121 | corr.mat[i, tag] <- cov.wt(cbind(x[, j],x[, k]), wt=Wi[1,],cor=TRUE)$cor[1,2] # Also replaced this as this way is a bit faster 122 | #s.corr.mat[i, tag] <- cov.wt(cbind(rank(x[, j]), rank(x[, k])), wt=Wi[1,],cor=TRUE)$cor[1,2] # Had to replace Spearmans Rho function - supplied one not correct for weighted version 123 | } 124 | ####Again correlation matrix for calculating local Variance inflation factors (VIFs) 125 | corr.mati <- cov.wt(x1, wt=Wi[1,],cor=TRUE)$cor 126 | vifs.mat[i,] <- diag(solve(corr.mati)) 127 | ################### Variance-decomposition proportions 128 | xw <- as.matrix(sweep(x,1,Wi,"*")) 129 | svd.x <- svd(sweep(xw, 2,sqrt(colSums(xw^2)), "/")) 130 | vdp.idx[i,] <- svd.x$d[1] / svd.x$d 131 | Phi = svd.x$v %*% diag(1/svd.x$d) 132 | Phi <- t(Phi^2) 133 | pi.ij <- prop.table(Phi, 2) 134 | vdp.pi[i,,] <- pi.ij 135 | } 136 | 137 | #############names for correlation, 138 | for (i in 1:(var.n - 1)) { 139 | for (j in (i + 1):var.n) { 140 | corr.v1v2 <- paste("Corr", paste(var.nms[i], var.nms[j], 141 | sep = "."), sep = "_") 142 | corr.nms <- c(corr.nms, corr.v1v2) 143 | } 144 | } 145 | nm1 <- corr.nms 146 | nm2 <-paste(var.nms[-1],"VIF", sep = "_") 147 | local_CN <- vdp.idx[, var.n] 148 | VDP <- vdp.pi[,var.n,] 149 | nm3 <-paste(var.nms,"VDP", sep = "_") 150 | res.df <- data.frame(vifs.mat,local_CN, VDP,corr.mat) 151 | colnames(res.df) <- c(nm2, "local_CN", nm3, nm1) 152 | 153 | if(spdf){ 154 | if (!is.null(polygons)) 155 | { 156 | rownames(res.df) <- sapply(slot(polygons, "polygons"), 157 | function(i) slot(i, "ID")) 158 | SDF <-SpatialPolygonsDataFrame(Sr=polygons, data=res.df, match.ID=F) 159 | } 160 | else 161 | { 162 | SDF <- SpatialPointsDataFrame(coords=dp.locat, data=res.df, proj4string=CRS(p4s), match.ID=F) 163 | if(griddedObj) 164 | gridded(SDF) <- griddedObj 165 | } 166 | } 167 | else 168 | { 169 | SDF <- st_sf(res.df, geometry = st_geometry(data)) 170 | } 171 | res <- list() 172 | res$corr.mat <- corr.mat 173 | res$VIF <- vifs.mat 174 | res$local_CN <- local_CN 175 | res$VDP <- VDP 176 | res$SDF <- SDF 177 | #res <- list(corr.mat, vifs.mat, vdp.idx, vdp.pi) 178 | timings[["stop"]] <- Sys.time() 179 | #res$timings <- timings 180 | res 181 | } 182 | -------------------------------------------------------------------------------- /R/gwr.robust.r: -------------------------------------------------------------------------------- 1 | gwr.robust<-function(formula, data, bw,filtered=FALSE, kernel = "bisquare", adaptive = FALSE, p = 2, theta = 0, longlat = F, dMat, F123.test = F, 2 | maxiter=20,cut.filter= 3,cut1=2,cut2=3,delta=1.0e-5, parallel.method = FALSE, 3 | parallel.arg = NULL) 4 | { 5 | W.vect<-NULL 6 | res1<- gwr.basic(formula=formula, data=data, bw=bw, kernel=kernel, adaptive=adaptive, p=p, theta=theta, longlat=longlat, dMat=dMat, F123.test=F123.test, cv=T,W.vect=W.vect, parallel.method = parallel.method, parallel.arg = parallel.arg) 7 | if(filtered==TRUE){ 8 | W.vect<-as.numeric(abs(res1$SDF$Stud_residual) cut1 19 | xg3 <- x > cut2 20 | span <- cut2 - cut1 21 | result[xg2] <- (1 - ((x[xg2]-cut1)/span)^2)^2 22 | result[xg3] <- rep(0,sum(xg3)) 23 | result 24 | } 25 | 26 | iter<-0 27 | diffmse<-1 28 | err<-res1$SDF$residual 29 | mse<- sum(err*err)/length(err) 30 | W.vect <- filt(abs(err/sqrt(mse))) 31 | W.vect[is.na(W.vect)]<-0 32 | 33 | while(diffmse>delta & iter 1] <- 1 52 | colnames(asf_pvals) <- paste(colnames(pvals), "_fb", sep = "") 53 | results <- list(t = tvals, p = pvals, by = bey_pvals, fb = asf_pvals, 54 | bo = bon_pvals, bh = beh_pvals) 55 | df.res<-data.frame(tvals, pvals, bey_pvals, asf_pvals,bon_pvals, beh_pvals) 56 | p4s <- proj4string(gwm.Obj$SDF) 57 | if(is(gwm.Obj$SDF, "SpatialPolygonsDataFrame")) 58 | polygons<-polygons(gwm.Obj$SDF) 59 | else 60 | { 61 | locat <- coordinates(gwm.Obj$SDF) 62 | rownames(locat)<-rownames(df.res) 63 | } 64 | griddedObj <- F 65 | if(inherits(gwm.Obj$SDF, "Spatial")) 66 | { 67 | if (is(gwm.Obj$SDF, "SpatialPolygonsDataFrame")) 68 | { 69 | polygons<-polygons(gwm.Obj$SDF) 70 | #SpatialPolygons(regression.points) 71 | #rownames(gwres.df) <- sapply(slot(polygons, "polygons"), 72 | # function(i) slot(i, "ID")) 73 | SDF <-SpatialPolygonsDataFrame(Sr=polygons, data=df.res, match.ID=F) 74 | } 75 | else 76 | { 77 | griddedObj <- gridded(gwm.Obj$SDF) 78 | SDF <- SpatialPointsDataFrame(coords=locat, data=df.res, proj4string=CRS(p4s), match.ID=F) 79 | gridded(SDF) <- griddedObj 80 | } 81 | } 82 | else if (inherits(gwm.Obj$SDF, "sf")) 83 | { 84 | SDF <- st_sf(df.res, geometry = st_geometry(gwm.Obj$SDF)) 85 | } 86 | else 87 | SDF <- SpatialPointsDataFrame(coords=locat, data=df.res, proj4string=CRS(p4s), match.ID=F) 88 | 89 | # if (is(gwm.Obj$SDF, "SpatialPolygonsDataFrame")) 90 | # { 91 | # SDF <-SpatialPolygonsDataFrame(Sr=polygons, data=df.res) 92 | # } 93 | # else 94 | # SDF <- SpatialPointsDataFrame(coords=locat, data=df.res, proj4string=CRS(p4s)) 95 | 96 | res<-list(results=results, SDF=SDF) 97 | res 98 | } -------------------------------------------------------------------------------- /R/writeGWR.r: -------------------------------------------------------------------------------- 1 | ###Write GWR results 2 | ##Author: Binbin Lu 3 | 4 | gwr.write<-function(x,fn="GWRresults") 5 | { 6 | if(!inherits(x, "gwrm")) stop("It's not a gwm object") 7 | fn1<-paste(fn,".txt",sep="") 8 | #fn2<-paste(fn,".csv",sep="") 9 | sink(fn1) 10 | print.gwrm(x) 11 | sink() 12 | # writeGWR.csv(x, fn=fn2) 13 | gwr.write.shp(x,fn=fn) 14 | invisible(x) 15 | } 16 | gwr.write.shp<-function(x,fn="GWRresults") 17 | { 18 | if(!inherits(x, "gwrm")) stop("It's not a gwm object") 19 | SDF<-x$SDF 20 | if(inherits(SDF, "Spatial")) 21 | st_write(st_as_sf(SDF), paste(fn, ".shp",sep=""),driver = "ESRI Shapefile",delete_dsn =T) 22 | else 23 | st_write(SDF, paste(fn, ".shp",sep=""),driver = "ESRI Shapefile",delete_dsn =T) 24 | invisible(SDF) 25 | } 26 | 27 | # This version of this function is kept to make the code work with the early versions of GWmodel (before 2.0-1) 28 | writeGWR<-function(x,fn="GWRresults") 29 | { 30 | if(!inherits(x, "gwrm")) stop("It's not a gwm object") 31 | fn1<-paste(fn,".txt",sep="") 32 | #fn2<-paste(fn,".csv",sep="") 33 | sink(fn1) 34 | print.gwrm(x) 35 | sink() 36 | # writeGWR.csv(x, fn=fn2) 37 | gwr.write.shp(x,fn=fn) 38 | invisible(x) 39 | } 40 | 41 | # This version of this function is kept to make the code work with the early versions of GWmodel (before 2.0-1) 42 | writeGWR.shp<-function(x,fn="GWRresults") 43 | { 44 | if(!inherits(x, "gwrm")) stop("It's not a gwm object") 45 | SDF<-x$SDF 46 | if(inherits(SDF, "Spatial")) 47 | st_write(st_as_sf(SDF), paste(fn, ".shp",sep=""),driver = "ESRI Shapefile",delete_dsn =T) 48 | else 49 | st_write(SDF, paste(fn, ".shp",sep=""),driver = "ESRI Shapefile",delete_dsn =T) 50 | invisible(SDF) 51 | } -------------------------------------------------------------------------------- /R/zzz.r: -------------------------------------------------------------------------------- 1 | .onAttach <- function(lib, pkg) { 2 | packageStartupMessage("Welcome to GWmodel version 2.4-2.\n", appendLF = FALSE) 3 | } -------------------------------------------------------------------------------- /build/partial.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/build/partial.rdb -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/sh +x 2 | 3 | rm -rf src/*.o src/*.so 4 | 5 | rm -rf config.log config.status autom4te.cache 6 | 7 | rm -rf src/tmp src/GWmodelCUDA.zip 8 | 9 | rm -rf src/GWmodelCUDA*.dll src/GWmodelCUDA/*.lib 10 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([GWmodel], 2.2-0) 2 | 3 | AC_LANG(C++) 4 | AC_REQUIRE_CPP 5 | 6 | echo "Checking for C++ Compiler" 7 | AC_PROG_CXX 8 | 9 | ENABLE_CUDA=0 10 | 11 | 12 | AC_ARG_ENABLE([cuda], [AS_HELP_STRING([--enable-cuda],[install cuda (default no)])], 13 | [ case "${enableval}" in 14 | yes) ENABLE_CUDA=1 ;; 15 | no) ENABLE_CUDA=0 ;; 16 | *) AC_MSG_ERROR(bad value ${enableval} for --enable-cuda) ;; 17 | esac]) 18 | 19 | if test ${ENABLE_CUDA} -eq 1; then 20 | AC_MSG_CHECKING("Checking environment variable CUDA_HOME") 21 | if test -z "${CUDA_HOME}"; then 22 | AC_MSG_RESULT("CUDA_HOME not set, stop finding nvcc") 23 | else 24 | AC_MSG_RESULT("using CUDA_HOME=${CUDA_HOME}") 25 | fi 26 | 27 | if test -z "${CUDA_HOME}"; then 28 | if test ${ENABLE_CUDA} -eq 1; then 29 | echo " 30 | It seams that you don't have CUDA environment and the --enable-cuda is yes 31 | 32 | Please make sure your cuda environment is under the /usr/local directory 33 | 34 | If you don't want to install cuda function, please set `--enable-cuda=no` 35 | " 36 | exit 1 37 | fi 38 | fi 39 | 40 | if test ${ENABLE_CUDA} -eq 1; then 41 | AC_MSG_CHECKING("whether this is the 64 bit linux version of CUDA") 42 | AC_CHECK_FILE([${CUDA_HOME}/lib64/libcudart.so], [BIT64="yes"]) 43 | if test -z "${BIT64}"; then 44 | AC_MSG_RESULT("no -- using ${CUDA_HOME}/lib for CUDA libs") 45 | cu_libdir="${CUDA_HOME}/lib" 46 | AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 47 | else 48 | AC_MSG_RESULT("yes -- using ${CUDA_HOME}/lib64 for CUDA libs") 49 | cu_libdir="${CUDA_HOME}/lib64" 50 | AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 51 | fi 52 | else 53 | AC_SUBST(CUDA_LIBDIR,[""]) 54 | fi 55 | fi 56 | 57 | if test ${ENABLE_CUDA} -eq 1; then 58 | AC_MSG_RESULT(You have CUDA environment and we will compile the cuda function for you) 59 | cu_sources="GWmodelKernel.cu" 60 | cu_sharedlibs="GWmodelKernel.o" 61 | cpp_sources_cuda="CGWmodelCUDA.cpp IGWmodelCUDA.cpp" 62 | cpp_sharedlibs_cuda="CGWmodelCUDA.o IGWmodelCUDA.o" 63 | OBJECTS_CUDA="${cu_sharedlibs} ${cpp_sharedlibs_cuda}" 64 | 65 | CDEFS="-DCUDA_ACCE" 66 | TARGET_CUDA_LIB="libgwmodelcuda.so" 67 | 68 | CUDA_LIBS="-L${CUDA_LIBDIR} -Wl,-rpath=${CUDA_LIBDIR} -lcudart -lcublas " 69 | PKG_LIBS=${PKG_LIBS}"${CUDA_LIBS} -L${HOME}/.cache/GWmodel -Wl,-rpath=${HOME}/.cache/GWmodel -lgwmodelcuda" 70 | AC_SUBST(cu_sources) 71 | AC_SUBST(cu_sharedlibs) 72 | AC_SUBST(cpp_sources_cuda) 73 | AC_SUBST(cpp_sharedlibs_cuda) 74 | AC_SUBST(OBJECTS_CUDA) 75 | AC_SUBST(CDEFS) 76 | AC_SUBST(TARGET_CUDA_LIB) 77 | AC_SUBST(CUDA_LIBS) 78 | fi 79 | 80 | 81 | AC_MSG_RESULT(building the nvcc command line) 82 | NVCC="${CUDA_HOME}/bin/nvcc" 83 | AC_MSG_RESULT(building the cuda include path) 84 | CUDA_INCL="${CUDA_HOME}/include" 85 | 86 | AC_SUBST(GWmodel_CUDA_LIB_PATH,["~/.cache/GWmodel"]) 87 | 88 | AC_MSG_NOTICE([Building Makevars]) 89 | AC_SUBST(CU_INCL) 90 | AC_SUBST(NVCC) 91 | AC_SUBST(PKG_LIBS) 92 | AC_SUBST(CUDA_INCL) 93 | AC_SUBST(ENABLE_CUDA) 94 | 95 | AC_CONFIG_FILES(src/Makevars) 96 | AC_OUTPUT 97 | 98 | -------------------------------------------------------------------------------- /data/DubVoter.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/DubVoter.rda -------------------------------------------------------------------------------- /data/EWHP.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/EWHP.rda -------------------------------------------------------------------------------- /data/EWOutline.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/EWOutline.rda -------------------------------------------------------------------------------- /data/Georgia.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/Georgia.rda -------------------------------------------------------------------------------- /data/GeorgiaCounties.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/GeorgiaCounties.rda -------------------------------------------------------------------------------- /data/LondonBorough.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/LondonBorough.rda -------------------------------------------------------------------------------- /data/LondonHP.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/LondonHP.rda -------------------------------------------------------------------------------- /data/USelect.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/GWmodel/60dc1cee77957aa4f899ca1bd4898d151dc579af/data/USelect.rda -------------------------------------------------------------------------------- /data/datalist: -------------------------------------------------------------------------------- 1 | DubVoter: Dub.voter 2 | EWHP: ewhp 3 | EWOutline: ewoutline 4 | Georgia: Gedu.df 5 | GeorgiaCounties: Gedu.counties 6 | LondonBorough: londonborough 7 | LondonHP: londonhp 8 | USelect: USelect2004 9 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite GWmodel in publications use:") 2 | 3 | bibentry(bibtype = "Article", 4 | title = "{GWmodel}: An {R} Package for Exploring Spatial Heterogeneity Using Geographically Weighted Models", 5 | author = c(person(c("Isabella", "Gollini")), 6 | person(c("Binbin", "Lu")), 7 | person(c("Martin", "Charlton")), 8 | person(c("Christopher", "Brunsdon")), 9 | person(c("Paul", "Harris"))), 10 | journal = "Journal of Statistical Software", 11 | year = "2015", 12 | volume = "63", 13 | number = "17", 14 | pages = "1--50", 15 | doi = "10.18637/jss.v063.i17", 16 | 17 | textVersion = 18 | paste("Isabella Gollini, Binbin Lu, Martin Charlton, Christopher Brunsdon, Paul Harris (2015).", 19 | "GWmodel: An R Package for Exploring Spatial Heterogeneity Using Geographically Weighted Models.", 20 | "Journal of Statistical Software, 63(17), 1-50.", 21 | "DOI 10.18637/jss.v063.i17") 22 | ) 23 | 24 | bibentry(bibtype = "Article", 25 | title = "The {GWmodel} {R} package: further topics for exploring spatial heterogeneity using geographically weighted models", 26 | author = c(person(c("Binbin", "Lu")), 27 | person(c("Paul", "Harris")), 28 | person(c("Martin", "Charlton")), 29 | person(c("Christopher", "Brunsdon"))), 30 | journal = "Geo-spatial Information Science", 31 | year = "2014", 32 | volume = "17", 33 | number = "2", 34 | pages = "85--101", 35 | doi = "10.1080/10095020.2014.917453", 36 | 37 | textVersion = 38 | paste("Binbin Lu, Paul Harris, Martin Charlton, Christopher Brunsdon (2014).", 39 | "The GWmodel R package: further topics for exploring spatial heterogeneity using geographically weighted models.", 40 | "Geo-spatial Information Science, 17(2), 85-101.", 41 | "DOI 10.1080/10095020.2014.917453") 42 | ) -------------------------------------------------------------------------------- /man/DubVoter.rd: -------------------------------------------------------------------------------- 1 | \name{DubVoter} 2 | \alias{DubVoter} 3 | \alias{Dub.voter} 4 | \docType{data} 5 | \title{Voter turnout data in Greater Dublin(SpatialPolygonsDataFrame)} 6 | \description{ 7 | Voter turnout and social characters data in Greater Dublin for the 2002 General election and the 2002 census. 8 | Note that this data set was originally thought to relate to 2004, so for continuity we have retained the associated variable names. 9 | } 10 | \usage{data(DubVoter)} 11 | \format{ 12 | A SpatialPolygonsDataFrame with 322 electoral divisions on the following 11 variables. 13 | \describe{ 14 | \item{DED_ID}{a vector of ID} 15 | \item{X}{a numeric vector of x coordinates} 16 | \item{Y}{a numeric vector of y coordinates} 17 | \item{DiffAdd}{percentage of the population in each ED who are one-year migrants (i.e. moved to a different address 1 year ago)} 18 | \item{LARent}{percentage of the population in each ED who are local authority renters} 19 | \item{SC1}{percentage of the population in each ED who are social class one (high social class)} 20 | \item{Unempl}{percentage of the population in each ED who are unemployed} 21 | \item{LowEduc}{percentage of the population in each ED who are with little formal education} 22 | \item{Age18_24}{percentage of the population in each ED who are age group 18-24} 23 | \item{Age25_44}{percentage of the population in each ED who are age group 25-44} 24 | \item{Age45_64}{percentage of the population in each ED who are age group 45-64} 25 | \item{GenEl2004}{percentage of population in each ED who voted in 2004 election} 26 | } 27 | } 28 | \details{ 29 | Variables are from DubVoter.shp. 30 | } 31 | \references{ 32 | Kavanagh A (2006) Turnout or turned off? Electoral participation in Dublin in the early 21st Century. Journal of Irish Urban Studies 3(2):1-24 33 | 34 | Harris P, Brunsdon C, Charlton M (2011) Geographically weighted principal components analysis. International Journal of Geographical Information Science 25 (10):1717-1736 35 | } 36 | \examples{ 37 | 38 | data(DubVoter) 39 | ls() 40 | \dontrun{ 41 | spplot(Dub.voter,names(Dub.voter)[4:12]) 42 | } 43 | } 44 | \keyword{data} 45 | \concept{Dublin Voter turnout} 46 | -------------------------------------------------------------------------------- /man/EWHP.Rd: -------------------------------------------------------------------------------- 1 | \name{EWHP} 2 | \alias{EWHP} 3 | \alias{ewhp} 4 | \docType{data} 5 | \title{House price data set (DataFrame) in England and Wales} 6 | \description{ 7 | A house price data set for England and Wales from 2001 with 9 hedonic (explanatory) variables. 8 | } 9 | \usage{data(EWHP)} 10 | \format{ 11 | A data frame with 519 observations on the following 12 variables. 12 | \describe{ 13 | \item{Easting}{a numeric vector, X coordinate} 14 | \item{Northing}{a numeric vector, Y coordinate} 15 | \item{PurPrice}{a numeric vector, the purchase price of the property} 16 | \item{BldIntWr}{a numeric vector, 1 if the property was built during the world war, 0 otherwise} 17 | \item{BldPostW}{a numeric vector, 1 if the property was built after the world war, 0 otherwise} 18 | \item{Bld60s}{a numeric vector, 1 if the property was built between 1960 and 1969, 0 otherwise} 19 | \item{Bld70s}{a numeric vector, 1 if the property was built between 1970 and 1979, 0 otherwise} 20 | \item{Bld80s}{a numeric vector, 1 if the property was built between 1980 and 1989, 0 otherwise} 21 | \item{TypDetch}{a numeric vector, 1 if the property is detached (i.e. it is a stand-alone house), 0 otherwise} 22 | \item{TypSemiD}{a numeric vector, 1 if the property is semi detached, 0 otherwise} 23 | \item{TypFlat}{a numeric vector, if the property is a flat (or 'apartment' in the USA), 0 otherwise} 24 | \item{FlrArea}{a numeric vector, floor area of the property in square metres} 25 | } 26 | } 27 | \references{ 28 | Fotheringham, A.S., Brunsdon, C., and Charlton, M.E. (2002), Geographically Weighted Regression: 29 | The Analysis of Spatially Varying Relationships, Chichester: Wiley. 30 | } 31 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 32 | \examples{ 33 | ### 34 | data(EWHP) 35 | head(ewhp) 36 | houses.spdf <- SpatialPointsDataFrame(ewhp[, 1:2], ewhp) 37 | ####Get the border of England and Wales 38 | data(EWOutline) 39 | plot(ewoutline) 40 | plot(houses.spdf, add = TRUE, pch = 16) 41 | } 42 | \keyword{data} 43 | \concept{house price} 44 | -------------------------------------------------------------------------------- /man/EWOutline.rd: -------------------------------------------------------------------------------- 1 | \name{EWOutline} 2 | \alias{ewoutline} 3 | \docType{data} 4 | \title{Outline of England and Wales for data \link{EWHP}} 5 | \description{ 6 | Outline (SpatialPolygonsDataFrame) of the England and Wales house price data \link{EWHP}. 7 | } 8 | \usage{data(EWOutline)} 9 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 10 | \keyword{data} 11 | \concept{England-Wales outline} 12 | -------------------------------------------------------------------------------- /man/GWmodel-package.Rd: -------------------------------------------------------------------------------- 1 | \name{GWmodel-package} 2 | \alias{GWmodel-package} 3 | \alias{GWmodel} 4 | \docType{package} 5 | \title{ 6 | Geographically-Weighted Models 7 | } 8 | \description{ 9 | In GWmodel, we introduce techniques from a particular branch of spatial statistics, 10 | termed geographically-weighted (GW) models. GW models suit situations when data are 11 | not described well by some global model, but where there are spatial regions where 12 | a suitably localised calibration provides a better description. GWmodel includes functions 13 | to calibrate: GW summary statistics, GW principal components analysis, GW discriminant analysis 14 | and various forms of GW regression; some of which are provided in basic and robust (outlier resistant) forms. 15 | In particular, the high-performence computing technologies, including multi-thread and CUDA techniques are started 16 | to be adopted for efficient calibrations. 17 | } 18 | \details{ 19 | \tabular{ll}{ 20 | Package: \tab GWmodel\cr 21 | Type: \tab Package\cr 22 | Version: \tab 2.4-1\cr 23 | Date: \tab 2024-09-06\cr 24 | License: \tab GPL (>=2)\cr 25 | LazyLoad: \tab yes\cr 26 | } 27 | 28 | } 29 | \author{ 30 | Binbin Lu, Paul Harris, Martin Charlton, Chris Brunsdon, Tomoki Nakaya, Daisuke Murakami,Isabella Gollini[ctb], Yigong Hu[ctb], Fiona H Evans[ctb] 31 | 32 | Maintainer: Binbin Lu 33 | } 34 | \note{ 35 | Acknowledgements: We gratefully acknowledge support from National Natural Science Foundation of China (42071368); Science Foundation Ireland 36 | under the National Development Plan through the award of a Strategic Research Centre 37 | grant 07-SRC-I1168. 38 | 39 | Beta versions can always be found at \url{https://github.com/lbb220/GWmodel}, 40 | which includes all the newly developed functions for GW models. 41 | 42 | For latest tutorials on using GWmodel please go to: \url{https://rpubs.com/gwmodel} 43 | } 44 | 45 | \references{ 46 | Gollini I, Lu B, Charlton M, Brunsdon C, Harris P (2015) GWmodel: an R Package 47 | for exploring Spatial Heterogeneity using Geographically Weighted Models. Journal 48 | of Statistical Software, 63(17):1-50, \doi{10.18637/jss.v063.i17} 49 | 50 | Lu B, Harris P, Charlton M, Brunsdon C (2014) The GWmodel R Package: further 51 | topics for exploring Spatial Heterogeneity using Geographically Weighted Models. 52 | Geo-spatial Information Science 17(2): 85-101, \doi{10.1080/10095020.2014.917453} 53 | 54 | Lu, B., Hu, Y., Yang, D., Liu, Y., Ou, G., Harris, P., Brunsdon, C., Comber, 55 | A., Dong, G., 2024. Gwmodels: A standalone software to train geographically 56 | weighted models. Geo-spatial Information Science, 1-23. 57 | 58 | Lu, B., Hu, Y., Murakami, D., Brunsdon, C., Comber, A., Charlton, M., 59 | Harris, P., 2022. High-performance solutions of geographically weighted 60 | regression in r. Geo-spatial Information Science 25 (4), 536-549. 61 | } 62 | \keyword{package} 63 | -------------------------------------------------------------------------------- /man/Georgia.Rd: -------------------------------------------------------------------------------- 1 | \name{Georgia} 2 | \alias{Georgia} 3 | \alias{Gedu.df} 4 | \docType{data} 5 | \title{Georgia census data set (csv file)} 6 | \description{ 7 | Census data from the county of Georgia, USA 8 | } 9 | \usage{data(Georgia)} 10 | \format{ 11 | A data frame with 159 observations on the following 13 variables. 12 | \describe{ 13 | \item{AreaKey}{An identification number for each county} 14 | \item{Latitude}{The latitude of the county centroid} 15 | \item{Longitud}{The longitude of the county centroid} 16 | \item{TotPop90}{Population of the county in 1990} 17 | \item{PctRural}{Percentage of the county population defined as rural} 18 | \item{PctBach}{Percentage of the county population with a bachelors degree} 19 | \item{PctEld}{Percentage of the county population aged 65 or over} 20 | \item{PctFB}{Percentage of the county population born outside the US} 21 | \item{PctPov}{Percentage of the county population living below the poverty line} 22 | \item{PctBlack}{Percentage of the county population who are black} 23 | \item{ID}{a numeric vector of IDs} 24 | \item{X}{a numeric vector of x coordinates} 25 | \item{Y}{a numeric vector of y coordinates} 26 | } 27 | } 28 | \details{ 29 | This data set can also be found in GWR 3 and in spgwr. 30 | } 31 | \references{ 32 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 33 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 34 | } 35 | \examples{ 36 | data(Georgia) 37 | ls() 38 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 39 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 40 | spplot(educ.spdf, names(educ.spdf)[4:10]) 41 | } 42 | \keyword{data} 43 | \concept{Georgia census} 44 | -------------------------------------------------------------------------------- /man/GeorgiaCounties.rd: -------------------------------------------------------------------------------- 1 | \name{GeorgiaCounties} 2 | \alias{Gedu.counties} 3 | \docType{data} 4 | \title{Georgia counties data (SpatialPolygonsDataFrame)} 5 | \description{ 6 | The Georgia census data with boundaries for mapping 7 | } 8 | \usage{data(GeorgiaCounties)} 9 | \details{ 10 | This data set can also be found in GWR 3 and in spgwr. 11 | } 12 | \examples{ 13 | data(GeorgiaCounties) 14 | plot(Gedu.counties) 15 | data(Georgia) 16 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 17 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 18 | plot(educ.spdf, add=TRUE) 19 | 20 | } 21 | \keyword{data} 22 | \concept{Georgia counties} 23 | -------------------------------------------------------------------------------- /man/LondonBorough.rd: -------------------------------------------------------------------------------- 1 | \name{LondonBorough} 2 | \alias{LondonBorough} 3 | \alias{londonborough} 4 | \docType{data} 5 | \title{London boroughs data} 6 | \description{ 7 | Outline (SpatialPolygonsDataFrame) of London boroughs for the \link{LondonHP} data. 8 | } 9 | \usage{data(LondonBorough)} 10 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 11 | \keyword{data} 12 | \concept{London Boroughs} 13 | -------------------------------------------------------------------------------- /man/LondonHP.Rd: -------------------------------------------------------------------------------- 1 | \name{LondonHP} 2 | \alias{LondonHP} 3 | \alias{londonhp} 4 | \docType{data} 5 | \title{London house price data set (SpatialPointsDataFrame)} 6 | \description{ 7 | A house price data set with 18 hedonic variables for London in 2001. 8 | } 9 | \usage{data(LondonHP)} 10 | \format{ 11 | A SpatialPointsDataFrame object (proj4string set to "+init=epsg:27700 +datum=OSGB36"). 12 | 13 | The "data" slot is a data frame with 372 observations on the following 21 variables. 14 | \describe{ 15 | \item{X}{a numeric vector, X coordinate} 16 | \item{Y}{a numeric vector, Y coordinate} 17 | \item{PURCHASE}{a numeric vector, the purchase price of the property} 18 | \item{FLOORSZ}{a numeric vector, floor area of the property in square metres} 19 | \item{TYPEDETCH}{a numeric vector, 1 if the property is detached (i.e. it is a stand-alone house), 0 otherwise} 20 | \item{TPSEMIDTCH}{a numeric vector, 1 if the property is semi detached, 0 otherwise} 21 | \item{TYPETRRD}{a numeric vector, 1 if the property is in a terrace of similar houses (commonly referred to as a 'row house' in the USA), 0 otherwise} 22 | \item{TYPEBNGLW}{a numeric vector, if the property is a bungalow (i.e. it has only one floor), 0 otherwise} 23 | \item{TYPEFLAT}{a numeric vector, if the property is a flat (or 'apartment' in the USA), 0 otherwise} 24 | \item{BLDPWW1}{a numeric vector, 1 if the property was built prior to 1914, 0 otherwise} 25 | \item{BLDPOSTW}{a numeric vector, 1 if the property was built between 1940 and 1959, 0 otherwise} 26 | \item{BLD60S}{a numeric vector, 1 if the property was built between 1960 and 1969, 0 otherwise} 27 | \item{BLD70S}{a numeric vector, 1 if the property was built between 1970 and 1979, 0 otherwise} 28 | \item{BLD80S}{a numeric vector, 1 if the property was built between 1980 and 1989, 0 otherwise} 29 | \item{BLD90S}{a numeric vector, 1 if the property was built between 1990 and 2000, 0 otherwise} 30 | \item{BATH2}{a numeric vector, 1 if the property has more than 2 bathrooms, 0 otherwise} 31 | \item{GARAGE}{a numeric vector,1 if the house has a garage, 0 otherwise} 32 | \item{CENTHEAT}{a numeric vector, 1 if the house has central heating, 0 otherwise} 33 | \item{BEDS2}{a numeric vector, 1 if the property has more than 2 bedrooms, 0 otherwise} 34 | \item{UNEMPLOY}{a numeric vector, the rate of unemployment in the census ward in which the house is located} 35 | \item{PROF}{a numeric vector, the proportion of the workforce in professional or managerial occupations in the census ward in which the house is located} 36 | } 37 | } 38 | \references{ 39 | Fotheringham, A.S., Brunsdon, C., and Charlton, M.E. (2002), Geographically Weighted Regression: 40 | The Analysis of Spatially Varying Relationships, Chichester: Wiley. 41 | 42 | Lu, B, Charlton, M, Harris, P, Fotheringham, AS (2014) Geographically weighted regression 43 | with a non-Euclidean distance metric: a case study using hedonic house price data. 44 | International Journal of Geographical Information Science 28(4): 660-681 45 | } 46 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 47 | \examples{ 48 | data(LondonHP) 49 | data(LondonBorough) 50 | ls() 51 | plot(londonborough) 52 | plot(londonhp, add=TRUE) 53 | } 54 | \keyword{data} 55 | \concept{house price} 56 | -------------------------------------------------------------------------------- /man/USelect.rd: -------------------------------------------------------------------------------- 1 | \name{USelect} 2 | \alias{USelect2004} 3 | \docType{data} 4 | \title{Results of the 2004 US presidential election at the county level (SpatialPolygonsDataFrame)} 5 | \description{ 6 | Results of the 2004 US presidential election at the county level, together with five socio-economic (census) variables. 7 | This data can be used with GW Discriminant Analysis. 8 | } 9 | \usage{data(USelect)} 10 | \format{ 11 | A SpatialPolygonsDataFrame with 3111 electoral divisions on the following 6 variables. 12 | \describe{ 13 | \item{winner}{Categorical variable with three classes: i) Bush, ii) Kerry and iii) Borderline (supporting ratio for a candidate ranges from 0.45 to 0.55)} 14 | \item{unemploy}{percentage unemployed} 15 | \item{pctcoled}{percentage of adults over 25 with 4 or more years of college education} 16 | \item{PEROVER65}{percentage of persons over the age of 65} 17 | \item{pcturban}{percentage urban} 18 | \item{WHITE}{percentage white} 19 | } 20 | } 21 | \references{ 22 | Robinson, A. C. (2013). Geovisualization of the 2004 Presidential Election. 23 | In: NATIONAL INSTITUTES OF HEALTH, P. S. U. (ed.). Penn State. 24 | 25 | Foley, P. & Demsar, U. (2012). Using geovisual analytics to compare the 26 | performance of geographically weighted discriminant analysis versus its global 27 | counterpart, linear discriminant analysis. International Journal of Geographical 28 | Information Science, 27, 633-661. 29 | } 30 | \examples{ 31 | 32 | data(USelect) 33 | ls() 34 | } 35 | \keyword{data} 36 | \concept{US presidential election} 37 | -------------------------------------------------------------------------------- /man/bw.ggwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.ggwr} 2 | \alias{bw.ggwr} 3 | \alias{ggwr.aic} 4 | \title{Bandwidth selection for generalised geographically weighted regression (GWR)} 5 | \description{ 6 | A function for automatic bandwidth selection to calibrate a generalised GWR model 7 | } 8 | \usage{ 9 | bw.ggwr(formula, data, family ="poisson", approach="CV", 10 | kernel="bisquare",adaptive=FALSE, p=2, theta=0, longlat=F,dMat) 11 | } 12 | \arguments{ 13 | \item{formula}{Regression model formula of a \link{formula} object } 14 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 15 | \item{family}{a description of the error distribution and link function to 16 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 17 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 18 | \item{kernel}{function chosen as follows: 19 | 20 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 21 | 22 | exponential: wgt = exp(-vdist/bw); 23 | 24 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 25 | 26 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 27 | 28 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 29 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 30 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 31 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 32 | \item{longlat}{if TRUE, great circle distances will be calculated} 33 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 34 | } 35 | \note{ 36 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 37 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 38 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 39 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 40 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 41 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 42 | This note is applicable to all GW models 43 | } 44 | \value{ 45 | Returns the adaptive or fixed distance bandwidth 46 | } 47 | 48 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 49 | 50 | \keyword{generalised GWR} 51 | \concept{bandwidth selection} 52 | 53 | -------------------------------------------------------------------------------- /man/bw.gtwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gtwr} 2 | \alias{bw.gtwr} 3 | \alias{gtwr.cv} 4 | \alias{gtwr.aic} 5 | \title{Bandwidth selection for GTWR} 6 | \description{ 7 | A function for automatic bandwidth selection to calibrate a GTWR model 8 | } 9 | \usage{ 10 | bw.gtwr(formula, data, obs.tv, approach="CV",kernel="bisquare",adaptive=FALSE, 11 | p=2, theta=0, longlat=F,lamda=0.05,t.units = "auto",ksi=0, st.dMat, 12 | verbose=T) 13 | } 14 | \arguments{ 15 | \item{formula}{Regression model formula of a \link{formula} object } 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 17 | \item{obs.tv}{a vector of time tags for each observation, which could be numeric or of \link{POSIXlt} class} 18 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) 31 | corresponds to the number of nearest neighbours (i.e. adaptive distance); default 32 | is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{lamda}{an parameter between 0 and 1 for calculating spatio-temporal distance} 37 | \item{t.units}{ character string to define time unit} 38 | \item{ksi}{an parameter between 0 and PI for calculating spatio-temporal distance, 39 | see details in Wu et al. (2014)} 40 | \item{st.dMat}{a pre-specified spatio-temporal distance matrix} 41 | \item{verbose}{logical variable to define whether show the selection procedure} 42 | } 43 | \note{ 44 | The function is developed according to the articles by Huang et al. (2010) and 45 | Wu et al. (2014). 46 | } 47 | 48 | \value{ 49 | Returns the adaptive or fixed distance bandwidth 50 | } 51 | \references{ 52 | Huang, B., Wu, B., & Barry, M. (2010). Geographically and temporally weighted 53 | regression for modeling spatio-temporal variation in house prices. International 54 | Journal of Geographical Information Science, 24, 383-401. 55 | 56 | Wu, B., Li, R., & Huang, B. (2014). A geographically and temporally weighted 57 | autoregressive model with application to housing prices. International Journal 58 | of Geographical Information Science, 28, 1186-1204. 59 | 60 | Fotheringham, A. S., Crespo, R., & Yao, J. (2015). Geographical and Temporal 61 | Weighted Regression (GTWR). Geographical Analysis, 47, 431-452. 62 | 63 | } 64 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 65 | 66 | \keyword{GTWR} 67 | \concept{bandwidth selection} 68 | -------------------------------------------------------------------------------- /man/bw.gwda.rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwda} 2 | \alias{bw.gwda} 3 | \alias{wqda.cr} 4 | \alias{wlda.cr} 5 | \title{Bandwidth selection for GW Discriminant Analysis} 6 | \description{ 7 | A function for automatic bandwidth selection for GW Discriminant Analysis using a cross-validation approach only 8 | } 9 | \usage{ 10 | bw.gwda(formula, data, COV.gw = T, prior.gw = T, mean.gw = T, 11 | prior = NULL, wqda = F, kernel = "bisquare", adaptive 12 | = FALSE, p = 2, theta = 0, longlat = F,dMat) 13 | } 14 | 15 | \arguments{ 16 | \item{formula}{Model formula of a \link{formula} object } 17 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 18 | \item{COV.gw}{if true, localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used} 19 | \item{mean.gw}{if true, localised mean is used for GW discriminant analysis; otherwise, global mean is used} 20 | \item{prior.gw}{if true, localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used} 21 | \item{prior}{a vector of given prior probability} 22 | \item{wqda}{if TRUE, a weighted quadratic discriminant analysis will be applied; otherwise a weighted linear discriminant analysis will be applied} 23 | \item{kernel}{function chosen as follows: 24 | 25 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 26 | 27 | exponential: wgt = exp(-vdist/bw); 28 | 29 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 30 | 31 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 32 | 33 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 34 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 35 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 36 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 37 | \item{longlat}{if TRUE, great circle distances will be calculated} 38 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 39 | } 40 | \note{ 41 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 42 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 43 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 44 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 45 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 46 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 47 | This note is applicable to all GW models 48 | } 49 | \value{ 50 | Returns the adaptive or fixed distance bandwidth. 51 | } 52 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 53 | \keyword{GWDA} 54 | \concept{bandwidth selection} 55 | 56 | -------------------------------------------------------------------------------- /man/bw.gwpca.rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwpca} 2 | \alias{bw.gwpca} 3 | \title{Bandwidth selection for Geographically Weighted Principal Components Analysis (GWPCA)} 4 | \description{ 5 | A function for automatic bandwidth selection to calibrate a basic or robust GWPCA via a cross-validation approach only 6 | } 7 | \usage{ 8 | bw.gwpca(data,vars,k=2, robust=FALSE, scaling=T, kernel="bisquare",adaptive=FALSE,p=2, 9 | theta=0, longlat=F,dMat) 10 | } 11 | 12 | \arguments{ 13 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 14 | \item{vars}{a vector of variable names to be evaluated} 15 | \item{k}{the number of retained components, and it must be less than the number of variables} 16 | \item{robust}{if TRUE, robust GWPCA will be applied; otherwise basic GWPCA will be applied} 17 | \item{scaling}{if TRUE, the data is scaled to have zero mean and unit variance (standardized); 18 | otherwise the data is centered but not scaled} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 32 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 33 | \item{longlat}{if TRUE, great circle distances will be calculated} 34 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 35 | } 36 | \value{ 37 | Returns the adaptive or fixed distance bandwidth 38 | } 39 | \note{ 40 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 41 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 42 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 43 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 44 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 45 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 46 | This note is applicable to all GW models 47 | } 48 | \references{ 49 | Harris P, Clarke A, Juggins S, Brunsdon C, Charlton M (2015) 50 | Enhancements to a geographically weighted principal components analysis in the context of an application to an environmental data set. 51 | Geographical Analysis 47: 146-172 52 | } 53 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 54 | \keyword{GWPCA} 55 | \concept{bandwidth selection} 56 | 57 | -------------------------------------------------------------------------------- /man/bw.gwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwr} 2 | \alias{bw.gwr} 3 | \alias{gwr.aic} 4 | \alias{gold} 5 | \alias{AICc_rss1} 6 | \alias{gw_BIC} 7 | \alias{e_vec} 8 | \alias{fitted} 9 | \alias{gw_cv_all} 10 | \alias{gw_cv_all_cuda} 11 | \title{Bandwidth selection for basic GWR} 12 | \description{ 13 | A function for automatic bandwidth selection to calibrate a basic GWR model 14 | } 15 | \usage{ 16 | bw.gwr(formula, data, approach="CV", kernel="bisquare", 17 | adaptive=FALSE, p=2, theta=0, longlat=F, dMat, 18 | parallel.method=F,parallel.arg=NULL) 19 | } 20 | \arguments{ 21 | \item{formula}{Regression model formula of a \link{formula} object } 22 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 23 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 24 | \item{kernel}{function chosen as follows: 25 | 26 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 27 | 28 | exponential: wgt = exp(-vdist/bw); 29 | 30 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 31 | 32 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 33 | 34 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 35 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 36 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 37 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 38 | \item{longlat}{if TRUE, great circle distances will be calculated} 39 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 40 | \item{parallel.method}{ FALSE as default, and the calibration will be conducted traditionally via the serial technique, 41 | "omp": multi-thread technique with the OpenMP API, 42 | "cluster": multi-process technique with the \pkg{parallel} package, 43 | "cuda": parallel computing technique with CUDA} 44 | \item{parallel.arg}{ if parallel.method is not FALSE, then set the argument by following: 45 | if parallel.method is "omp", parallel.arg refers to the number of threads used, and its default value is 46 | the number of cores - 1; 47 | if parallel.method is "cluster", parallel.arg refers to the number of R sessions used, and its default value is 48 | the number of cores - 1; 49 | if parallel.method is "cuda", parallel.arg refers to the number of calibrations included in each group, 50 | but note a too large value may cause the overflow of GPU memory. } 51 | } 52 | \note{ 53 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 54 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 55 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 56 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 57 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 58 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 59 | This note is applicable to all GW models 60 | } 61 | 62 | \value{ 63 | Returns the adaptive or fixed distance bandwidth 64 | } 65 | 66 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 67 | 68 | \keyword{GWR} 69 | \concept{bandwidth selection} 70 | 71 | -------------------------------------------------------------------------------- /man/bw.gwr.lcr.rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwr.lcr} 2 | \alias{bw.gwr.lcr} 3 | \title{Bandwidth selection for locally compensated ridge GWR (GWR-LCR)} 4 | \description{ 5 | A function for automatic bandwidth selection for \link{gwr.lcr} via a cross-validation approach only 6 | } 7 | \usage{ 8 | bw.gwr.lcr(formula, data, kernel="bisquare", 9 | lambda=0,lambda.adjust=FALSE,cn.thresh=NA, 10 | adaptive=FALSE, p=2, theta=0, longlat=F,dMat) 11 | } 12 | \arguments{ 13 | \item{formula}{Regression model formula of a \link{formula} object } 14 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 15 | \item{kernel}{function chosen as follows: 16 | 17 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 18 | 19 | exponential: wgt = exp(-vdist/bw); 20 | 21 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 22 | 23 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 24 | 25 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 26 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 27 | \item{lambda}{option for a globally-defined (constant) ridge parameter. Default is lambda=0, which gives a basic GWR fit} 28 | \item{lambda.adjust}{a locally-varying ridge parameter. Default FALSE, refers to: (i) a basic GWR without 29 | a local ridge adjustment (i.e. lambda=0, everywhere); or (ii) a penalised GWR with a global ridge adjustment 30 | (i.e. lambda is user-specified as some constant, other than 0 everywhere); if TRUE, use cn.tresh 31 | to set the maximum condition number. For locations with a condition number (for its local design matrix), 32 | above this user-specified threshold, a local ridge parameter is found} 33 | \item{cn.thresh}{maximum value for condition number, commonly set between 20 and 30} 34 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 35 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 36 | \item{longlat}{if TRUE, great circle distances will be calculated} 37 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 38 | } 39 | \value{ 40 | Returns the adaptive or fixed distance bandwidth 41 | } 42 | \note{ 43 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 44 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 45 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 46 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 47 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 48 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 49 | This note is applicable to all GW models 50 | } 51 | \references{ 52 | Gollini I, Lu B, Charlton M, Brunsdon C, Harris P (2015) GWmodel: an R Package for 53 | exploring Spatial Heterogeneity using Geographically Weighted Models. Journal of 54 | Statistical Software 63(17): 1-50 55 | } 56 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 57 | \keyword{GWR-LCR} 58 | \concept{bandwidth selection} 59 | 60 | -------------------------------------------------------------------------------- /man/bw.gwss.average.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwss.average} 2 | \alias{bw.gwss.average} 3 | \alias{gw.mean.cv} 4 | \alias{gw.median.cv} 5 | \alias{gw.average.cv} 6 | \alias{gw.average.cv.contrib} 7 | \title{Bandwidth selection for GW summary averages} 8 | \description{ 9 | A function for automatic bandwidth selections to calculate GW summary averages, including means and medians, via a cross-validation approach. 10 | } 11 | \usage{ 12 | bw.gwss.average(data, summary.locat, vars, kernel = "bisquare", adaptive = FALSE, 13 | p = 2, theta = 0, longlat = F, dMat) 14 | } 15 | \arguments{ 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{summary.locat}{a Spatial*DataFrame object for providing summary locations, 18 | i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame 19 | as defined in package \pkg{sp}} 20 | \item{vars}{a vector of variable names to be summarized} 21 | \item{kernel}{function chosen as follows: 22 | 23 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 24 | 25 | exponential: wgt = exp(-vdist/bw); 26 | 27 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 28 | 29 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 30 | 31 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 32 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 37 | } 38 | \value{ 39 | Returns the adaptive or fixed distance bandwidths (in a two-column matrix) for calculating the averages of each variable. 40 | } 41 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 42 | 43 | \keyword{GWSS} 44 | \concept{bandwidth selection} 45 | 46 | -------------------------------------------------------------------------------- /man/ggwr.basic.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.basic} 2 | \alias{ggwr.basic} 3 | \alias{gwr.generalised} 4 | \alias{gwr.binomial} 5 | \alias{gwr.binomial.wt} 6 | \alias{gwr.poisson} 7 | \alias{gwr.poisson.wt} 8 | \alias{gwr.fitted} 9 | \alias{print.ggwrm} 10 | \title{Generalised GWR models with Poisson and Binomial options} 11 | \description{ 12 | This function implements generalised GWR 13 | } 14 | \usage{ 15 | ggwr.basic(formula, data, regression.points, bw, family = 16 | "poisson", kernel = "bisquare", adaptive = FALSE, cv = 17 | T, tol = 1e-05, maxiter = 20, p = 2, theta = 0, 18 | longlat = F, dMat, dMat1) 19 | 20 | \method{print}{ggwrm}(x, \dots) 21 | } 22 | 23 | \arguments{ 24 | \item{formula}{Regression model formula of a \link{formula} object } 25 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 26 | \item{regression.points}{a Spatial*DataFrame object, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 27 | \item{bw}{bandwidth used in the weighting function, possibly calculated by bw.ggwr();fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 28 | \item{family}{a description of the error distribution and link function to 29 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 30 | \item{kernel}{function chosen as follows: 31 | 32 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 33 | 34 | exponential: wgt = exp(-vdist/bw); 35 | 36 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 37 | 38 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 39 | 40 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 41 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 42 | \item{cv}{if TRUE, cross-validation data will be calculated} 43 | \item{tol}{the threshold that determines the convergence of the IRLS procedure} 44 | \item{maxiter}{the maximum number of times to try the IRLS procedure} 45 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 46 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 47 | \item{longlat}{if TRUE, great circle distances will be calculated} 48 | \item{dMat}{a pre-specified distance matrix between regression points and observations, it can be calculated by the function \code{\link{gw.dist}}} 49 | \item{dMat1}{a square distance matrix between each pair of observations, it can be calculated by the function \code{\link{gw.dist}}} 50 | \item{x}{an object of class \dQuote{ggwrm}, returned by the function \link{gwr.generalised}} 51 | \item{...}{arguments passed through (unused)} 52 | } 53 | \value{ 54 | A list of class \dQuote{ggwrm}: 55 | \item{GW.arguments}{a \link{list} class object including the model fitting parameters for generating the report file} 56 | \item{GW.diagnostic}{a \link{list} class object including the diagnostic information of the model fitting} 57 | \item{glm.res}{an object of class inheriting from \dQuote{glm} which inherits from the class \dQuote{lm}, see \link{glm}. } 58 | \item{SDF}{a SpatialPointsDataFrame (may be gridded), or 59 | SpatialPolygonsDataFrame object (see package \dQuote{sp}), or sf object (see package \dQuote{sf}) integrated with 60 | regression.points, GWR coefficient estimates, y value,predicted values, coefficient standard errors and t-values in its "data" slot.} 61 | \item{CV}{a data vector consisting of the cross-validation data} 62 | } 63 | \note{ 64 | Note that this function calibrates a Generalised GWR model via an approximating 65 | algorithm, which is different from the back-fitting algorithm used in the GWR4 software 66 | by Tomoki Nakaya. 67 | } 68 | \references{ 69 | Nakaya, T., A. S. Fotheringham, C. Brunsdon & M. Charlton (2005) Geographically 70 | weighted Poisson regression for disease association mapping. Statistics in Medicine, 71 | 24, 2695-2717. 72 | 73 | Nakaya, T., M. Charlton, S. Fotheringham & C. Brunsdon. 2009. How to use SGWRWIN (GWR4.0). 74 | Maynooth, Ireland: National Centre for Geocomputation. 75 | 76 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 77 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 78 | } 79 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 80 | \examples{ 81 | data(LondonHP) 82 | \dontrun{ 83 | DM<-gw.dist(dp.locat=coordinates(londonhp)) 84 | bw.f1 <- bw.ggwr(BATH2~FLOORSZ,data=londonhp, dMat=DM) 85 | res.poisson<-ggwr.basic(BATH2~FLOORSZ, bw=bw.f1,data=londonhp, dMat=DM) 86 | bw.f2 <- bw.ggwr(BATH2~FLOORSZ,data=londonhp, dMat=DM,family ="binomial") 87 | res.binomial<-ggwr.basic(BATH2~FLOORSZ, bw=bw.f2,data=londonhp, dMat=DM, 88 | family ="binomial") 89 | } 90 | } 91 | \keyword{generalised GWR} 92 | -------------------------------------------------------------------------------- /man/ggwr.cv.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv} 2 | \alias{ggwr.cv} 3 | \title{Cross-validation score for a specified bandwidth for generalised GWR} 4 | \description{ 5 | This function finds the cross-validation score for a specified bandwidth for generalised GWR. 6 | It can be used to construct the bandwidth function across all possible bandwidths and compared to that found automatically. 7 | } 8 | \usage{ 9 | ggwr.cv(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, dp.locat, 10 | p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV.score}{cross-validation score} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{Cross-validation score} 43 | 44 | -------------------------------------------------------------------------------- /man/ggwr.cv.contrib.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv.contrib} 2 | \alias{ggwr.cv.contrib} 3 | \title{Cross-validation data at each observation location for a generalised GWR model} 4 | \description{ 5 | This function finds the individual cross-validation score at each observation location, for a generalised GWR model, for a specified bandwidth. 6 | These data can be mapped to detect unusually high or low cross-validations scores. 7 | } 8 | \usage{ 9 | ggwr.cv.contrib(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, 10 | dp.locat, p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV}{a data vector consisting of squared residuals, whose sum is the cross-validation score for the specified bandwidth} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{point-wise cross-validation score} -------------------------------------------------------------------------------- /man/gtwr.Rd: -------------------------------------------------------------------------------- 1 | \name{gtwr} 2 | \alias{gtwr} 3 | \alias{print.gtwrm} 4 | \alias{ti.distv} 5 | \alias{ti.distm} 6 | \alias{ti.dist} 7 | \title{Geographically and Temporally Weighted Regression} 8 | \description{ 9 | A function for calibrating a Geographically and Temporally Weighted Regression 10 | (GTWR) model. 11 | } 12 | \usage{ 13 | gtwr(formula, data, regression.points, obs.tv, reg.tv, st.bw, kernel="bisquare", 14 | adaptive=FALSE, p=2, theta=0, longlat=F,lamda=0.05,t.units = "auto",ksi=0, 15 | st.dMat) 16 | } 17 | \arguments{ 18 | \item{formula}{Regression model formula of a \link{formula} object } 19 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}, or a sf object defined in package \pkg{sf}} 20 | \item{regression.points}{a Spatial*DataFrame object, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}; Note that no diagnostic information will returned if it is assigned} 21 | \item{obs.tv}{a vector of time tags for each observation, which could be numeric or of \link{POSIXlt} class} 22 | \item{reg.tv}{a vector of time tags for each regression location, which could be numeric or of \link{POSIXlt} class} 23 | \item{st.bw}{spatio-temporal bandwidth used in the weighting function, possibly calculated by \link{bw.gwr};fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 24 | \item{kernel}{function chosen as follows: 25 | 26 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 27 | 28 | exponential: wgt = exp(-vdist/bw); 29 | 30 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 31 | 32 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 33 | 34 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 35 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) 36 | corresponds to the number of nearest neighbours (i.e. adaptive distance); default 37 | is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 38 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 39 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 40 | \item{longlat}{if TRUE, great circle distances will be calculated} 41 | \item{lamda}{an parameter between 0 and 1 for calculating spatio-temporal distance} 42 | \item{t.units}{ character string to define time unit} 43 | \item{ksi}{an parameter between 0 and PI for calculating spatio-temporal distance, 44 | see details in Wu et al. (2014)} 45 | \item{st.dMat}{a pre-specified spatio-temporal distance matrix, and can be calculated via the function \link{st.dist}} 46 | } 47 | \note{ 48 | The function implements GTWR model proposed by Huang et al. (2010) and 49 | Wu et al. (2014). 50 | } 51 | 52 | \value{ 53 | A list of class \dQuote{gtwrm}: 54 | \item{GTW.arguments}{a list class object including the model fitting parameters for generating the report file} 55 | \item{GTW.diagnostic}{a list class object including the diagnostic information of the model fitting} 56 | \item{lm}{an object of class inheriting from \dQuote{lm}, see \link{lm}. } 57 | \item{SDF}{a SpatialPointsDataFrame (may be gridded), or 58 | SpatialPolygonsDataFrame object (see package \dQuote{sp}), or sf object (see package \dQuote{sf}) integrated with regression.points, 59 | GTWR coefficient estimates, y value,predicted values, coefficient standard errors 60 | and t-values in its "data" slot.} 61 | \item{timings}{starting and ending time.} 62 | \item{this.call}{the function call used.} 63 | } 64 | \references{ 65 | Huang, B., Wu, B., & Barry, M. (2010). Geographically and temporally weighted 66 | regression for modeling spatio-temporal variation in house prices. International 67 | Journal of Geographical Information Science, 24, 383-401. 68 | 69 | Wu, B., Li, R., & Huang, B. (2014). A geographically and temporally weighted 70 | autoregressive model with application to housing prices. International Journal 71 | of Geographical Information Science, 28, 1186-1204. 72 | 73 | Fotheringham, A. S., Crespo, R., & Yao, J. (2015). Geographical and Temporal 74 | Weighted Regression (GTWR). Geographical Analysis, 47, 431-452. 75 | 76 | } 77 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 78 | 79 | \keyword{GTWR} 80 | 81 | -------------------------------------------------------------------------------- /man/gw.dist.Rd: -------------------------------------------------------------------------------- 1 | \name{gw.dist} 2 | \alias{gw.dist} 3 | \alias{gw_dist} 4 | \title{Distance matrix calculation} 5 | \description{ 6 | Calculate a distance vector(matrix) between any GW model calibration point(s) and the data points. 7 | } 8 | \usage{ 9 | gw.dist(dp.locat, rp.locat, focus=0, p=2, theta=0, longlat=F) 10 | } 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{dp.locat}{a numeric matrix of two columns giving the coordinates of the data points} 14 | \item{rp.locat}{a numeric matrix of two columns giving the coordinates of the GW model calibration points} 15 | \item{focus}{an integer, indexing to the current GW model point, if focus=0, all the distances between all the GW model calibration points and data points will be calculated and a distance matrix will be returned; if 00.975 then the true local summary statistics can be said to 41 | be significantly different (at the 0.95 level) to such a local summary statistics found by chance.} 42 | } 43 | \note{ 44 | The function \dQuote{montecarlo.gwss} (in the early versions of GWmodel) has been renamed as 45 | \dQuote{gwss.montecarlo}, while the old name is still kept valid. 46 | } 47 | \references{ 48 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 49 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 50 | 51 | Brunsdon C, Fotheringham AS, Charlton ME (2002) Geographically weighted summary statistics - a framework for localised exploratory data analysis. Computers, Environment and Urban Systems 26:501-524 52 | 53 | Harris P, Brunsdon C (2010) Exploring spatial variation and spatial relationships in a freshwater acidification critical load data set for Great Britain using geographically weighted summary statistics. Computers & Geosciences 36:54-70 54 | } 55 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 56 | \examples{ 57 | \dontrun{ 58 | data(LondonHP) 59 | DM<-gw.dist(dp.locat=coordinates(londonhp)) 60 | test.lss<-gwss.montecarlo(data=londonhp, vars=c("PURCHASE","FLOORSZ"), bw=5000, 61 | kernel ="gaussian", dMat=DM,nsim=99) 62 | test.lss 63 | } 64 | } 65 | \keyword{GWSS} 66 | \concept{Monte Carlo} 67 | 68 | -------------------------------------------------------------------------------- /man/gwss.rd: -------------------------------------------------------------------------------- 1 | \name{gwss} 2 | \alias{gwss} 3 | \alias{local.corr} 4 | \alias{print.gwss} 5 | \title{Geographically weighted summary statistics (GWSS)} 6 | \description{ 7 | This function calculates basic and robust GWSS. This includes geographically weighted means, standard deviations and skew. Robust alternatives include geographically weighted medians, inter-quartile ranges and quantile imbalances. This function also calculates basic geographically weighted covariances together with basic and robust 8 | geographically weighted correlations. 9 | } 10 | \usage{ 11 | gwss(data, summary.locat,vars,kernel="bisquare",adaptive=FALSE, bw,p=2, 12 | theta=0, longlat=F,dMat,quantile=FALSE) 13 | \method{print}{gwss}(x, \dots) 14 | } 15 | \arguments{ 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{summary.locat}{a Spatial*DataFrame object for providing summary locations, 18 | i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame 19 | as defined in package \pkg{sp}} 20 | \item{vars}{a vector of variable names to be summarized} 21 | \item{bw}{bandwidth used in the weighting function} 22 | \item{kernel}{function chosen as follows: 23 | 24 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 25 | 26 | exponential: wgt = exp(-vdist/bw); 27 | 28 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 29 | 30 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 31 | 32 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 33 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 34 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 35 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 36 | \item{longlat}{if TRUE, great circle distances will be calculated} 37 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 38 | \item{quantile}{if TRUE, median, interquartile range, quantile imbalance will be calculated} 39 | \item{x}{an object of class \dQuote{gwss}, returned by the function \link{gwss}} 40 | \item{...}{arguments passed through (unused)} 41 | } 42 | \value{ 43 | A list of class \dQuote{lss}: 44 | \item{SDF}{a SpatialPointsDataFrame (may be gridded) or 45 | SpatialPolygonsDataFrame object (see package \dQuote{sp}) 46 | with local means,local standard deviations,local variance, 47 | local skew,local coefficients of variation, local covariances, 48 | local correlations (Pearson's), local correlations (Spearman's), 49 | local medians, local interquartile ranges, local quantile imbalances and coordinates. 50 | } 51 | \item{...}{other information for reporting} 52 | } 53 | \references{ 54 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 55 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 56 | 57 | Brunsdon C, Fotheringham AS, Charlton ME (2002) Geographically weighted summary statistics - a framework for localised exploratory data analysis. Computers, Environment and Urban Systems 26:501-524 58 | 59 | Harris P, Clarke A, Juggins S, Brunsdon C, Charlton M (2014) Geographically 60 | weighted methods and their use in network re-designs for environmental monitoring. 61 | Stochastic Environmental Research and Risk Assessment 28: 1869-1887 62 | } 63 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 64 | \examples{ 65 | \dontrun{ 66 | data(EWHP) 67 | data(EWOutline) 68 | head(ewhp) 69 | houses.spdf <- SpatialPointsDataFrame(ewhp[, 1:2], ewhp) 70 | localstats1 <- gwss(houses.spdf, vars = c("PurPrice", "FlrArea"), bw = 50000) 71 | head(data.frame(localstats1$SDF)) 72 | localstats1 73 | ##A function for mapping data 74 | if(require("RColorBrewer")) 75 | { 76 | quick.map <- function(spdf,var,legend.title,main.title) 77 | { 78 | x <- spdf@data[,var] 79 | cut.vals <- pretty(x) 80 | x.cut <- cut(x,cut.vals) 81 | cut.levels <- levels(x.cut) 82 | cut.band <- match(x.cut,cut.levels) 83 | colors <- brewer.pal(length(cut.levels), "YlOrRd") 84 | colors <- rev(colors) 85 | par(mar=c(1,1,1,1)) 86 | plot(ewoutline,col="olivedrab",bg="lightblue1") 87 | title(main.title) 88 | plot(spdf,add=TRUE,col=colors[cut.band],pch=16) 89 | legend("topleft",cut.levels,col=colors,pch=16,bty="n",title=legend.title) 90 | } 91 | quick.map(localstats1$SDF, "PurPrice_LM", "1000's Uk Pounds", 92 | "Geographically Weighted Mean") 93 | par(mfrow = c(1, 2)) 94 | quick.map(localstats1$SDF, "PurPrice_LSKe", "Skewness Level", "Local Skewness") 95 | quick.map(localstats1$SDF, "PurPrice_LSD", "1000's Pounds", "Local Standard Deviation") 96 | #Exploring Non-Stationarity of Relationships 97 | quick.map(localstats1$SDF, "Corr_PurPrice.FlrArea", expression(rho), 98 | "Geographically Weighted Pearson Correlation") 99 | #Robust, Quantile Based Local Summary Statistics 100 | localstats2 <- gwss(houses.spdf, vars = c("PurPrice", "FlrArea"), 101 | bw = 50000, quantile = TRUE) 102 | quick.map(localstats2$SDF, "PurPrice_Median", "1000 UK Pounds", 103 | "Geographically Weighted Median House Price") 104 | } 105 | } 106 | } 107 | \keyword{GWSS} 108 | 109 | -------------------------------------------------------------------------------- /man/st.dist.Rd: -------------------------------------------------------------------------------- 1 | \name{st.dist} 2 | \alias{st.dist} 3 | \title{Spatio-temporal distance matrix calculation} 4 | \description{ 5 | Calculate a distance vector(matrix) between any GW model calibration point(s) and the data points. 6 | } 7 | \usage{ 8 | st.dist(dp.locat, rp.locat, obs.tv, reg.tv,focus=0, p=2, 9 | theta=0, longlat=F,lamda=0.05,t.units = "auto", 10 | ksi=0, s.dMat,t.dMat) 11 | } 12 | \arguments{ 13 | \item{dp.locat}{a numeric matrix of two columns giving the coordinates of the data points} 14 | \item{rp.locat}{a numeric matrix of two columns giving the coordinates of the GW model calibration points} 15 | \item{obs.tv}{a vector of time tags for each observation, which could be numeric or of \link{POSIXlt} class} 16 | \item{reg.tv}{a vector of time tags for each regression location, which could be numeric or of \link{POSIXlt} class} 17 | \item{focus}{an integer, indexing to the current GW model point, if focus=0, all the distances between all the GW model calibration points and data points will be calculated and a distance matrix will be returned; if 0 3 | 4 | #include "IGWmodelCUDA.h" 5 | 6 | using namespace arma; 7 | 8 | class CGWmodelCUDA : public IGWmodelCUDA 9 | { 10 | private: 11 | mat x; 12 | vec y; 13 | mat dp; 14 | mat rp; 15 | mat dMat; 16 | bool rp_given; 17 | bool dm_given; 18 | mat betas; 19 | mat betasSE; 20 | vec s_hat; 21 | vec qdiag; 22 | public: 23 | CGWmodelCUDA(); 24 | CGWmodelCUDA(int N, int K, bool rp_given, int n, bool dm_given); 25 | ~CGWmodelCUDA(); 26 | 27 | virtual void SetX(int i, int k, double value); 28 | virtual void SetY(int i, double value); 29 | virtual void SetDp(int i, double u, double v); 30 | virtual void SetRp(int i, double u, double v); 31 | virtual void SetDmat(int i, int j, double value); 32 | 33 | virtual double GetBetas(int i, int k); 34 | virtual double GetBetasSE(int i, int k); 35 | virtual double GetShat1(); 36 | virtual double GetShat2(); 37 | virtual double GetQdiag(int i); 38 | 39 | 40 | virtual bool Regression( 41 | bool hatmatrix, 42 | double p, double theta, bool longlat, 43 | double bw, int kernel, bool adaptive, 44 | int groupl, int gpuID 45 | ); 46 | 47 | virtual double CV( 48 | double p, double theta, bool longlat, 49 | double bw, int kernel, bool adaptive, 50 | int groupl, int gpuID 51 | ); 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(GWmodelCUDA LANGUAGES CXX CUDA) 3 | 4 | if(WIN32 AND NOT MSVC) 5 | message(FATAL_ERROR "CUDA only support MSVC complier on Windows!") 6 | endif(WIN32 AND NOT MSVC) 7 | 8 | find_package(Armadillo REQUIRED) 9 | include_directories(${ARMADILLO_INCLUDE_DIRS}) 10 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 12 | find_package(cuBLAS REQUIRED) 13 | include_directories(${CUBLAS_INCLUDE_DIRS}) 14 | 15 | add_definitions(-DCREATDLL_EXPORTS) 16 | 17 | set(SOURCES_CXX 18 | CGWmodelCUDA.cpp 19 | IGWmodelCUDA.cpp 20 | ) 21 | 22 | set(SOURCES_CUDA 23 | GWmodelKernel.cu 24 | ) 25 | 26 | set(HEADERS 27 | CGWmodelCUDA.h 28 | GWmodelKernel.h 29 | helper.h 30 | IGWmodelCUDA.h 31 | ) 32 | 33 | 34 | add_library(GWmodelCUDA64 SHARED ${SOURCES_CUDA} ${SOURCES_CXX} ${HEADERS}) 35 | set_property(TARGET GWmodelCUDA64 PROPERTY CUDA_ARCHITECTURES 35 37 52 60 61 70 75) 36 | target_link_libraries(GWmodelCUDA64 PRIVATE 37 | ${CUDA_LIBRARIES} 38 | ${CUBLAS_LIBRARIES} 39 | ${ARMADILLO_LIBRARIES} 40 | ) 41 | target_compile_features(GWmodelCUDA64 PUBLIC cxx_std_11) 42 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 43 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 44 | ) 45 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 46 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 47 | ) 48 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 49 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}" 50 | ) -------------------------------------------------------------------------------- /src/GWmodelCUDA/GWmodelKernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | cudaError_t gw_coordinate_rotate_cuda(double* d_coords, int n, double theta, int threads); 5 | cudaError_t gw_dist_cuda(double *d_dp, double *d_rp, int ndp, int nrp, int focus, double p, double theta, bool longlat, bool rp_given, double *d_dists, int threads); 6 | cudaError_t gw_weight_cuda(double bw, int kernel, bool adaptive, double *d_dists, double *d_weight, int ndp, int nrp, int threads); 7 | cudaError_t gw_xtw_cuda(const double* d_x, const double* d_weight, int n, int k, double* d_xtw, int threads); 8 | cudaError_t gw_xdy_cuda(const double* d_x, const double* d_y, int n, double * d_xdoty, int threads); 9 | cudaError_t gw_xdx_cuda(const double* d_x, int n, double * d_xdotx, int threads); 10 | cudaError_t gw_qdiag_cuda(const double* d_si, int n, int p, double* d_q, int threads); 11 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/IGWmodelCUDA.cpp: -------------------------------------------------------------------------------- 1 | #include "IGWmodelCUDA.h" 2 | #include "CGWmodelCUDA.h" 3 | 4 | 5 | IGWmodelCUDA * GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given) 6 | { 7 | return new CGWmodelCUDA(N, K, rp_given, n, dm_given); 8 | } 9 | 10 | void GWCUDA_Del(IGWmodelCUDA * pInstance) 11 | { 12 | delete pInstance; 13 | } 14 | 15 | bool gwr_reg_cuda(IGWmodelCUDA * pInstance, bool hatmatrix, double p, double theta, bool longlat, double bw, int kernel, bool adaptive, int groupl, int gpuID) 16 | { 17 | return pInstance->Regression(hatmatrix, p, theta, longlat, bw, kernel, adaptive, groupl, gpuID); 18 | } 19 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/IGWmodelCUDA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #ifdef CREATDLL_EXPORTS 5 | #define GWMODELCUDA_API __declspec(dllexport) 6 | #else 7 | #define GWMODELCUDA_API __declspec(dllimport) 8 | #endif // CREATDLL_EXPORTS 9 | #else 10 | #define GWMODELCUDA_API 11 | #endif 12 | 13 | class GWMODELCUDA_API IGWmodelCUDA 14 | { 15 | public: 16 | virtual void SetX(int i, int k, double value) = 0; 17 | virtual void SetY(int i, double value) = 0; 18 | virtual void SetDp(int i, double u, double v) = 0; 19 | virtual void SetRp(int i, double u, double v) = 0; 20 | virtual void SetDmat(int i, int j, double value) = 0; 21 | 22 | virtual double GetBetas(int i, int k) = 0; 23 | virtual double GetBetasSE(int i, int k) = 0; 24 | virtual double GetShat1() = 0; 25 | virtual double GetShat2() = 0; 26 | virtual double GetQdiag(int i) = 0; 27 | 28 | 29 | virtual bool Regression( 30 | bool hatmatrix, 31 | double p, double theta, bool longlat, 32 | double bw, int kernel, bool adaptive, 33 | int groupl, int gpuID 34 | ) = 0; 35 | 36 | virtual double CV( 37 | double p, double theta, bool longlat, 38 | double bw, int kernel, bool adaptive, 39 | int groupl, int gpuID 40 | ) = 0; 41 | }; 42 | 43 | extern "C" GWMODELCUDA_API IGWmodelCUDA* GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given); 44 | extern "C" GWMODELCUDA_API void GWCUDA_Del(IGWmodelCUDA* pInstance); 45 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/cmake/FindcuBLAS.cmake: -------------------------------------------------------------------------------- 1 | # ================================================================================================== 2 | # This file is part of the cuBLASt project. The project is licensed under Apache Version 2.0. This 3 | # project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- 4 | # width of 100 characters per line. 5 | # 6 | # Author(s): 7 | # Cedric Nugteren 8 | # 9 | # ================================================================================================== 10 | # 11 | # Defines the following variables: 12 | # CUBLAS_FOUND Boolean holding whether or not the cuBLAS library was found 13 | # CUBLAS_INCLUDE_DIRS The CUDA and cuBLAS include directory 14 | # CUDA_LIBRARIES The CUDA library 15 | # CUBLAS_LIBRARIES The cuBLAS library 16 | # 17 | # In case CUDA is not installed in the default directory, set the CUDA_ROOT variable to point to 18 | # the root of cuBLAS, such that 'cublas_v2.h' can be found in $CUDA_ROOT/include. This can either be 19 | # done using an environmental variable (e.g. export CUDA_ROOT=/path/to/cuBLAS) or using a CMake 20 | # variable (e.g. cmake -DCUDA_ROOT=/path/to/cuBLAS ..). 21 | # 22 | # ================================================================================================== 23 | 24 | # Sets the possible install locations 25 | set(CUBLAS_HINTS 26 | ${CUDA_PATH} 27 | $ENV{CUDA_PATH} 28 | $ENV{CUDA_TOOLKIT_ROOT_DIR} 29 | ) 30 | set(CUBLAS_PATHS 31 | /usr 32 | /usr/local 33 | /usr/local/cuda 34 | ) 35 | 36 | # Finds the include directories 37 | find_path(CUBLAS_INCLUDE_DIRS 38 | NAMES cublas_v2.h cuda.h 39 | HINTS ${CUBLAS_HINTS} 40 | PATH_SUFFIXES include inc include/x86_64 include/x64 41 | PATHS ${CUBLAS_PATHS} 42 | DOC "cuBLAS include header cublas_v2.h" 43 | ) 44 | mark_as_advanced(CUBLAS_INCLUDE_DIRS) 45 | 46 | # Finds the libraries 47 | find_library(CUDA_LIBRARIES 48 | NAMES cudart 49 | HINTS ${CUBLAS_HINTS} 50 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 51 | PATHS ${CUBLAS_PATHS} 52 | DOC "CUDA library" 53 | ) 54 | mark_as_advanced(CUDA_LIBRARIES) 55 | find_library(CUBLAS_LIBRARIES 56 | NAMES cublas 57 | HINTS ${CUBLAS_HINTS} 58 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 59 | PATHS ${CUBLAS_PATHS} 60 | DOC "cuBLAS library" 61 | ) 62 | mark_as_advanced(CUBLAS_LIBRARIES) 63 | 64 | # ================================================================================================== 65 | 66 | # Notification messages 67 | if(NOT CUBLAS_INCLUDE_DIRS) 68 | message(STATUS "Could NOT find 'cuBLAS.h', install CUDA/cuBLAS or set CUDA_ROOT") 69 | endif() 70 | if(NOT CUDA_LIBRARIES) 71 | message(STATUS "Could NOT find CUDA library, install it or set CUDA_ROOT") 72 | endif() 73 | if(NOT CUBLAS_LIBRARIES) 74 | message(STATUS "Could NOT find cuBLAS library, install it or set CUDA_ROOT") 75 | endif() 76 | 77 | # Determines whether or not cuBLAS was found 78 | include(FindPackageHandleStandardArgs) 79 | find_package_handle_standard_args(cuBLAS DEFAULT_MSG CUBLAS_INCLUDE_DIRS CUDA_LIBRARIES CUBLAS_LIBRARIES) 80 | 81 | # ================================================================================================== -------------------------------------------------------------------------------- /src/GWmodelCUDA/helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | static const char *_cudaGetErrorEnum(cudaError_t error) { 7 | return cudaGetErrorName(error); 8 | } 9 | 10 | static const char *_cudaGetErrorEnum(cublasStatus_t error) { 11 | switch (error) { 12 | case CUBLAS_STATUS_SUCCESS: 13 | return "CUBLAS_STATUS_SUCCESS"; 14 | 15 | case CUBLAS_STATUS_NOT_INITIALIZED: 16 | return "CUBLAS_STATUS_NOT_INITIALIZED"; 17 | 18 | case CUBLAS_STATUS_ALLOC_FAILED: 19 | return "CUBLAS_STATUS_ALLOC_FAILED"; 20 | 21 | case CUBLAS_STATUS_INVALID_VALUE: 22 | return "CUBLAS_STATUS_INVALID_VALUE"; 23 | 24 | case CUBLAS_STATUS_ARCH_MISMATCH: 25 | return "CUBLAS_STATUS_ARCH_MISMATCH"; 26 | 27 | case CUBLAS_STATUS_MAPPING_ERROR: 28 | return "CUBLAS_STATUS_MAPPING_ERROR"; 29 | 30 | case CUBLAS_STATUS_EXECUTION_FAILED: 31 | return "CUBLAS_STATUS_EXECUTION_FAILED"; 32 | 33 | case CUBLAS_STATUS_INTERNAL_ERROR: 34 | return "CUBLAS_STATUS_INTERNAL_ERROR"; 35 | 36 | case CUBLAS_STATUS_NOT_SUPPORTED: 37 | return "CUBLAS_STATUS_NOT_SUPPORTED"; 38 | 39 | case CUBLAS_STATUS_LICENSE_ERROR: 40 | return "CUBLAS_STATUS_LICENSE_ERROR"; 41 | } 42 | 43 | return ""; 44 | } 45 | 46 | #define DEVICE_RESET cudaDeviceReset(); 47 | 48 | template 49 | bool check(T result, char const *const func, const char *const file, 50 | int const line) { 51 | if (result) { 52 | fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, 53 | static_cast(result), _cudaGetErrorEnum(result), func); 54 | DEVICE_RESET 55 | // Make sure we call CUDA Device Reset before exiting 56 | return true; 57 | } 58 | else return false; 59 | } 60 | 61 | #ifndef WIN32 62 | #ifdef _DEBUG 63 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 64 | #else 65 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 66 | #endif // _DEBUG 67 | 68 | #ifdef _DEBUG 69 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 70 | #else 71 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 72 | #endif // _DEBUG 73 | #else 74 | #ifdef _DEBUG 75 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 76 | #else 77 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 78 | #endif // _DEBUG 79 | 80 | #ifdef _DEBUG 81 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 82 | #else 83 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 84 | #endif // _DEBUG 85 | #endif 86 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | CDEFS = @CDEFS@ 2 | R_INC = -I./GWmodelCUDA 3 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) $(CDEFS) $(R_INC) 4 | CUDA_LIBS = @CUDA_LIBS@ 5 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) @PKG_LIBS@ 6 | ENABLE_CUDA = @ENABLE_CUDA@ 7 | GWmodel_CUDA_LIB_PATH=@GWmodel_CUDA_LIB_PATH@ 8 | 9 | cu_sources = @cu_sources@ 10 | cu_sharedlibs =@cu_sharedlibs@ 11 | cpp_sources_cuda = @cpp_sources_cuda@ 12 | cpp_sharedlibs_cuda = @cpp_sharedlibs_cuda@ 13 | OBJECTS_CUDA = @OBJECTS_CUDA@ 14 | 15 | #CDEFS = @CDEFS@ 16 | TARGET_CUDA_LIB =@TARGET_CUDA_LIB@ 17 | 18 | cpp_sources = RcppExports.cpp GWmodel.cpp 19 | cpp_sharedlibs= RcppExports.o GWmodel.o 20 | 21 | c_sources = init.c 22 | c_sharedlibs = init.o 23 | 24 | OBJECTS = ${cpp_sharedlibs} ${c_sharedlibs} 25 | 26 | #R_INC = -I./GWmodelCUDA 27 | CXX_ARGS = @R_CPIC@ $(SHLIB_OPENMP_CXXFLAGS) -DNDEBUG ${CXX11FLAGS} 28 | 29 | CU_ARGS = -std=c++14 -Xcompiler -fPIC -Xcudafe --diag_suppress=boolean_controlling_expr_is_constant -DNDEBUG 30 | CU_INCL = ${R_INCL} 31 | CU_ARCH = \ 32 | -gencode arch=compute_35,code=sm_35 \ 33 | -gencode arch=compute_37,code=sm_37 \ 34 | -gencode arch=compute_52,code=sm_52 \ 35 | -gencode arch=compute_60,code=sm_60 \ 36 | -gencode arch=compute_61,code=sm_61 \ 37 | -gencode arch=compute_70,code=sm_70 \ 38 | -gencode arch=compute_75,code=sm_75 39 | 40 | NVCC=@NVCC@ 41 | CUDA_INCL = @CUDA_INCL@ 42 | 43 | vpath %.cu ./GWmodelCUDA 44 | vpath %.cpp ./GWmodelCUDA 45 | 46 | .PHONY: all clean 47 | 48 | all : ${TARGET_CUDA_LIB} GWmodel.so 49 | 50 | ${TARGET_CUDA_LIB}: ${OBJECTS_CUDA} 51 | ${SHLIB_LINK} -o $@ $^ ${CUDA_LIBS} 52 | mkdir -p ${GWmodel_CUDA_LIB_PATH} 53 | cp $@ ${GWmodel_CUDA_LIB_PATH} 54 | chown -R ${USER}:${USER} ${HOME}/.cache/GWmodel 55 | 56 | 57 | GWmodel.so : ${TARGET_CUDA_LIB} ${OBJECTS_CUDA} ${OBJECTS} 58 | 59 | ${cpp_sharedlibs_cuda}: %.o: %.cpp 60 | $(CXX) $(SHLIB_OPENMP_CXXFLAGS) -DNDEBUG ${CXX11FLAGS} -DCUDA_ARCH=52 $(R_INC) -I${CUDA_INCL} -fPIC $< -c 61 | 62 | ${cu_sharedlibs}: %.o: %.cu 63 | $(NVCC) $(CU_ARCH) $(CU_ARGS) $(CU_INCL) -I${CUDA_INCL} $< -c 64 | 65 | ${cpp_sharedlibs}: %.o :%.cpp 66 | 67 | clean: 68 | rm -rf *.o Makevars 69 | 70 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 2 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) 3 | 4 | ifdef CUDA_PATH 5 | ifeq "$(WIN)" "64" 6 | PKG_CXXFLAGS += -DCUDA_ACCE -I"./GWmodelCUDA" 7 | PKG_LIBS += -L"./GWmodelCUDA" -lGWmodelCUDA64 8 | CUDA_LIB = GWmodelCUDA64.dll GWmodelCUDA64.lib 9 | endif 10 | endif 11 | 12 | 13 | 14 | vpath %.lib ./GWmodelCUDA 15 | 16 | .PHONY: all 17 | 18 | all: GWmodel.dll 19 | 20 | GWmodel.dll: ${CUDA_LIB} 21 | 22 | ${CUDA_LIB}: 23 | sh -c 'powershell.exe -Command -' < download.ps1 24 | unzip -d tmp -o GWmodelCUDA.zip 25 | mv tmp/*.dll . 26 | mv tmp/*.lib GWmodelCUDA 27 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // for NULL 4 | #include 5 | 6 | extern SEXP GWmodel_gw_dist(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 7 | extern SEXP GWmodel_gw_weight(SEXP, SEXP, SEXP, SEXP); 8 | extern SEXP GWmodel_gw_weight_vec(SEXP, SEXP, SEXP, SEXP); 9 | extern SEXP GWmodel_gw_weight_mat(SEXP, SEXP, SEXP, SEXP); 10 | extern SEXP GWmodel_gw_reg(SEXP, SEXP, SEXP, SEXP, SEXP); 11 | extern SEXP GWmodel_gw_reg_1(SEXP, SEXP, SEXP); 12 | extern SEXP GWmodel_trhat2(SEXP); 13 | extern SEXP GWmodel_fitted(SEXP, SEXP); 14 | extern SEXP GWmodel_ehat(SEXP, SEXP, SEXP); 15 | extern SEXP GWmodel_rss(SEXP, SEXP, SEXP); 16 | extern SEXP GWmodel_gwr_diag(SEXP, SEXP, SEXP, SEXP); 17 | extern SEXP GWmodel_gwr_diag1(SEXP, SEXP, SEXP, SEXP); 18 | extern SEXP GWmodel_AICc(SEXP, SEXP, SEXP, SEXP); 19 | extern SEXP GWmodel_AICc1(SEXP, SEXP, SEXP, SEXP); 20 | extern SEXP GWmodel_AICc_rss(SEXP, SEXP, SEXP, SEXP); 21 | extern SEXP GWmodel_AICc_rss1(SEXP, SEXP, SEXP, SEXP); 22 | extern SEXP GWmodel_Ci_mat(SEXP, SEXP); 23 | extern SEXP GWmodel_gw_local_r2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 24 | extern SEXP GWmodel_BIC(SEXP, SEXP, SEXP, SEXP); 25 | extern SEXP GWmodel_gw_reg_2(SEXP, SEXP, SEXP); 26 | extern SEXP GWmodel_gwr_q(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 27 | extern SEXP GWmodel_scgwr_pre(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 28 | extern SEXP GWmodel_scgwr_loocv(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 29 | extern SEXP GWmodel_scgwr_reg(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 30 | extern SEXP GWmodel_gw_reg_all(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 31 | extern SEXP GWmodel_gw_reg_all_omp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 32 | extern SEXP GWmodel_gw_cv_all(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 33 | extern SEXP GWmodel_gw_cv_all_omp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 34 | extern SEXP GWmodel_gw_reg_cuda(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 35 | extern SEXP GWmodel_gw_cv_all_cuda(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 36 | extern SEXP GWmodel_e_vec(SEXP, SEXP); 37 | extern SEXP GWmodel_gwr_mixed_trace(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 38 | extern SEXP GWmodel_gwr_mixed_2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 39 | extern SEXP _GWmodel_new_multiscale(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 40 | 41 | static const R_CallMethodDef CallEntries[] = { 42 | {"GWmodel_gw_dist", (DL_FUNC) &GWmodel_gw_dist, 7}, 43 | {"GWmodel_gw_weight", (DL_FUNC) &GWmodel_gw_weight, 4}, 44 | {"GWmodel_gw_weight_vec", (DL_FUNC) &GWmodel_gw_weight_vec, 4}, 45 | {"GWmodel_gw_weight_mat", (DL_FUNC) &GWmodel_gw_weight_mat, 4}, 46 | {"GWmodel_gw_reg", (DL_FUNC) &GWmodel_gw_reg, 5}, 47 | {"GWmodel_gw_reg_1", (DL_FUNC) &GWmodel_gw_reg_1, 3}, 48 | {"GWmodel_trhat2", (DL_FUNC) &GWmodel_trhat2, 1}, 49 | {"GWmodel_fitted", (DL_FUNC) &GWmodel_fitted, 2}, 50 | {"GWmodel_ehat", (DL_FUNC) &GWmodel_ehat, 3}, 51 | {"GWmodel_rss", (DL_FUNC) &GWmodel_rss, 3}, 52 | {"GWmodel_gwr_diag", (DL_FUNC) &GWmodel_gwr_diag, 4}, 53 | {"GWmodel_gwr_diag1", (DL_FUNC) &GWmodel_gwr_diag1, 4}, 54 | {"GWmodel_AICc", (DL_FUNC) &GWmodel_AICc, 4}, 55 | {"GWmodel_AICc1", (DL_FUNC) &GWmodel_AICc1, 4}, 56 | {"GWmodel_AICc_rss", (DL_FUNC) &GWmodel_AICc_rss, 4}, 57 | {"GWmodel_AICc_rss1", (DL_FUNC) &GWmodel_AICc_rss1, 4}, 58 | {"GWmodel_Ci_mat", (DL_FUNC) &GWmodel_Ci_mat, 2}, 59 | {"GWmodel_gw_local_r2", (DL_FUNC) &GWmodel_gw_local_r2, 11}, 60 | {"GWmodel_BIC", (DL_FUNC) &GWmodel_BIC, 4}, 61 | {"GWmodel_gw_reg_2", (DL_FUNC) &GWmodel_gw_reg_2, 3}, 62 | {"GWmodel_gwr_q", (DL_FUNC) &GWmodel_gwr_q, 6}, 63 | {"GWmodel_scgwr_pre", (DL_FUNC) &GWmodel_scgwr_pre, 7}, 64 | {"GWmodel_scgwr_loocv", (DL_FUNC) &GWmodel_scgwr_loocv, 9}, 65 | {"GWmodel_scgwr_reg", (DL_FUNC) &GWmodel_scgwr_reg, 11}, 66 | {"GWmodel_gw_reg_all", (DL_FUNC) &GWmodel_gw_reg_all, 16}, 67 | {"GWmodel_gw_reg_all_omp", (DL_FUNC) &GWmodel_gw_reg_all_omp, 17}, 68 | {"GWmodel_gw_cv_all", (DL_FUNC) &GWmodel_gw_cv_all, 13}, 69 | {"GWmodel_gw_cv_all_omp", (DL_FUNC) &GWmodel_gw_cv_all_omp, 14}, 70 | {"GWmodel_gw_reg_cuda", (DL_FUNC) &GWmodel_gw_reg_cuda, 16}, 71 | {"GWmodel_gw_cv_all_cuda", (DL_FUNC) &GWmodel_gw_cv_all_cuda, 13}, 72 | {"GWmodel_e_vec", (DL_FUNC) &GWmodel_e_vec, 2}, 73 | {"GWmodel_gwr_mixed_trace", (DL_FUNC) &GWmodel_gwr_mixed_trace, 7}, 74 | {"GWmodel_gwr_mixed_2", (DL_FUNC) &GWmodel_gwr_mixed_2, 8}, 75 | {"_GWmodel_new_multiscale", (DL_FUNC) &_GWmodel_new_multiscale, 19}, 76 | {NULL, NULL, 0} 77 | }; 78 | 79 | void R_init_GWmodel(DllInfo *dll) 80 | { 81 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 82 | R_useDynamicSymbols(dll, FALSE); 83 | } 84 | --------------------------------------------------------------------------------