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

Phangorn with binary state data generates error with modelTest and warning with optim.pml #98

Open
fpbarthel opened this issue Jun 11, 2020 · 0 comments

Comments

@fpbarthel
Copy link

fpbarthel commented Jun 11, 2020

Hi there!

Thanks for the great phangorn package. I'm having some trouble using this with binary data and wonder why this is.

I have two issues:

  1. Using my data I get the following error when I try to use modelTest to determine the optimal model:
Error in as.vector(x, "character") : 
cannot coerce type 'closure' to vector of type 'character'
  1. Using my data I get the following "warning message" when I use optim.pml to fit a JC model.
Warning message:
In QM[lower.tri(QM)] <- x$Q :
  number of items to replace is not a multiple of replacement length

Here is a toy example I generated that reproduces the first issue and generates an error (rather than a warning) when trying to fit a JC model. Unfortunately I was not able to reproduce the warning message above using toy data. Nevertheless, using my actual data it seems to output a model with an improved log-likelihood, so perhaps I can ignore the warning message?

library(ape)
library(phangorn)

## Generate 10 taxa with 1000 binary (0/1) characters each
m <- sapply(sprintf("taxon%s",1:10), function(taxon) round(runif(1000, 0, 1)))
rownames(m) <- sprintf("char%s",1:nrow(m))
d <- dist(t(m), method = "binary")
tre <- bionj(d)

## Convert to phangorn format
mphy <- as.phyDat(t(m), type = "USER", levels = c(0,1))

## This fails with the error above (issue 1)
modelTest(mphy)

## Works fine
fit   <- pml(tre, mphy)

## Generates error below, different from the warning in issue 2
fitJC <- optim.pml(fit, TRUE)

The error when trying to fit the JC model on the toy data is as follows:

Error in if (!any(betahat < 0)) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In if (!is.binary(tree)) tree <- multi2di(tree) :
the condition has length > 1 and only the first element will be used
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

1 participant