diff --git a/DESCRIPTION b/DESCRIPTION index 64da9ab..25345f9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: onpoint Title: Helper Functions for Point Pattern Analysis -Version: 1.0.5 +Version: 1.0.6 Authors@R: person("Maximilian H.K.", "Hesselbarth", email = "mhk.hesselbarth@gmail.com", @@ -29,5 +29,5 @@ Suggests: spatstat (>= 2.0.0), testthat (>= 3.0.0) Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index 7983db8..c0d84ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,55 +1,58 @@ -# onpoint 1.0.5 -* Streamlined documentation -* Updated testthat v3 -* Updated ggplot2 linewidth internally -* `verbose` does not affect warnings - -# onpoint 1.0.4 -* Update some plotting functions - -# onpoint 1.0.3 -* Small updates to internal code structure -* Fix DESCRIPTION -* Update CI actions -* Update `spatstat` dependency - -# onpoint 1.0.2 -* Adapt new `spatstat` package structure - -# onpoint 1.0.1 -* Improve documentation for CRAN submission -* Renamed `summarise_envelope` to `summarize_envelope` - -# onpoint 1.0 -* Use GPL3 license -* Adapt to new `spatstat` structure -* Prepare CRAN submission - -# onpoint 0.6.1 -* Use GitHub actions - -# onpoint 0.6 -* `plot_quantums()` uses `geom_linerange()` - -# onpoint 0.5 -* add `rlabel_local()` function - -# onpoint 0.4 -* Printing method for result of `summarise_envelope()` -* Plotting method for result of `summarise_envelope()` - -# onpoint 0.3 -* New function `summarise_envelope()` - -# onpoint 0.2.1 -* Better size arguments for lines and base_size for `plot_quantums()` -* Generic labels for `plot_quantums()` -* Use fix_n argument in `simulate_heterogenous_patter()` - -# onpoint 0.2.0 -* Added `simulate_antecedent_conditions`. -* Added `estimate_pcf_fast` - -# onpoint 0.1.0 -* Initialised package -* Added a `NEWS.md` file to track changes to the package. +# onpoint 1.0.6 +* Order of stable `i` and randomized pattern `j` changed in `simulate_antecedent_conditions` + +# onpoint 1.0.5 +* Streamlined documentation +* Updated testthat v3 +* Updated ggplot2 linewidth internally +* `verbose` does not affect warnings + +# onpoint 1.0.4 +* Update some plotting functions + +# onpoint 1.0.3 +* Small updates to internal code structure +* Fix DESCRIPTION +* Update CI actions +* Update `spatstat` dependency + +# onpoint 1.0.2 +* Adapt new `spatstat` package structure + +# onpoint 1.0.1 +* Improve documentation for CRAN submission +* Renamed `summarise_envelope` to `summarize_envelope` + +# onpoint 1.0 +* Use GPL3 license +* Adapt to new `spatstat` structure +* Prepare CRAN submission + +# onpoint 0.6.1 +* Use GitHub actions + +# onpoint 0.6 +* `plot_quantums()` uses `geom_linerange()` + +# onpoint 0.5 +* add `rlabel_local()` function + +# onpoint 0.4 +* Printing method for result of `summarise_envelope()` +* Plotting method for result of `summarise_envelope()` + +# onpoint 0.3 +* New function `summarise_envelope()` + +# onpoint 0.2.1 +* Better size arguments for lines and base_size for `plot_quantums()` +* Generic labels for `plot_quantums()` +* Use fix_n argument in `simulate_heterogenous_patter()` + +# onpoint 0.2.0 +* Added `simulate_antecedent_conditions`. +* Added `estimate_pcf_fast` + +# onpoint 0.1.0 +* Initialised package +* Added a `NEWS.md` file to track changes to the package. diff --git a/R/simulate_antecedent_conditions.R b/R/simulate_antecedent_conditions.R index 6f5000e..8e886c6 100644 --- a/R/simulate_antecedent_conditions.R +++ b/R/simulate_antecedent_conditions.R @@ -3,19 +3,20 @@ #' @description Simulate heterogenous pattern #' #' @param x ppp -#' @param i Mark of points that are randomized. -#' @param j Mark of points that do not change. +#' @param i Mark of points that are not not changed. +#' @param j Mark of points that are randomized. #' @param nsim Number of patterns to simulate. -#' @param heterogenous If TRUE, points with the mark i are randomized using a heterogeneous +#' @param heterogenous If TRUE, points with the mark j are randomized using a heterogeneous #' Poisson process. #' @param ... Arguments passed to \code{spatstat.explore::density.ppp()}. #' #' @details #' Simulate point patterns as null model data for \code{spatstat.explore::envelope()} using -#' antecedent conditions as null model. \code{x} must be marked point pattern. -#' Antecedent conditions are suitable as a null model if points of type j may influence -#' points of type i, but not the other way around (Velazquez et al 2016). One example are -#' the positions of seedlings that may be influenced by the position of mature trees. +#' antecedent conditions as null model. \code{x} must be a marked point pattern with +#' two types of marks. Antecedent conditions are suitable as a null model if points +#' of type i may influence points of type j, but not the other way around (Velazquez et al 2016). +#' One example are the positions of seedlings that may be influenced by the position +#' of mature trees. #' #' Returns a \code{list} with \code{ppp} objects. #' @@ -32,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 = "b", j = "a", nsim = 19) +#' null_model <- simulate_antecedent_conditions(x = pattern, i = "a", j = "b", nsim = 19) #' spatstat.explore::envelope(Y = pattern, fun = spatstat.explore::pcf, #' nsim = 19, simulate = null_model) #' @@ -62,41 +63,32 @@ simulate_antecedent_conditions <- function(x, i, j, nsim, heterogenous = FALSE, stop("i and j must be marks of x.", call. = FALSE) } - # only points with mark j - pattern_j <- spatstat.geom::subset.ppp(x, marks == j, drop = TRUE) - - # only points with mark i + # only points with mark i to keep stable pattern_i <- spatstat.geom::subset.ppp(x, marks == i, drop = TRUE) - if (heterogenous) { + # only points with mark j to randomze + pattern_j <- spatstat.geom::subset.ppp(x, marks == j, drop = TRUE) - lambda_xy <- spatstat.explore::density.ppp(pattern_i, ...) + if (heterogenous) { + lambda_j <- spatstat.explore::density.ppp(pattern_j, ...) } # create nsim patterns result <- lapply(seq_len(length.out = nsim), function(current_nsim) { + # use heterogeneous Poisson if (!heterogenous) { - - # random pattern i - random_i <- spatstat.random::rpoint(n = pattern_i$n, - win = pattern_i$window) - } - - else { - - # random pattern i - random_i <- spatstat.random::rpoint(n = pattern_i$n, - f = lambda_xy, - win = x$window) + random_j <- spatstat.random::rpoint(n = pattern_j$n, win = pattern_j$window) + # use homogenous Poisson + } else { + random_j <- spatstat.random::rpoint(n = pattern_j$n, f = lambda_j, win = x$window) } # assign same marks again - spatstat.geom::marks(random_i) <- spatstat.geom::marks(pattern_i) + spatstat.geom::marks(random_j) <- spatstat.geom::marks(pattern_j) # combine random i with original j - pattern_combined <- spatstat.geom::superimpose(j = pattern_j, - i = random_i, + pattern_combined <- spatstat.geom::superimpose(i = pattern_i, j = random_j, W = pattern_j$window) # select only original marks diff --git a/README.Rmd b/README.Rmd index 6d9a75f..e24bde5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -25,7 +25,7 @@ README Last updated: `r Sys.Date()` [![Project Status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) [![CRAN status](https://www.r-pkg.org/badges/version/onpoint)](https://CRAN.R-project.org/package=onpoint) -[![CRAN logs](http://cranlogs.r-pkg.org/badges/grand-total/onpoint)](http://cran.rstudio.com/web/packages/onpoint/index.html) +[![CRAN logs](https://cranlogs.r-pkg.org/badges/grand-total/onpoint)](http://cran.rstudio.com/web/packages/onpoint/index.html) [![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) diff --git a/README.md b/README.md index 5b6a6cc..78aedac 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ -README Last updated: 2023-03-08 +README Last updated: 2024-07-29 [![R-CMD-check](https://github.com/r-spatialecology/onpoint/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-spatialecology/onpoint/actions/workflows/R-CMD-check.yaml) [![codecov](https://codecov.io/gh/r-spatialecology/onpoint/branch/main/graph/badge.svg?token=RkgCfHnPyf)](https://codecov.io/gh/r-spatialecology/onpoint) @@ -15,7 +15,7 @@ Status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repost [![CRAN status](https://www.r-pkg.org/badges/version/onpoint)](https://CRAN.R-project.org/package=onpoint) [![CRAN -logs](http://cranlogs.r-pkg.org/badges/grand-total/onpoint)](http://cran.rstudio.com/web/packages/onpoint/index.html) +logs](https://cranlogs.r-pkg.org/badges/grand-total/onpoint)](http://cran.rstudio.com/web/packages/onpoint/index.html) [![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) diff --git a/cran-comments.md b/cran-comments.md index 17af412..9d3269f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,36 +1,39 @@ -# onpoint 1.0.5 -* Minor cosmetic updates - -# onpoint 1.0.4 -* Some small function updates - -# onpoint 1.0.3 -* Small DESCRIPTION fixes - -# onpoint 1.0.2 -* Adapt new `spatstat` package structure - -# onpoint 1.0.1 -Please add some more details about the package functionality and implemented methods in your Description text. - -* Done as suggested - -Please add \value to .Rd files regarding exported methods and explain the functions results in the documentation. [...] - -* Done as suggested - -# onpoint 1.0 -* First submission to CRAN - -## Test environments -* local R installation, R 4.1.1 -* GitHub Actions - * {os: windows-latest, r: 'release'} - * {os: macOS-latest, r: 'release'} - * {os: ubuntu-20.04, r: 'release'} - -## R CMD check results - -0 errors ✓ | 0 warnings ✓ | 0 notes ✓ - -* This is a new release. +# onpoint 1.0.6 +* Minor methodological improvements + +# onpoint 1.0.5 +* Minor cosmetic updates + +# onpoint 1.0.4 +* Some small function updates + +# onpoint 1.0.3 +* Small DESCRIPTION fixes + +# onpoint 1.0.2 +* Adapt new `spatstat` package structure + +# onpoint 1.0.1 +Please add some more details about the package functionality and implemented methods in your Description text. + +* Done as suggested + +Please add \value to .Rd files regarding exported methods and explain the functions results in the documentation. [...] + +* Done as suggested + +# onpoint 1.0 +* First submission to CRAN + +## Test environments +* local R installation, R 4.1.1 +* GitHub Actions + * {os: windows-latest, r: 'release'} + * {os: macOS-latest, r: 'release'} + * {os: ubuntu-20.04, r: 'release'} + +## R CMD check results + +0 errors ✓ | 0 warnings ✓ | 0 notes ✓ + +* This is a new release. diff --git a/man/figures/README-plot_antecedent-1.png b/man/figures/README-plot_antecedent-1.png index d1ed57b..bcdb195 100644 Binary files a/man/figures/README-plot_antecedent-1.png and b/man/figures/README-plot_antecedent-1.png differ diff --git a/man/figures/README-plot_hetero-1.png b/man/figures/README-plot_hetero-1.png index d2ac8bd..2559f47 100644 Binary files a/man/figures/README-plot_hetero-1.png and b/man/figures/README-plot_hetero-1.png differ diff --git a/man/figures/README-plot_oring-1.png b/man/figures/README-plot_oring-1.png index 0e413a1..a6461ba 100644 Binary files a/man/figures/README-plot_oring-1.png and b/man/figures/README-plot_oring-1.png differ diff --git a/man/figures/README-plot_quantums-1.png b/man/figures/README-plot_quantums-1.png index 282d75e..18e3031 100644 Binary files a/man/figures/README-plot_quantums-1.png and b/man/figures/README-plot_quantums-1.png differ diff --git a/man/onpoint.Rd b/man/onpoint.Rd index 75a87c6..3d96817 100644 --- a/man/onpoint.Rd +++ b/man/onpoint.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/onpoint-package.R \docType{package} \name{onpoint} -\alias{onpoint} \alias{onpoint-package} +\alias{onpoint} \title{onpoint} \description{ Growing collection of small helper functions for point pattern analysis. Most functions diff --git a/man/simulate_antecedent_conditions.Rd b/man/simulate_antecedent_conditions.Rd index 6b25496..b69066e 100644 --- a/man/simulate_antecedent_conditions.Rd +++ b/man/simulate_antecedent_conditions.Rd @@ -9,13 +9,13 @@ simulate_antecedent_conditions(x, i, j, nsim, heterogenous = FALSE, ...) \arguments{ \item{x}{ppp} -\item{i}{Mark of points that are randomized.} +\item{i}{Mark of points that are not not changed.} -\item{j}{Mark of points that do not change.} +\item{j}{Mark of points that are randomized.} \item{nsim}{Number of patterns to simulate.} -\item{heterogenous}{If TRUE, points with the mark i are randomized using a heterogeneous +\item{heterogenous}{If TRUE, points with the mark j are randomized using a heterogeneous Poisson process.} \item{...}{Arguments passed to \code{spatstat.explore::density.ppp()}.} @@ -28,10 +28,11 @@ Simulate heterogenous pattern } \details{ Simulate point patterns as null model data for \code{spatstat.explore::envelope()} using -antecedent conditions as null model. \code{x} must be marked point pattern. -Antecedent conditions are suitable as a null model if points of type j may influence -points of type i, but not the other way around (Velazquez et al 2016). One example are -the positions of seedlings that may be influenced by the position of mature trees. +antecedent conditions as null model. \code{x} must be a marked point pattern with +two types of marks. Antecedent conditions are suitable as a null model if points +of type i may influence points of type j, but not the other way around (Velazquez et al 2016). +One example are the positions of seedlings that may be influenced by the position +of mature trees. Returns a \code{list} with \code{ppp} objects. } @@ -43,7 +44,7 @@ pattern_b <- spatstat.random::runifpoint(n = 100) spatstat.geom::marks(pattern_b) <- "b" pattern <- spatstat.geom::superimpose(pattern_a, pattern_b) -null_model <- simulate_antecedent_conditions(x = pattern, i = "b", j = "a", nsim = 19) +null_model <- simulate_antecedent_conditions(x = pattern, i = "a", j = "b", nsim = 19) spatstat.explore::envelope(Y = pattern, fun = spatstat.explore::pcf, nsim = 19, simulate = null_model) diff --git a/onpoint.Rproj b/onpoint.Rproj index 8f290f9..3509a42 100644 --- a/onpoint.Rproj +++ b/onpoint.Rproj @@ -1,22 +1,22 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -AutoAppendNewline: Yes -StripTrailingWhitespace: Yes - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source -PackageCheckArgs: --no-multiarch --as-cran -PackageRoxygenize: rd,collate,namespace,vignette +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageCheckArgs: --no-multiarch --as-cran +PackageRoxygenize: rd,collate,namespace,vignette diff --git a/tests/testthat/test-simulate_antecedent_conditions.R b/tests/testthat/test-simulate_antecedent_conditions.R index 26151de..ba1b705 100644 --- a/tests/testthat/test-simulate_antecedent_conditions.R +++ b/tests/testthat/test-simulate_antecedent_conditions.R @@ -17,30 +17,29 @@ test_that("simulate_antecedent_conditions returns nsim", { expect_length(null_model, n = 19) }) -test_that("simulate_antecedent_conditions does not randomize pattern j", { +test_that("simulate_antecedent_conditions does not randomize pattern i", { - null_model <- simulate_antecedent_conditions(x = pattern, - i = "b", j = "a", + null_model <- simulate_antecedent_conditions(x = pattern, i = "b", j = "a", nsim = 19) - pattern_j <- spatstat.geom::subset.ppp(null_model[[1]], marks == "a") + pattern_i <- spatstat.geom::subset.ppp(null_model[[1]], marks == "b") - check <- all(spatstat.geom::coords(pattern_j) == - spatstat.geom::coords(spatstat.geom::subset.ppp(pattern, marks == "a"))) + check <- all(spatstat.geom::coords(pattern_i) == + spatstat.geom::coords(spatstat.geom::subset.ppp(pattern, marks == "b"))) expect_true(check) }) -test_that("simulate_antecedent_conditions randomizes pattern i", { +test_that("simulate_antecedent_conditions randomizes pattern j", { null_model <- simulate_antecedent_conditions(x = pattern, i = "b", j = "a", nsim = 19) - pattern_i <- spatstat.geom::subset.ppp(null_model[[1]], marks == "b") + pattern_j <- spatstat.geom::subset.ppp(null_model[[1]], marks == "a") - check <- all(spatstat.geom::coords(pattern_i) != - spatstat.geom::coords(spatstat.geom::subset.ppp(pattern, marks == "b"))) + check <- all(spatstat.geom::coords(pattern_j) != + spatstat.geom::coords(spatstat.geom::subset.ppp(pattern, marks == "a"))) expect_true(check) })