ericgoolsby / Rphylopars

Phylogenetic Comparative Tools for Missing Data and Within-Species Variation
28 stars 11 forks source link

Error for data type #21

Open hz424 opened 6 years ago

hz424 commented 6 years ago

I am using Rphylopars and it gave me error " ** On entry to DLASCL, parameter number 4 had an illegal value Error in tp(L = X, R = R, Rmat = as.matrix(Rmat), mL = ncol(X), mR = 1, : Not compatible with requested type: [type=character; target=double]." when I try the step "p_BM <- phylopars(trait_data = trait_data[1:30,],tree = AMP_tree)"

I am sure the data type was the same with the tutorial data. is.factor(trait_data[,1]): TRUE; & is.double(trait_data[,2]): TRUE

Anyone has solutions for this? Thanks

screen shot 2018-04-21 at 1 05 16 pm

@ericgoolsby @qdread

r03ert0 commented 6 years ago

got a similar error:

Error in tp(L = X, R = R, Rmat = as.matrix(Rmat), mL = ncol(X), mR = 1,  : 
  Not compatible with requested type: [type=character; target=double].

I was fitting several phenotypes, and the issue appeared when I log10 a specific one (Rphylopars only like that parameter when it's not log10 transformed). I checked for NaNs, but there were none.

tdjames1 commented 6 years ago

I have also had a persistent problem with certain datasets producing errors of the above form. I'm posting the results of my investigations into the problem.

The quoted error is about incompatible types, meaning that something passed into to tp is not of an appropriate type (tp is written in C++ which is strongly typed). Here it seems to be receiving a object of type character instead of the required double.

Note that the problem that I encountered may be different to the one noted by OP above, as the error message simply indicates that one of the passed in parameters has an unexpected type.

The problem that I was seeing appeared to be a result of calling mat_to_pars for an ill-conditioned phenotypic covariance matrix (itself the output of EM_Fels2008). This causes the Cholesky decomposition to fail, at which point mat_to_pars returns an object of class "try-error". In the section of the code that applies the Felsenstein 2008 EM algorithm, starting at: https://github.com/ericgoolsby/Rphylopars/blob/937848206a29e1ecde77657c55c63ac8bcac634a/R/phylopars_update.R#L456 the class of the output from mat_to_pars is not checked, which results in calls to tp with an incorrect type for the pars parameter. A possible fix would be to check for class(pars) == "try-error" and replace the value if needed, but I don't know what a suitable alternative would be.

The only workaround I have found for this in my work is to set pheno_error = FALSE in my calls to phylopars. This is not ideal as I would like to include phenotypic variation in my imputation analysis.

Jonathan-Abrahams commented 6 years ago

I had this problem.

My branch lengths were too small. I am working with bacterial strains which are only differ by a few mutations and evidently, also 0 mutations.

randomizing the branch lengths like this worked:

alt_tree$edge.length=sample(sample(seq(0,0.1,length.out = 10000)),1738)
p_BM <- phylopars(trait_data = BP2451_data,tree = alt_tree)

But then its actually the 0 branch lengths that cock it all up.This works:

alt_tree$edge.length[which(alt_tree$edge.length==0)]=0.0001
p_BM <- phylopars(trait_data = BP2451_data,tree = alt_tree)
bmaitner commented 5 years ago

I ran into the "Not compatible with requested type: [type=character; target=double]." bug while trying to run Rphylopars in parrallel with foreach. Oddly enough, it worked fine with %do%, but when using %dopar% I got the error. After a bit of thinking I came up with a reasonable workaround: I replaced the taxa names on my phylogeny and character matrix with numbers. Since all of the columns in the traits matrix are now double, the error disappears. Then I just swap the names back once phylopars has run.

    temp_traits <- traits
    temp_tree <- tree
    temp_tree$tip.label <- 1:length(tree$tip.label)

    temp_traits$species <- sapply(X = temp_traits$species, FUN = function(x){which(tree$tip.label==x)})

    #Just to make sure all the columns are being processed as double

    temp_traits[,1:ncol(temp_traits)] <- 
            apply(X = temp_traits[,1:ncol(temp_traits)],MARGIN = 2,FUN = as.double)

    phylopars_output <- Rphylopars::phylopars(trait_data = temp_traits,tree = temp_tree)

I'm not sure if this will address all the instances of this bug, but it might be of use for some of them!

lauramencue commented 4 years ago

Hi, I am also getting a similar error when I run phylopars on my data:

Error in tp(L = X_complete, R = as.matrix(as.double(dat)), Rmat = as.matrix(dat), : basic_ios::clear

My tree has 2539 tips (class phylo) and I have checked that the species on the tree tips and the traits table (class data frame) are exactly the same. Has anyone run into the same problem or knows what this error might mean?? Thanks!!

rafalopespx commented 2 years ago

I had this same problem with a pipeline where I ran simplex to find embedding dimensions and after this give the optimal embedding to the ccm function, when I ran the pipeline in whole, it has no problem because the embedding dimension I give it was as a double, if I ran my pipeline in separate parts, by pick the embedding dimension from a .csv it read it as a unknown and passing it to ccm() like this it gives me this same error, so I just transform the embedding dimension value into a double and it worked