Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Jun 17, 2024
1 parent 8ecbfe3 commit a5b60be
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 29 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(ecological_detector)
export(factor_detector)
export(gd)
export(gd_bestunidisc)
export(gd_rpart)
export(gd_sesu)
export(gozh)
export(interaction_detector)
Expand Down
12 changes: 9 additions & 3 deletions R/gozh.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param cores positive integer(default is 1). If cores > 1, a 'parallel' package
#' cluster with that many cores is created and used. You can also supply a cluster
#' object.
#' @param ... (optional) Other arguments passed to `rpart::rpart`.
#' @param ... (optional) Other arguments passed to `rpart::rpart()`.
#'
#' @return A list of the GOZH model result.
#' @export
Expand Down Expand Up @@ -69,11 +69,17 @@ gozh = \(formula,data,cores = 1,...){
return(res)
}


#' @title Q-statistics of geographical detector based on Recursive Partitioning
#' @author Wenbo Lv \email{[email protected]}
#'
#' @param formula A formula.
#' @param data A data.frame or tibble of observation data.
#' @param ... (optional) Other arguments passed to `rpart::rpart()`.
#'
#' @importFrom rpart rpart
#' @importFrom tibble as_tibble_row
#' @noRd
#' @return A tibble contains the Q-statistic and the p-value.
#' @export
gd_rpart = \(formula,data,...){
formula = stats::as.formula(formula)
formula.vars = all.vars(formula)
Expand Down
15 changes: 13 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,28 @@ tictoc::toc()
fvc_opgd
```

### GOZH model

```{r}
tictoc::tic()
g = gozh(fvc ~ ., data = fvc, cores = 6)
tictoc::tic()
g
```

### RGD model

To run `RGD`,remember to set up your python dependence, see `RGD` vignette to get more details.

```{r}
reticulate::use_condaenv('geocompy')
tictoc::tic()
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 15,
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 10,
discvar = names(select(fvc,-c(fvc,lulc))),
cores = 8, type = 'factor')
cores = 6, type = 'factor')
tictoc::toc()
fvc_rgd
```



74 changes: 51 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fvc_opgd = opgd(fvc ~ ., data = fvc, discnum = 3:15,
discvar = names(select(fvc,-c(fvc,lulc))),
cores = 6, type = 'factor')
tictoc::toc()
## 2.92 sec elapsed
## 3.11 sec elapsed
```

``` r
Expand All @@ -74,16 +74,44 @@ fvc_opgd
|:--------:|:-----------:|:---------:|
| presum | 0.6626 | 9.145e-10 |
| lulc | 0.6597 | 8.782e-10 |
| premin | 0.4638 | 8.103e-10 |
| tmpmin | 0.4278 | 5.541e-10 |
| tmpmax | 0.2536 | 7.849e-10 |
| slope | 0.233 | 8.055e-10 |
| elev | 0.2318 | 8.79e-10 |
| tmpavg | 0.2116 | 7.357e-10 |
| pop | 0.1896 | 7.855e-10 |
| premax | 0.1417 | 7.869e-10 |
| premin | 0.4654 | 4.831e-10 |
| tmpmin | 0.4323 | 4.367e-10 |
| tmpmax | 0.2543 | 4.168e-10 |
| elev | 0.2353 | 2.885e-10 |
| slope | 0.2338 | 7.849e-10 |
| tmpavg | 0.2214 | 7.616e-10 |
| pop | 0.1953 | 2.428e-10 |
| premax | 0.1442 | 1.682e-10 |
| ntl | 0.02272 | 0.0301 |
| aspect | 0.0118 | 0.1859 |
| aspect | 0.0186 | 0.7491 |

### GOZH model

``` r
tictoc::tic()
g = gozh(fvc ~ ., data = fvc, cores = 6)
tictoc::tic()
g
## Spatial Stratified Heterogeneity Test
##
## Factor detector
```

| variable | Q-statistic | P-value |
|:---------------------------------:|:-----------:|:---------:|
| Explanatory Variables Association | 0.8052 | 7.146e-10 |
| presum | 0.6372 | 9.492e-11 |
| lulc | 0.6106 | 4.797e-10 |
| premin | 0.4658 | 5.484e-10 |
| tmpmin | 0.4112 | 2.948e-10 |
| tmpmax | 0.2478 | 7.308e-10 |
| slope | 0.2286 | 6.05e-10 |
| pop | 0.2238 | 3.753e-10 |
| elev | 0.2237 | 4.671e-10 |
| tmpavg | 0.2188 | 6.543e-10 |
| premax | 0.1259 | 1.436e-10 |
| ntl | 0.02365 | 1.832e-10 |
| aspect | 0.01413 | 8.938e-09 |

### RGD model

Expand All @@ -93,11 +121,11 @@ vignette to get more details.
``` r
reticulate::use_condaenv('geocompy')
tictoc::tic()
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 15,
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 10,
discvar = names(select(fvc,-c(fvc,lulc))),
cores = 8, type = 'factor')
cores = 6, type = 'factor')
tictoc::toc()
## 2980.2 sec elapsed
## 1886.14 sec elapsed
```

``` r
Expand All @@ -109,15 +137,15 @@ fvc_rgd

| variable | Q-statistic | P-value |
|:--------:|:-----------:|:---------:|
| presum | 0.6745 | 6.166e-10 |
| presum | 0.6678 | 4.284e-10 |
| lulc | 0.6597 | 8.782e-10 |
| premin | 0.4855 | 5.461e-10 |
| tmpmin | 0.4575 | 6.232e-10 |
| tmpmax | 0.2816 | 5.853e-10 |
| elev | 0.2576 | 5.407e-10 |
| pop | 0.2566 | 4.386e-10 |
| slope | 0.2525 | 9.439e-10 |
| tmpavg | 0.2502 | 4.2e-10 |
| premax | 0.1668 | 9.434e-10 |
| aspect | 0.03427 | 0.06239 |
| premin | 0.4781 | 7.04e-10 |
| tmpmin | 0.448 | 5.718e-10 |
| tmpmax | 0.2692 | 3.296e-10 |
| elev | 0.248 | 4.734e-10 |
| slope | 0.2464 | 8.852e-10 |
| pop | 0.2446 | 9.414e-10 |
| tmpavg | 0.2405 | 5.228e-10 |
| premax | 0.1572 | 5.383e-10 |
| aspect | 0.02759 | 0.003456 |
| ntl | 0.02334 | 4.623e-10 |
24 changes: 24 additions & 0 deletions man/gd_rpart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gozh.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a5b60be

Please sign in to comment.