This function computes the population-genetic statistic Fst on any matrix with rows that sum to 1. Values of 0 are achieved when each row is a permutation of (1,0,..., 0) and at least two categories have non-zero abundance across all rows. The value equals 1 when each row is identical.
Usage
fava(
relab_matrix,
K = NULL,
S = NULL,
w = NULL,
time = NULL,
group = NULL,
normalized = FALSE
)
Arguments
- relab_matrix
A matrix or data frame with rows containing non-negative entries that sum to 1. Each row represents a sample, each column represents a category, and each entry represents the abundance of that category in the sample. If
relab_matrix
contains any metadata, it must be on the left-hand side of the matrix, the rightK
entries of each row must sum to 1, andK
must be specified. Otherwise, all entries of each row must sum to 1.- K
Optional; an integer specifying the number of categories in the data. Default is
K=ncol(relab_matrix)
.- S
Optional; a K x K similarity matrix with diagonal elements equal to 1 and off-diagonal elements between 0 and 1. Entry
S[i,k]
fori!=k
is the similarity between category andi
and categoryk
, equaling 1 if the categories are to be treated as identical and equaling 0 if they are to be treated as totally dissimilar. The default value isS = diag(ncol(relab_matrix))
.- w
Optional; a vector of length
I
with non-negative entries that sum to 1. Entryw[i]
represents the weight placed on rowi
in the computation of the mean abundance of each category across rows. The default value isw = rep(1/nrow(relab_matrix), nrow(relab_matrix))
.- time
Optional; a string specifying the name of the column that describes the sampling time for each row. Include if you wish to weight FAVA by the distance between samples.
- group
Optional; a string (or vector of strings) specifying the name(s) of the column(s) that describes which group(s) each row (sample) belongs to. Use if
relab_matrix
is a single matrix containing multiple groups of samples you wish to compare.- normalized
Optional; should normalized FAVA be used? Default is
normalized = FALSE
; usenormalized = TRUE
to compute normalized FAVA. FAVA can only be normalized if it is not weighted.
Examples
# Compute the Fst of
# the following compositional vectors:
q1 = c(1, 0, 0, 0)
q2 = c(0.5, 0.5, 0, 0)
q3 = c(1/4, 1/4, 1/4, 1/4)
q4 = c(0, 0, 1, 0)
relative_abundances = matrix(c(q1, q2, q3, q4),
byrow = TRUE, nrow = 4)
fava(relative_abundances)
#> [1] 0.5348837
# Incoporating weights:
# Compute fava ignoring
# rows 2 and 3
row_weights = c(0.5, 0, 0, 0.5)
fava(relative_abundances, w = row_weights)
#> [1] 1
# Compute fava assuming that
# categories 1 and 2 are identical:
similarity_matrix = diag(4)
similarity_matrix[1,2] = 1
similarity_matrix[2,1] = 1
fava(relative_abundances, S = similarity_matrix)
#> [1] 0.6923077
# Assume categories 1 and 2 are identical AND
# ignore rows 2 and 4:
row_weights = c(0.5, 0, 0.5, 0)
fava(relative_abundances, w = row_weights, S = similarity_matrix)
#> [1] 0.2307692