Skip to content

Commit

Permalink
Merge pull request #25 from r-spatialecology/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mhesselbarth authored Feb 10, 2025
2 parents f68faf6 + 9062aab commit c783cfc
Show file tree
Hide file tree
Showing 41 changed files with 159 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Deploy-pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

on:
push:
branches: [main, development]
branches: [main, dev]
tags: ['*']
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

on:
push:
branches: [main, development]
branches: [main, dev]
pull_request:
branches: [main]
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Render-README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

on:
push:
branches: [main, development]
branches: [main, dev]
paths: ["README.Rmd"]
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

on:
push:
branches: [main, development]
branches: [main, dev]
pull_request:
branches: [main]
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
docs
CRAN-SUBMISSION
.DS_Store
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: onpoint
Title: Helper Functions for Point Pattern Analysis
Version: 1.0.6
Version: 1.1
Authors@R:
person("Maximilian H.K.", "Hesselbarth",
email = "[email protected]",
Expand Down
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

S3method(plot,env_summarized)
S3method(print,env_summarized)
export(Oest)
export(balance_points)
export(center_l_function)
export(estimate_o_ring)
export(estimate_pcf_fast)
export(center_Lest)
export(pcf_fast)
export(plot_quantums)
export(rheteroppp)
export(rlabel_local)
export(simulate_antecedent_conditions)
export(simulate_heterogenous_pattern)
export(simulate_antecedent)
export(summarize_envelope)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# onpoint 1.1
* Improved function names

# onpoint 1.0.6
* Order of stable `i` and randomized pattern `j` changed in `simulate_antecedent_conditions`
* Fix anchors in documentation
Expand Down
6 changes: 3 additions & 3 deletions R/estimate_o_ring.R → R/Oest.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' estimate_o_ring
#' Oest
#'
#' @description O-ring function
#'
Expand Down Expand Up @@ -26,7 +26,7 @@
#'
#' @examples
#' input_pattern <- spatstat.random::runifpoint(n = 100)
#' estimate_o_ring(input_pattern)
#' Oest(input_pattern)
#'
#' @references
#' Wiegand, T., Moloney, K.A., 2004. Rings, circles, and null models for point pattern
Expand All @@ -36,7 +36,7 @@
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @export
estimate_o_ring <- function(x, ...) {
Oest <- function(x, ...) {

if (!spatstat.geom::is.ppp(x)) {
stop("Please provide ppp.")
Expand Down
4 changes: 2 additions & 2 deletions R/balance_points.R → R/balance-points.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#'
#' @details
#' The function balances out the number of points in the input pattern to either
#' the provided number of points as integer or the same number of points if a \code{ppp}
#' object is provided.
#' the provided number of points as integer or the same number of points if a
#' \code{ppp} object is provided.
#'
#' @return ppp
#'
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions R/center_l_function.R → R/center-Lest.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' center_l_function
#' center_Lest
#'
#' @description Centered L-function
#'
Expand All @@ -18,10 +18,10 @@
#'
#' @examples
#' input_pattern <- spatstat.random::runifpoint(n = 100)
#' center_l_function(input_pattern, correction = "Ripley")
#' center_Lest(input_pattern, correction = "Ripley")
#'
#' lest <- spatstat.explore::Lest(input_pattern)
#' center_l_function(lest)
#' center_Lest(lest)
#'
#' @references
#' Besag, J.E., 1977. Discussion on Dr. Ripley’s paper. Journal of the Royal Statistical
Expand All @@ -36,7 +36,7 @@
#' <https://doi.org/10.2307/3236356>
#'
#' @export
center_l_function <- function(x, ...) {
center_Lest <- function(x, ...) {

if (!spatstat.geom::is.ppp(x) && !spatstat.geom::is.fv(x)) {
stop("Please provide either ppp or fv object.")
Expand Down
6 changes: 3 additions & 3 deletions R/estimate_pcf_fast.R → R/pcf-fast.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' estimate_pcf_fast
#' pcf_fast
#'
#' @description Fast estimation of the pair correlation function
#'
Expand All @@ -22,7 +22,7 @@
#' @examples
#' set.seed(42)
#' pattern <- spatstat.random::runifpoint(n = 100)
#' pcf_fast <- estimate_pcf_fast(pattern)
#' pcf_fast <- pcf_fast(pattern)
#'
#' @references
#' Ripley, B.D., 1977. Modelling spatial patterns. Journal of the Royal Statistical Society.
Expand All @@ -32,7 +32,7 @@
#' John Wiley & Sons, Chichester, UK. <isbn:978-0-471-93757-9>
#'
#' @export
estimate_pcf_fast <- function(pattern, ...){
pcf_fast <- function(pattern, ...){

k_fun <- suppressMessages(spatstat.explore::Kest(X = pattern, ...)) # estimate K-fct

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions R/simulate_heterogenous_pattern.R → R/rheteroppp.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' simulate_heterogenous_pattern
#' rheteroppp
#'
#' @description Simulate heterogeneous pattern
#'
Expand All @@ -23,7 +23,7 @@
#' @examples
#' set.seed(42)
#' input_pattern <- spatstat.random::rpoispp(lambda = function(x , y) {100 * exp(-3 * x)}, nsim = 1)
#' null_model <- simulate_heterogenous_pattern(input_pattern, nsim = 19)
#' null_model <- rheteroppp(input_pattern, nsim = 19)
#' spatstat.explore::envelope(Y = input_pattern, fun = spatstat.explore::pcf, nsim = 19,
#' simulate = null_model)
#'
Expand All @@ -35,7 +35,7 @@
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @export
simulate_heterogenous_pattern <- function(x, nsim, fix_n = FALSE, ...) {
rheteroppp <- function(x, nsim, fix_n = FALSE, ...) {

if (!inherits(x = x, what = "ppp")) {
stop("Please provide ppp object.", call. = FALSE)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' simulate_antecedent_conditions
#' simulate_antecedent
#'
#' @description Simulate heterogenous pattern
#'
Expand Down Expand Up @@ -33,7 +33,7 @@
#' spatstat.geom::marks(pattern_b) <- "b"
#' pattern <- spatstat.geom::superimpose(pattern_a, pattern_b)
#'
#' null_model <- simulate_antecedent_conditions(x = pattern, i = "a", j = "b", nsim = 19)
#' null_model <- simulate_antecedent(x = pattern, i = "a", j = "b", nsim = 19)
#' spatstat.explore::envelope(Y = pattern, fun = spatstat.explore::pcf,
#' nsim = 19, simulate = null_model)
#'
Expand All @@ -46,7 +46,7 @@
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @export
simulate_antecedent_conditions <- function(x, i, j, nsim, heterogenous = FALSE, ...) {
simulate_antecedent <- function(x, i, j, nsim, heterogenous = FALSE, ...) {

# check if pattern ist marked
if (!spatstat.geom::is.marked(x)) {
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 12 additions & 13 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ data(spruces)

Currently, `onpoint` provides three second-order summary functions, namely Besag's L-function centered to zero and the O-ring statistic and a fast estimation of the pair-correlation function.

Centering Besag's L-function to zero has the advantage of an easier interpretation and plotting (Haase 1995). The function `center_l_function()` can either deal with a point pattern and calculated the centered L-function directly, or center the L-function afterwards it was calculating using `spatstat`s `Lest()`.
Centering Besag's L-function to zero has the advantage of an easier interpretation and plotting (Haase 1995). The function `center_Lest()` can either deal with a point pattern and calculated the centered L-function directly, or center the L-function afterwards it was calculating using `spatstat`s `Lest()`.

```{r calc_lfun}
# calculate L-function
l_function <- Lest(spruces, correction = "Ripley")
# center L-function to zero
# center_l_function <- center_l_function(l_function)
l_function_centered <- center_l_function(spruces, correction = "Ripley")
l_function_centered <- center_Lest(spruces, correction = "Ripley")
```

```{r plot_lfun, echo = FALSE, fig.width = 10, fig.height = 5, fig.align = "center"}
Expand All @@ -76,10 +75,10 @@ plot(l_function_centered, main = "centered Besag's L-function")
par(mfrow = c(1, 1))
```

The O-ring statistic O(r) (Wiegand & Moloney 2004) can be calculated using `estimate_o_ring()`. Generally speaking, O(r) scales the pair correlation g(r) function with help of the intensity \eqn{\lambda}. One advantage of the O-ring statistic is that it can be interpreted as a neighborhood density because it is a probability density function (Wiegand & Moloney 2004).
The O-ring statistic O(r) (Wiegand & Moloney 2004) can be calculated using `Oest()`. Generally speaking, O(r) scales the pair correlation g(r) function with help of the intensity \eqn{\lambda}. One advantage of the O-ring statistic is that it can be interpreted as a neighborhood density because it is a probability density function (Wiegand & Moloney 2004).

```{r calc_oring}
o_ring <- estimate_o_ring(spruces)
o_ring <- Oest(spruces)
```

Of course, both summary functions can be used in combination with `spatstat`'s `envelope()` function.
Expand All @@ -92,20 +91,20 @@ oring_envelope <- envelope(spruces, fun = estimate_o_ring, nsim = 199, verbose =
plot(oring_envelope, main = "O-ring statistic")
```

`estimate_pcf_fast()` estimates the pair-correlation function based on Ripley's K-function, which is faster than estimation the pair-correlation function directly.
`pcf_fast()` estimates the pair-correlation function based on Ripley's K-function, which is faster than estimation the pair-correlation function directly.

```{r calc_fast, collapse = TRUE}
estimate_pcf_fast(spruces)
pcf_fast(spruces)
```

### Null models

`onpoint` includes two functions to simulate null model patterns.

`simulate_heterogenous_pattern()` is a convienent wrapper around a few `spatstat` functions to straighforward simulate a heterogeneous Poisson process.
`rheteroppp()` is a convienent wrapper around a few `spatstat` functions to straighforward simulate a heterogeneous Poisson process.

```{r calc_hetero}
null_model_hetero <- simulate_heterogenous_pattern(spruces, nsim = 199)
null_model_hetero <- rheteroppp(spruces, nsim = 199)
hetero <- envelope(spruces, fun = pcf,
funargs = list(correction = "Ripley", divisor = "d"),
Expand All @@ -117,13 +116,13 @@ hetero <- envelope(spruces, fun = pcf,
plot(hetero, main = "Heterogeneous Poisson process")
```

To simulate antecedent conditions in which only one pattern influences the other, but not the other way around (Wiegand & Moloney 2004, Velazquez et al. 2016), `simulate_antecedent_conditions()` can be used. This null model randomizes only one type of points (e.g. seedlings), while keeping the other type of points constant (e.g. mature trees) to check for associations between the two.
To simulate antecedent conditions in which only one pattern influences the other, but not the other way around (Wiegand & Moloney 2004, Velazquez et al. 2016), `simulate_antecedent()` can be used. This null model randomizes only one type of points (e.g. seedlings), while keeping the other type of points constant (e.g. mature trees) to check for associations between the two.

```{r calc_antecedent}
marks(spruces) <- ifelse(marks(spruces) > 0.3, yes = "adult", no = "seedling")
null_model_antecedent <- simulate_antecedent_conditions(spruces,
i = "seedling", j = "adult", nsim = 199)
null_model_antecedent <- simulate_antecedent(spruces, i = "seedling", j = "adult",
nsim = 199)
antecedent <- envelope(spruces, fun = pcf,
funargs = list(correction = "Ripley", divisor = "d"),
Expand All @@ -137,7 +136,7 @@ plot(antecedent, main = "Antecedent conditions")

### Various

To plot simulation envelopes using quantum plots (e.g. Esser et al. 2015), just pass an `envelope` object as input to `plot_quantums()`.
To plot simulation envelopes using quantum plots (e.g., Esser et al. 2015), just pass an `envelope` object as input to `plot_quantums()`.

```{r plot_quantums, fig.width = 7.5, fig.height = 5, fig.align = "center"}
plot_quantums(antecedent, ylab = "g(r)")
Expand Down
10 changes: 5 additions & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ template:
reference:
- title: Summary functions
contents:
- center_l_function
- estimate_o_ring
- estimate_pcf_fast
- center_Lest
- Oest
- pcf_fast
- summarize_envelope

- title: Null models
contents:
- rlabel_local
- simulate_heterogenous_pattern
- simulate_antecedent_conditions
- rheteroppp
- simulate_antecedent

- title: Various
contents:
Expand Down
3 changes: 3 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# onpoint 1.1
* Improved function names

# onpoint 1.0.6
* Minor methodological improvements

Expand Down
12 changes: 6 additions & 6 deletions man/estimate_o_ring.Rd → man/Oest.Rd

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

6 changes: 3 additions & 3 deletions man/balance_points.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/calc_area.Rd

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

14 changes: 7 additions & 7 deletions man/center_l_function.Rd → man/center_Lest.Rd

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

Loading

0 comments on commit c783cfc

Please sign in to comment.