Skip to content

Instantly share code, notes, and snippets.

@bomeara
bomeara / # treepl - 2018-08-07_14-05-22.txt
Created August 7, 2018 19:44
treepl (brewsci/bio/treepl) on macOS 10.13.6 - Homebrew build logs
Homebrew build logs for brewsci/bio/treepl on macOS 10.13.6
Build date: 2018-08-07 14:05:22
@bomeara
bomeara / distances.R
Last active August 9, 2019 08:08
Solution to @joel_nitta's "Heya phylotweeps! Anybody know of the right model to use for ancestral state reconstruction on a multivariate trait when the parts of the trait must sum to 1? Thinking OU but not sure how to implement it🤔 @Lagomarsino_L @kfeilich @omearabrian"
chunks <- seq(from=0, to=1, length.out=7) # how finely we want to divide each univariate character
# 0.0000000 0.1666667 0.3333333 0.5000000 0.6666667 0.8333333 1.0000000
possible_states <- expand.grid(a=chunks, b=chunks, c=chunks) # all possible combinations (not adding up to 1).
#Doing just three chars here, you can add more: d=chunks, e=chunks....
sums <- apply(possible_states,1, sum)
possible_states <- possible_states[which(abs(sums-1)<0.00001),] # now limiting to those that add up to 1
rownames(possible_states) <- sequence(nrow(possible_states)) - 1 # state 0, 1, 2...