ancr: Compute marginal or joint ancestral state estimates

View source: R/asr.R

ancrR Documentation

Compute marginal or joint ancestral state estimates

Description

By default, ancr computes marginal ancestral states, also known as empirical Bayes posterior probabilities, conditioning on the fitted (or set) model of object.

Can also perform joint ancestral state estimation, if the optional argument type is set to type="joint".

hide.hidden merges hidden states (if any).

Usage

ancr(object, ...)
hide.hidden(object, ...)
## S3 method for class 'ancr'
plot(x, args.plotTree=list(...), args.nodelabels=list(...), ...)

Arguments

object

fitted Mk model (presently object of class "fitMk", "fitpolyMk", and "fitHRM"), or a set of models in the form of a table from anova comparison. For hide.hidden, object of class "ancr".

...

optional arguments.

x

in the case of plot.ancr, an object of class "ancr".

args.plotTree

arguments to be passed to plotTree, in a list.

args.nodelabels

arguments to be passed to nodelabels, in a list.

Details

If the optional argument tips=TRUE, then the matrix returned contains empirical Bayes posterior probabilities (marginal scaled likelihoods) for both tips and internal nodes. Otherwise (the default) only node marginal states are returned.

If the input object is a set of models (in the form of an anova table), then ancr will compute model-averaged marginal ancestral states (for type="marginal", unless the optional argument weighted=FALSE, in which case only the best-supported model is used.

Value

An object of class "ancr". In the case of type="marginal", this object consists of a matrix of marginal (empirical Bayes) probabilities and a likelihood. In the case of type="joint", the object contains a set of most-likely internal node states stored in a data frame.

Author(s)

Liam Revell liam.revell@umb.edu

References

Pagel, M. (1999) The Maximum Likelihood approach to reconstructing ancestral character states of discrete characters on phylogenies. Systematic Biology, 3, 612-622.

Revell, L. J. (2024) phytools 2.0: an updated R ecosystem for phylogenetic comparative methods (and other things). PeerJ, 12, e16505.

See Also

fitMk

Examples

## load tree and data from Revell & Collar (2009)
data(sunfish.tree)
data(sunfish.data)
## extract discrete character (feeding mode)
fmode<-setNames(sunfish.data$feeding.mode,
  rownames(sunfish.data))
## fit ARD model
ard_fmode<-fitMk(sunfish.tree,fmode,model="ARD",
  pi="fitzjohn")
## compute ancestral states
anc_fmode<-ancr(ard_fmode)
## plot the results
par(mfrow=c(2,1))
cols<-setNames(c("blue","red"),levels(fmode))
plot(anc_fmode,
  args.plotTree=list(lwd=2,direction="upwards",
    mar=c(0.1,1.1,2.1,1.1),fsize=0.8),
  args.nodelabels=list(piecol=cols),
  args.tiplabels=list(cex=0.3),
  legend="bottomright")
mtext("a) marginal states under ARD model",adj=0)
## fit ER model
er_fmode<-fitMk(sunfish.tree,fmode,model="ER",
  pi="fitzjohn")
## compare models
aov_fmode<-anova(er_fmode,ard_fmode)
## compute model-averaged ancestral states
anc_fmode_model.averaged<-ancr(aov_fmode)
plot(anc_fmode_model.averaged,
  args.plotTree=list(lwd=2,direction="upwards",
    mar=c(0.1,1.1,2.1,1.1),fsize=0.8),
  args.nodelabels=list(piecol=cols),
  args.tiplabels=list(cex=0.3),
  legend="bottomright")
mtext("b) marginal states model-averaging ER & ARD models",
  adj=0)
par(mar=c(5.1,4.1,4.1,2.1),mfrow=c(1,1))

phytools documentation built on June 22, 2024, 10:39 a.m.