# this function fits two or more evolutionary rates for a continuous trait on the tree # based on O'Meara et al. (2006) # written by Liam J. Revell 2011/2012 brownie.lite<-function(tree,x,maxit=2000,test="chisq",nsim=100,se=NULL){ # some minor error checking if(class(tree)!="phylo") stop("tree object must be of class 'phylo.'") x<-matchDatatoTree(tree,x,"x") x<-x[tree$tip.label] if(!is.null(se)) se<-matchDatatoTree(tree,se,"se") else { se<-rep(0,length(x)) names(se)<-names(x) } n<-length(x) # number of species p<-ncol(tree$mapped.edge) # number of states C1<-vcv.phylo(tree) a<-as.numeric(colSums(solve(C1))%*%x/sum(solve(C1))) sig<-as.numeric(t(x-a)%*%solve(C1)%*%(x-a)/n) # single rate model model1<-optim(c(sig,a),fn=lik.single,y=x,C=C1,se=se,control=list(maxit=maxit),hessian=TRUE,method="L-BFGS-B",lower=c(0,-Inf)) logL1<--model1$value sig1<-model1$par[1] a1<-model1$par[2] vcv1<-solve(model1$hessian); rownames(vcv1)<-c("sig","a"); colnames(vcv1)<-rownames(vcv1) # multiple rate model C2<-multiC(tree) s<-c(rep(sig1,p),a1) l<-c(rep(0.0001*sig1,p),-Inf) model2<-optim(s,fn=lik.multiple,y=x,C=C2,se=se,control=list(maxit=maxit),hessian=TRUE,method="L-BFGS-B",lower=l) logL2<--model2$value while(logL2