Skip to content

Commit

Permalink
update gca vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Sep 22, 2024
1 parent f4a7edc commit 5b06927
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
47 changes: 20 additions & 27 deletions vignettes/gca.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ vignette: >
``` r
library(sf)
library(tidyverse)
## ── Attaching core tidyverse packages ────────────────────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── Conflicts ──────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(geocomplexity)

econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity'))
Expand All @@ -39,19 +30,19 @@ mlr1 = lm(Gini ~ ., data = st_drop_geometry(econineq))

gc1 = geocd_vector(dplyr::select(econineq,-Gini),
wt = wt1, returnsf = FALSE)
mlr2 = lm(Gini ~ ., data = st_drop_geometry(econineq) %>%
mlr2 = lm(Gini ~ ., data = st_drop_geometry(econineq) %>%
dplyr::bind_cols(gc1))

eval_mlr = \(models,mnames){
R2 = purrr::map_dbl(models,\(m) summary(m)$r.squared)
R2 = purrr::map_dbl(models,\(m) summary(m)$r.squared)
AdjR2 = purrr::map_dbl(models,\(m) summary(m)$adj.r.squared)
t_eval = tibble::tibble(Model = mnames,
R2,AdjR2)
return(t_eval)
}

eval_mlr(list(mlr1,mlr2),
c("MLR","GCMLR")) |>
c("MLR","GCMLR")) |>
pander::pander()
```

Expand All @@ -71,22 +62,11 @@ eval_mlr(list(mlr1,mlr2),

``` r
library(spatialreg)
## Loading required package: spData
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack


wtl1 = spdep::mat2listw(wt1)
## Warning in spdep::mat2listw(wt1): style is M (missing); style should be set to a valid value
## Warning in spdep::mat2listw(wt1): neighbour object has 2 sub-graphs
gc2 = geocs_vector(dplyr::select(econineq,-Gini),
wt = wt_mat, returnsf = FALSE)
## Error: object 'wt_mat' not found

wt2 = geocs_swm(econineq,wt1)
wtl2 = spdep::mat2listw(wt2,zero.policy = TRUE)
## Warning in spdep::mat2listw(wt2, zero.policy = TRUE): style is M (missing); style should be
Expand All @@ -109,10 +89,23 @@ eval_slm = \(models,mnames){
return(evt)
}

eval_slmmodel(list(slm1,slm2,sem1,sem2),
c("SLM","GCSLM","SEM","GCSEM")) |>
eval_slm(list(slm1,slm2,sem1,sem2),
c("SLM","GCSLM","SEM","GCSEM")) |>
pander::pander()
## Error in eval_slmmodel(list(slm1, slm2, sem1, sem2), c("SLM", "GCSLM", : could not find function "eval_slmmodel"
## Error in if (tail(stdout, 1) == "") {: argument is of length zero
```


--------------------------------
Model AIC BIC logLik
------- ------- ------- --------
SLM -1355 -1313 688.6

GCSLM -1355 -1314 688.7

SEM -1468 -1426 745

GCSEM -1362 -1320 692.1
--------------------------------



4 changes: 2 additions & 2 deletions vignettes/gca.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ eval_slm = \(models,mnames){
return(evt)
}

eval_slmmodel(list(slm1,slm2,sem1,sem2),
c("SLM","GCSLM","SEM","GCSEM")) |>
eval_slm(list(slm1,slm2,sem1,sem2),
c("SLM","GCSLM","SEM","GCSEM")) |>
pander::pander()
```

0 comments on commit 5b06927

Please sign in to comment.