# R/minimum_di.R In desire: Desirability functions

#### Documented in minimumDI

```##
## minimum_di.R - minimum desirability index
##
## Authors:
##  Heike Trautmann  <[email protected]>
##  Detlef Steuer    <[email protected]>
##  Olaf Mersmann    <[email protected]>
##

minimumDI <- function(f, ...)
UseMethod("minimumDI", f)

## Vector input
minimumDI.numeric <- function(f, ...)
min(f)

## Matrix input
minimumDI.matrix <- function(f, margin=1, ...)
apply(f, margin, min)

## Array input
minimumDI.array <- function(f, margin=1, ...)
apply(f, margin, min)

minimumDI.desire.function <- function(f, ...) {
ev <- function(x) {
fn <- function(z)
min(sapply(i, function(k) dfs[[k]](z[k])))

if (is.matrix(x)) {
apply(x, 1, fn)
} else {
fn(x)
}
}

dfs <- list(f, ...)
if (!all(sapply(dfs, is.desirability)))
stop("Not all supplied arguments are desirability functions.")

i <- 1:length(dfs)
class(ev) <- "desire.index"
return(ev)
}

minimumDI.composite.desire.function <- function(f, ...) {
ev <- function(x) {
dval <- sapply(dfs, function(f) f(x))

if (is.matrix(dval)) {
apply(dval, 1, min)
} else {
min(dval)
}
}

dfs <- list(f, ...)
if (!all(sapply(dfs, is.composite.desirability)))
stop("Not all supplied arguments are composite desirability functions.")

class(ev) <- "desire.index"
return(ev)
}
```

## Try the desire package in your browser

Any scripts or data that you put into this service are public.

desire documentation built on May 31, 2017, 4:06 a.m.