Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtt function no longer handles NAs in dates #73

Closed
brj1 opened this issue Mar 7, 2023 · 5 comments
Closed

rtt function no longer handles NAs in dates #73

brj1 opened this issue Mar 7, 2023 · 5 comments

Comments

@brj1
Copy link

brj1 commented Mar 7, 2023

The rrt function performs root-to-tip regression on trees. In previous versions, you could put NA in the dates parameter to censor tips from the regression. However, this does not seem to be possible anymore. I can make a PR to fix this, if you want.

@emmanuelparadis
Copy link
Owner

Would a line like this:

if (anyNA(tip.dates)) stop("missing values not allowed in 'tip.dates'")

at the start of rtt() be enough?
I can add a note in rtt.Rd too.

@brj1
Copy link
Author

brj1 commented Mar 14, 2023

Could you add the ability to censor tip dates with NAs back? I need this functionality for some of the software that I maintain.

@emmanuelparadis
Copy link
Owner

You mean change nothing with respect to the current version?

@brj1
Copy link
Author

brj1 commented Mar 16, 2023

The problem is an update in R. Consider the following code:

library(ape)
set.seed(0)
tree <- rtree(5)
dates <- c(1, 2, 3, NA, NA)
rtt(tree, dates)

In R version 4.2.2 it gives an error:

Error in cor(y, x) : incompatible dimensions
In addition: There were 50 or more warnings (use warnings() to see the first 50)

In R version 4.0.5 it roots the tree.

tree

The issue is that the cor() function changed in the latest version of R so that by default NA are included in he correlation calculation where previously they would be censored.

The fix is fairly simple. Just change line 31 of rtt.R to:

cor(y, x, use = "complete.obs")

@emmanuelparadis
Copy link
Owner

Fixed and pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants