Skip to contents

Apply fit_regime_covariances() to each search/run in a named list. This is the package analogue of the manuscript fitPosthocModels() step: the top-level run iteration is explicit, while each run can still fit its regime subtrees in parallel through cores.

Usage

fit_regime_covariance_runs(
  x,
  trait_data,
  formula = trait_data ~ 1,
  model = "BM",
  min_tips = 2L,
  cores = 1L,
  error = TRUE,
  tree_element = "tree_no_uncertainty_untransformed",
  verbose = FALSE,
  ...
)

Arguments

x

Named list of bifrost_search objects, compatible search-like lists, or SIMMAP-style phylo trees. Missing or blank names are generated and names must be unique after normalization.

trait_data

Matrix or data frame with unique, non-empty row names matching the tree tip labels. Column names may be omitted; when present, they must also be unique and non-empty.

formula

Formula used for each regime-specific mvgls() fit. The default treats trait_data as the multivariate response. Formulae may refer to trait_data directly, as in trait_data[, 1:5] ~ trait_data[, 6], or to columns by name.

model

Evolutionary model passed to mvMORPH::mvgls(). The default "BM" matches the independent post-hoc covariance workflow.

min_tips

Minimum number of tips required before a regime is fitted. Regimes are fitted when tip_count >= min_tips; regimes with fewer tips are returned with status "skipped". The default of two tips matches the Berv et al. post-hoc fitting script.

cores

Number of workers. Values greater than one use future.apply::future_lapply() with a temporary multisession plan.

error

Logical passed to mvMORPH::mvgls().

tree_element

For search-like list inputs, the element containing the mapped tree to use for post-hoc refits. Set to NULL to let fit_regime_covariances() resolve the tree from each run directly.

verbose

Logical; if TRUE, print progress messages by run name.

...

Additional arguments passed to mvMORPH::mvgls().

Value

A named list of regime_covariances objects with class regime_covariance_runs.

Examples

tree <- ape::read.tree(text = paste0(
  "(((a:1,b:1):1,(c:1,d:1):1):1,",
  "((e:1,f:1):1,(g:1,h:1):1):1);"
))
tree <- phytools::paintSubTree(
  tree, node = ape::Ntip(tree) + 1L, state = "root"
)
tree <- phytools::paintSubTree(
  tree, node = ape::getMRCA(tree, c("a", "d")), state = "slow"
)
tree <- phytools::paintSubTree(
  tree, node = ape::getMRCA(tree, c("e", "h")), state = "fast"
)
set.seed(2)
traits <- matrix(
  stats::rnorm(16),
  nrow = 8,
  dimnames = list(tree$tip.label, c("bill", "wing"))
)
run_fits <- fit_regime_covariance_runs(
  list(first = tree, second = tree),
  trait_data = traits,
  min_tips = 4,
  error = FALSE,
  method = "LL"
)
vapply(run_fits, function(x) sum(x$status$status == "ok"), integer(1))
#>  first second 
#>      2      2