make.metric  R Documentation 
Testing the dimensionlevel of disparity metrics
make.metric(
fun,
...,
silent = FALSE,
check.between.groups = FALSE,
data.dim,
tree = NULL,
covar = FALSE
)
fun 
A 
... 
Some arguments to be passed to 
silent 

check.between.groups 

data.dim 
optional, two 
tree 
optional, a 
covar 

This function tests:
1: if your function can deal with a matrix as an input
.
2: which dimensionlevel 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:
"dimensionlevel 1": for functions that decompose a matrix
into a single value.
"dimensionlevel 2": for functions that decompose a matrix
into a vector
.
"dimensionlevel 3": for functions that transform the matrix
into another matrix
.
For example, the disparity metric sum
of variances
is composed of two metric dimensionlevels:
The variances
(dimensionlevel 2) that calculates the variances for each column in a matrix (aggregates a matrix
into a vector
).
The sum
(dimensionlevel 1) that transforms the vector
of variances into a single value.
See function example for a concrete illustration (three different dimensionlevels 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 dimensionlevel 1 function
my_fun < function(matrix) sum(matrix)
make.metric(my_fun)
## A dimensionlevel 2 function
my_fun < function(matrix) apply(matrix, 2, sum)
make.metric(my_fun)
## A dimensionlevel 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.