Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGoueguel committed Nov 6, 2024
1 parent 67a77c3 commit 8d1b3af
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
9 changes: 4 additions & 5 deletions R/directOutlyingness.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#' @return A tibble with columns:
#' - `data`: The original numeric values.
#' - `score`: The calculated outlyingness score.
#' - `outlier`: A logical vector indicating whether each value is a potential outlier or not.
#' - `flag`: A logical vector indicating whether each value is a potential outlier or not.
#'
#' @export directOutlyingness
#'
#' @examples
#' vec <- c(1, 5, 3, 9, 2, 6, 4, 8, 7, 1e3)
#' directOutlyingness(vec)
#' x <- c(1, 5, 3, 9, 2, 6, 4, 8, 7, 1e3)
#' directOutlyingness(x)
#'
directOutlyingness <- function(x, cutoff.quantile = 0.995, rmZeroes = FALSE, maxRatio = NULL, precScale = 1e-10) {
if (missing(x)) {
Expand Down Expand Up @@ -86,7 +86,7 @@ directOutlyingness <- function(x, cutoff.quantile = 0.995, rmZeroes = FALSE, max
tbl <- tibble::tibble(
data = x,
score = res,
outlier = dplyr::if_else(res > cutoff, TRUE, FALSE)
flag = dplyr::if_else(res > cutoff, TRUE, FALSE)
) %>%
dplyr::arrange(dplyr::desc(score))

Expand Down Expand Up @@ -133,7 +133,6 @@ scale1StepM <- function(x, precScale) {
}
}


computeCutoff <- function(outl, quant) {
Ltemp <- log(0.1 + outl)
cutoff <- exp(stats::qnorm(quant) * stats::mad(Ltemp) + stats::median(Ltemp)) - 0.1
Expand Down
9 changes: 5 additions & 4 deletions R/iqrMethod.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#'
#' @return A tibble with two columns:
#' - `data`: The original numeric values.
#' - `outlier`: A logical vector indicating whether each value is a potential outlier or not.
#' - `flag`: A logical vector indicating whether each value is a potential outlier or not.
#' @examples
#' set.seed(3317)
#' x <- stats::rexp(7, rate = 0.5)
Expand All @@ -56,6 +56,7 @@
#' @export iqrMethod
#'
iqrMethod <- function(x, k = 1.5, skew = FALSE, drop.na = FALSE) {
options(mc_doScale_quiet = TRUE)
if (missing(x)) {
stop("Missing 'x' argument.")
}
Expand All @@ -78,7 +79,7 @@ iqrMethod <- function(x, k = 1.5, skew = FALSE, drop.na = FALSE) {
iqr <- q3 - q1

value <- NULL
outlier <- NULL
flag <- NULL
name <- NULL
x_tbl <- tibble::enframe(x)

Expand All @@ -100,10 +101,10 @@ iqrMethod <- function(x, k = 1.5, skew = FALSE, drop.na = FALSE) {
}

x_tbl <- x_tbl %>%
dplyr::mutate(outlier = value < lower_fence | value > upper_fence) %>%
dplyr::mutate(flag = value < lower_fence | value > upper_fence) %>%
dplyr::select(-name) %>%
dplyr::rename(data = value) %>%
dplyr::arrange(dplyr::desc(outlier))
dplyr::arrange(dplyr::desc(flag))

return(x_tbl)
}
6 changes: 3 additions & 3 deletions man/directOutlyingness.Rd

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

2 changes: 1 addition & 1 deletion man/iqrMethod.Rd

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

0 comments on commit 8d1b3af

Please sign in to comment.