Learn R Programming

dispRity (version 1.7.0)

sim.morpho: Simulates morphological data.

Description

Generates a morphological matrix using rTraitDisc or gen.seq.HKY functions.

Usage

sim.morpho(
  tree,
  characters,
  states = 1,
  model = "ER",
  rates,
  substitution = c(stats::runif, 2, 2),
  invariant = TRUE,
  verbose = FALSE
)

Arguments

tree

A phylogenetic tree to use for generating the characters.

characters

The number of morphological characters to generate.

states

A numeric string of probabilities for the number of states for each character (default = 1; i.e. 100% binary state characters; see details).

model

Either an implemented ("ER", "HKY" or "MIXED") or user defined model (see details).

rates

A function an its parameters for the rates distribution (see details).

substitution

A function an its parameters for the substitutions distribution (see details; default = c(runif, 2, 2)).

invariant

logical, whether to allow any invariant sites (default = TRUE).

verbose

Whether to be verbose or not (default = FALSE).

Author

Thomas Guillerme

Details

  • The model arguments must be either a user's defined function for generating the discrete morphological characters (that takes the states, rates and substitution arguments) or one of the two following:

    • "ER" uses the ape::rTraitDisc function with the "ER" model argument (= Mk model).

    • "HKY" uses the phyclust::gen.seq.HKY function with kappa sampled from the substitution argument, pi = runif(4) (divided by sum(runif(4))), rate.scale sampled from the rates distribution and L being the number of characters and transforms the purines (A, G) into 0 and the pyrimidines (C, T) into 1.

    • "MIXED" randomly uses "ER" or "HKY" for binary characters and "ER" for any character with more than two states.

    • the user defined model must be a function that generates a single discrete morphological character and takes one element from at least the following arguments: tree, states, rates, substitution.

  • The states argument attributes a number of states to each character by using the given probability vector for each number of states starting from two. For example states = c(0.7, 0.2, 0.1) will generate 70% of characters with two states, 20% of characters with three states and 10% of characters with four states.

  • The rates and substitution arguments require a function that outputs a distribution and its optional parameters. For example rates = c(runif, 1, 10) creates a uniform distribution between 1 and 10 for the rates distribution.

See Also

check.morpho, apply.NA, rTraitDisc, gen.seq.HKY

Examples

Run this code

set.seed(4)
## A random tree with 15 tips
tree <- rcoal(15)
## Setting up the parameters
my_rates = c(rgamma, rate = 10, shape = 5)
my_substitutions = c(runif, 2, 2)

## HKY binary (15*50)
matrixHKY <- sim.morpho(tree, characters = 50, model = "HKY",
     rates = my_rates, substitution = my_substitutions)

## Mk matrix (15*50) (for Mkv models)
matrixMk <- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates) 

## Mk invariant matrix (15*50) (for Mk models)
matrixMk <- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates,
     invariant = FALSE)

## MIXED model invariant matrix (15*50)
matrixMixed <- sim.morpho(tree, characters = 50, model = "MIXED",
     rates = my_rates, substitution = my_substitutions,  invariant = FALSE,
     verbose = TRUE)

Run the code above in your browser using DataLab