wrap.meaningdistfunction {cultevo} | R Documentation |
Make a meaning distance function vectorisable.
Description
This function takes as its only argument a function f(m1, m2)
which
returns a single numeric indicating the distance between two 'meanings'
m1, m2
(which are themselves most likely vectors or lists). Based
on f
, this function returns a function g(mm)
which takes as
its only argument a matrix or data frame mm
with the meaning
elements (equivalent to the ones in m1, m2
) along columns and
different meaning combinations (like m1, m2, ...
) along rows. This
function returns a distance matrix of class dist
containing all pairwise distances between the rows of mm
. The
resulting function g
can be passed to other functions in this
package, in particular mantel.test
.
Usage
wrap.meaningdistfunction(pairwisemeaningdistfun)
Arguments
pairwisemeaningdistfun |
a function of two arguments returning a single numeric indicating the semantic distance between its arguments |
Details
The meaning distance function should be commutative, i.e.
f(a,b) = f(b,a)
, and meanings should have a distance of zero to
themselves, i.e. f(a,a) = 0
.
Value
A function that takes a meaning matrix and returns a corresponding
distance matrix of class dist
.
Examples
trivialdistance <- function(a, b) return(a - b)
trivialmeanings <- as.matrix(3:1)
trivialdistance(trivialmeanings[1], trivialmeanings[2])
trivialdistance(trivialmeanings[1], trivialmeanings[3])
trivialdistance(trivialmeanings[2], trivialmeanings[3])
distmatrixfunction <- wrap.meaningdistfunction(trivialdistance)
distmatrixfunction(trivialmeanings)