generate_weights {Morphoscape} | R Documentation |
Generate a matrix containing weight combinations
Description
generate_weights()
generates a matrix containing weight combinations for a set of variables such that each set of weights sums to 1. This can be supplied to calc_all_lscps
to calculate fitness landscapes corresponding to a variety of possible sets of weights for weighting functional characteristics. The weights are generated by partitioning a weight of 1 across however many variables are requested in all possible ways.
Usage
generate_weights(step, n, data = NULL, nvar = NULL,
varnames = NULL, verbose = TRUE)
Arguments
step |
|
n |
|
data |
an optional |
nvar |
the number of variables across which to allocate the weights. Ignored if |
varnames |
the names of the variables across which to allocate the weights. Ignored if |
verbose |
whether to display a message noting the number of sets of weights created. |
Details
generate_weights()
works by fining all possible allocations of n
objects into nvar
bins. When step
is supplied, n
is computed as round(1/step)
, so the resulting weight partitions may not be exactly equal to step
when its inverse is not an integer. The larger n
is (or the smaller step
) is, the more possible allocations will be produced (i.e., and the resulting object will have more rows). The output of generate_weights()
can quickly become very large with increasing number of variables, and will make subsequent analyses slow. It is recommended to start with a large step
size, or small n
, and increment up.
Value
A grid_weights
object, which is a matrix with a row for each each set of weights and a column for each variable over which the weights are allocated. The weights in each row will sum to 1.
Examples
# Allocating 10 partitions of .1 across 3 variables
wmat <- generate_weights(n = 10, nvar = 3)
head(wmat)
# Allocating 5 partitions of .2 across the 4 functional
# characteristics in the warps dataset
data("warps")
warps_fnc <- as_fnc_df(warps)
wmat <- generate_weights(n = 5, data = warps_fnc)
head(wmat)
# Using 'step' for the same result:
wmat <- generate_weights(step = .2, data = warps_fnc)
head(wmat)