TreeSearch (version 0.4.0)

MinimumLength: Minimum length

Description

The smallest length that a character can obtain on any tree.

Usage

MinimumLength(states)

MinimumSteps(states)

Arguments

states

Integer vector listing the tokens that may be present at each tip along a single character, with each token represented as a binary digit; e.g. a value of 11 ( = 2^0 + 2^1 + 2^3) means that the tip may have tokens 0, 1 or 3.

Inapplicable tokens should be denoted with the integer 0 (not 2^0).

Tokens that are ambiguous for an inapplicable and an applicable state are not presently supported; for an approximate value, denote such ambiguity with the integer 0.

Value

An integer specifying the minimum number of steps that the character must contain.

Examples

Run this code
# NOT RUN {
{
  data('inapplicable.datasets')
  myPhyDat <- inapplicable.phyData[[4]] 
  class(myPhyDat) # phyDat object
  # load your own data with
  # my.PhyDat <- as.phyDat(read.nexus.data('filepath'))
  # or Windows users can select a file interactively using:
  # my.PhyDat <- as.phyDat(read.nexus.data(choose.files()))
  
  # Convert list of character codings to an array
  myData <- vapply(myPhyDat, I, myPhyDat[[1]])
  
  # Convert phyDat's representation of states to binary
  myContrast <- attr(myPhyDat, 'contrast')
  tokens <- colnames(myContrast)
  binaryContrast <- integer(length(tokens))
  tokenApplicable <- tokens != '-'
  binaryContrast[tokenApplicable] <- 2 ^ (seq_len(sum(tokenApplicable)) - 1)
  binaryValues <- apply(myContrast, 1, 
    function (row) sum(binaryContrast[as.logical(row)]))
  myStates <- matrix(binaryValues[myData], nrow=nrow(myData),
                     ncol=ncol(myData), dimnames=dimnames(myData))
 
  # Finally, work out minimum steps 
  apply(myStates, 1, MinimumLength)
  
}

# }

Run the code above in your browser using DataLab