permute_all_polymorphisms: Permute all possible polymorphisms for a given set of states

View source: R/permute_all_polymorphisms.r

permute_all_polymorphismsR Documentation

Permute all possible polymorphisms for a given set of states

Description

Given a set of discrete states, will permute all possible polymorphic combinations of those states.

Usage

permute_all_polymorphisms(single_states)

Arguments

single_states

A vector of single states (e.g., 0, 1, 2 etc.).

Details

This function solves a simple phylogenetic combinatorics problem - what are all the possible outcomes for a character to be in given polymorphisms (of any size) are allowed?

For example, for three states (0, 1, 2) there are four possible polymorphisms: 0&1, 0&2, 1&2 and 0&1&2.

If the user is instead only interested in the size of this state space, this is simply given by 2^N - N - 1, where N is the number of single states. Thus, the first several outcomes are:

----------------------------------
| N states | N possible outcomes |
----------------------------------
|     2    |          1          |
|     3    |          4          |
|     4    |          11         |
|     5    |          26         |
|     6    |          57         |
|     7    |          120        |
|     8    |          247        |
|     9    |          502        |
|    10    |          1,013      |
|    11    |          2,036      |
|    12    |          4,083      |
|    13    |          8,178      |
|    14    |          16,369     |
----------------------------------

Note that this function is really designed for internal use, but may have value to some users and so is available "visibly" here.

Value

A vector of all possible polymorphic states.

Author(s)

Graeme T. Lloyd graemetlloyd@gmail.com

See Also

make_costmatrix and permute_all_uncertainties

Examples


# Get all possible states for the character 0, 1, and 2:
permute_all_polymorphisms(single_states = 0:2)


graemetlloyd/Claddis documentation built on May 9, 2024, 8:07 a.m.