Showing 1 of 4 files from the diff.

@@ -24,31 +24,38 @@
Loading
24 24
#' @export
25 25
#'
26 26
#' @usage
27 -
#' outliersMAD(x, MADCutOff = 2.5, replaceOutliersWith = NA,
27 +
#' outliersMAD(x, MADCutOff = 3.0, replaceOutliersWith = NA,
28 28
#' showMADValues = FALSE, outlierIndices = FALSE, bConstant = 1.4826, digits = 2)
29 29
#'
30 30
#' @examples
31 -
#' example <- c(1, 3, 3, 6, 8, 10, 10, 1000) # 1000 is an outlier
31 +
#' example <- c(1, 3, 3, 6, 8, 10, 10, 1000, -1000) # 1000 is an outlier
32 32
#' outliersMAD(example)
33 33
#' outliersMAD(example, MADCutOff = 3.0)
34 34
#' outliersMAD(example, MADCutOff = 2.5, replaceOutliersWith = -999)
35 35
#' outliersMAD(example, MADCutOff = 1.5, outlierIndices = TRUE)
36 36
#' outliersMAD(example, MADCutOff = 1.5, showMADValues = TRUE)
37 -
outliersMAD <- function(x, MADCutOff = 2.5, replaceOutliersWith = NA, showMADValues = FALSE, outlierIndices = FALSE, bConstant = 1.4826, digits = 2) {
37 +
#' outliersMAD(example, MADCutOff = 1.5, showMADValues = TRUE, replaceOutliersWith = -88)
38 +
outliersMAD <- function(x, MADCutOff = 3.0, replaceOutliersWith = NA, showMADValues = FALSE, outlierIndices = FALSE, bConstant = 1.4826, digits = 2) {
38 39
  # bConstant: usually, b = 1.4826, a constant linked to the assumption of normality of the data, disregarding the abnormality induced by out- liers (Rousseeuw & Croux, 1993).
39 40
40 41
  # compute number of absolute MADs away for each value: formula: abs( ( x - median(x) ) )/ mad(x)
41 -
  absMADAway <- abs((x - stats::median(x, na.rm = T))/stats::mad(x, constant = bConstant, na.rm = T))
42 +
  MADAway <- (x - stats::median(x, na.rm = T)) / stats::mad(x, constant = bConstant, na.rm = T)
43 +
  absMADAway <- abs(MADAway)
42 44
  # subset data that has absMADAway greater than the MADCutOff and replace them with replace
43 45
  x[absMADAway > MADCutOff] <- replaceOutliersWith
44 46
  outliers <- length(x[absMADAway > MADCutOff])
45 47
  if (showMADValues) { # if values == TRUE, return number of mads for each value
46 -
    message("Showing absolute MAD from median for each value.")
48 +
    message("Showing MAD from median for each value.")
47 49
    message(paste0(outliers, " outliers detected."))
48 -
    return(round(absMADAway, digits))
50 +
    return(round(MADAway, digits))
49 51
  } else if (outlierIndices) {
50 52
    message("Showing indices of outliers.")
51 -
    return(which(is.na(x)))
53 +
    if (is.na(replaceOutliersWith)) {
54 +
      return(which(is.na(x)))
55 +
    } else {
56 +
      return(x[x == replaceOutliersWith])
57 +
    }
58 +
52 59
  } else {
53 60
    message(paste0(outliers, " outliers detected."))
54 61
    message(paste0("Outliers replaced with ", replaceOutliersWith))
Files Coverage
R 4.01%
Project Totals (11 files) 4.01%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading