Skip to content

Commit a7ec413

Browse files
authored
Merge pull request #136 from signaturescience/v0.0.3
v0.0.3 release
2 parents a06dbc6 + 49c3c4d commit a7ec413

File tree

11 files changed

+74
-17
lines changed

11 files changed

+74
-17
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: rplanes
22
Title: Plausibility Analysis of Epidemiological Signals in 'R'
3-
Version: 0.0.2
3+
Version: 0.0.3
44
Authors@R:
55
c(person(given = "VP",
66
family = "Nagraj",

NEWS.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# rplanes 0.0.3
2+
3+
## New features
4+
5+
### Better handling of locations with all missing data
6+
7+
In the previous version of the package, if a user input signal data that included a location with all values missing the `plane_seed()` function would proceed. However, this would lead to background characteristics in the seed that could not be used in downstream algorithms (e.g., infinite range). We now trigger an error if the input data for `to_signal()` includes any locations with all values missing.
8+
9+
### More intuitive `plane_repeat()` behavior
10+
11+
The PLANES scoring includes `plane_repeat()` to implement a "repeat" algorithm (i.e., checking if the evaluated signal creates a repeat sequence longer than any previously observed in the seed). We observed that this was flagging instances where all values of the time series were the same. In this release we have adjusted the algorithm to no longer flag a constant time series as implausible.
12+
13+
### Weighting scheme constraints
14+
15+
In this release, we have introduced a new feature to constrain component weights passed to `plane_score()` at values >= 1. Before adding this constraint, we saw inconsistent behavior in some cases when weights were set a < 1. We have updated the function documentation for `plane_score()` "weights" argument to reflect this change.
16+
17+
## Bug fixes
18+
19+
### Documentation typos
20+
21+
This release introduces minor fixes for typos in function documentation and the README.
22+
123
# rplanes 0.0.2
224

325
## New features

R/planes.R

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ plane_taper <- function(location, input, seed) {
248248
#'
249249
#' @description
250250
#'
251-
#' This function evaluates whether consecutive values in observations or forecasts are repeated a k number of times. This function takes in a [forecast][to_signal()] or [observed][to_signal()] object that is either from an observed dataset or forecast dataset.
251+
#' This function evaluates whether consecutive values in observations or forecasts are repeated a k number of times. This function takes in a [forecast][to_signal()] or [observed][to_signal()] object that is either from an observed dataset or forecast dataset. Note that if a signal is contant (i.e., the same value is repeated for all time points) then the repeat component will return `FALSE`.
252252
#'
253253
#' @param location Character vector with location code; the location must appear in input and seed
254254
#' @param input Input signal data to be scored; object must be one of [forecast][to_signal()] or [observed][to_signal()]
@@ -367,9 +367,16 @@ plane_repeat <- function(location, input, seed, tolerance = NULL, prepend = NULL
367367
dplyr::filter(.data$n_repeats >= k) %>%
368368
dplyr::select(-"repeat_id", -"n_repeats", -"prepend_type")
369369

370-
## indicator for whether or not the number of rows is > 0
371-
## this would indicate that there are repeats
372-
ind <- nrow(repeat_tbl) > 0
370+
## logic to check if data is constant in the reported signal
371+
## if so ... we cannot fairly say there is a repeat so set to FALSE
372+
if(length(unique(tmp_seed$all_values)) == 1) {
373+
ind <- FALSE
374+
## if not ... look at the repeat table to determine if flag is raised
375+
} else {
376+
## indicator for whether or not the number of rows is > 0
377+
## this would indicate that there are repeats
378+
ind <- nrow(repeat_tbl) > 0
379+
}
373380

374381
## return list with indicator and info
375382
return(list(indicator = ind, repeats = repeat_tbl))
@@ -386,7 +393,7 @@ plane_repeat <- function(location, input, seed, tolerance = NULL, prepend = NULL
386393
#' @param seed Prepared [seed][plane_seed()]
387394
#' @param components Character vector specifying component; must be either `"all"` or any combination of `"cover"`, `"diff"`, `"taper"`, `"trend"`, `"repeat"`, `"shape"`, and `"zero"`; default is `"all"` and will use all available components for the given signal
388395
#' @param args Named list of arguments for component functions. List elements must be named to match the given component and arguments passed as a nested list (e.g., `args = list("trend" = list("sig_lvl" = 0.05))`). Default is `NULL` and defaults for all components will be used
389-
#' @param weights Named vector with weights to be applied; default is `NULL` and all components will be equally weighted; if not `NULL` then the length of the vector must equal the number of components, with each component given a numeric weight (see Examples)
396+
#' @param weights Named vector with weights to be applied; default is `NULL` and all components will be equally weighted; if not `NULL` then the length of the vector must equal the number of components, with each component given a numeric weight (see Examples). Specified weights must be real numbers greater than or equal to 1.
390397
#'
391398
#'
392399
#'
@@ -424,7 +431,7 @@ plane_repeat <- function(location, input, seed, tolerance = NULL, prepend = NULL
424431
#'
425432
#' ## run plane scoring with specific components and weights
426433
#' comps <- c("cover", "taper", "diff")
427-
#' wts <- c("cover" = 2, "taper" = 1, "diff" = 4)
434+
#' wts <- c("cover" = 1.5, "taper" = 1, "diff" = 4)
428435
#' plane_score(input = prepped_forecast, seed = prepped_seed, components = comps, weights = wts)
429436
#'
430437
#' }
@@ -504,14 +511,17 @@ plane_score <- function(input, seed, components = "all", args = NULL, weights =
504511
## construct a tibble with weights for components
505512
## if the weights argument is NULL then apply equal weights to all components
506513
if(is.null(weights)) {
507-
weights_tbl <-
508-
dplyr::tibble(component = components, weight = 1)
514+
weights_tbl <- dplyr::tibble(component = components, weight = 1)
509515
} else {
516+
if(any(weights < 1)) {
517+
stop("Weights must be a real number >= 1")
518+
}
519+
510520
if(!all(sort(names(weights)) == sort(components))) {
511521
stop("Weights must be provided as a vector with all components used included by name (e.g., c('diff' = 4, 'cover' = 1))")
512522
}
513-
weights_tbl <-
514-
dplyr::tibble(component = names(weights), weight = weights)
523+
524+
weights_tbl <- dplyr::tibble(component = names(weights), weight = weights)
515525
}
516526

517527
## convert the tibble into a list

R/seed.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ seed_engine <- function(input, location, cut_date=NULL) {
3939
tmp_data %>%
4040
dplyr::pull(input$outcome)
4141

42+
if(all(is.na(tmp_obs))) {
43+
stop(sprintf("The values for the signal selected are missing for all dates in the following location: %s. Cannot create seed characteristics. Remove any locations that are missing signal input data for all dates prior to seeding.", location))
44+
}
45+
4246
## return max diff
4347
max_diff <-
4448
(tmp_obs - dplyr::lag(tmp_obs)) %>%

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The `rplanes` package (**pl**ausibility **an**alysis of **e**pidemiological **s*
3131
## Installation
3232

3333
``` r
34-
#install.pacakges("remotes")
34+
#install.packages("remotes")
3535
remotes::install_github("signaturescience/rplanes", build_vignettes=TRUE)
3636
```
3737

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ independently and then presented as a combined score.
2727
## Installation
2828

2929
``` r
30-
#install.pacakges("remotes")
30+
#install.packages("remotes")
3131
remotes::install_github("signaturescience/rplanes", build_vignettes=TRUE)
3232
```
3333

inst/app/app.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ server <- function(input, output, session){
145145
## value will be set at 1 by default
146146
## id will be weight_ component to make it easy to find / parse as input for plane_score
147147
components() %>%
148-
purrr::map(., function(x) numericInput(inputId = paste0("weight_",x), label = paste0("Weight: ", tcase(x)), value = 1))
148+
purrr::map(., function(x) numericInput(inputId = paste0("weight_",x), label = paste0("Weight: ", tcase(x)), value = 1, min = 1))
149149
})
150150

151151
# pass in actionBttn to module plots

man/plane_repeat.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plane_score.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-plane-components.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ test_that("plane_score handles weights", {
257257
expect_error(plane_score(prepped_forecast, prepped_seed, components = c("diff","repeat"), weights = c("diff" = 4, "foo"= 1)))
258258
expect_error(plane_score(prepped_forecast, prepped_seed, components = c("diff","repeat"), weights = c("diff" = 4, "cover"= 1)))
259259

260+
## check that weights are enforced to be >= 1
261+
expect_error( plane_score(prepped_forecast, prepped_seed, components = c("diff","repeat"), weights = c("diff" = 0.5, "repeat"= 1)))
262+
260263
})
261264

262265
test_that("plane_trend flags known changepoints and is sensitive to changes in sig.lvl", {

0 commit comments

Comments
 (0)