[R-sig-ME] genetic distance as covariance matrix through ginverse?

Matthew Wolak s06mw3 at abdn.ac.uk
Thu Jun 5 11:18:01 CEST 2014


Dear Dean,

MCMCglmm needs the generalized inverse (your M1) formatted in a specific
way - for example as the "dgCMatrix" class defined in the Matrix package.

Substituting the lines below gets the model to work.  NOTE, I had to
substitute "0.00" wherever you had NA in the M matrix in order to invert
it.  This is probably not the best practice and maybe some simulations
to determine the sensitivity of your parameter estimates when there is
error (i.e., saying NA=0.00) in your genetic distance matrix.

INSTEAD OF:

M1<-ginv(M) #I have also been using M in the model with the same error

dimnames(M1) <- list(c("sp1","sp2","sp3","sp4"),c("sp1","sp2","sp3","sp4"))


DO

M1 <- as(ginv(M), "dgCMatrix")

M1 at Dimnames <- list(c("sp1", "sp2", "sp3", "sp4"), c("sp1", "sp2", "sp3", "sp4"))



Sincerely,
Matthew

....................................................
Dr. Matthew E. Wolak
School of Biological Sciences
Zoology Building
University of Aberdeen
Tillydrone Avenue
Aberdeen AB24 2TZ
office phone: +44 (0)1224 273255

On 04/06/14 19:33, Dean Castillo wrote:
> I am currently using MCMCglmm to model species ability to cross with one
> another. For most of the datasets species relationships can be defined by a
> phylogeny and I can simply incorporate this information into the model
> using the pedigree or ginverse options.
>
> I would like to run similar models now but for subspecies/races that do not
> have well defined phylogenies (the questions is identical). I have genetic
> distances for some of the species in these data sets (some I have complete
> pairwise genetic distances, others I only have distances for specific
> species pairs). I have considered making a  simple NJ tree based on
> distance matrices and incorporating this "phylogeny" via pedigree or
> ginverse, but this strategy will not work without complete pairwise
> distances.
>
> Is there a way to utilize the distance matrix (complete or more sparse)
> directly? Since the genetic distance matrix looks very similar to the
> relationship matrix "A" in the MCMCglmm tutorial and coursenotes I tried
> incorporating it into the model but have run into a few errors.
>
> Here is the fake data I have been playing around with. Any help would be
> greatly appreciated
>
> #Genetic Distance Matrix. I have also been replacing NA with 0 but still
> encounter same error
>
> x <- c( 0.07 ,0.08, 0.11,NA,
>
>   0.16, NA)
>
> M <- matrix(0, 4, 4)
>
> M[lower.tri(M)] <- x
>
> M <- t(M)
>
> M[lower.tri(M)] <- x
>
> dimnames(M) <- list(c("sp1","sp2","sp3","sp4"),c("sp1","sp2","sp3","sp4"))
>
> diag(M)<-1
>
> #Fake response variable, species ID, and categorical predictor
>
>
> y<-c(5,5,6,6,10,10,12,11,4,3,4,5,11,12,13,14)
>
> species<-c("sp1","sp1","sp1","sp1","sp2","sp2","sp2","sp2","sp3","sp3","sp3"
> ,"sp3","sp4","sp4","sp4","sp4")
>
> species<-as.factor(species)
>
> ms<-c(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1)
>
> data<-data.frame(y,ms,species)
>
>
> # want to run a model for y~ma taking into account species
>
> library(MCMCglmm)
>
> #define prior
>
> p.var<-var(y)
>
> prior1=list(R=list(V=p.var/2, n=1), G=list(G1=list(V=p.var/2, n=1)))
>
> library(MASS)
>
> M1<-ginv(M) #I have also been using M in the model with the same error
>
> dimnames(M1) <- list(c("sp1","sp2","sp3","sp4"),c("sp1","sp2","sp3","sp4"))
>
> model1<-MCMCglmm(y~ms,random=~species,ginverse=list(species=M1),prior=prior1
> ,data=data)
>
> #The error I receive.
>
> Error in FUN(X[[1L]], ...) :
>
>    trying to get slot "Dim" from an object of a basic class ("matrix") with
> no slots
>
>       [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models



The University of Aberdeen is a charity registered in Scotland, No SC013683.
Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir. SC013683.



More information about the R-sig-mixed-models mailing list