Skip to content

Commit

Permalink
Updates for vignette for v0.2.0 and documentation fixes
Browse files Browse the repository at this point in the history
Updated vignette with new package changes
* 'spatstat.geom' and 'sf' packages
*  New color for Navy Yard plot
* Updated documentation of various hypothesis testing
* Changed `lower_tail` argument in `spatial_power()` to `alpha` argument
* Fixed colors and typos
* Use `cut()` function instead of `reclassify()` function from 'raster' package

Renamed internal `wind` argument in `spatial_power()` as `win` to match `jitter_power()`

Updated documentation with correct order of `cols` in `spatial_plots()` function
  • Loading branch information
Ian Buller, PhD, MA committed Feb 6, 2021
1 parent 74b4b34 commit 627a28c
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 398 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sparrpowR
Title: Power Analysis to Detect Spatial Relative Risk Clusters
Version: 0.2.0
Date: 2021-02-05
Date: 2021-02-06
Authors@R:
c(person(given = "Ian D.",
family = "Buller",
Expand Down
12 changes: 7 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Updates to dependencies
* Updated 'spatstat' package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). 'spatstat.geom' and 'spatstat.core' packages replace 'spatstat' package in Depends
* Imports 'lifecycle' package to document deprecated argument `cascon` in `spatial_power()` and `jitter_power()` functions
* Replaced 'parallel' and 'doParallel' packages in Imports with 'doFuture', 'doRNG', and 'future' packages to allow for parallel processing in `spatial_power()` and `jitter_power()` functions to work across environments
* Replaced 'parallel' and 'doParallel' packages in Imports with 'doFuture', 'doRNG', and 'future' packages to allow for parallel processing in `spatial_power()` and `jitter_power()` functions to work across all CRAN environments
* Removed 'utils' package from Imports because the progress bar in `spatial_power()` and `jitter_power()` functions is now produced with a helper function in utils.R that imports the 'iterators' package
* Removed 'tidyverse' package from Suggests
* Changes to DESCRIPTION
Expand All @@ -29,9 +29,10 @@
* Added `plot_axes` argument to toggle the display of axes in plots
* Added `plot_square` argument to toggle the margins of plots
* Changed the value of `cex.axis` and `cex` in plots
* Updated documentation with correct order of `cols`
* Changes to `jitter_power()`
* Added `p_correct` argument to apply a multiple testing correction
* Specify all packages for functions
* Specified all packages for functions
* Deprecated `cascon` argument (moved to `spatial_plots()` function)
* Estimates case-only power (lower tail) and case/control (lower and upper tail) and captures both outputs. Case-only is now a one-tailed hypothesis test by default. The arguments `lower_tail` and `upper_tail` have been replaced with argument `alpha`
* Used `as.solist()` to specify appropriate class to lists
Expand All @@ -42,9 +43,10 @@
* Increased the `sim_total` value for a more realistic example
* Specify all packages for functions
* Updated code to reflect updates to functions in 'sparrpowR'
* Changes to README.md
* Added CRAN badges
* Added plotting for case and control clustering
* Updated code to use 'sf' package
* Updated explanation of the `cascon` argument to plot various hypothesis tests
* Changed `cols` values to be more visible
* Used `cut` instead of `reclassify` in 'raster' package for categorical plot
* Added utils.R file
* Removed the helper `comb()` function functions from `jitter_power()`, `spatial_power()`, and `spatial_plots()` and added to the utils.R file
* Removed 'utils' package from Imports because the progress bar in `spatial_power()` and `jitter_power()` functions is now produced with a helper `progBar()` function
Expand Down
6 changes: 3 additions & 3 deletions R/jitter_power.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
#'
#' The function uses the \code{\link[sparr]{risk}} function to estimate the spatial relative risk function and forces the \code{tolerate} argument to be TRUE in order to calculate asymptotic p-values.
#'
#' If \code{samp_control = "uniform"} the control locations are randomly generated uniformly within the window of \code{obs_data}. By default, the resolution is an integer value of 128 and can be specified using the \code{resolution} argument in the internally called \code{\link[sparr]{risk}} function.
#' If \code{samp_control = "uniform"} the control locations are randomly generated uniformly within the dow of \code{obs_data}. By default, the resolution is an integer value of 128 and can be specified using the \code{resolution} argument in the internally called \code{\link[sparr]{risk}} function.
#'
#' If \code{samp_control = "CSR"} the control locations are randomly generated assuming complete spatial randomness (homogeneous Poisson process) within the window of \code{obs_data} with a \code{lambda = number of controls / [resolution x resolution]}. By default, the resolution is an integer value of 128 and can be specified using the \code{resolution} argument in the internally called \code{\link[sparr]{risk}} function.
#' If \code{samp_control = "CSR"} the control locations are randomly generated assuming complete spatial randomness (homogeneous Poisson process) within the dow of \code{obs_data} with a \code{lambda = number of controls / [resolution x resolution]}. By default, the resolution is an integer value of 128 and can be specified using the \code{resolution} argument in the internally called \code{\link[sparr]{risk}} function.
#'
#' If \code{samp_control = "MVN"} the control locations are randomly generated assuming a multivariate normal distribution \emph{centered at each observed location}. The optional argument \code{s_control} specifies the standard deviation of the multivariate normal distribution (1 by default) in the units of the \code{obs_data}.
#'
#' The function computes a one-sided hypothesis test for case clustering (\code{alpha = 0.05} by default). The function also computes a two-sided hypothesis test for case clustering and control clustering (lower tail = 0.025 and upper tail = 0.975).
#'
#' The function has functionality for a correction for multiple testing. If \code{p_correct = "FDR"}, calculates a False Discovery Rate by Benjamini and Hochberg. If \code{p_correct = "Sidak"}, calculates a Sidak correction. If \code{p_correct = "Bonferroni"}, calculates a Bonferroni correction. If \code{p_correct = "none"} (the default), then the function does not account for multiple testing and uses the uncorrected \code{alpha} level. See the internal \code{pval_correct} function documentation for more details.
#'
#' @return An object of class "list". This is a named list with the following components:
#' @return An object of class "list". This is a named list with the follog components:
#'
#' \describe{
#' \item{\code{sim}}{An object of class 'rrs' for the first iteration of simulated data.}
Expand Down
4 changes: 2 additions & 2 deletions R/spatial_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#'
#' @param input An object of class "ppplist" from the \code{\link{spatial_data}} function or an object of class "list" from the \code{\link{spatial_power}} or \code{\link{jitter_power}} functions.
#' @param p_thresh A numeric value between 0 and 1 (default = 0.8) for the power threshold.
#' @param cascon Logical. If TRUE, displays the statistical power to detect case clusters and control clusters. If FALSE (the default), displays the statistical power to detect case clusters only.
#' @param cascon Logical. If TRUE, displays the statistical power to detect case clusters and control clusters (two-tailed hypothesis). If FALSE (the default), displays the statistical power to detect case clusters only (one-tailed, lower-tail hypothesis).
#' @param n_sim Integer. The number of simulated iterations to plot. The default is one (1).
#' @param cols Character string of length four (4) specifying the colors for plotting: 1) sufficiently powered, 2) insufficiently powered, 3) case locations, 4) control locations. The default colors in hex are \code{c("#000000", "#CCCCCC", "#FF0000", "#0000FF")} or \code{c("grey0", "grey80", "red", "blue")}.
#' @param cols Character string of length four (4) specifying the colors for plotting: 1) insufficiently powered, 2) sufficiently powered, 3) case locations, 4) control locations. The default colors in hex are \code{c("#000000", "#CCCCCC", "#FF0000", "#0000FF")} or \code{c("grey0", "grey80", "red", "blue")}.
#' @param chars Vector of integers or character string of length two (2) for symbols of case and control locations. Default is \code{c(1,1)}.
#' @param sizes Vector of integers of length two (2) for the size of the symbols for case and control locations. Default is \code{c(1,1)}.
#' @param scale Integer. A graphical expansion factor (default is 1) for text (and point) size within plots. Intended for scaling plot features with plot resolution.
Expand Down
28 changes: 14 additions & 14 deletions R/spatial_power.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
match.arg(p_correct, choices = c("none", "FDR", "Sidak", "Bonferroni"))

# marked uniform disc ppp with user-specified radius for cases
rcluster_case <- function(x0, y0, rad, n, scalar, lamb, wind, types = "case", ...) {
rcluster_case <- function(x0, y0, rad, n, scalar, lamb, win, types = "case", ...) {

if (samp_case == "uniform") {
x <- spatstat.core::runifdisc(n = n, radius = rad, centre = c(x0, y0), win = wind, ...)
x <- spatstat.core::runifdisc(n = n, radius = rad, centre = c(x0, y0), win = win, ...)
}

if (samp_case == "MVN") {
x1 <- rep(x0, n)
y1 <- rep(y0, n)
x2 <- x1 + stats::rnorm(n, 0, scalar)
y2 <- y1 + stats::rnorm(n, 0, scalar)
x <- spatstat.geom::ppp(x2, y2, window = wind)
x <- spatstat.geom::ppp(x2, y2, window = win)
}

if (samp_case == "CSR") {
Expand All @@ -230,33 +230,33 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
}

# marked uniform ppp for controls
rcluster_control <- function(x0, y0, scalar, n, lamb, ex, nclust, rad, types = "control", wind, ...) {
rcluster_control <- function(x0, y0, scalar, n, lamb, ex, nclust, rad, types = "control", win, ...) {
if (samp_control == "uniform") {
x <- spatstat.core::runifpoint(n, win = wind, ...)
x <- spatstat.core::runifpoint(n, win = win, ...)
}

if (samp_control == "systematic") {
x <- spatstat.geom::rsyst(nx = sqrt(n), win = wind, ...)
x <- spatstat.geom::rsyst(nx = sqrt(n), win = win, ...)
}

if (samp_control == "MVN") {
x1 <- rep(x0, n)
y1 <- rep(y0, n)
x2 <- x1 + stats::rnorm(n, 0, scalar)
y2 <- y1 + stats::rnorm(n, 0, scalar)
x <- spatstat.geom::ppp(x2, y2, window = wind)
x <- spatstat.geom::ppp(x2, y2, window = win)
}

if (samp_control == "CSR") {
l <- n / (diff(wind$xrange) * diff(wind$yrange))
x <- spatstat.core::rpoispp(lambda = l, win = wind, ...)
l <- n / (diff(win$xrange) * diff(win$yrange))
x <- spatstat.core::rpoispp(lambda = l, win = win, ...)
}

if (samp_control == "IPP") {
if (class(lamb) != "function") {
stop("The argument 'l_control' should be an intensity function")
}
x <- spatstat.core::rpoispp(lambda = lamb, win = wind, ...)
x <- spatstat.core::rpoispp(lambda = lamb, win = win, ...)
}

if (samp_control == "clustered") {
Expand All @@ -269,7 +269,7 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
rcluster = control_clustering,
n = nclust,
radius = rad,
win = wind,
win = win,
...)
}
spatstat.geom::marks(x) <- types
Expand All @@ -285,7 +285,7 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
x1 <- rcluster_case(x0 = x_case[i], y0 = y_case[i],
rad = r_case[i], n = n_case[i],
scalar = s_case[i], lamb = l_case[[i]],
wind = win, ...))
win = win, ...))
pppCase[[i]] <- x1
}
pppCase <- spatstat.geom::as.solist(pppCase)
Expand Down Expand Up @@ -325,7 +325,7 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
n = n_control[i],
scalar = s_control[i],
lamb =NULL,
wind = win, ...))
win = win, ...))
pppControl[[i]] <- y1
}
pppControl <- spatstat.geom::as.solist(pppControl)
Expand All @@ -339,7 +339,7 @@ spatial_power <- function(win = spatstat.geom::unit.square(),
ex = e_control,
lamb = l_control,
scalar = NULL,
wind = win,
win = win,
...))
}

