thej022214 / corHMM

Fits a generalized form of the covarion model that allows different transition rate classes on different portions of a phylogeny by treating rate classes as “hidden” states in a Markov process.
11 stars 13 forks source link

Allow fixing more than one node in stochastic character map makeSimmap #45

Closed SimonGreenhill closed 2 years ago

SimonGreenhill commented 2 years ago

It would be awesome if the makeSimmap function could fix node states in the same way that corHMM does. Currently makeSimmap only allows you to fix a single node with fix.node/fix.state. I have two nodes I want to fix :)

jboyko commented 2 years ago

Should be added now! Let me know if it works.

library(corHMM)   # follow example in corHMM docs
library(phytools)

data(primates)
phy <- primates[[1]]
phy <- multi2di(phy)

## make character with character labels
data <- data.frame(
  Genus_sp=phy$tip.label,
  Trait=sample(x=c("A", "B"),size=Ntip(phy), replace=TRUE)
)

##run corhmm 
MK <- corHMM(phy, data, 1, collapse = FALSE)
model <- MK$solution
simmap.corhmm <- makeSimmap(tree=phy, data=data, model=model/500, rate.cat=1, nSim=1, nCores=1, fix.node = c(61, 62, 63, 64, 65), fix.state = c(2, 2, 2, 2, 2))

phytools::plotSimmap(simmap.corhmm[[1]])
SimonGreenhill commented 2 years ago

you've made my day - thank you!