Skip to content

Commit

Permalink
Amended test scripts and documentation for release of v1_1_0. Still n…
Browse files Browse the repository at this point in the history
…eed to update vignettes and sort qpdf issues.
  • Loading branch information
PHEgeorginaanderson committed Feb 15, 2019
1 parent 4e511be commit 077ff11
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 137 deletions.
4 changes: 2 additions & 2 deletions R/Proportions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @param n field name from data containing the number of cases in the sample (the denominator for the proportion);
#' unquoted string; no default
#' @param multiplier the multiplier used to express the final values (eg 100 = percentage); numeric; default 1
#' @param percentage this argument is deprecated, please use multiplier argument instead
#'
#' @inheritParams phe_dsr
#'
Expand All @@ -21,7 +20,8 @@
#' @importFrom rlang sym quo_name :=
#'
#' @section Notes: Wilson Score method [1,2] is applied using the \code{\link{wilson_lower}}
#' and \code{\link{wilson_upper}} functions.
#' and \code{\link{wilson_upper}} functions. \cr \cr
#' The percentage argument was deprecated in v1_1_0, please use multiplier argument instead
#'
#' @examples
#'
Expand Down
24 changes: 15 additions & 9 deletions R/Quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ phe_quantile <- function(data, values, highergeog = NULL, nquantiles=10L,
data <- mutate(data,invert_calc = invert)
} else if (inverttype == "field") {
invert_q <- enquo(invert)
data <- rename(data,invert_calc = !!invert_q)
if (deparse(substitute(invert)) %in% colnames(data)) {

data <- mutate(data,invert_calc = !!invert_q)

} else stop("invert is not a field name from data")
# data <- rename(data,invert_calc = !!invert_q)
}


# apply quotes to field names
values_q <- enquo(values)
highergeog_q = enquo(highergeog)
highergeog_q <- enquo(highergeog)


# error handling for valid data types and values
Expand Down Expand Up @@ -118,13 +123,14 @@ phe_quantile <- function(data, values, highergeog = NULL, nquantiles=10L,
phe_quantile <- data %>%
add_count(naflag = is.na(!!values_q)) %>%
mutate(adj_value = if_else(invert_calc == TRUE, max(!!values_q, na.rm=TRUE)-!!values_q,!!values_q),
rank = rank(adj_value, ties.method="min", na.last = "keep"),
quantile = floor((nquantiles+1)-ceiling(((n+1)-rank)/(n/nquantiles))),
quantile = if_else(quantile == 0,1,quantile)) %>%
rank = rank(adj_value, ties.method="min", na.last = "keep"),
quantile = floor((nquantiles+1)-ceiling(((n+1)-rank)/(n/nquantiles))),
quantile = if_else(quantile == 0,1,quantile)) %>%
select(-naflag,-n,-adj_value, -rank) %>%
mutate(nquantiles = nquantiles,
mutate(nquantiles = nquantiles,
highergeog_column = rlang::quo_name(highergeog_q),
invert = invert)
qinverted = if_else(invert_calc == TRUE,"lowest quantile represents highest values",
"lowest quantile represents lowest values"))


#rename quantile column in output - not implemented to ensure consistent output column names
Expand All @@ -135,9 +141,9 @@ phe_quantile <- function(data, values, highergeog = NULL, nquantiles=10L,


# if invert provided as logical then delete invert_calc column created for calculation
if (inverttype == "logical") {
# if (inverttype == "logical") {
phe_quantile <- phe_quantile %>% select(-invert_calc)
}
# }


# remove columns if not required based on value of type argument
Expand Down
16 changes: 16 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#'
#' converts NAs to zeros
#'
#' @param y input vector
#'
na.zero <- function (y) {
y[is.na(y)] <- 0
return(y)
Expand All @@ -17,6 +19,8 @@ na.zero <- function (y) {
#'
#' @param x the observed numbers of events; numeric vector; no default
#'
#' @inheritParams phe_dsr
#'
#' @return Returns lower confidence limits for observed numbers of events using Byar's method [1]
#'
#' @section Notes: \code{byars_lower} and \code{\link{byars_upper}} together return symmetric confidence
Expand Down Expand Up @@ -69,6 +73,8 @@ byars_lower <- function(x, confidence = 0.95) {
#'
#' @param x the observed numbers of events; numeric vector; no default
#'
#' @inheritParams phe_dsr
#'
#' @return Returns upper confidence limits for observed numbers of events using Byar's method [1]
#'
#' @section Notes: \code{\link{byars_lower}} and \code{byars_upper} together return symmetric confidence
Expand Down Expand Up @@ -111,6 +117,11 @@ byars_upper <- function(x, confidence = 0.95) {
#'
#' Calculates lower confidence limits for observed numbers of events using the Wilson Score method [1,2].
#'
#' @param x the observed numbers of cases in the samples meeting the required condition; numeric vector; no default
#' @param n the numbers of cases in the samples; numeric vector; no default
#'
#' @inheritParams phe_dsr
#'
#' @return Returns lower confidence limits for observed numbers of events using the Wilson Score method [1,2]
#'
#' @section Notes: \code{wilson_lower} and \code{\link{wilson_upper}} together return symmetric confidence
Expand Down Expand Up @@ -164,6 +175,11 @@ wilson_lower <- function(x, n, confidence = 0.95) {
#'
#' Calculates upper confidence limits for observed numbers of events using the Wilson Score method [1,2].
#'
#' @param x the observed numbers of cases in the samples meeting the required condition; numeric vector; no default
#' @param n the numbers of cases in the samples; numeric vector; no default
#'
#' @inheritParams phe_dsr
#'
#' @return Returns upper confidence limits for observed numbers of events using the Wilson Score method [1,2]
#'
#' @section Notes: \code{\link{wilson_lower}} and \code{wilson_upper} together return symmetric confidence
Expand Down
3 changes: 3 additions & 0 deletions man/byars_lower.Rd

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

3 changes: 3 additions & 0 deletions man/byars_upper.Rd

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

3 changes: 3 additions & 0 deletions man/na.zero.Rd

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

5 changes: 3 additions & 2 deletions man/phe_dsr.Rd

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

7 changes: 4 additions & 3 deletions man/phe_isr.Rd

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

5 changes: 3 additions & 2 deletions man/phe_mean.Rd

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

16 changes: 8 additions & 8 deletions man/phe_proportion.Rd

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

29 changes: 14 additions & 15 deletions man/phe_quantile.Rd

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

5 changes: 3 additions & 2 deletions man/phe_rate.Rd

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

7 changes: 4 additions & 3 deletions man/phe_smr.Rd

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

8 changes: 8 additions & 0 deletions man/wilson_lower.Rd

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

Loading

0 comments on commit 077ff11

Please sign in to comment.