make.metric | R Documentation |
Testing the dimension-level of disparity metrics
make.metric(
fun,
...,
silent = FALSE,
check.between.groups = FALSE,
data.dim,
tree = NULL,
covar = FALSE,
get.help = FALSE
)
fun |
A |
... |
Some arguments to be passed to |
silent |
|
check.between.groups |
|
data.dim |
optional, two |
tree |
optional, a |
covar |
|
get.help |
|
This function tests:
1: if your function can deal with a matrix as an input
.
2: which dimension-level is your function (1, 2 or 3, see dispRity.metric
).
3: whether the function can properly be implemented in the dispRity
function.
The three different metric levels correspond to the dimensions of the output and are:
"dimension-level 1": for functions that decompose a matrix
into a single value.
"dimension-level 2": for functions that decompose a matrix
into a vector
.
"dimension-level 3": for functions that transform the matrix
into another matrix
.
For example, the disparity metric sum
of variances
is composed of two metric dimension-levels:
The variances
(dimension-level 2) that calculates the variances for each column in a matrix (aggregates a matrix
into a vector
).
The sum
(dimension-level 1) that transforms the vector
of variances into a single value.
See function example for a concrete illustration (three different dimension-levels of the function sum
).
HINT: it is better practice to name the first argument of fun
matrix
to avoid potential argument conflicts down the line (the dispRity
function assumes the matrix
argument for the parsing the metrics).
The input fun
can be a "normal" metric function (i.e. that takes a matrix as first argument) or a "between.groups" metric (i.e. that takes two matrix as arguments). If the arguments are named matrix
and matrix2
, the metric will be assumed to be "between.groups" and be run in a for
loop rather than a apply
loop in dispRity
.
Thomas Guillerme
dispRity
, dispRity.metric
.
## A dimension-level 1 function
my_fun <- function(matrix) sum(matrix)
make.metric(my_fun)
## A dimension-level 2 function
my_fun <- function(matrix) apply(matrix, 2, sum)
make.metric(my_fun)
## A dimension-level 3 function
my_fun <- function(matrix) (matrix + sum(matrix))
make.metric(my_fun)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.