specify_manifest_trait_metadata: Specify Manifest Trait Metadata

View source: R/manifest_trait_metadata.R

specify_manifest_trait_metadataR Documentation

Specify Manifest Trait Metadata

Description

Converts metadata relating to a data frame of manifest traits into a dataframe. Ensures that the meta data is correctly formatted, allowing CAVI for comparative analysis and ancestral reconstruction,

Usage

specify_manifest_trait_metadata(
  n_traits,
  trait_names,
  trait_type,
  trait_levels,
  manifest_trait_index,
  auxiliary_trait_index,
  link_functions,
  inverse_link_functions,
  cut_off_points,
  categories,
  manifest_trait_df = NULL,
  perform_checks = TRUE
)

Arguments

n_traits

A natural number. The number of manifest traits.

trait_names

A P-dimensional character vector. The manifest trait names.

trait_type

A P-dimensional vector of unordered factors belonging to one of 4 levels. The trait type corresponding to each of the named manifest traits. Ordinal traits are denoted ord, nominal are nom, scalar-valued continuous are con, and function-valued traits are fvt.

trait_levels

A P-dimensional vector. The number of levels associated with each manifest trait. NA for continuous traits.

manifest_trait_index

A P-dimensional list. columns of manifest_trait_df associated with each trait. List elements will be scalar valued for ordinal, nominal, and scalar-valued continuous traits. Function-valued traits are multi-variate and indexed by a vector of values.

auxiliary_trait_index

A P-dimensional list. Columns of the auxiliary trait matrix to be associated with each trait. List elements will be scalar valued for ordinal, nominal, and scalar-valued continuous traits. Function-valued traits are multi-variate and indexed by a vector of values.

link_functions

A P-dimensional list. Functions mapping auxiliary traits to manifest traits. For traits taking continuous values these must be specified by the user and can be the identity function.

inverse_link_functions

A P-dimensional list. Functions mapping manifest traits to auxiliary traits. For traits taking continuous values these must be specified by the user and can be the identity function.

cut_off_points

A P-dimensional list. The set of cut-off points for ordinal traits. NA for all other traits.

categories

A P-dimensional list. The set of categories for nominal traits, stored as an unordered factor. NA for all other traits.

manifest_trait_df

The data frame of manifest traits. If included allows for a non-exhaustive series of checks comparing metadata provided to that implicit in the manifest traits.

perform_checks

Logical. Check if function inputs are specified correctly.

Value

A data frame containing required metadata for each manifest trait.

Examples

P <- 4
tn <- c("ord", "nom", "con", "fvt")
tt <- factor(tn, levels = c("ord", "nom", "con", "fvt"))
ind_mt <- list(
  ord = 2L, nom = 3L, con = 4L, fvt = 5:36
)
mt <- cbind(synthetic_traits[, 1:4], fvt = t(simplify2array(synthetic_traits$fvt)))
K <- c(4, 3, NA, NA)
ind_at <- list(
  ord = 1L, nom = 1 + 1:3, con = 5L, fvt = 5 + 1:32
)
g <- list(
  ord = ordinal_link,
  nom = nominal_link,
  con = function(x) x,
  fvt = function(x) exp(x)
)
g_inv <- list(
  ord = ordinal_inverse_link,
  nom = nominal_inverse_link,
  con = function(y) y,
  fvt = function(y) log(y)
)
gamma <- list(
  ord = c(-Inf, 0, 1, 2, Inf),
  nom = NA, con = NA, fvt = NA
)
cat <- list(
  ord = NA,
  nom = factor(levels(mt$nom)),
  con = NA, fvt = NA
)

meta <- specify_manifest_trait_metadata(
  n_traits = P, trait_names = tn, trait_type = tt,
  trait_levels = K,
  manifest_trait_index = ind_mt, auxiliary_trait_index = ind_at,
  link_functions = g,
  inverse_link_functions = g_inv,
  cut_off_points = gamma, categories = cat,
  manifest_trait_df = mt,
  perform_checks = TRUE
)
checkmate::expect_data_frame(meta)

jpmeagher/vbar documentation built on Nov. 22, 2022, 5:48 a.m.