## 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))
Run the code above in your browser using DataLab