xavierdidelot / BactDating

Bayesian inference of ancestral dates on bacterial phylogenetic trees
https://xavierdidelot.github.io/BactDating
MIT License
80 stars 15 forks source link

Is it possible to combine different date formats? #24

Closed maesaar closed 4 years ago

maesaar commented 4 years ago

Is it possible and how to combine dates to one set to use with BactDating when dataset has different date formats: 1) Date with only known year (2010)? 2) Date with year and month (march 2010)? 3) Complete date year month day as decimal?

Could you provide an example?

xavierdidelot commented 4 years ago

You can input uncertainty in the sampling dates by using as the second argument of the bactdate function a matrix with two columns where the first one is the minimum date and the second one is the maximum date. So for example if you have the three situations you mentioned you could use something like:

rbind(c(2010,2011),c(2010+2/12,2010+3/12),c(2010.12345,2010.12345))

maesaar commented 4 years ago

Hi thanks for quick answer! When using what you suggested First two worked fine but the third one (2010.123,2010.123) gave me the following error in R: Error in if (new - old < 0 && (!is.na(tab[j, 4]) && new < tab[tab[j, 4], : missing value where TRUE/FALSE needed In addition: Warning message: In rnorm(1, old, (rangedate[j, 2] - rangedate[j, 1]) * 0.05) : NAs produced

When I changed exact dates from third decimal place (2010.123,2010.124) it worked again!

Could you test it and give feedback on the issue?

xavierdidelot commented 4 years ago

Thanks, it sounds like there is a small bug and that it is in fact not possible to give a range without any difference between minimum and maximum values. I will try to fix this soon, but in the meantime you can use a very small range as you did and should get exactly the same results.

maesaar commented 4 years ago

Thank you - your suggestion works!

xavierdidelot commented 4 years ago

I was unable to reproduce this problem on my side, but I've just submitted a new version 1.0.8 which hopefully fixes this issue for you. Let me know if not!

Tonny-zhou commented 3 years ago

我无法重现此问题,但我刚刚提交了一个新版本1.0.8,希望可以为您解决此问题。让我知道是否!

I have a question! When I used the date parameter as a matrix with two columns in the roottotip function, an error occurred as "Error in cor(date2, ys, use = "complete.obs") ".
Could you tell me how to solve this? Thanks!

xavierdidelot commented 3 years ago

The format with two columns only works for bactdate, not for roottotip. You could apply rowMeans to your dates in order to use the mean of the two columns.