diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 1da0495..039bd60 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,7 +5,7 @@ articles: pdrm: pdrm.html sesp: sesp.html whysed: whysed.html -last_built: 2024-11-25T09:08Z +last_built: 2024-11-25T09:19Z urls: reference: https://stscl.github.io/sesp/reference article: https://stscl.github.io/sesp/articles diff --git a/docs/reference/sesp.html b/docs/reference/sesp.html index 5e40266..341a4f2 100644 --- a/docs/reference/sesp.html +++ b/docs/reference/sesp.html @@ -180,10 +180,10 @@

Examples#> Q values are estimated using *Ordinary Least Square* #> #> -------------- Global Power of Determinant : ------------ -#> Variable Qvalue AIC BIC LogLik -#> watershed 0.638 -10.039 -10.039 15.020 -#> elevation 0.607 1.183 1.183 7.409 -#> soiltype 0.386 79.675 79.675 -33.838 +#> Variable Qvalue AIC BIC LogLik +#> watershed 0.638 -10.039 22.164 15.020 +#> elevation 0.607 1.183 26.946 7.409 +#> soiltype 0.386 79.675 98.997 -33.838 #> #> ------------- Global Variable Interaction : ------------ #> Variable Interaction diff --git a/docs/search.json b/docs/search.json index d4a1197..7e55886 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -[{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"q-values","dir":"Articles","previous_headings":"","what":"1. Q Values","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"\\[ q = 1 - \\frac{\\sum\\limits_{h = 1}^{L}N_h\\sigma_h^2}{N\\sigma^2} = 1 - \\frac{\\sum\\limits_{h = 1}^{L}\\sum\\limits_{= 1}^{N_h}\\left({y_{hi} - \\overline{y}_h}^2\\right)}{\\sum\\limits_{= 1}^{N} \\left({y_i - \\overline{y}}^2\\right)} \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"linear-regression-model-with-dummy-variables","dir":"Articles","previous_headings":"","what":"2. Linear Regression Model with Dummy Variables","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"Consider linear regression model response variable \\(y\\) depends \\(k\\) dummy variables \\(D_1, D_2, \\dots, D_k\\). dummy variable \\(D_j\\) indicates membership particular category group, taking value 1 observation belongs category \\(j\\) 0 otherwise. model expressed : \\[ y_i = \\beta_0 + \\beta_1 D_{i1} + \\beta_2 D_{i2} + \\cdots + \\beta_k D_{ik} + \\epsilon_i \\] : \\(y_i\\) response variable \\(\\)-th observation, \\(\\beta_0\\) intercept term, \\(\\beta_j\\) coefficient associated dummy variable \\(D_j\\), \\(D_{ij}\\) value dummy variable \\(D_j\\) \\(\\)-th observation, 1 \\(\\)-th observation belongs category \\(j\\) 0 otherwise, \\(\\epsilon_i\\) error term.","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"behavior-of-dummy-variables","dir":"Articles","previous_headings":"","what":"3. Behavior of Dummy Variables","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"observation belongs exactly one categories represented dummy variables. \\(\\)-th observation belongs category \\(j\\), \\(D_{ij} = 1\\) dummy variables 0 observation. Thus, regression equation observation \\(\\) belonging category \\(j\\) simplifies : \\[ y_i = \\beta_0 + \\beta_j + \\epsilon_i \\] equation holds observations \\(\\) belong category \\(j\\).","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"predicted-value-for-a-category","dir":"Articles","previous_headings":"","what":"4. Predicted Value for a Category","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"predicted value \\(\\widehat{y}_j\\) observation category \\(j\\) expected value \\(y_i\\), given \\(D_{ij} = 1\\) dummy variables 0. Since error term \\(\\epsilon_i\\) expected value 0, predicted value category \\(j\\) : \\[ \\widehat{y}_j = \\mathbb{E}(y_i | D_{ij} = 1) = \\beta_0 + \\beta_j \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"ordinary-least-squares-ols-estimation","dir":"Articles","previous_headings":"","what":"5. Ordinary Least Squares (OLS) Estimation","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"linear regression, coefficients \\(\\beta_0, \\beta_1, \\dots, \\beta_k\\) estimated using Ordinary Least Squares (OLS) method, minimizes sum squared residuals: \\[ \\text{Minimize } \\sum_{=1}^n (y_i - \\widehat{y}_i)^2 \\] OLS solution leads estimate \\(\\beta_j\\) dummy variable predicted value \\(\\widehat{y}_j = \\beta_0 + \\beta_j\\) represents mean value \\(y_i\\) observations category \\(j\\). Specifically, OLS ensures : \\[ \\widehat{y}_j = \\frac{1}{N_j} \\sum_{: D_{ij} = 1} y_i = \\bar{y}_j \\] \\(N_j\\) number observations category \\(j\\), \\(\\bar{y}_j\\) mean response category \\(j\\).","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"conclusion","dir":"Articles","previous_headings":"","what":"6. Conclusion","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"\\[ q = 1 - \\frac{\\sum\\limits_{h = 1}^{L}N_h\\sigma_h^2}{N\\sigma^2} = 1 - \\frac{\\sum\\limits_{h = 1}^{L}\\sum\\limits_{= 1}^{N_h}\\left({y_{hi} - \\overline{y}_h}^2\\right)}{\\sum\\limits_{= 1}^{N} \\left({y_i - \\overline{y}}^2\\right)} = \\frac{\\sum\\limits_{= 1}^{N}\\left({y_i - \\widehat{y}_i}^2\\right)}{\\sum\\limits_{= 1}^{N}\\left({y_i - \\overline{y}}^2\\right)} = R^2 \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"real-world-example","dir":"Articles","previous_headings":"","what":"7. Real-world example","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"library(sf) ## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE library(sesp) library(gdverse) NTDs = sf::st_as_sf(gdverse::NTDs, coords = c('X','Y')) system.time({ go1 = sesp(incidence ~ ., data = NTDs, discvar = 'none', model = 'ols', overlay = 'intersection') }) ## user system elapsed ## 0.22 0.03 0.65 system.time({ go2 = gd(incidence ~ ., data = NTDs, type = c('factor','interaction')) }) ## user system elapsed ## 0.04 0.00 0.08"},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"factor-detector","dir":"Articles","previous_headings":"7. Real-world example","what":"Factor detector","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"go1$factor ## # A tibble: 3 × 5 ## Variable Qvalue AIC BIC LogLik ## ## 1 watershed 0.638 -10.0 -10.0 15.0 ## 2 elevation 0.607 1.18 1.18 7.41 ## 3 soiltype 0.386 79.7 79.7 -33.8 go2$factor ## # A tibble: 3 × 3 ## variable `Q-statistic` `P-value` ## ## 1 watershed 0.638 0.000129 ## 2 elevation 0.607 0.0434 ## 3 soiltype 0.386 0.372"},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"interaction-detector","dir":"Articles","previous_headings":"7. Real-world example","what":"Interaction detector","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"go1$interaction ## # A tibble: 3 × 7 ## Variable Interaction Qv1 Qv2 Qv12 Variable1 Variable2 ## ## 1 watershed ∩ elevation Enhance, bi- 0.638 0.607 0.714 watershed elevation ## 2 watershed ∩ soiltype Enhance, bi- 0.638 0.386 0.736 watershed soiltype ## 3 elevation ∩ soiltype Enhance, bi- 0.607 0.386 0.664 elevation soiltype go2$interaction ## # A tibble: 3 × 6 ## variable1 variable2 Interaction `Variable1 Q-statistics` `Variable2 Q-statistics` ## ## 1 watershed elevation Enhance, bi- 0.638 0.607 ## 2 watershed soiltype Enhance, bi- 0.638 0.386 ## 3 elevation soiltype Enhance, bi- 0.607 0.386 ## # ℹ 1 more variable: `Variable1 and Variable2 interact Q-statistics` "},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"install-and-load-r-packages","dir":"Articles","previous_headings":"","what":"Install and load R packages","title":"Spatially Explicit Stratified Power Model","text":"Using data gdverse idsa vignette:","code":"install.packages(c(\"sf\",\"gdverse\"), dep = T) # install.packages(\"devtools\") devtools::install_github(\"stscl/sesp\",build_vignettes = TRUE,dep = TRUE) library(sf) ## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE library(sesp) library(gdverse) depression = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) ## Rows: 1072 Columns: 13 ## ── Column specification ─────────────────────────────────────────────────────────────────────────── ## Delimiter: \",\" ## dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHealthInsurance, Neig... ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. depression ## Simple feature collection with 1072 features and 11 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: -83.1795 ymin: 32.11464 xmax: -78.6023 ymax: 35.17354 ## Geodetic CRS: WGS 84 ## # A tibble: 1,072 × 12 ## Depression_prevelence PopulationDensity Population65 NoHealthInsurance Neighbor_Disadvantage ## * ## 1 23.1 61.5 22.5 7.98 -0.0525 ## 2 22.8 58.3 16.8 11.0 -0.254 ## 3 23.2 35.9 24.5 9.31 -0.0540 ## 4 21.8 76.1 21.8 13.2 0.0731 ## 5 20.7 47.3 22.0 11 0.763 ## 6 21.3 32.5 19.2 13.0 0.422 ## 7 22 36.9 19.2 10.8 0.113 ## 8 21.2 61.5 15.9 8.57 -0.154 ## 9 22.7 67.2 15.7 17.8 -0.320 ## 10 20.6 254. 11.3 12.7 0.457 ## # ℹ 1,062 more rows ## # ℹ 7 more variables: Beer , MentalHealthPati , NatureParks , Casinos , ## # DrinkingPlaces , X.HouseRent , geometry "},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-linear-regression","dir":"Articles","previous_headings":"","what":"SESP With Linear Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g1 = sesp(Depression_prevelence ~ ., data = depression, model = 'ols', overlay = 'intersection', cores = 8) }) ## user system elapsed ## 2.45 0.23 29.56 g1 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Ordinary Least Square* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.296 4370.901 4370.901 -2179.450 ## MentalHealthPati 0.260 4428.205 4428.205 -2206.103 ## NoHealthInsurance 0.255 4435.513 4435.513 -2209.756 ## X.HouseRent 0.225 4476.344 4476.344 -2231.172 ## Casinos 0.205 4503.507 4503.507 -2244.754 ## DrinkingPlaces 0.203 4503.855 4503.855 -2245.927 ## PopulationDensity 0.202 4505.365 4505.365 -2246.682 ## Beer 0.200 4507.758 4507.758 -2247.879 ## NatureParks 0.181 4533.589 4533.589 -2260.794 ## Population65 0.159 4561.304 4561.304 -2274.652 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Enhance, bi- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Enhance, bi- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g1,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-lag-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Lag Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g2 = sesp(Depression_prevelence ~ ., data = depression, model = 'lag', cores = 8) }) ## user system elapsed ## 5.86 0.18 250.97 g2 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Lag Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.289 4248.866 4248.866 -2117.433 ## MentalHealthPati 0.240 4288.518 4288.518 -2135.259 ## NoHealthInsurance 0.216 4267.870 4267.870 -2124.935 ## X.HouseRent 0.187 4316.759 4316.759 -2150.380 ## Beer 0.187 4319.936 4319.936 -2149.968 ## DrinkingPlaces 0.160 4330.763 4330.763 -2158.382 ## PopulationDensity 0.154 4333.170 4333.170 -2159.585 ## Casinos 0.153 4346.299 4346.299 -2166.149 ## NatureParks 0.138 4364.690 4364.690 -2175.345 ## Population65 0.122 4370.485 4370.485 -2178.242 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Weaken, uni- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Weaken, uni- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g2,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-error-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Error Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g3 = sesp(Depression_prevelence ~ ., data = depression, model = 'error', cores = 8) }) ## user system elapsed ## 8.17 0.89 135.08 g3 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Error Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.289 4238.682 4238.682 -2112.341 ## NoHealthInsurance 0.253 4230.432 4230.432 -2106.216 ## MentalHealthPati 0.247 4262.110 4262.110 -2122.055 ## X.HouseRent 0.219 4279.959 4279.959 -2131.979 ## PopulationDensity 0.199 4288.640 4288.640 -2137.320 ## DrinkingPlaces 0.198 4295.621 4295.621 -2140.811 ## Beer 0.193 4292.395 4292.395 -2139.197 ## Casinos 0.184 4305.020 4305.020 -2145.510 ## NatureParks 0.171 4325.679 4325.679 -2155.839 ## Population65 0.156 4335.830 4335.830 -2160.915 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Weaken, uni- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g3,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-durbin-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Durbin Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g4 = sesp(Depression_prevelence ~ ., data = depression, model = 'lag', durbin = TRUE, cores = 8) }) ## user system elapsed ## 8.33 0.77 246.39 g4 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Durbin Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.316 4226.864 4226.864 -2102.432 ## MentalHealthPati 0.296 4247.222 4247.222 -2108.611 ## NoHealthInsurance 0.261 4238.839 4238.839 -2104.420 ## NatureParks 0.252 4285.895 4285.895 -2125.948 ## X.HouseRent 0.239 4280.458 4280.458 -2127.229 ## Casinos 0.237 4291.052 4291.052 -2132.526 ## PopulationDensity 0.211 4291.372 4291.372 -2134.686 ## DrinkingPlaces 0.210 4294.833 4294.833 -2136.417 ## Beer 0.209 4291.057 4291.057 -2134.529 ## Population65 0.163 4340.250 4340.250 -2159.125 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Enhance, bi- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Enhance, bi- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g4,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-geographically-weighted-regression","dir":"Articles","previous_headings":"","what":"SESP With Geographically Weighted Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g5 = sesp(Depression_prevelence ~ ., data = depression, model = 'gwr', cores = 8) }) ## user system elapsed ## 8.40 0.68 147.00 g5 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Geographically Weighted Regression* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC ## X.HouseRent 0.370 4255.989 ## MentalHealthPati 0.367 4258.876 ## PopulationDensity 0.366 4260.457 ## Neighbor_Disadvantage 0.354 4277.147 ## Beer 0.350 4288.285 ## Population65 0.317 4337.745 ## Casinos 0.307 4354.933 ## DrinkingPlaces 0.294 4373.148 ## NatureParks 0.266 4412.671 ## NoHealthInsurance 0.254 4429.183 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Weaken, uni- ## PopulationDensity ∩ DrinkingPlaces Weaken, uni- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g5,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"results-of-optimal-spatial-discretization","dir":"Articles","previous_headings":"","what":"Results of optimal spatial discretization","title":"Spatially Explicit Stratified Power Model","text":"","code":"plot_optdisc = \\(g){ gmap = sf::st_set_geometry(g$optdisc,sf::st_geometry(depression)) fig1 = seq_along(g$optdisc) |> purrr::map(\\(.x) ggplot2::ggplot(data = gmap) + ggplot2::geom_sf(ggplot2::aes(color = factor(g$optdisc[,.x,drop = TRUE])), alpha = .65, size = 0.5) + ggplot2::labs(color = 'zones') + ggplot2::theme_void() + ggplot2::theme( legend.position = \"none\") ) %>% patchwork::wrap_plots(ncol = 3, byrow = TRUE) + patchwork::plot_annotation( tag_levels = 'a', tag_prefix = '(', tag_suffix = ')', tag_sep = '', theme = ggplot2::theme(plot.tag = ggplot2::element_text(family = \"serif\"), plot.tag.position = \"topleft\")) return(fig1) } plot_optdisc(g1) plot_optdisc(g2) plot_optdisc(g3) plot_optdisc(g4) plot_optdisc(g5)"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"install-necessary-r-packages","dir":"Articles","previous_headings":"","what":"Install necessary R packages","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"install.packages(\"gdverse\",dep = TRUE) # install.packages(\"devtools\") devtools::install_github(\"stscl/sesp\",build_vignettes = TRUE,dep = TRUE)"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"the-spatial-autocorrelation-of-the-example-data","dir":"Articles","previous_headings":"","what":"The spatial autocorrelation of the example data","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"dt = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) |> dplyr::select(y = Depression_prevelence, x = PopulationDensity) ## Rows: 1072 Columns: 13 ## ── Column specification ─────────────────────────────────────────────────────────────────────────── ## Delimiter: \",\" ## dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHealthInsurance, Neig... ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. sdsfun::moran_test(dt) ## *** global moran test"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"q-values-corresponding-to-spatial-implicit-discretization","dir":"Articles","previous_headings":"","what":"Q values corresponding to spatial implicit discretization","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"geom = sf::st_geometry(dt) y = dt$y x = dt$x x_naturaldisc = sdsfun::discretize_vector(x,5,method = \"natural\") x_hclustdisc = sdsfun::hclustgeo_disc(dplyr::select(dt,x),5,alpha = 0) x_robustdisc = gdverse::robust_disc(y ~ ., data = tibble::tibble(y = y,x = x), discnum = 5, cores = 1) |> dplyr::pull(1) |> as.factor() |> as.integer() qv_naturaldisc = gdverse::factor_detector(y,x_naturaldisc)[[1]] qv_naturaldisc ## [1] 0.07985365 qv_hclustdisc = gdverse::factor_detector(y,x_hclustdisc)[[1]] qv_hclustdisc ## [1] 0.07315131 qv_robustdisc = gdverse::factor_detector(y,x_robustdisc)[[1]] qv_robustdisc ## [1] 0.1199684"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"a-monte-carlo-simulation-experiment-demonstrating-the-necessity-of-spatial-explicit-discretization","dir":"Articles","previous_headings":"","what":"A Monte Carlo simulation experiment demonstrating the necessity of spatial explicit discretization","title":"Why Is Spatially Explicit Discretization Necessary?","text":"repeated experiment, \\(X\\) shuffled 5000 times, global Moran’s original independent variable \\(X\\) serves degree spatial soft constraint (0.365 case). Subsequently, q-values simulation round computed. selected simulated q-values consistent actual situation, specifically global Moran’s permuted data statistically significant (p-value < 0.05) greater zero. q-value derived classifying five categories using natural breaks method 0.07985, q-value five-category hierarchical clustering without spatial constraints 0.07315. comparison, q-value obtained robust discretization five categories 0.11997. Monte Carlo simulation experiment, q-values range 0.1138 0.22158. Among randomized simulations best align actual conditions, q-value range spans 0.13359 0.21584. results indicate spatially implicit discretization tends underestimate q-value variable moderate spatial autocorrelation, highlighting importance spatially explicit discretization. results also reveal robust discretization, accounts relationship independent dependent variables, can effectively reduce q-value estimation bias introduced spatially implicit discretization methods. However, still underestimates q-value approximately 35.2584%. highlights need spatially explicit discretization approach fully considers relationship independent dependent variables accurately capture impact spatial dependence discretization.","code":"mc_simq = \\(times = 1000, cores = 6){ doclust = FALSE if (inherits(cores, \"cluster\")) { doclust = TRUE } else if (cores > 1) { doclust = TRUE cores = parallel::makeCluster(cores) on.exit(parallel::stopCluster(cores), add = TRUE) } calcul_q = \\(n_sim) { x_sim = sample(x) x_sim = sf::st_set_geometry(tibble::tibble(x_sim = x_sim),geom) g = sdsfun::moran_test(x_sim) moran = dplyr::pull(g$result,2) moran_p = dplyr::pull(g$result,6) x_sed = sdsfun::hclustgeo_disc(x_sim, n = 5, alpha = 0.365) qv1 = gdverse::factor_detector(y,x_sed)[[1]] res = tibble::tibble(qv_sed = qv1, moran = moran, moran_p = moran_p) return(res) } if (doclust) { parallel::clusterExport(cores,varlist = c(\"geom\",\"x\",\"y\")) out_g = parallel::parLapply(cores,seq(1,times,by = 1),calcul_q) out_g = tibble::as_tibble(do.call(rbind, out_g)) } else { out_g = purrr::map_dfr(seq(1,times,by = 1),calcul_q) } return(out_g) } qv = mc_simq(times = 5000, cores = 12) qv ## # A tibble: 5,000 × 3 ## qv_sed moran moran_p ## ## 1 0.177 0.00782 0.312 ## 2 0.136 -0.00580 0.607 ## 3 0.210 0.00788 0.311 ## 4 0.180 0.0145 0.194 ## 5 0.180 0.0177 0.148 ## 6 0.199 0.00956 0.278 ## 7 0.174 -0.00721 0.637 ## 8 0.195 -0.0190 0.844 ## 9 0.200 -0.00940 0.682 ## 10 0.167 0.0140 0.202 ## # ℹ 4,990 more rows ggplot2::ggplot(data = qv, ggplot2::aes(x = qv_sed)) + ggplot2::geom_histogram(ggplot2::aes(y = ggplot2::after_stat(density)), bins = 50, fill = \"skyblue\", color = \"black\", alpha = 0.7) + ggplot2::geom_density(color = \"red\", linewidth = 1.2) + ggplot2::scale_x_continuous(expand = c(0.01, 0)) + ggplot2::scale_y_continuous(expand = c(0, 0)) + ggplot2::labs(x = \"Q Value\", y = \"Density\") + ggplot2::theme_classic() qv_sign = dplyr::filter(qv,moran>=0&moran_p<=0.05) qv_sign ## # A tibble: 252 × 3 ## qv_sed moran moran_p ## ## 1 0.204 0.0308 0.0376 ## 2 0.175 0.0304 0.0395 ## 3 0.171 0.0325 0.0305 ## 4 0.189 0.0523 0.00143 ## 5 0.197 0.0296 0.0437 ## 6 0.151 0.0423 0.00774 ## 7 0.175 0.0388 0.0131 ## 8 0.191 0.0328 0.0294 ## 9 0.206 0.0331 0.0285 ## 10 0.197 0.0720 0.0000222 ## # ℹ 242 more rows ggplot2::ggplot(data = qv_sign, ggplot2::aes(x = qv_sed)) + ggplot2::geom_histogram(ggplot2::aes(y = ggplot2::after_stat(density)), bins = 50, fill = \"skyblue\", color = \"black\", alpha = 0.7) + ggplot2::geom_density(color = \"red\", linewidth = 1.2) + ggplot2::scale_x_continuous(expand = c(0.01, 0)) + ggplot2::scale_y_continuous(expand = c(0, 0)) + ggplot2::labs(x = \"Q Value\", y = \"Density\") + ggplot2::theme_classic()"},{"path":"https://stscl.github.io/sesp/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Wenbo Lv. Author, maintainer, copyright holder. Yongze Song. Author. Zehua Zhang. Author. Shaoqing Dai. Author. Jianwu Yan. Author. Wufan Zhao. Author.","code":""},{"path":"https://stscl.github.io/sesp/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Lv W, Song Y, Zhang Z, Dai S, Yan J, Zhao W (2024). sesp: Spatially Explicit Stratified Power. R package version 1.0-0, https://github.com/stscl/sesp, https://stscl.github.io/sesp/.","code":"@Manual{, title = {sesp: Spatially Explicit Stratified Power}, author = {Wenbo Lv and Yongze Song and Zehua Zhang and Shaoqing Dai and Jianwu Yan and Wufan Zhao}, year = {2024}, note = {R package version 1.0-0, https://github.com/stscl/sesp}, url = {https://stscl.github.io/sesp/}, }"},{"path":"https://stscl.github.io/sesp/index.html","id":"sesp-","dir":"","previous_headings":"","what":"sesp | Spatially Explicit Stratified Power\n","title":"sesp | Spatially Explicit Stratified Power\n","text":"Spatially Explicit Stratified Power Model","code":""},{"path":"https://stscl.github.io/sesp/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"sesp | Spatially Explicit Stratified Power\n","text":"Install binary version R-universe : Install source code GitHub :","code":"install.packages('sesp', repos = c(\"https://stscl.r-universe.dev\", \"https://cloud.r-project.org\"), dep = TRUE) if (!requireNamespace(\"devtools\")) { install.packages(\"devtools\") } devtools::install_github(\"stscl/sesp\", build_vignettes = TRUE, dep = TRUE)"},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":null,"dir":"Reference","previous_headings":"","what":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"Spatial fuzzy overlay variables pairwise","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"","code":"fuzzyoverlay2(formula, data, method = \"and\")"},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"formula formula. data data.frame tibble discretized data. method (optional) Spatial overlay method. One , , intersection. Default .","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"list overlay overlay results pairs variables variable pairwise interacting variable","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"","code":"sim = tibble::tibble(y = stats::runif(7,0,10), x1 = c(1,rep(2,3),rep(3,3)), x2 = c(rep(1,2),rep(2,2),rep(3,3)), x3 = c(rep(1,3),rep(2,2),rep(3,2))) fo1 = fuzzyoverlay2(y ~ .,data = sim, method = 'and') fo1 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 1 1 1 #> 2 3 3 1 #> 3 4 3 2 #> 4 4 4 4 #> 5 2 4 4 #> 6 2 2 3 #> 7 2 2 3 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #> fo2 = fuzzyoverlay2(y ~ .,data = sim, method = 'or') fo2 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 3 3 3 #> 2 1 1 3 #> 3 1 1 3 #> 4 1 1 1 #> 5 2 2 2 #> 6 2 4 4 #> 7 2 4 4 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #> fo3 = fuzzyoverlay2(y ~ .,data = sim, method = 'intersection') fo3 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 1 1 1 #> 2 2 2 1 #> 3 3 2 2 #> 4 3 3 3 #> 5 4 4 4 #> 6 4 5 5 #> 7 4 5 5 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #>"},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate GWR model coefficients — gwr_betas","title":"Estimate GWR model coefficients — gwr_betas","text":"Estimate GWR model coefficients","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate GWR model coefficients — gwr_betas","text":"","code":"gwr_betas( formula, data, bw = \"AIC\", adaptive = TRUE, kernel = \"gaussian\", intercept = FALSE )"},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate GWR model coefficients — gwr_betas","text":"formula formula. data sf object observation data bw (optional) bandwidth used selecting models. optimal bandwidth can selected using one two methods: AIC, CV. Default use AIC. adaptive (optional) Whether bandwidth value adaptive . Default TRUE. kernel (optional) Kernel function. Default gaussian. intercept (optional) Whether include intercept term coefficient tibble. Default FALSE`.","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate GWR model coefficients — gwr_betas","text":"tibble","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate GWR model coefficients — gwr_betas","text":"","code":"# \\donttest{ depression = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) #> Rows: 1072 Columns: 13 #> ── Column specification ──────────────────────────────────────────────────────── #> Delimiter: \",\" #> dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHe... #> #> ℹ Use `spec()` to retrieve the full column specification for this data. #> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. gwr_betas(Depression_prevelence ~ ., data = depression) #> # A tibble: 1,072 × 10 #> PopulationDensity Population65 NoHealthInsurance Neighbor_Disadvantage #> #> 1 -0.00117 -0.0746 0.0681 0.493 #> 2 -0.00123 -0.0861 0.0826 0.546 #> 3 -0.00124 -0.0963 0.0999 0.816 #> 4 -0.00120 -0.102 0.0882 0.334 #> 5 -0.00116 -0.105 0.0931 0.271 #> 6 -0.00121 -0.103 0.0919 0.611 #> 7 -0.000301 -0.122 0.0801 0.248 #> 8 -0.000261 -0.104 0.113 0.394 #> 9 -0.000608 -0.0873 0.133 0.851 #> 10 -0.000668 -0.0831 0.139 0.812 #> # ℹ 1,062 more rows #> # ℹ 6 more variables: Beer , MentalHealthPati , NatureParks , #> # Casinos , DrinkingPlaces , X.HouseRent gwr_betas(Depression_prevelence ~ ., data = depression, intercept = TRUE) #> # A tibble: 1,072 × 11 #> Intercept PopulationDensity Population65 NoHealthInsurance #> #> 1 24.0 -0.00117 -0.0746 0.0681 #> 2 23.7 -0.00123 -0.0861 0.0826 #> 3 23.4 -0.00124 -0.0963 0.0999 #> 4 23.7 -0.00120 -0.102 0.0882 #> 5 23.4 -0.00116 -0.105 0.0931 #> 6 23.4 -0.00121 -0.103 0.0919 #> 7 22.6 -0.000301 -0.122 0.0801 #> 8 22.0 -0.000261 -0.104 0.113 #> 9 20.5 -0.000608 -0.0873 0.133 #> 10 20.6 -0.000668 -0.0831 0.139 #> # ℹ 1,062 more rows #> # ℹ 7 more variables: Neighbor_Disadvantage , Beer , #> # MentalHealthPati , NatureParks , Casinos , #> # DrinkingPlaces , X.HouseRent # }"},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"NULL (magrittr pipe operator)","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":null,"dir":"Reference","previous_headings":"","what":"Spatially Explicit Stratified Power (SESP) Model — sesp","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"Spatially Explicit Stratified Power (SESP) Model","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"","code":"sesp( formula, data, listw = NULL, discvar = \"all\", discnum = 3:8, model = \"ols\", durbin = FALSE, overlay = \"and\", alpha = 0.5, intercept = FALSE, bw = \"AIC\", adaptive = TRUE, kernel = \"gaussian\", increase_rate = 0.05, cores = 1, ... )"},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"formula formula enhanced stratified power model. data sf object observation data. Please note column names independent variables none. listw (optional) listw object. See spdep::mat2listw() spdep::nb2listw() details. discvar (optional) Name continuous variable columns need discretized. Noted formula discvar, data must columns. Default , means independent variables used discvar. discvar set none, independent variables need discretized. discnum (optional) Number discretization. Default use 3:8. model (optional) type linear model used, default ols. model value must ols, gwr, lag,error sac. durbin (optional) Whether consider spatial durbin terms, default false. overlay (optional) Spatial overlay method. One , , intersection. Default . alpha (optional) Controlling strength spatial soft constraints, larger alpha, stronger spatial soft constraint. Default 0.5. intercept (optional) Whether include intercept term gwr coefficient tibble. Default FALSE. bw (optional) bandwidth used selecting models. optimal bandwidth can selected using one two methods: AIC, CV. Default AIC. adaptive (optional) Whether bandwidth value adaptive . Default TRUE. kernel (optional) Kernel function. Default gaussian. increase_rate (optional) critical increase rate number discretization. Default 5%. cores (optional) Positive integer (default 1). cores greater 1, use multi-core parallel computing. ... (optional) arguments passed sdsfun::hclustgeo_disc().","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"list. factor global factor detection result interaction global interactive detection results optdisc independent variable optimal spatial discretization allfactor factor detection results corresponding different numbers discreteization model regression model used estimate equivalent q values","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"Note number continuous independent variables small (three fewer), built-spatial explicit discretization sesp may overestimate variable q value (fewer input independent variables, GWR tends overestimate contribution variable). cases, recommended discretize variables beforehand input sesp computation.","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"","code":"NTDs = sf::st_as_sf(gdverse::NTDs, coords = c('X','Y')) g = sesp(incidence ~ ., data = NTDs, discvar = 'none', model = 'ols', overlay = 'intersection', cores = 1) g #> *** Spatially Explicit Stratified Power #> #> Q values are estimated using *Ordinary Least Square* #> #> -------------- Global Power of Determinant : ------------ #> Variable Qvalue AIC BIC LogLik #> watershed 0.638 -10.039 -10.039 15.020 #> elevation 0.607 1.183 1.183 7.409 #> soiltype 0.386 79.675 79.675 -33.838 #> #> ------------- Global Variable Interaction : ------------ #> Variable Interaction #> watershed ∩ elevation Enhance, bi- #> watershed ∩ soiltype Enhance, bi- #> elevation ∩ soiltype Enhance, bi- #> #> ! Only the top ten items of global scale are displayed. #> ! The others can be accessed through specific subsets."},{"path":"https://stscl.github.io/sesp/news/index.html","id":"sesp-10-0","dir":"Changelog","previous_headings":"","what":"sesp 1.0-0","title":"sesp 1.0-0","text":"First stable release.","code":""}] +[{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"q-values","dir":"Articles","previous_headings":"","what":"1. Q Values","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"\\[ q = 1 - \\frac{\\sum\\limits_{h = 1}^{L}N_h\\sigma_h^2}{N\\sigma^2} = 1 - \\frac{\\sum\\limits_{h = 1}^{L}\\sum\\limits_{= 1}^{N_h}\\left({y_{hi} - \\overline{y}_h}^2\\right)}{\\sum\\limits_{= 1}^{N} \\left({y_i - \\overline{y}}^2\\right)} \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"linear-regression-model-with-dummy-variables","dir":"Articles","previous_headings":"","what":"2. Linear Regression Model with Dummy Variables","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"Consider linear regression model response variable \\(y\\) depends \\(k\\) dummy variables \\(D_1, D_2, \\dots, D_k\\). dummy variable \\(D_j\\) indicates membership particular category group, taking value 1 observation belongs category \\(j\\) 0 otherwise. model expressed : \\[ y_i = \\beta_0 + \\beta_1 D_{i1} + \\beta_2 D_{i2} + \\cdots + \\beta_k D_{ik} + \\epsilon_i \\] : \\(y_i\\) response variable \\(\\)-th observation, \\(\\beta_0\\) intercept term, \\(\\beta_j\\) coefficient associated dummy variable \\(D_j\\), \\(D_{ij}\\) value dummy variable \\(D_j\\) \\(\\)-th observation, 1 \\(\\)-th observation belongs category \\(j\\) 0 otherwise, \\(\\epsilon_i\\) error term.","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"behavior-of-dummy-variables","dir":"Articles","previous_headings":"","what":"3. Behavior of Dummy Variables","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"observation belongs exactly one categories represented dummy variables. \\(\\)-th observation belongs category \\(j\\), \\(D_{ij} = 1\\) dummy variables 0 observation. Thus, regression equation observation \\(\\) belonging category \\(j\\) simplifies : \\[ y_i = \\beta_0 + \\beta_j + \\epsilon_i \\] equation holds observations \\(\\) belong category \\(j\\).","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"predicted-value-for-a-category","dir":"Articles","previous_headings":"","what":"4. Predicted Value for a Category","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"predicted value \\(\\widehat{y}_j\\) observation category \\(j\\) expected value \\(y_i\\), given \\(D_{ij} = 1\\) dummy variables 0. Since error term \\(\\epsilon_i\\) expected value 0, predicted value category \\(j\\) : \\[ \\widehat{y}_j = \\mathbb{E}(y_i | D_{ij} = 1) = \\beta_0 + \\beta_j \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"ordinary-least-squares-ols-estimation","dir":"Articles","previous_headings":"","what":"5. Ordinary Least Squares (OLS) Estimation","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"linear regression, coefficients \\(\\beta_0, \\beta_1, \\dots, \\beta_k\\) estimated using Ordinary Least Squares (OLS) method, minimizes sum squared residuals: \\[ \\text{Minimize } \\sum_{=1}^n (y_i - \\widehat{y}_i)^2 \\] OLS solution leads estimate \\(\\beta_j\\) dummy variable predicted value \\(\\widehat{y}_j = \\beta_0 + \\beta_j\\) represents mean value \\(y_i\\) observations category \\(j\\). Specifically, OLS ensures : \\[ \\widehat{y}_j = \\frac{1}{N_j} \\sum_{: D_{ij} = 1} y_i = \\bar{y}_j \\] \\(N_j\\) number observations category \\(j\\), \\(\\bar{y}_j\\) mean response category \\(j\\).","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"conclusion","dir":"Articles","previous_headings":"","what":"6. Conclusion","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"\\[ q = 1 - \\frac{\\sum\\limits_{h = 1}^{L}N_h\\sigma_h^2}{N\\sigma^2} = 1 - \\frac{\\sum\\limits_{h = 1}^{L}\\sum\\limits_{= 1}^{N_h}\\left({y_{hi} - \\overline{y}_h}^2\\right)}{\\sum\\limits_{= 1}^{N} \\left({y_i - \\overline{y}}^2\\right)} = \\frac{\\sum\\limits_{= 1}^{N}\\left({y_i - \\widehat{y}_i}^2\\right)}{\\sum\\limits_{= 1}^{N}\\left({y_i - \\overline{y}}^2\\right)} = R^2 \\]","code":""},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"real-world-example","dir":"Articles","previous_headings":"","what":"7. Real-world example","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"library(sf) ## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE library(sesp) library(gdverse) NTDs = sf::st_as_sf(gdverse::NTDs, coords = c('X','Y')) system.time({ go1 = sesp(incidence ~ ., data = NTDs, discvar = 'none', model = 'ols', overlay = 'intersection') }) ## user system elapsed ## 0.22 0.03 0.65 system.time({ go2 = gd(incidence ~ ., data = NTDs, type = c('factor','interaction')) }) ## user system elapsed ## 0.04 0.00 0.08"},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"factor-detector","dir":"Articles","previous_headings":"7. Real-world example","what":"Factor detector","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"go1$factor ## # A tibble: 3 × 5 ## Variable Qvalue AIC BIC LogLik ## ## 1 watershed 0.638 -10.0 -10.0 15.0 ## 2 elevation 0.607 1.18 1.18 7.41 ## 3 soiltype 0.386 79.7 79.7 -33.8 go2$factor ## # A tibble: 3 × 3 ## variable `Q-statistic` `P-value` ## ## 1 watershed 0.638 0.000129 ## 2 elevation 0.607 0.0434 ## 3 soiltype 0.386 0.372"},{"path":"https://stscl.github.io/sesp/articles/pdrm.html","id":"interaction-detector","dir":"Articles","previous_headings":"7. Real-world example","what":"Interaction detector","title":"Equivalent Q Values Within Statistical Variance and Linear Regression Framework","text":"","code":"go1$interaction ## # A tibble: 3 × 7 ## Variable Interaction Qv1 Qv2 Qv12 Variable1 Variable2 ## ## 1 watershed ∩ elevation Enhance, bi- 0.638 0.607 0.714 watershed elevation ## 2 watershed ∩ soiltype Enhance, bi- 0.638 0.386 0.736 watershed soiltype ## 3 elevation ∩ soiltype Enhance, bi- 0.607 0.386 0.664 elevation soiltype go2$interaction ## # A tibble: 3 × 6 ## variable1 variable2 Interaction `Variable1 Q-statistics` `Variable2 Q-statistics` ## ## 1 watershed elevation Enhance, bi- 0.638 0.607 ## 2 watershed soiltype Enhance, bi- 0.638 0.386 ## 3 elevation soiltype Enhance, bi- 0.607 0.386 ## # ℹ 1 more variable: `Variable1 and Variable2 interact Q-statistics` "},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"install-and-load-r-packages","dir":"Articles","previous_headings":"","what":"Install and load R packages","title":"Spatially Explicit Stratified Power Model","text":"Using data gdverse idsa vignette:","code":"install.packages(c(\"sf\",\"gdverse\"), dep = T) # install.packages(\"devtools\") devtools::install_github(\"stscl/sesp\",build_vignettes = TRUE,dep = TRUE) library(sf) ## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE library(sesp) library(gdverse) depression = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) ## Rows: 1072 Columns: 13 ## ── Column specification ─────────────────────────────────────────────────────────────────────────── ## Delimiter: \",\" ## dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHealthInsurance, Neig... ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. depression ## Simple feature collection with 1072 features and 11 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: -83.1795 ymin: 32.11464 xmax: -78.6023 ymax: 35.17354 ## Geodetic CRS: WGS 84 ## # A tibble: 1,072 × 12 ## Depression_prevelence PopulationDensity Population65 NoHealthInsurance Neighbor_Disadvantage ## * ## 1 23.1 61.5 22.5 7.98 -0.0525 ## 2 22.8 58.3 16.8 11.0 -0.254 ## 3 23.2 35.9 24.5 9.31 -0.0540 ## 4 21.8 76.1 21.8 13.2 0.0731 ## 5 20.7 47.3 22.0 11 0.763 ## 6 21.3 32.5 19.2 13.0 0.422 ## 7 22 36.9 19.2 10.8 0.113 ## 8 21.2 61.5 15.9 8.57 -0.154 ## 9 22.7 67.2 15.7 17.8 -0.320 ## 10 20.6 254. 11.3 12.7 0.457 ## # ℹ 1,062 more rows ## # ℹ 7 more variables: Beer , MentalHealthPati , NatureParks , Casinos , ## # DrinkingPlaces , X.HouseRent , geometry "},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-linear-regression","dir":"Articles","previous_headings":"","what":"SESP With Linear Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g1 = sesp(Depression_prevelence ~ ., data = depression, model = 'ols', overlay = 'intersection', cores = 8) }) ## user system elapsed ## 2.45 0.23 29.56 g1 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Ordinary Least Square* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.296 4370.901 4370.901 -2179.450 ## MentalHealthPati 0.260 4428.205 4428.205 -2206.103 ## NoHealthInsurance 0.255 4435.513 4435.513 -2209.756 ## X.HouseRent 0.225 4476.344 4476.344 -2231.172 ## Casinos 0.205 4503.507 4503.507 -2244.754 ## DrinkingPlaces 0.203 4503.855 4503.855 -2245.927 ## PopulationDensity 0.202 4505.365 4505.365 -2246.682 ## Beer 0.200 4507.758 4507.758 -2247.879 ## NatureParks 0.181 4533.589 4533.589 -2260.794 ## Population65 0.159 4561.304 4561.304 -2274.652 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Enhance, bi- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Enhance, bi- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g1,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-lag-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Lag Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g2 = sesp(Depression_prevelence ~ ., data = depression, model = 'lag', cores = 8) }) ## user system elapsed ## 5.86 0.18 250.97 g2 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Lag Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.289 4248.866 4248.866 -2117.433 ## MentalHealthPati 0.240 4288.518 4288.518 -2135.259 ## NoHealthInsurance 0.216 4267.870 4267.870 -2124.935 ## X.HouseRent 0.187 4316.759 4316.759 -2150.380 ## Beer 0.187 4319.936 4319.936 -2149.968 ## DrinkingPlaces 0.160 4330.763 4330.763 -2158.382 ## PopulationDensity 0.154 4333.170 4333.170 -2159.585 ## Casinos 0.153 4346.299 4346.299 -2166.149 ## NatureParks 0.138 4364.690 4364.690 -2175.345 ## Population65 0.122 4370.485 4370.485 -2178.242 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Weaken, uni- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Weaken, uni- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g2,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-error-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Error Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g3 = sesp(Depression_prevelence ~ ., data = depression, model = 'error', cores = 8) }) ## user system elapsed ## 8.17 0.89 135.08 g3 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Error Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.289 4238.682 4238.682 -2112.341 ## NoHealthInsurance 0.253 4230.432 4230.432 -2106.216 ## MentalHealthPati 0.247 4262.110 4262.110 -2122.055 ## X.HouseRent 0.219 4279.959 4279.959 -2131.979 ## PopulationDensity 0.199 4288.640 4288.640 -2137.320 ## DrinkingPlaces 0.198 4295.621 4295.621 -2140.811 ## Beer 0.193 4292.395 4292.395 -2139.197 ## Casinos 0.184 4305.020 4305.020 -2145.510 ## NatureParks 0.171 4325.679 4325.679 -2155.839 ## Population65 0.156 4335.830 4335.830 -2160.915 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Weaken, uni- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g3,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-spatial-durbin-regression","dir":"Articles","previous_headings":"","what":"SESP With Spatial Durbin Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g4 = sesp(Depression_prevelence ~ ., data = depression, model = 'lag', durbin = TRUE, cores = 8) }) ## user system elapsed ## 8.33 0.77 246.39 g4 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Spatial Durbin Model* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC BIC LogLik ## Neighbor_Disadvantage 0.316 4226.864 4226.864 -2102.432 ## MentalHealthPati 0.296 4247.222 4247.222 -2108.611 ## NoHealthInsurance 0.261 4238.839 4238.839 -2104.420 ## NatureParks 0.252 4285.895 4285.895 -2125.948 ## X.HouseRent 0.239 4280.458 4280.458 -2127.229 ## Casinos 0.237 4291.052 4291.052 -2132.526 ## PopulationDensity 0.211 4291.372 4291.372 -2134.686 ## DrinkingPlaces 0.210 4294.833 4294.833 -2136.417 ## Beer 0.209 4291.057 4291.057 -2134.529 ## Population65 0.163 4340.250 4340.250 -2159.125 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Enhance, bi- ## PopulationDensity ∩ Casinos Enhance, bi- ## PopulationDensity ∩ DrinkingPlaces Enhance, bi- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Enhance, bi- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g4,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"sesp-with-geographically-weighted-regression","dir":"Articles","previous_headings":"","what":"SESP With Geographically Weighted Regression","title":"Spatially Explicit Stratified Power Model","text":"","code":"system.time({ g5 = sesp(Depression_prevelence ~ ., data = depression, model = 'gwr', cores = 8) }) ## user system elapsed ## 8.40 0.68 147.00 g5 ## *** Spatially Explicit Stratified Power ## ## Q values are estimated using *Geographically Weighted Regression* ## ## -------------- Global Power of Determinant : ------------ ## Variable Qvalue AIC ## X.HouseRent 0.370 4255.989 ## MentalHealthPati 0.367 4258.876 ## PopulationDensity 0.366 4260.457 ## Neighbor_Disadvantage 0.354 4277.147 ## Beer 0.350 4288.285 ## Population65 0.317 4337.745 ## Casinos 0.307 4354.933 ## DrinkingPlaces 0.294 4373.148 ## NatureParks 0.266 4412.671 ## NoHealthInsurance 0.254 4429.183 ## ## ------------- Global Variable Interaction : ------------ ## Variable Interaction ## PopulationDensity ∩ Population65 Enhance, bi- ## PopulationDensity ∩ NoHealthInsurance Enhance, bi- ## PopulationDensity ∩ Neighbor_Disadvantage Enhance, bi- ## PopulationDensity ∩ Beer Enhance, bi- ## PopulationDensity ∩ MentalHealthPati Enhance, bi- ## PopulationDensity ∩ NatureParks Weaken, uni- ## PopulationDensity ∩ Casinos Weaken, uni- ## PopulationDensity ∩ DrinkingPlaces Weaken, uni- ## PopulationDensity ∩ X.HouseRent Enhance, bi- ## Population65 ∩ NoHealthInsurance Weaken, uni- ## ## ! Only the top ten items of global scale are displayed. ## ! The others can be accessed through specific subsets. plot(g5,slicenum = 10) + ggplot2::theme(axis.text.x = ggplot2::element_text( angle = 30,vjust = 0.85,hjust = 0.75) )"},{"path":"https://stscl.github.io/sesp/articles/sesp.html","id":"results-of-optimal-spatial-discretization","dir":"Articles","previous_headings":"","what":"Results of optimal spatial discretization","title":"Spatially Explicit Stratified Power Model","text":"","code":"plot_optdisc = \\(g){ gmap = sf::st_set_geometry(g$optdisc,sf::st_geometry(depression)) fig1 = seq_along(g$optdisc) |> purrr::map(\\(.x) ggplot2::ggplot(data = gmap) + ggplot2::geom_sf(ggplot2::aes(color = factor(g$optdisc[,.x,drop = TRUE])), alpha = .65, size = 0.5) + ggplot2::labs(color = 'zones') + ggplot2::theme_void() + ggplot2::theme( legend.position = \"none\") ) %>% patchwork::wrap_plots(ncol = 3, byrow = TRUE) + patchwork::plot_annotation( tag_levels = 'a', tag_prefix = '(', tag_suffix = ')', tag_sep = '', theme = ggplot2::theme(plot.tag = ggplot2::element_text(family = \"serif\"), plot.tag.position = \"topleft\")) return(fig1) } plot_optdisc(g1) plot_optdisc(g2) plot_optdisc(g3) plot_optdisc(g4) plot_optdisc(g5)"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"install-necessary-r-packages","dir":"Articles","previous_headings":"","what":"Install necessary R packages","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"install.packages(\"gdverse\",dep = TRUE) # install.packages(\"devtools\") devtools::install_github(\"stscl/sesp\",build_vignettes = TRUE,dep = TRUE)"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"the-spatial-autocorrelation-of-the-example-data","dir":"Articles","previous_headings":"","what":"The spatial autocorrelation of the example data","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"dt = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) |> dplyr::select(y = Depression_prevelence, x = PopulationDensity) ## Rows: 1072 Columns: 13 ## ── Column specification ─────────────────────────────────────────────────────────────────────────── ## Delimiter: \",\" ## dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHealthInsurance, Neig... ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. sdsfun::moran_test(dt) ## *** global moran test"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"q-values-corresponding-to-spatial-implicit-discretization","dir":"Articles","previous_headings":"","what":"Q values corresponding to spatial implicit discretization","title":"Why Is Spatially Explicit Discretization Necessary?","text":"","code":"geom = sf::st_geometry(dt) y = dt$y x = dt$x x_naturaldisc = sdsfun::discretize_vector(x,5,method = \"natural\") x_hclustdisc = sdsfun::hclustgeo_disc(dplyr::select(dt,x),5,alpha = 0) x_robustdisc = gdverse::robust_disc(y ~ ., data = tibble::tibble(y = y,x = x), discnum = 5, cores = 1) |> dplyr::pull(1) |> as.factor() |> as.integer() qv_naturaldisc = gdverse::factor_detector(y,x_naturaldisc)[[1]] qv_naturaldisc ## [1] 0.07985365 qv_hclustdisc = gdverse::factor_detector(y,x_hclustdisc)[[1]] qv_hclustdisc ## [1] 0.07315131 qv_robustdisc = gdverse::factor_detector(y,x_robustdisc)[[1]] qv_robustdisc ## [1] 0.1199684"},{"path":"https://stscl.github.io/sesp/articles/whysed.html","id":"a-monte-carlo-simulation-experiment-demonstrating-the-necessity-of-spatial-explicit-discretization","dir":"Articles","previous_headings":"","what":"A Monte Carlo simulation experiment demonstrating the necessity of spatial explicit discretization","title":"Why Is Spatially Explicit Discretization Necessary?","text":"repeated experiment, \\(X\\) shuffled 5000 times, global Moran’s original independent variable \\(X\\) serves degree spatial soft constraint (0.365 case). Subsequently, q-values simulation round computed. selected simulated q-values consistent actual situation, specifically global Moran’s permuted data statistically significant (p-value < 0.05) greater zero. q-value derived classifying five categories using natural breaks method 0.07985, q-value five-category hierarchical clustering without spatial constraints 0.07315. comparison, q-value obtained robust discretization five categories 0.11997. Monte Carlo simulation experiment, q-values range 0.1138 0.22158. Among randomized simulations best align actual conditions, q-value range spans 0.13359 0.21584. results indicate spatially implicit discretization tends underestimate q-value variable moderate spatial autocorrelation, highlighting importance spatially explicit discretization. results also reveal robust discretization, accounts relationship independent dependent variables, can effectively reduce q-value estimation bias introduced spatially implicit discretization methods. However, still underestimates q-value approximately 35.2584%. highlights need spatially explicit discretization approach fully considers relationship independent dependent variables accurately capture impact spatial dependence discretization.","code":"mc_simq = \\(times = 1000, cores = 6){ doclust = FALSE if (inherits(cores, \"cluster\")) { doclust = TRUE } else if (cores > 1) { doclust = TRUE cores = parallel::makeCluster(cores) on.exit(parallel::stopCluster(cores), add = TRUE) } calcul_q = \\(n_sim) { x_sim = sample(x) x_sim = sf::st_set_geometry(tibble::tibble(x_sim = x_sim),geom) g = sdsfun::moran_test(x_sim) moran = dplyr::pull(g$result,2) moran_p = dplyr::pull(g$result,6) x_sed = sdsfun::hclustgeo_disc(x_sim, n = 5, alpha = 0.365) qv1 = gdverse::factor_detector(y,x_sed)[[1]] res = tibble::tibble(qv_sed = qv1, moran = moran, moran_p = moran_p) return(res) } if (doclust) { parallel::clusterExport(cores,varlist = c(\"geom\",\"x\",\"y\")) out_g = parallel::parLapply(cores,seq(1,times,by = 1),calcul_q) out_g = tibble::as_tibble(do.call(rbind, out_g)) } else { out_g = purrr::map_dfr(seq(1,times,by = 1),calcul_q) } return(out_g) } qv = mc_simq(times = 5000, cores = 12) qv ## # A tibble: 5,000 × 3 ## qv_sed moran moran_p ## ## 1 0.177 0.00782 0.312 ## 2 0.136 -0.00580 0.607 ## 3 0.210 0.00788 0.311 ## 4 0.180 0.0145 0.194 ## 5 0.180 0.0177 0.148 ## 6 0.199 0.00956 0.278 ## 7 0.174 -0.00721 0.637 ## 8 0.195 -0.0190 0.844 ## 9 0.200 -0.00940 0.682 ## 10 0.167 0.0140 0.202 ## # ℹ 4,990 more rows ggplot2::ggplot(data = qv, ggplot2::aes(x = qv_sed)) + ggplot2::geom_histogram(ggplot2::aes(y = ggplot2::after_stat(density)), bins = 50, fill = \"skyblue\", color = \"black\", alpha = 0.7) + ggplot2::geom_density(color = \"red\", linewidth = 1.2) + ggplot2::scale_x_continuous(expand = c(0.01, 0)) + ggplot2::scale_y_continuous(expand = c(0, 0)) + ggplot2::labs(x = \"Q Value\", y = \"Density\") + ggplot2::theme_classic() qv_sign = dplyr::filter(qv,moran>=0&moran_p<=0.05) qv_sign ## # A tibble: 252 × 3 ## qv_sed moran moran_p ## ## 1 0.204 0.0308 0.0376 ## 2 0.175 0.0304 0.0395 ## 3 0.171 0.0325 0.0305 ## 4 0.189 0.0523 0.00143 ## 5 0.197 0.0296 0.0437 ## 6 0.151 0.0423 0.00774 ## 7 0.175 0.0388 0.0131 ## 8 0.191 0.0328 0.0294 ## 9 0.206 0.0331 0.0285 ## 10 0.197 0.0720 0.0000222 ## # ℹ 242 more rows ggplot2::ggplot(data = qv_sign, ggplot2::aes(x = qv_sed)) + ggplot2::geom_histogram(ggplot2::aes(y = ggplot2::after_stat(density)), bins = 50, fill = \"skyblue\", color = \"black\", alpha = 0.7) + ggplot2::geom_density(color = \"red\", linewidth = 1.2) + ggplot2::scale_x_continuous(expand = c(0.01, 0)) + ggplot2::scale_y_continuous(expand = c(0, 0)) + ggplot2::labs(x = \"Q Value\", y = \"Density\") + ggplot2::theme_classic()"},{"path":"https://stscl.github.io/sesp/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Wenbo Lv. Author, maintainer, copyright holder. Yongze Song. Author. Zehua Zhang. Author. Shaoqing Dai. Author. Jianwu Yan. Author. Wufan Zhao. Author.","code":""},{"path":"https://stscl.github.io/sesp/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Lv W, Song Y, Zhang Z, Dai S, Yan J, Zhao W (2024). sesp: Spatially Explicit Stratified Power. R package version 1.0-0, https://github.com/stscl/sesp, https://stscl.github.io/sesp/.","code":"@Manual{, title = {sesp: Spatially Explicit Stratified Power}, author = {Wenbo Lv and Yongze Song and Zehua Zhang and Shaoqing Dai and Jianwu Yan and Wufan Zhao}, year = {2024}, note = {R package version 1.0-0, https://github.com/stscl/sesp}, url = {https://stscl.github.io/sesp/}, }"},{"path":"https://stscl.github.io/sesp/index.html","id":"sesp-","dir":"","previous_headings":"","what":"sesp | Spatially Explicit Stratified Power\n","title":"sesp | Spatially Explicit Stratified Power\n","text":"Spatially Explicit Stratified Power Model","code":""},{"path":"https://stscl.github.io/sesp/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"sesp | Spatially Explicit Stratified Power\n","text":"Install binary version R-universe : Install source code GitHub :","code":"install.packages('sesp', repos = c(\"https://stscl.r-universe.dev\", \"https://cloud.r-project.org\"), dep = TRUE) if (!requireNamespace(\"devtools\")) { install.packages(\"devtools\") } devtools::install_github(\"stscl/sesp\", build_vignettes = TRUE, dep = TRUE)"},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":null,"dir":"Reference","previous_headings":"","what":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"Spatial fuzzy overlay variables pairwise","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"","code":"fuzzyoverlay2(formula, data, method = \"and\")"},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"formula formula. data data.frame tibble discretized data. method (optional) Spatial overlay method. One , , intersection. Default .","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"list overlay overlay results pairs variables variable pairwise interacting variable","code":""},{"path":"https://stscl.github.io/sesp/reference/fuzzyoverlay2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spatial fuzzy overlay between variables pairwise — fuzzyoverlay2","text":"","code":"sim = tibble::tibble(y = stats::runif(7,0,10), x1 = c(1,rep(2,3),rep(3,3)), x2 = c(rep(1,2),rep(2,2),rep(3,3)), x3 = c(rep(1,3),rep(2,2),rep(3,2))) fo1 = fuzzyoverlay2(y ~ .,data = sim, method = 'and') fo1 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 1 1 1 #> 2 3 3 1 #> 3 4 3 2 #> 4 4 4 4 #> 5 2 4 4 #> 6 2 2 3 #> 7 2 2 3 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #> fo2 = fuzzyoverlay2(y ~ .,data = sim, method = 'or') fo2 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 3 3 3 #> 2 1 1 3 #> 3 1 1 3 #> 4 1 1 1 #> 5 2 2 2 #> 6 2 4 4 #> 7 2 4 4 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #> fo3 = fuzzyoverlay2(y ~ .,data = sim, method = 'intersection') fo3 #> $overlay #> # A tibble: 7 × 3 #> xi1 xi2 xi3 #> #> 1 1 1 1 #> 2 2 2 1 #> 3 3 2 2 #> 4 3 3 3 #> 5 4 4 4 #> 6 4 5 5 #> 7 4 5 5 #> #> $variable #> [1] \"x1 ∩ x2\" \"x1 ∩ x3\" \"x2 ∩ x3\" #>"},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate GWR model coefficients — gwr_betas","title":"Estimate GWR model coefficients — gwr_betas","text":"Estimate GWR model coefficients","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate GWR model coefficients — gwr_betas","text":"","code":"gwr_betas( formula, data, bw = \"AIC\", adaptive = TRUE, kernel = \"gaussian\", intercept = FALSE )"},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate GWR model coefficients — gwr_betas","text":"formula formula. data sf object observation data bw (optional) bandwidth used selecting models. optimal bandwidth can selected using one two methods: AIC, CV. Default use AIC. adaptive (optional) Whether bandwidth value adaptive . Default TRUE. kernel (optional) Kernel function. Default gaussian. intercept (optional) Whether include intercept term coefficient tibble. Default FALSE`.","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate GWR model coefficients — gwr_betas","text":"tibble","code":""},{"path":"https://stscl.github.io/sesp/reference/gwr_betas.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate GWR model coefficients — gwr_betas","text":"","code":"# \\donttest{ depression = system.file('extdata/Depression.csv',package = 'gdverse') |> readr::read_csv() |> sf::st_as_sf(coords = c('X','Y'), crs = 4326) #> Rows: 1072 Columns: 13 #> ── Column specification ──────────────────────────────────────────────────────── #> Delimiter: \",\" #> dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHe... #> #> ℹ Use `spec()` to retrieve the full column specification for this data. #> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. gwr_betas(Depression_prevelence ~ ., data = depression) #> # A tibble: 1,072 × 10 #> PopulationDensity Population65 NoHealthInsurance Neighbor_Disadvantage #> #> 1 -0.00117 -0.0746 0.0681 0.493 #> 2 -0.00123 -0.0861 0.0826 0.546 #> 3 -0.00124 -0.0963 0.0999 0.816 #> 4 -0.00120 -0.102 0.0882 0.334 #> 5 -0.00116 -0.105 0.0931 0.271 #> 6 -0.00121 -0.103 0.0919 0.611 #> 7 -0.000301 -0.122 0.0801 0.248 #> 8 -0.000261 -0.104 0.113 0.394 #> 9 -0.000608 -0.0873 0.133 0.851 #> 10 -0.000668 -0.0831 0.139 0.812 #> # ℹ 1,062 more rows #> # ℹ 6 more variables: Beer , MentalHealthPati , NatureParks , #> # Casinos , DrinkingPlaces , X.HouseRent gwr_betas(Depression_prevelence ~ ., data = depression, intercept = TRUE) #> # A tibble: 1,072 × 11 #> Intercept PopulationDensity Population65 NoHealthInsurance #> #> 1 24.0 -0.00117 -0.0746 0.0681 #> 2 23.7 -0.00123 -0.0861 0.0826 #> 3 23.4 -0.00124 -0.0963 0.0999 #> 4 23.7 -0.00120 -0.102 0.0882 #> 5 23.4 -0.00116 -0.105 0.0931 #> 6 23.4 -0.00121 -0.103 0.0919 #> 7 22.6 -0.000301 -0.122 0.0801 #> 8 22.0 -0.000261 -0.104 0.113 #> 9 20.5 -0.000608 -0.0873 0.133 #> 10 20.6 -0.000668 -0.0831 0.139 #> # ℹ 1,062 more rows #> # ℹ 7 more variables: Neighbor_Disadvantage , Beer , #> # MentalHealthPati , NatureParks , Casinos , #> # DrinkingPlaces , X.HouseRent # }"},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://stscl.github.io/sesp/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"NULL (magrittr pipe operator)","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":null,"dir":"Reference","previous_headings":"","what":"Spatially Explicit Stratified Power (SESP) Model — sesp","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"Spatially Explicit Stratified Power (SESP) Model","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"","code":"sesp( formula, data, listw = NULL, discvar = \"all\", discnum = 3:8, model = \"ols\", durbin = FALSE, overlay = \"and\", alpha = 0.5, intercept = FALSE, bw = \"AIC\", adaptive = TRUE, kernel = \"gaussian\", increase_rate = 0.05, cores = 1, ... )"},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"formula formula enhanced stratified power model. data sf object observation data. Please note column names independent variables none. listw (optional) listw object. See spdep::mat2listw() spdep::nb2listw() details. discvar (optional) Name continuous variable columns need discretized. Noted formula discvar, data must columns. Default , means independent variables used discvar. discvar set none, independent variables need discretized. discnum (optional) Number discretization. Default use 3:8. model (optional) type linear model used, default ols. model value must ols, gwr, lag,error sac. durbin (optional) Whether consider spatial durbin terms, default false. overlay (optional) Spatial overlay method. One , , intersection. Default . alpha (optional) Controlling strength spatial soft constraints, larger alpha, stronger spatial soft constraint. Default 0.5. intercept (optional) Whether include intercept term gwr coefficient tibble. Default FALSE. bw (optional) bandwidth used selecting models. optimal bandwidth can selected using one two methods: AIC, CV. Default AIC. adaptive (optional) Whether bandwidth value adaptive . Default TRUE. kernel (optional) Kernel function. Default gaussian. increase_rate (optional) critical increase rate number discretization. Default 5%. cores (optional) Positive integer (default 1). cores greater 1, use multi-core parallel computing. ... (optional) arguments passed sdsfun::hclustgeo_disc().","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"list. factor global factor detection result interaction global interactive detection results optdisc independent variable optimal spatial discretization allfactor factor detection results corresponding different numbers discreteization model regression model used estimate equivalent q values","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"Note number continuous independent variables small (three fewer), built-spatial explicit discretization sesp may overestimate variable q value (fewer input independent variables, GWR tends overestimate contribution variable). cases, recommended discretize variables beforehand input sesp computation.","code":""},{"path":"https://stscl.github.io/sesp/reference/sesp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spatially Explicit Stratified Power (SESP) Model — sesp","text":"","code":"NTDs = sf::st_as_sf(gdverse::NTDs, coords = c('X','Y')) g = sesp(incidence ~ ., data = NTDs, discvar = 'none', model = 'ols', overlay = 'intersection', cores = 1) g #> *** Spatially Explicit Stratified Power #> #> Q values are estimated using *Ordinary Least Square* #> #> -------------- Global Power of Determinant : ------------ #> Variable Qvalue AIC BIC LogLik #> watershed 0.638 -10.039 22.164 15.020 #> elevation 0.607 1.183 26.946 7.409 #> soiltype 0.386 79.675 98.997 -33.838 #> #> ------------- Global Variable Interaction : ------------ #> Variable Interaction #> watershed ∩ elevation Enhance, bi- #> watershed ∩ soiltype Enhance, bi- #> elevation ∩ soiltype Enhance, bi- #> #> ! Only the top ten items of global scale are displayed. #> ! The others can be accessed through specific subsets."},{"path":"https://stscl.github.io/sesp/news/index.html","id":"sesp-10-0","dir":"Changelog","previous_headings":"","what":"sesp 1.0-0","title":"sesp 1.0-0","text":"First stable release.","code":""}]