if (FALSE) {
DataCetaceans$treecet->treecet
plot(treecet,show.tip.label = FALSE,no.margin = TRUE)
nodelabels(frame="n",col="red")
# Select two clades for stratified random sampling
clanods=c("crown_Odo"=150,"crown_Mysti"=131)
sdata1<-do.call(rbind,lapply(1:length(clanods),function(w)
data.frame(species=tips(treecet,clanods[w]),group=names(clanods)[w])))
# generate a vector of probabilities based on body mass
prdata<-max(DataCetaceans$masscet)-DataCetaceans$masscet
# select two nodes to be preserved
nn=c(180,159)
# generate two fictional categorical vectors to be preserved
cat1<-sample(rep(c("a","b","c"),each=39),Ntip(treecet))
names(cat1)<-treecet$tip.label
cat2<-rep(c("d","e"),each=100)
names(cat2)<-sample(treecet$tip.label,100)
# 1. Random sampling
resampleTree(treecet,s=0.25,swap.si=0.3)->treecet1
# 1.1 Random sampling preserving clades
resampleTree(treecet,s=0.25,nodes=nn)->treecet2
# 2. Stratified random sampling
resampleTree(treecet,sdata = sdata1,s=0.25)->treecet3
# 2.1 Stratified random sampling preserving clades and categories
resampleTree(treecet,sdata = sdata1,s=0.25,nodes=nn,categories = list(cat1,cat2))->treecet4
# 3. Sampling conditioned on probability
resampleTree(treecet,sdata = prdata,s=0.25,nsim=5)->treecet5
}
Run the code above in your browser using DataLab