Re: [R-sig-phylo] Trait simulations

2009-05-20 Thread Emmanuel Paradis

Liam,

The package MASS has the function mvrnorm that simulates from a  
multivariate normal distribution. Its help page says:


 The matrix decomposition is done via 'eigen'; although a Choleski
 decomposition might be faster, the eigen decomposition is stabler.

The package mvtnorm (on CRAN) can also do that with its function  
rmvnorm which also uses eigen.


Emmanuel

Liam J. Revell lrev...@fas.harvard.edu a écrit :

Hi Jeremy,

Perhaps you've already figured this out.  There may be a function
available in R to do this, but if not, in principle for BM it should be
fairly easy to do this manually.

First, read your tree in:


tree-read.tree(FILE, etc.) % put filename or paste in tree


then compute the phylogenetic VCV matrix (let's call it T):


T-vcv.phylo(tree)


then specify your desired correlation matrix, R.  If you wanted an
evolutionary correlation of 0.95 this would be:


R-matrix(c(1,0.95,0.95,1),nrow=2,ncol=2)


then generate a matrix of random, uncorrelated values (U), e.g.:


U-matrix(,nrow=N,ncol=2) % where N is the number of taxa
U[,1]-rnorm(N) % (am I using this function correctly?)
U[,2]-rnorm(N)


now give them a correlation based on R (using the Cholesky decomposite):


V-U%*%chol(R)


now give the data correlation due to the tree:


X-t(V)%*%chol(T)


I think that should be it.  The data in X should be as data evolved by
BM on your tree with the correlation specified in your matrix, R (0.95
in this case).

More experience users, please let me know if this is incorrect (it is
untested, so it may include errors, but I think the logic is sound).

Sincerely, Liam

Liam J. Revell
Department of Organismic and Evolutionary Biology
Harvard University
web: http://anolis.oeb.harvard.edu/~liam/
email: lrev...@fas.harvard.edu

On Mon, 18 May 2009, jeremy.beaul...@yale.edu wrote:


Hi all~

I was just wondering if there is a package or function in R that   
can simulate

two continuous traits with a user-specified correlation coefficient using a
known tree topology, branch lengths, and a model of Brownian motion (or even
OU, if possible)?

All the best,

Jeremy Beaulieu

___
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


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


Re: [R-sig-phylo] Trait simulations

2009-05-19 Thread Liam J. Revell

Hi Jeremy,

Perhaps you've already figured this out.  There may be a function 
available in R to do this, but if not, in principle for BM it should be 
fairly easy to do this manually.


First, read your tree in:


tree-read.tree(FILE, etc.) % put filename or paste in tree


then compute the phylogenetic VCV matrix (let's call it T):


T-vcv.phylo(tree)


then specify your desired correlation matrix, R.  If you wanted an 
evolutionary correlation of 0.95 this would be:



R-matrix(c(1,0.95,0.95,1),nrow=2,ncol=2)


then generate a matrix of random, uncorrelated values (U), e.g.:


U-matrix(,nrow=N,ncol=2) % where N is the number of taxa
U[,1]-rnorm(N) % (am I using this function correctly?)
U[,2]-rnorm(N)


now give them a correlation based on R (using the Cholesky decomposite):


V-U%*%chol(R)


now give the data correlation due to the tree:


X-t(V)%*%chol(T)


I think that should be it.  The data in X should be as data evolved by BM 
on your tree with the correlation specified in your matrix, R (0.95 in 
this case).


More experience users, please let me know if this is incorrect (it is 
untested, so it may include errors, but I think the logic is sound).


Sincerely, Liam

Liam J. Revell
Department of Organismic and Evolutionary Biology
Harvard University
web: http://anolis.oeb.harvard.edu/~liam/
email: lrev...@fas.harvard.edu

On Mon, 18 May 2009, jeremy.beaul...@yale.edu wrote:


Hi all~

I was just wondering if there is a package or function in R that can simulate
two continuous traits with a user-specified correlation coefficient using a
known tree topology, branch lengths, and a model of Brownian motion (or even
OU, if possible)?

All the best,

Jeremy Beaulieu

___
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


[R-sig-phylo] Trait simulations

2009-05-18 Thread jeremy . beaulieu
Hi all~

I was just wondering if there is a package or function in R that can simulate
two continuous traits with a user-specified correlation coefficient using a
known tree topology, branch lengths, and a model of Brownian motion (or even
OU, if possible)?

All the best,

Jeremy Beaulieu

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