Expand Down
12 changes: 7 additions & 5 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Updates to dependencies
* Updated 'spatstat' package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). 'spatstat.geom' and 'spatstat.core' packages replace 'spatstat' package in Depends
* Imports 'lifecycle' package to document deprecated argument `cascon` in `spatial_power()` and `jitter_power()` functions
* Replaced 'parallel' and 'doParallel' packages in Imports with 'doFuture', 'doRNG', and 'future' packages to allow for parallel processing in `spatial_power()` and `jitter_power()` functions to work across environments
* Replaced 'parallel' and 'doParallel' packages in Imports with 'doFuture', 'doRNG', and 'future' packages to allow for parallel processing in `spatial_power()` and `jitter_power()` functions to work across all CRAN environments
* Removed 'tidyverse' package from Suggests
* Changes to DESCRIPTION
* Added ORCID for all authors and contributors
Expand All @@ -28,9 +28,10 @@
* Added `plot_axes` argument to toggle the display of axes in plots
* Added `plot_square` argument to toggle the margins of plots
* Changed the value of `cex.axis` and `cex` in plots
* Updated documentation with correct order of `cols`
* Changes to `jitter_power()`
* Added `p_correct` argument to apply a multiple testing correction
* Specify all packages for functions
* Specified all packages for functions
* Deprecated `cascon` argument (moved to `spatial_plots()` function)
* Estimates case-only power (lower tail) and case/control (lower and upper tail) and captures both outputs. Case-only is now a one-tailed hypothesis test by default. The arguments `lower_tail` and `upper_tail` have been replaced with argument `alpha`
* Used `as.solist()` to specify appropriate class to lists
Expand All @@ -41,9 +42,10 @@
* Increased the `sim_total` value for a more realistic example
* Specify all packages for functions
* Updated code to reflect updates to functions in 'sparrpowR'
* Changes to README.md
* Added CRAN badges
* Added plotting for case and control clustering
* Updated code to use 'sf' package
* Updated explanation of the `cascon` argument to plot various hypothesis tests
* Changed `cols` values to be more visible
* Used `cut` instead of `reclassify` in 'raster' package for categorical plot
* Added utils.R file
* Removed the helper `comb()` function functions from `jitter_power()`, `spatial_power()`, and `spatial_plots()` and added to the utils.R file
* Removed 'utils' package from Imports because the progress bar in `spatial_power()` and `jitter_power()` functions is now produced with a helper `progBar()` function
Expand Down
6 changes: 3 additions & 3 deletions man/jitter_power.Rd

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

4 changes: 2 additions & 2 deletions man/spatial_plots.Rd

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

Loading

0 comments on commit 627a28c

Please sign in to comment.