Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited plane_score so that weights must be >= 1. Also edited documentation #134

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions R/planes.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ plane_repeat <- function(location, input, seed, tolerance = NULL, prepend = NULL
#' @param seed Prepared [seed][plane_seed()]
#' @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
#' @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
#' @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)
#' @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.
#'
#'
#'
Expand Down Expand Up @@ -424,7 +424,7 @@ plane_repeat <- function(location, input, seed, tolerance = NULL, prepend = NULL
#'
#' ## run plane scoring with specific components and weights
#' comps <- c("cover", "taper", "diff")
#' wts <- c("cover" = 2, "taper" = 1, "diff" = 4)
#' wts <- c("cover" = 1.5, "taper" = 1, "diff" = 4)
#' plane_score(input = prepped_forecast, seed = prepped_seed, components = comps, weights = wts)
#'
#' }
Expand Down Expand Up @@ -504,14 +504,17 @@ plane_score <- function(input, seed, components = "all", args = NULL, weights =
## construct a tibble with weights for components
## if the weights argument is NULL then apply equal weights to all components
if(is.null(weights)) {
weights_tbl <-
dplyr::tibble(component = components, weight = 1)
weights_tbl <- dplyr::tibble(component = components, weight = 1)
} else {
if(any(weights < 1)) {
stop("Weights must be a real number >= 1")
}

if(!all(sort(names(weights)) == sort(components))) {
stop("Weights must be provided as a vector with all components used included by name (e.g., c('diff' = 4, 'cover' = 1))")
}
weights_tbl <-
dplyr::tibble(component = names(weights), weight = weights)

weights_tbl <- dplyr::tibble(component = names(weights), weight = weights)
}

## convert the tibble into a list
Expand Down
4 changes: 2 additions & 2 deletions man/plane_score.Rd

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

Loading