尽管@jeremycg 帮助我开发了以下代码,但我再次发布此内容。它有效,但它的表现不是我想要的!快速提醒:我有一组树,我需要用一个称为 gamma 的因子来衡量,如果每棵树的值不在定义的范围内,它会重新调整,直到它的值在定义的范围内......让我们试试这个例子:
library(ape)
library(phytools)
trees<- pbtree(b=1, n=100, nsim=50)
fixmytrees <- function(tree, rescaleamt = NULL){
if(is.null(rescaleamt)){
rescaleamt <- sample(seq(from = 0.1, to = 0.9, by = 0.1), 1)
}
if(is.na(gammaStat(tree))){return("bad tree")}
if(gammaStat(tree) < 6){
return(tree)
} else {
return(rescale(tree, model ="delta", rescaleamt))
}
}
z<-lapply(tree, fixmytrees)
#The script does rescale trees but they are not extreme enough. In this case if you try
gammaStat(z[[]]) #You would probably see values lower than 6 and sometimes NA!!!
谢谢你!