phylo_average | R Documentation |
Calculates phylogenetic weights according to the ACL method (see ACL) and BranchManager method (see BM), for one or more reference trees, and applies the resulting sets of weights to one or more numerical variables which characterize the languages in the trees, resulting in phylogenetically-sensitive (i.e., phylogenetically-weighted) averages. If the data is in the form of binary {0,1} values, this is equivalent to a phylogenetically-sensitive proportion.
phylo_average(phy, data, na.rm = FALSE)
phy |
A phylo or multiPhylo object, containing one or more trees, representing one or more hypotheses on the phylogenetic relatedness of a set of languages. |
data |
A dataframe, containing data on the languages. Must contain a
column |
na.rm |
A logical. Whether to ignore languages with NA values in the data. If TRUE then for each column of data, tips with NA values are ignored and the weights of the remaining tips are re-scaled to sum to 1. |
The function returns a list, containing: phy
, the input tree(s);
data
, the input dataframe; and dataframes ACL_weights
,
BM_weights
, ACL_averages
, BM_averages
. Dataframe
ACL_weights
contains one column for each tree in phy
. In those
columns are the phylogenetic weights obtained using the ACL method.
Additionally, ACL_weights
contains all non-numeric columns of the
input data
dataframe. Dataframe BM_weights
is similar but with
phylogenetic weights obtained using the BM method. Dataframe
ACL_averages
has one row per tree and one column for each numerical
column in data
, and contains phylogenetically-sensitive averages
obtained using the ACL method. Dataframe BM_averages
is similar but
with phylogenetically-sensitive averages obtained using the BM method.
A list, containing phy, data, and dataframes: ACL_weights, BM_weights, ACL_averages, BM_averages
library(ape)
# A dataframe of language data, with columns: tip, is_SOV, n_consonants
dat <- data.frame(
tip = c("A", "B", "C", "D"),
is_SOV = c(1, 1, 1, 0),
n_consonants = c(18, 20, 22, 40))
# Three trees, representing three genealogical hypotheses, that relate
# the same languages A,B,C,D:
trees <- c(
read.tree(text = "(((A:1,B:1,C:1):1,D:2):0.3);"),
read.tree(text = "(((A:0.2,B:0.2,C:0.2):1.8,D:2):0.3);"),
read.tree(text = "(((A:1.8,B:1.8,C:1.8):0.2,D:2):0.3);"))
p_ave <- phylo_average(phy = trees, data = dat)
# Phylogenetic weights, calculated from the trees:
p_ave$ACL_weights
p_ave$BM_weights
# Phylogenetically-weighted averages, or, for binary data, phylogenetically-
# weighted proportions
p_ave$ACL_averages
p_ave$BM_averages
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.