Skip to content

Commit

Permalink
update WINratio
Browse files Browse the repository at this point in the history
  • Loading branch information
abusjahn committed Jan 25, 2024
1 parent ebeb975 commit 3a4bdbd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Imports:
Depends:
R (>= 4.2)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
LazyData: true
VignetteBuilder: knitr
Suggests: rmarkdown, testthat, ggrepel
Expand Down
18 changes: 9 additions & 9 deletions R/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ utils::globalVariables('p_wcox_t_out')
#' @param data name of data set (tibble/data.frame) to analyze.
#' @param groupvar name of grouping variable, has to translate to 2 groups.
#' @param testvars names of variables for sequential rules.
#' @param rules list of rules (cut-offs) for sequential comparison.
#' @param rules list of rules (minimal cut-offs) for sequential comparison, negative if reduction is success, positive if increase is beneficial, must not be 0.
#' @param idvar name of identifier variable. If NULL, rownumber is used.
#' @param p_digits level for rounding p-value.
#'
Expand All @@ -1199,6 +1199,9 @@ utils::globalVariables('p_wcox_t_out')
#'
WINratio <- function(data,groupvar,testvars,rules, idvar=NULL,
p_digits=3){
if(any(rules==0)){
stop("rules must not be 0 but give direction and magnitude of minimal difference")
}
data <- select(data,any_of(c(groupvar,testvars,idvar)))
if((!is.factor(data[[groupvar]]))){
data[[groupvar]] <- factor(data[[groupvar]])
Expand All @@ -1221,21 +1224,18 @@ WINratio <- function(data,groupvar,testvars,rules, idvar=NULL,
mutate(
!!sym(paste0("rule",rule_i,"out")) :=
case_when(
#already decided
WIN!=0 ~ NA_integer_,
#sign of delta=sign of rule and win
abs(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))>=abs(rules[rule_i]) &
(sign(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))==sign(rules[rule_i])) |
(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))>=rules[rule_i] &
sign(rules[rule_i])==0 ~ 1,
!!sym(paste0("Y",rule_i)))==sign(rules[rule_i])) ~1,
#sign of delta!=sign of rule and loose
abs(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))>=abs(rules[rule_i]) &
(sign(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))!=sign(rules[rule_i])) |
(!!sym(paste0("X",rule_i))-
!!sym(paste0("Y",rule_i)))<=rules[rule_i] &
sign(rules[rule_i])==0 ~ -1,
!!sym(paste0("Y",rule_i)))!=sign(rules[rule_i])) ~-1,
.default=0),
WIN=sum(c_across(starts_with("rule")),na.rm=TRUE)
) |>
Expand Down
2 changes: 1 addition & 1 deletion man/WINratio.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/wrappedtools-package.Rd

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

0 comments on commit 3a4bdbd

Please sign in to comment.