philr: Data transformation and driver of PhILR.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/philr.R


This is the main function for building the phylogenetic ILR basis, calculating the weightings (of the parts and the ILR coordinates) and then transforming the data.


philr(df, tree, sbp = NULL, part.weights = "uniform",
  ilr.weights = "uniform", return.all = FALSE)



matrix of data to be transformed (samples are rows, compositional parts are columns) - zero must be dealt with either with pseudocount, multiplicative replacement, or another method.


a phylo class tree object that is binary (see multi2di)


(Optional) give a precomputed sbp matrix phylo2sbp if you are going to build multiple ILR bases (e.g., with different weightings).


weightings for parts, can be a named vector with names corresponding to colnames(df) otherwise can be a string, options include:


(default) uses the uniform reference measure


geometric mean of parts of df


aitchison norm of parts of df (after closure)


'anorm' times 'gm.counts'


euclidean norm of parts of df (after closure)


'enorm' times 'gm.counts', often gives good results


weightings for the ILR coordiantes can be a named vector with names corresponding to names of internal nodes of tree otherwise can be a string, options include:


(default) no weighting of the ILR basis


sum of children's branch lengths


square root of 'blw' option


sum of children's branch lengths PLUS the sum of each child's mean distance to its descendent tips


return all computed parts (e.g., computed sign matrix(sbp), part weightings (codep), ilr weightings (codeilr.weights), contrast matrix (V)) as a list (default=FALSE) in addition to in addition to returning the transformed data (df.ilrp). If return.all==FALSE then only returns the transformed data (not in list format) If FALSE then just returns list containing df.ilrp.


This is a utility function that pulls together a number of other functions in philr. The steps that are executed are as follows:

  1. Create sbp (sign matrix) if not given

  2. Create parts weightings if not given

  3. Shift the dataset with respect to the new reference measure (e.g., part weightings)

  4. Create the basis contrast matrix from the sign matrix and the reference measure

  5. Transform the data based on the contrast matrix and the reference measure

  6. Calculate the specified ILR weightings and multiply each balance by the corresponding weighting

Note for both the reference measure (part weightings) and the ILR weightings, specifying 'uniform' will give the same results as not weighting at all.

Note that some of the prespecified part.weights assume df is given as counts and not as relative abundances. Except in this case counts or relative abundances can be given.


matrix if return.all=FALSE, if return.all=TRUE then a list is returned (see above).


Justin Silverman

See Also

phylo2sbp calculate.blw


tr <- named_rtree(5)
df <- t(rmultinom(10,100,c(.1,.6,.2,.3,.2))) + 0.65   # add a small pseudocount
colnames(df) <- tr$tip.label

philr(df, tr, part.weights='',
                  ilr.weights='blw.sqrt', return.all=FALSE)

jsilve24/philr documentation built on Aug. 1, 2019, 5:48 p.m.