Skip to contents

Runs any of ecodive's measures of association between the features of a count table by name, as count_ord() does for ordinations. Every one returns a dist over the features.

Usage

feature_assoc(counts, method, ...)

Arguments

counts

A numeric matrix of counts (samples \(\times\) features), or any of the objects listed under Input Types.

method

The name of an association measure: "vlr", "rho_p", "phi_s" or "sparcc". Flexible matching is supported (see below). Programmatic access via list_feature_assocs().

...

Further arguments for the method's function, such as margin, pseudocount, clust and cpus, rho_p()'s and phi_s()'s denominator, or sparcc()'s n_draws, permutations and seed. Each method keeps its own defaults. seed is ignored by the methods that have no random parts (all but sparcc()). sparcc() takes no pseudocount: it handles zeros itself.

Value

The method's result: a dist over the features, of class c("ecodive_dist", "dist"), with attribute method set to the method's ID. feature_assoc(counts, 'sparcc', ...) is the same as sparcc(counts, ...).

Details

List of Association Measures

Option / Function NameMeasureKindRange
vlrVariance of log ratiosdissimilarity\([0, \infty)\)
rho_pProportionality \(\rho_p\)similarity\([-1, 1]\)
phi_sSymmetric proportionality \(\phi_s\)dissimilarity\([0, \infty)\)
sparccSparCC correlationsimilarity\([-1, 1]\)

The similarities (rho_p() and sparcc()) can be made into networks with assoc_network(), or listed with assoc_pairs().

Flexible name matching

Case insensitive and partial matching, ignoring anything but letters. Other names also work: 'rho' or 'propr' for rho_p; 'phi' or 'phs' for phi_s; 'FastSpar' for sparcc; 'log ratio variance' for vlr. 'proportionality' matches both rho_p and phi_s, and so is an error.

Finished code should always use the full primary option name to avoid ambiguity with future additions to the list of methods.

Input Types

The counts parameter is designed to accept a simple numeric matrix, but seamlessly supports objects from the following biological data packages:

  • phyloseq

  • rbiom

  • SummarizedExperiment

  • TreeSummarizedExperiment

For large datasets, standard matrix operations may be slow. See vignette('performance') for details on using optimized formats (e.g. sparse matrices) and parallel processing.

Examples

    r <- feature_assoc(ex_counts, 'rho_p', pseudocount = 1)
    r
#> # A dist: 6 features (lower triangle)
#> # Proportionality (rho_p)
#>                   Streptococcus Bacteroides Corynebacterium Haemophilus
#> Bacteroides              -0.354
#> Corynebacterium          -0.753     -0.284
#> Haemophilus               0.887     -0.0663          -0.887
#> Propionibacterium        -0.491     -0.463            0.915      -0.668
#> Staphylococcus           -0.664     -0.253            0.955      -0.833
#> # … 1 more column: Propionibacterium
#> # Attributes: method

    # The same arguments for every log-ratio measure.
    lapply(c('vlr', 'rho_p', 'phi_s'), function (m)
      range(feature_assoc(ex_counts, m, pseudocount = 1)) )
#> [[1]]
#> [1]  0.3212435 23.7749710
#> 
#> [[2]]
#> [1] -0.8874735  0.9549243
#> 
#> [[3]]
#> [1]  0.0230575 16.7735862
#>