ericgoolsby / Rphylopars

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

Error: Not compatible with requested type #32

Closed brmagalis closed 4 years ago

brmagalis commented 4 years ago

Hello,

I have tried everything under the sun to try and pull off the anc.recon function, including modifying my trait data and changing edges in my phylo tree to characters, but I'm getting some form of the following error every time, so I am missing something. Any help would be appreciated:

Error in C_anc_recon(Y = trait_data, anc = tree$edge[, 1], des = tree$edge[, : Not compatible with requested type: [type=character; target=double].

Commands used (in a nutshell):

sub_tree <- read.tree("sub_tree.nwk") traits <- read.table("asr_traits.txt", sep='\t', header=T, stringsAsFactors = F) ASR <- anc.recon(traits, sub_tree, vars=F, CI=F)

Files: asr_traits.txt sub_tree.txt

ericgoolsby commented 4 years ago

Hi there! The Rphylopars package only works for continuous traits. If you want to perform ancestral state reconstruction on a discrete trait, you could use the ape package:

ASR <- ace(x = setNames(traits$V1,traits$species),phy = sub_tree,type = "discrete",model = "ER")

This assumes an equal probability of transition among any state. You can change the model to model="SYM" so transitions between for example states A and B can vary (but P(A-->B)=P(B-->A)). Or you can set model="ARD" so that P(A-->B) != P(B-->A).

Then ASR$lik.anc corresponds to the probabilities of the state at each ancestral node such that row numbers correspond to node numbers (nspecies+1) on the tree.

brmagalis commented 4 years ago

I have indeed been doing this, but I was just under the impression that rphylopars was faster, but I had no idea it did not work for discrete states. Thank you,

--

Brittany Rife Magalis, PhD

Postdoctoral Associate, UF College of Medicine

Emerging Pathogens Institute

Gainesville, FL 32601

Phone: +1 (540) 383-1395

From: "Eric W. Goolsby" notifications@github.com Reply-To: ericgoolsby/Rphylopars reply@reply.github.com Date: Wednesday, December 11, 2019 at 12:48 PM To: ericgoolsby/Rphylopars Rphylopars@noreply.github.com Cc: Brittany Rife Magalis brmagalis@gmail.com, Author author@noreply.github.com Subject: Re: [ericgoolsby/Rphylopars] Error: Not compatible with requested type (#32)

Hi there! The Rphylopars package only works for continuous traits. If you want to perform ancestral state reconstruction on a discrete trait, you could use the ape package:

ASR <- ace(x = setNames(traits$V1,traits$species),phy = sub_tree,type = "discrete",model = "ER")

This assumes an equal probability of transition among any state. You can change the model to model="SYM" so transitions between for example states A and B can vary (but P(A-->B)=P(B-->A)). Or you can set model="ARD" so that P(A-->B) != P(B-->A).

Then ASR$lik.anc corresponds to the probabilities of the state at each ancestral node such that row numbers correspond to node numbers (nspecies+1) on the tree.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Jigyasa3 commented 4 years ago

Hey @ericgoolsby

I have been getting the same error, but this time for continuous traits. If I decrease the no. of traits to >20 then the function runs. Otherwise, it gives an error-

error- p_BM <- phylopars(trait_data = functions3,tree = tree,model = "BM") 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].

files- https://github.com/Jigyasa3/errors/blob/master/above500_tpm_mainfunctions_NAvalues.csv https://github.com/Jigyasa3/errors/blob/master/500bps_termitetree.nwk

code that I am running- `func<-read.csv("above500_tpm_mainfunctions_NAvalues.csv",row.names=1) tree<-read.tree("500bps_termitetree.nwk")

library(Rphylopars) p_BM <- phylopars(trait_data = func,tree = tree,model = "BM") `