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

Error in apply(X, 1, sum/rstate) : dim(X) must have a positive length #149

Open
alrichardbollans opened this issue Jan 31, 2024 · 0 comments

Comments

@alrichardbollans
Copy link

I am trying to use ancThresh to do ancestral state reconstruction but when I pass my data to ancThresh I keep getting errors related to the format of the data and I'm not sure how to change the input to fix this.

Some code to recreate the errors is given below:

### MWE
### Create some data
# Define the row names and column values
row_names <- c('Mastixiodendron pachyclados', 'Aphanocarpus steyermarkii', 'Perama dichotoma')
values <- c(0, 0, 1)
df <- data.frame(`Binary_Var` = values, row.names = row_names)

simulated_tree <- ape::rtree(3)
simulated_tree$tip.label <- row_names # Assign tip names to the simulated tree

### The following give:
### Error in apply(X, 1, sum) : dim(X) must have a positive length
mcmc<-phytools::ancThresh(simulated_tree,df,sequence = c(0,1))

mcmc<-phytools::ancThresh(simulated_tree,as.matrix(df),sequence = c(0,1))

### The following give:
### Error in apply(X, 1, rstate) : dim(X) must have a positive length

mcmc<-phytools::ancThresh(simulated_tree,df$Binary_Var,sequence = c(0,1)) 

mcmc<-phytools::ancThresh(simulated_tree,c(setNames(df$Binary_Var, row_names)),sequence = c(0,1))

R version: 4.2
phytools version: 2.1-1

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