hmorlon / PANDA

Phylogenetic ANalyses of DiversificAtion
24 stars 15 forks source link

How to run environmental-dependent models with a sample of trees #28

Closed KaterynPino closed 4 years ago

KaterynPino commented 4 years ago

Hello,

I want to fit the environmental-dependent models in RPANDA, but with a sample of trees, but I don't know-how. All the examples I found are with a single tree. There is some script to do this?. A lot of thanks!

Cheers,

Kateryn

FabienCondamine commented 4 years ago

Dear Kateryn,

One simple way to do this is as follows:

missing.lineages <- # a numerical value for your total clade species diversity trees <- read.tree("Posteriors_trees.tre") #Can be read.nexus() especially if posterior trees come from a BEAST analysis subsampled.trees <- sample(trees, 100)

for (i in 1:length(subsampled.trees)) { tree <- subsampled.trees[[i]] tot_time <- max(node.age(tree)$ages) f <- Ntip(tree)/(Ntip(tree)+missing.lineages) cond = "crown"

print("BTempVar EXPO") f.lamb<-function(t,x,y){y[1]exp(y[2]x)} f.mu<-function(t,x,y){0} lamb_par<-c(0.1,0.0) mu_par<-c() cst.lamb=F; cst.mu=T; expo.lamb=F; expo.mu=F; fix.mu=T

tree_BTempVar_EXPO <- fit_env(tree, env_data, tot_time, f.lamb, f.mu,lamb_par, mu_par, f=f, cst.lamb=cst.lamb, cst.mu=cst.mu, expo.lamb=expo.lamb, expo.mu=expo.mu, fix.mu=fix.mu, cond=cond, dt=1e-3)
print(tree_BTempVar_EXPO)

}

Of course, you need to create an object (list, vector, matrix) to store the results for each tree of your distribution. Also, you need to load the temperature data, here named env_data in the fit_env function (e.g. data(InfTemp)).

I hope this helps. Don't hesitate if you have any questions.

Best regards,

KaterynPino commented 4 years ago

Dear Fabien,

I appreciate your response. It has been a great help.

But, now I have a problem with the initial parameters (Error in optim(init, optimLH, method = meth function cannot be evaluated at initial parameters). This is weird because I ran a bunch of different models of time dependency (fit_bd function) and everything ok. Nevertheless, when I traying with environmental dependency models (fit_env function) the analysis stops with this error after ran the first 5 or 10 samples trees. I try changing the initial parameters several times but it doesn't work. What can I do?.

A lot of thanks!

Best regards,

JClavel commented 4 years ago

Hi Kateryn,

Just to check, what is the height of your tree? (e.g. max(nodeHeights(phylo))) The age must be < to the total length (age) of the climatic curve.

Regards,

Julien


De : KaterynPino notifications@github.com Envoyé : dimanche 23 février 2020 16:10 À : hmorlon/PANDA PANDA@noreply.github.com Cc : Subscribed subscribed@noreply.github.com Objet : Re: [hmorlon/PANDA] How to run environmental-dependent models with a sample of trees (#28)

Dear Fabien,

I appreciate your response. It has been a great help.

But, now I have a problem with the initial parameters (Error in optim(init, optimLH, method = meth function cannot be evaluated at initial parameters). This is weird because I ran a bunch of different models of time dependency (fit_bd function) and everything ok. Nevertheless, when I traying with environmental dependency models (fit_env function) the analysis stops with this error after ran the first 5 or 10 samples trees. I try changing the initial parameters several times but it doesn't work. What can I do?.

A lot of thanks!

Best regards,

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/hmorlon/PANDA/issues/28?email_source=notifications&email_token=ACSCJSMNI6RMHE6WKCY7563REKGWPA5CNFSM4KX67USKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMV6CRY#issuecomment-590078279, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACSCJSKJTNREBBW5SD2IH6LREKGWPANCNFSM4KX67USA.

KaterynPino commented 4 years ago

Hi Julien,

You are right, everything it's ok now. A lot of thanks!

Regards,

Kate