Package: pyCoDaMath
pyCoDaMathpyCoDaMath provides compositional data (CoDa) analysis tools for PythonSource code:https://bitbucket.org/genomicepidemiology/pycodaGetting StartedThis package extends the Pandas dataframe object with various CoDa tools. It also provides a set of plotting functions for CoDa figures.InstallationClone the git repo to your local hard drive:git clone https://brinch@bitbucket.org/genomicepidemiology/pycoda.gitEnter pycoda directory and typepip install ./UsageThe pyCoDaMath module is loaded asimport pycodamathAt this point, in order to get CLR values from a Pandas DataFrame df, dodf.coda.clr()DocumentationCLR transformation - point estimatedf.coda.clr()Returns centered logratio coefficients. If the data frame contains zeros, values
will be replaced by the Aitchison mean point estimate.CLR transformation - standard deviationdf.coda.clr_std(n_samples=5000)Returns the standard deviation of n_samples random draws in CLR space.Parametersn_samples (int) - Number of random draws from a Dirichlet distribution.ALR transformation - point estimatedf.coda.alr(part=None)Same as clr() but returning additive logratio values. If part is None, then the last part of the composition is used, otherwise part is used as denominator.Parameterspart (str) - Name of the part to be used as denominator.ALR transformation - standard deviationdf.coda.alr_std(part=None, n_samples=5000)Same as clr_std, but in ALR space.Parameterspart (str) - Name of the part to be used as denominator.n_samples (int) - Number of random draws from a Dirichlet distribution.ILR transformation - point estimatedf.coda.ilr(psi=None)Same as clr() but for isometric logratio transform. An orthonormal basis can be
provided as psi. If no basis is given, a default sequential binary partition basis will be used.Parameterspsi (array_like) - Orthonormal basis.ILR transformation - standard deviationdf.coda.ilr_std(psi=None, n_samples=5000)This method does not exist (yet).Bayesian zero replacementdf.coda.zero_replacement(n_samples=5000)Returns a count table with zero values replaced by finite values using Bayesian inference.Parametersn_samples (int) - Number of random draws from a Dirichlet distribution.Closuredf.coda.closure(N)Apply closure to constant N to the composition.ParametersN (int) - Closure constant.Total variancedf.coda.totvar()Calculates the total variance of a set of compositions.Geometric meandf.coda.gmean()Calculates the geometric mean of a set of compositions.Centeringdf.coda.center()Centers (and scales) the composition by dividing by the geometric mean and powering by the reciprocal variance.Plotting functionsPCA biplotclass pycoda.pca.Biplot(data, default=True)Plots a PCA biplot. Set default to False for an empty plot.
The parameter data (DataFrame) is the data to be analyzed. Use counts, not CLR values.A number of methods are available for customizing the biplot:plotloadings(cutoff=0, scale=None, labels=None)plotloadinglabels(labels=None)plotscores(group=None, palette=None, legend=True, labels=None)plotscorelables(labels=None)plotellipses(group=None, palette=None)plotcentroids(group=None, palette=None)plothulls(group=None, palette=None)plotcontours(group=None, palette=None, size=None, levels=None)removepatches()removescores()removelabels()The keyword labels is a list of labelnames. If labels is None, all labels are plottet. Use labels=[] for no labels.The keyword group is a Pandas dataframe with index equal to the index of data.The keyword palette is a dict with colors to use to each unique member of group.Example
import pycoda as coda
import pandas as pddata = pd.read_csv('example/kilauea_iki_chem.csv')
mypca = coda.pca.Biplot(data)
mypca.plothulls()
mypca.removelabels()
mypca.plotloadinglabels(['FeO'])Ternary diagrampycoda.plot.ternary()