File: deal.ties.R

package info (click to toggle)
r-cran-modeest 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 280 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
# #' @author 
# #' Adapted from the function written by Wolfgang Huber and Ligia Pedroso Bras 
# #' in package \pkg{genefilter}. 
# #' 
# #' @importFrom stats median
.deal.ties <-
function(ny,         # length of the data
         i,          # index
         tie.action, # action to be taken
         tie.limit,  # limit
         warn = FALSE)
{
  ## Deal with ties
  maxi <- max(i)
  mini <- min(i)
  if (maxi-mini > tie.limit * ny) {
    warning(paste("encountered a tie, and the difference between minimal and 
                   maximal value is > length('x') * 'tie.limit'",
                  "the distribution could be multimodal", sep="\n"), 
            call. = FALSE)
  }
  
  ## Take the action specified in "tie.action"
  switch(tie.action,
         mean = mean(i),
         median = stats::median(i),
         max = maxi,
         min = mini,
         stop(sprintf("invalid value '%s' for argument 'tie.action'", tie.action), 
              call. = FALSE))
}