Skip to contents

Converts a phylogeny, species niche estimates, and environmental data into the list format required by the Stan evolutionary models.

Usage

prepare_phylo_data(
  phy,
  species,
  niche_params,
  occ_data,
  env_m_data,
  mu_anc_prior = c(0, 0),
  mu_anc_sigma = c(5, 5),
  rate_mu_scale = 1,
  rate_log_sigma_scale = 0.5,
  z_rho_anc_prior = 0,
  z_rho_anc_sigma = 1,
  rate_rho_scale = 0.5,
  alpha_mu_scale = c(1, 1),
  sigma_sq_mu_scale = c(1, 1),
  alpha_log_sigma_scale = c(1, 1),
  sigma_sq_log_sigma_scale = c(1, 1),
  alpha_rho_scale = 1,
  sigma_sq_rho_scale = 1,
  grain_size = 1
)

Arguments

phy

An object of class phylo from the ape package, representing the phylogenetic tree of the species.

species

Character vector of species names, in the same order as the rows of niche_params.

niche_params

A matrix or data.frame with columns: mu_1, mu_2 (centroid dimensions), sigma_1, sigma_2 (tolerances), rho (correlation), one row per species.

occ_data

A list of matrices, one per species, with environmental values at occurrence points.

env_m_data

A list of matrices, one per species, with environmental values at background points.

mu_anc_prior

Numeric vector of length 2, prior mean for ancestral centroid.

mu_anc_sigma

Numeric vector of length 2, prior SD for ancestral centroid.

rate_mu_scale

Numeric, scale for half-normal prior on BM rate of centroid.

rate_log_sigma_scale

Numeric, scale for half-normal prior on BM rate of log tolerances.

z_rho_anc_prior

Numeric, prior mean for ancestral z_rho (atanh(rho)).

z_rho_anc_sigma

Numeric, prior SD for ancestral z_rho.

rate_rho_scale

Numeric, scale for half-normal prior on BM rate of z_rho.

alpha_mu_scale

Numeric vector of length 2, scale for prior on OU alpha (centroid).

sigma_sq_mu_scale

Numeric vector of length 2, scale for prior on OU sigma^2 (centroid).

alpha_log_sigma_scale

Numeric vector of length 2, scale for prior on OU alpha (log tolerances).

sigma_sq_log_sigma_scale

Numeric vector of length 2, scale for prior on OU sigma^2 (log tolerances).

alpha_rho_scale

Numeric, scale for prior on OU alpha (rho).

sigma_sq_rho_scale

Numeric, scale for prior on OU sigma^2 (rho).

grain_size

Integer, grainsize for reduce_sum parallelisation.

Value

A named list suitable for passing to fit_evolution() as the stan_data argument.