Skip to content

Commit

Permalink
release spEcula 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Jun 23, 2024
1 parent 74dc9d1 commit 2bec676
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 51 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: spEcula
Title: Spatial Prediction Methods In R
Version: 0.1.2.9000
Version: 0.1.3
Authors@R: c(
person("Wenbo", "Lv", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0002-6003-3800")),
Expand Down
16 changes: 16 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ export(gos)
export(gos_bestkappa)
export(inverse_bcPower)
export(sandwich)
importFrom(dplyr,all_of)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,pick)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
Expand All @@ -21,7 +28,16 @@ importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(purrr,map_dfr)
importFrom(sf,st_area)
importFrom(sf,st_as_sf)
importFrom(sf,st_drop_geometry)
importFrom(sf,st_geometry)
importFrom(sf,st_intersection)
importFrom(sf,st_join)
importFrom(sf,st_union)
importFrom(stats,as.formula)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(tibble,as_tibble)
importFrom(tidyr,replace_na)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

* support more advanced spatial methods.

# spEcula 0.1.3

* Remove spatial hierarchical heterogeneity test, please consider the [**gdverse**](https://spatlyu.github.io/gdverse) package for related functions.

# spEcula 0.1.2

* Support GOS and sandwich mapping model.
3 changes: 0 additions & 3 deletions R/gos.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ gos_bestkappa = \(formula, data = NULL, kappa = seq(0.05,1,0.05),
cv.out = out_rmse %>%
dplyr::summarise(rmse = mean(rmse,na.rm = T),
.by = kappa)

k = which(cv.out$rmse == min(cv.out$rmse))[1]
best_kappa = cv.out$kappa[k]

Expand All @@ -227,11 +226,9 @@ gos_bestkappa = \(formula, data = NULL, kappa = seq(0.05,1,0.05),
max(cv.out$rmse))) +
ggplot2::theme_bw()


out = list("bestkappa" = best_kappa,
"cvrmse" = out_rmse,
"cvmean" = cv.out,
"plot" = p1)

return(out)
}
4 changes: 4 additions & 0 deletions R/sandwich.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#' Default is `area`.
#'
#' @return A `sf` object with estimated mean `sandwichest_mean` and standard error `sandwichest_standarderror`.
#' @importFrom sf st_as_sf st_join st_drop_geometry st_intersection st_union
#' @importFrom dplyr group_by pick group_by summarise n ungroup select left_join mutate all_of
#' @importFrom tidyr replace_na
#' @importFrom stats var
#' @export
#'
#' @examples
Expand Down
2 changes: 2 additions & 0 deletions R/spEcula_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CalRMSE = \(yobse,ypred){
}

#' @title Rename sf object geometry name
#' @importFrom sf st_geometry
#' @noRd
st_rename_geometry = \(g, name){
current = attr(g, "sf_column")
Expand All @@ -40,6 +41,7 @@ st_rename_geometry = \(g, name){
}

#' @title Calculate the area of the polygon element using the specified unit
#' @importFrom sf st_area
#' @noRd
st_geographical_area = \(g){
garea = g %>%
Expand Down
27 changes: 13 additions & 14 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ knitr::opts_chunk$set(

The goal of **spEcula** is to make it easier to use **R** for **spatial prediction** based on **various spatial relationships** (e.g. spatial dependence, spatial heterogeneity and geographical similarity).

## Overview

Full document of the most recent release of **spEcula** is online:
<https://spatlyu.github.io/spEcula/>

Current models and functions provided by **spEcula** are:

| **spatial prediction method** | **spEcula function** | **support status** |
|-----------------------------------|--------------------------|------------------------|
| Geographically Optimal Similarity | `gos()` | ✔️ |
| Sandwich Mapping Model | `sandwich()` | ✔️ |


## Installation

You can install the development version of *spEcula* from [*github*](https://github.com/SpatLyu/spEcula):
Expand Down Expand Up @@ -89,20 +102,6 @@ plot_grid(f1,f2,nrow = 1,label_fontfamily = 'serif',
p
```

### Spatial Stratified Heterogeneity Test

```{r example_ssh_test}
library(spEcula)
data(NTDs)
head(NTDs)
```

```{r}
fd = ssh.test(incidence ~ watershed + elevation + soiltype,
data = NTDs,type = 'factor')
fd
```

### Sandwich Mapping Model

```{r sandwich,fig.width=5.5,fig.height=3.5}
Expand Down
46 changes: 13 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ The goal of **spEcula** is to make it easier to use **R** for **spatial
prediction** based on **various spatial relationships** (e.g. spatial
dependence, spatial heterogeneity and geographical similarity).

## Overview

Full document of the most recent release of **spEcula** is online:
<https://spatlyu.github.io/spEcula/>

Current models and functions provided by **spEcula** are:

| **spatial prediction method** | **spEcula function** | **support status** |
|-----------------------------------|----------------------|--------------------|
| Geographically Optimal Similarity | `gos()` | ✔️ |
| Sandwich Mapping Model | `sandwich()` | ✔️ |

## Installation

You can install the development version of *spEcula* from
Expand Down Expand Up @@ -45,7 +57,7 @@ tictoc::tic()
g1 = gos(Zn ~ Slope + Water + NDVI + SOC + pH + Road + Mine,
data = zn, newdata = grid, kappa = 0.08,cores = 6)
tictoc::toc()
## 6.85 sec elapsed
## 6.6 sec elapsed
```

``` r
Expand Down Expand Up @@ -99,38 +111,6 @@ p

<img src="man/figures/README-gos_result-1.png" width="100%" />

### Spatial Stratified Heterogeneity Test

``` r
library(spEcula)
data(NTDs)
head(NTDs)
## # A tibble: 6 × 5
## SP_ID incidence watershed elevation soiltype
## <chr> <dbl> <int> <int> <int>
## 1 0 5.94 5 5 5
## 2 1 5.87 5 5 4
## 3 2 5.88 5 5 5
## 4 3 5.98 5 5 5
## 5 4 5.96 5 5 1
## 6 5 5.66 5 5 4
```

``` r
fd = ssh.test(incidence ~ watershed + elevation + soiltype,
data = NTDs,type = 'factor')
fd
## Spatial Stratified Heterogeneity Test
##
## Factor detector
```

| variable | Q-statistic | P-value |
|:---------:|:-----------:|:---------:|
| watershed | 0.6378 | 0.0001288 |
| elevation | 0.6067 | 0.04338 |
| soiltype | 0.3857 | 0.3721 |

### Sandwich Mapping Model

``` r
Expand Down

0 comments on commit 2bec676

Please sign in to comment.