I used to do this before ape existed.

Here is some example code.

library(ape)
data(bird.orders)

# some made up data
dat <- data.frame(y=rnorm(23), x=rnorm(23))
rownames(dat) <- bird.orders$tip.label

mat <- vcv(bird.orders, cor=TRUE)
fit <- gls(y~x, correlation=corSymm(mat[lower.tri(mat)], fixed=TRUE), data=dat) 
#assuming ultrametric tree
# compare with corBrownian structure:
 fit2 <- gls(y~x, correlation=corBrownian(phy=bird.orders), data=dat)

# are the regression coefficients the same?

 all.equal(coef(fit), coef(fit2))
[1] TRUE
> 

I hope this helps,

Simon.
________________________________________
From: r-sig-phylo-boun...@r-project.org [r-sig-phylo-boun...@r-project.org] On 
Behalf Of Tomlinson, Kyle [kyle.tomlin...@wur.nl]
Sent: Friday, July 08, 2011 5:30 AM
To: 'r-sig-phylo@r-project.org'
Subject: [R-sig-phylo] query: how to use an existing covariance matrix directly 
in a gls procedure in R?

Dear Dr Paradis

I trust that I am allowed to contact you directly  like this? If not, my 
sincere apologies.

I have constructed the covariance matrix for a phylogenetic tree (using the 
vcv() command), which i would like to use directly in a gls() procedure, 
instead of using the tree directly as appears to be done in ape (because I only 
use a very small part of the tree i have constructed..).
{I am doing this in order to check my own gls procedure and the gls procedure 
of PHYLOGr which I dont trust.}

Do you know if this can be done? I have tried to figure it out by considering 
the corStruct class options in nlme, but none of these options seems to allow 
one to directly input an existing covariance matrix, and I simply dont 
understand the object construction methods of R well enough to build a suitable 
corStruct object myself.

I hope you can help.


sincerely

Kyle Tomlinson

Resource Ecology Group
Centre for Ecosystem Studies
Wageningen University
Droevendaalsesteeg 3a
6708 PB Wageningen
The Netherlands

Phone: +31 317 485314
Fax:     +31 317 484845
email:   kyle.tomlin...@wur.nl



        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to