Skip to content

Commit

Permalink
Checked all functions, examples and test scripts for handling new typ…
Browse files Browse the repository at this point in the history
…e=full default argument value - amended from type=standard for LE function.
  • Loading branch information
PHEgeorginaanderson committed Mar 21, 2019
1 parent 1dbbdc0 commit f4cec83
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
Binary file modified .RData
Binary file not shown.
3 changes: 2 additions & 1 deletion R/DSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
# -------------------------------------------------------------------------------------------------

# define the DSR function using Dobson method
phe_dsr <- function(data, x, n, stdpop = esp2013, stdpoptype = "vector", type = "full", confidence = 0.95, multiplier = 100000) {
phe_dsr <- function(data, x, n, stdpop = esp2013, stdpoptype = "vector",
type = "full", confidence = 0.95, multiplier = 100000) {

# check required arguments present
if (missing(data)|missing(x)|missing(n)) {
Expand Down
10 changes: 5 additions & 5 deletions R/LifeExpectancy.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#' "all", where the function returns the life expectancy values for all ages
#' appended onto the input table. Any other value (or vector of values) must be age bands
#' described by the age_contents input
#' @param type type of output; can be "standard" or "full" (which contains
#' details added details on the calculation within the dataframe); quoted
#' string; default standard
#' @param type type of output; can be "standard" or "full" (full contains
#' added details on the calculation within the dataframe); quoted
#' string; default full
#' @details This function aligns with the methodology in Public Health England's
#' \href{https://fingertips.phe.org.uk/documents/PHE Life Expectancy Calculator.xlsm}{Life Expectancy Excel Tool}.
#'
Expand Down Expand Up @@ -83,7 +83,7 @@
#'
#' ## OR
#'
#' phe_life_expectancy(df, deaths, pops, startage, le_age = c(5, 25), type = "full")
#' phe_life_expectancy(df, deaths, pops, startage, le_age = c(5, 25), type = "standard")
#'
#' ## Unordered age bands example
#' df <- data.frame(startage = c("0", "1-4", "5-9", "10 - 14", "15 - 19", "20 - 24", "25 - 29",
Expand Down Expand Up @@ -129,7 +129,7 @@ phe_life_expectancy <- function(data, deaths, population, startage,
20L, 25L, 30L, 35L, 40L,
45L, 50L, 55L, 60L, 65L,
70L, 75L, 80L, 85L, 90L),
le_age = "all", type = "standard", confidence = 0.95) {
le_age = "all", type = "full", confidence = 0.95) {

# check required arguments present
if (missing(data) | missing(deaths) | missing(population) | missing(startage)) {
Expand Down
3 changes: 2 additions & 1 deletion R/Rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#' pop = rep(c(100,10000,10000,10000), each=3))
#'
#' phe_rate(df, obs, pop)
#' phe_rate(df, obs, pop, type="full", confidence=99.8, multiplier=100)
#' phe_rate(df, obs, pop, type="standard")
#' phe_rate(df, obs, pop, confidence=99.8, multiplier=100)
#'
#' # grouped data frame
#' library(dplyr)
Expand Down
7 changes: 4 additions & 3 deletions R/SMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
#'
#' df %>%
#' group_by(indicatorid, year, sex) %>%
#' phe_smr(obs, pop, refdf$refcount, refdf$refpop)
#' phe_smr(obs, pop, refdf$refcount, refdf$refpop, type="standard")
#'
#' ## OR
#'
#' df %>%
#' group_by(indicatorid, year, sex) %>%
#' phe_smr(obs, pop, refdf$refcount, refdf$refpop, type="standard", confidence=99.8, refvalue=100)
#' phe_smr(obs, pop, refdf$refcount, refdf$refpop, confidence=99.8, refvalue=100)
#'
#' @section Notes: User MUST ensure that x, n, x_ref and n_ref vectors are all ordered by
#' the same standardisation category values as records will be matched by position. \cr \cr
Expand All @@ -60,7 +60,8 @@
# -------------------------------------------------------------------------------------------------


phe_smr <- function(data, x, n, x_ref, n_ref, refpoptype = "vector", type = "full", confidence = 0.95, refvalue = 1) {
phe_smr <- function(data, x, n, x_ref, n_ref, refpoptype = "vector",
type = "full", confidence = 0.95, refvalue = 1) {

# check required arguments present
if (missing(data)|missing(x)|missing(n)|missing(x_ref)|missing(n_ref)) {
Expand Down
4 changes: 2 additions & 2 deletions man/phe_life_expectancy.Rd

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

3 changes: 2 additions & 1 deletion man/phe_rate.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/phe_smr.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/testLifeExpectancy.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ answer2 <- cbind(df1[c(3, 7),],
statistic = paste("life expectancy at", c(5, 25)),
method = rep("Chiang, using Silcocks et al for confidence limits", 2)))

test1 <- phe_life_expectancy(df1, deaths, pops, startage) %>%
test1 <- phe_life_expectancy(df1, deaths, pops, startage, type="standard") %>%
select(value:uppercl)
test1.1 <- phe_life_expectancy(df1, deaths, pops, startage, confidence = 95) %>%
select(value:uppercl)
Expand All @@ -163,7 +163,7 @@ test4 <- phe_life_expectancy(df3, deaths, pops, startage,
select(value:uppercl)
test5 <- phe_life_expectancy(df1, deaths, pops, startage, le_age = 5) %>%
select(value:uppercl)
test6 <- phe_life_expectancy(df1, deaths, pops, startage, le_age = c(5, 25), type = "full") %>%
test6 <- phe_life_expectancy(df1, deaths, pops, startage, le_age = c(5, 25), type="full") %>%
mutate_at(c("value", "lowercl", "uppercl"), round, digits = n)
negative_warning <- capture_warnings(test_neg <- phe_life_expectancy(df_neg_deaths, deaths, pop, age) %>%
select(value:uppercl))
Expand All @@ -188,7 +188,7 @@ multi_warnings <- capture_warnings(
#test calculations
test_that("LE and CIs calculate correctly",{
expect_equal(round(test1, n), round(answer1, n),
info = "test default")
info = "test defaults but with type standard")
expect_equal(round(test1.1, n), round(answer1, n),
info = "test confidence = 95")
expect_equal(round(test2, n), round(answer1, n),
Expand Down

0 comments on commit f4cec83

Please sign in to comment.