prepare_invasible: Prepare data and phylogeny for analyses (mandatory step)

View source: R/prepare_invasible.R

prepare_invasibleR Documentation

Prepare data and phylogeny for analyses (mandatory step)

Description

Aligns species-level invasion data with a phylogeny and stores predictor information for downstream analyses.

Usage

prepare_invasible(
  df,
  tree = NULL,
  predictors = NULL,
  species_col = "Species",
  rho = 0.5,
  plot = FALSE
)

Arguments

df

Data frame containing at least a Species column formatted as "Genus_species", and an Invasive column (0: not invasive, 1: invasive).

tree

Optional object of class "phylo". If NULL, a phylogeny is retrieved from the Open Tree of Life.

predictors

Optional character vector of column names containing additional predictors. If NULL, no additional predictors are stored.

species_col

Character string giving the name of the species column. Defaults to "Species".

rho

Numeric value controlling the power parameter used for Grafen branch lengths. Defaults to 0.5.

plot

Logical. If TRUE, plots the resulting phylogeny as a fan tree using phytools.

Details

If no phylogeny is supplied, a tree is retrieved from the Open Tree of Life using rotl. Unmatched species names are removed with a warning. When multiple submitted names resolve to the same Open Tree taxon, the first occurrence is retained and subsequent occurrences are removed with a warning.

If a supplied phylogeny has species that are absent from the data, those tips are removed. Species present in the data but absent from the phylogeny are removed from the data with a warning.

If branch lengths are absent, Grafen branch lengths are added.

Value

An object of class "invasible_prepared" containing:

  • data: the aligned data frame;

  • tree: the aligned phylogeny;

  • predictors: the supplied predictor names.

Examples

## Not run: 
prep <- prepare_invasible(
  fish_beginning_with_E,
  rho = 1,
  predictors = c(
    "Fake_categorical_trait",
    "Fake_continuous_trait"
  )
)

prep$tree

## End(Not run)


invasible documentation built on Oct. 8, 2026, 5:07 p.m.