Hi, Thank you Krzysztof, thank you Jonas! Both suggestions are very useful. Jonas, is there a publication that could be cited, please?
Cheers, Chris On Fri, Nov 11, 2022 at 3:00 AM <r-sig-phylo-requ...@r-project.org> wrote: > Send R-sig-phylo mailing list submissions to > r-sig-phylo@r-project.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > or, via email, send a message with subject or body 'help' to > r-sig-phylo-requ...@r-project.org > > You can reach the person managing the list at > r-sig-phylo-ow...@r-project.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of R-sig-phylo digest..." > > > Today's Topics: > > 1. Re: ancestral state reconstruction with a complex discrete > trait (Jonas Eberle) > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 10 Nov 2022 15:32:58 +0100 > From: Jonas Eberle <eberle.jo...@gmail.com> > To: r-sig-phylo@r-project.org > Subject: Re: [R-sig-phylo] ancestral state reconstruction with a > complex discrete trait > Message-ID: <77d6c73f-b316-b728-1cf4-20bb68f82...@gmail.com> > Content-Type: text/plain; charset="utf-8" > > Dear Chris, > > phangorn might provide a solution for your problem. You can define > user-specific data via a contrast matrix and use this matrix to create a > phyDat object. You can then use parsimony or maximum likelihood (maybe > also Bayesian?) in phangorn to reconstruct ancestral states. I actually > used it for reconstructing ancestral petal colours some years ago. Here > is some code that you could recycle: > > library(phangorn) > > # define ambiguous characters > contrast <- matrix(data = c( > 1,0,0,0,0,0, > 0,1,0,0,0,0, > 0,0,1,0,0,0, > 0,0,0,1,0,0, > 0,0,0,0,1,0, > 1,1,0,0,0,0, > 1,0,1,0,0,0, > 1,0,0,1,0,0, > 0,1,1,0,0,0, > 0,1,0,0,1,0, > 0,0,1,1,0,0, > 0,0,1,0,1,0, > 0,0,0,0,0,1), > ncol = 6, byrow = TRUE) > dimnames(contrast) <- list(c("0", > "1","2","3","4","01","02","03","12","14","23","24","-"), > c("0", "1", "2", "3", "4", "-")) > contrast > > traits <- matrix( > data = c("01", "24", "4", "1", "-", "03", "0", "01", "23", "01"), > ncol = 1, > dimnames = list( > paste0("t",1:10), > "trait" > ) > ) > > data <- phyDat(traits, > type="USER", > levels=c("0", > "1","2","3","4","01","02","03","12","14","23","24","-"), > contrast=contrast) > data > > tree <- rtree(10) > > # maximum parsimony ancestral reconstruction > anc.pars <- ancestral.pars(tree, data, type="MPR") > > cols <- c("#33a02c", "#a6cee3", "#1f78b4", "#000000", "#000000", "#000000") > plotAnc(tree, anc.pars, 1, col=cols, cex.pie=.75) > > I made up some data so that there are more states in the contrasts > matrix than in the data... > > Best, > Jonas > > > Am 10.11.2022 um 12:00 schrieb r-sig-phylo-requ...@r-project.org: > > Send R-sig-phylo mailing list submissions to > > r-sig-phylo@r-project.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > > or, via email, send a message with subject or body 'help' to > > r-sig-phylo-requ...@r-project.org > > > > You can reach the person managing the list at > > r-sig-phylo-ow...@r-project.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of R-sig-phylo digest..." > > > > Today's Topics: > > > > 1. Re: R-sig-phylo Digest, Vol 178, Issue 3 (Krzysztof Kozak) > > 2. Re: ancestral state reconstruction with a complex discrete > > trait (Krzysztof Bartoszek) (Krzysztof Bartoszek) > > > > _______________________________________________ > > R-sig-phylo mailing list > > R-sig-phylo@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > > [[alternative HTML version deleted]] > > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > R-sig-phylo mailing list > R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > > > ------------------------------ > > End of R-sig-phylo Digest, Vol 178, Issue 5 > ******************************************* [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/