Re: [R-sig-phylo] understanding variance-covariance matrix

2018-08-27 Thread Theodore Garland
I just wanted to clarify one thing.  Agus wrote:

" Under the case of phylo dependence, all off-diagonal values are expected
to
be non zero "

That is incorrect for species on opposite sides of the root of the
phylogenetic tree, as they have zero shared phylogenetic history in the
context of the set of species under analysis.  So, your expected
variance-covariance matrix for the trait (or for residuals from a
regression model) will have some blocks of zeros on the off-diagonals.

Cheers,
Ted


Theodore Garland, Jr., Distinguished Professor

Department of Evolution, Ecology, and Organismal Biology (EEOB)

University of California, Riverside

Riverside, CA 92521

Office Phone:  (951) 827-3524

Facsimile:  (951) 827-4286 (not confidential)

Email:  tgarl...@ucr.edu

http://www.biology.ucr.edu/people/faculty/Garland.html

http://scholar.google.com/citations?hl=en=iSSbrhwJ


Director, UCR Institute for the Development of
Educational
Applications 


Editor in Chief, *Physiological and Biochemical Zoology
*


Fail Lab: Episode One

*https://www.youtube.com/watch?v=c0msBWyTzU0
*

On Mon, Aug 27, 2018 at 7:28 AM, Agus Camacho 
wrote:

> Many thanks to all for your very helpful references, commands and examples.
>
> For the sake of future readers, a summary of the off-list discussions and
> further reading.
>
> Andrew Hipp provided a very didactic way to look at the vcv matrix as a
> triangular distance matrix
>
> library(geiger)
> tr <- sim.bdtree(n = 100)
> C = as.dist(vcv(tr))
> C
>
> Now, it made sense that for n species where a trait X has been measured,
> Cov[xi,xj] is an nxn matrix with species coordinates, which for any pair of
> tip values Xi and Xj, represents the shared distances of these tips from
> the root, multiplied for a rate of evolution, or matrix of rates. The
> results of such multiplication constitute the *expected *covariances among
> values at the tips.
>
> Under the case of phylo independence, all off-diagonal values of Cov[xi,xj]
> are expected to become zero (because of shared history=0, and is a
> multiplicative term in the covariance formula). At the diagonal, each trait
> covariance with itself consists in the squared distance from the tip to the
> root of the tree multiplied by the rate of evolution (or rates, if they are
> not homogeneous). That can be represented by a unity matrix multiplied by
> the squared term "sigma", which represents the rate of evolution, or a
> matrix of rates of evolution along the tree.
>
> Under the case of phylo dependence, all off-diagonal values are expected to
> be non zero (because of shared history>0 and is a multiplicative term in
> the covariance formula). The rest of Cov [xi,xj] is similar to a case of
> phylo independence.
>
> Thus, during a PGLS model fit procedure, R calculates  Cov [xi,xj] for a
> given model of evolution over the residuals of the OLS regression. These
> residuals should contain phylogenetic dependence coming from shared
> evolution of trait values in X and Y. That is because the OLS regression
> does not account for such dependence. The residuals of an OLS do not need
> to be one unity matrix, but the dependence in residuals should look like it
> to assume phylo independence in trait values. Finally, the PGLS procedure
> modifies the predictive and predicted variables accordingly, to avoid a
> case of phylo dependence under the specified model of evolution, and
> finally performs an OLS.
>
> Many thanks again to the refs pointed by Brian, and Liam's 2010 paper on
> phylo signal. Matterial from Andrew, Julen and Diogo Provete were also
> super didactic.
>
> Hope that help others too,
> Cheers
>
> Dr. Agustín Camacho Guerrero. Universidade de São Paulo.
> http://www.agustincamacho.com
> Laboratório de Comportamento e Fisiologia Evolutiva, Departamento de
> Fisiologia,
> Instituto de Biociências, USP.Rua do Matão, trav. 14, nº 321, Cidade
> Universitária,
> São Paulo - SP, CEP: 05508-090, Brasil.
>
>
>
> El dom., 26 ago. 2018 a las 21:55, Julien Clavel (<
> julien.cla...@hotmail.fr>)
> escribió:
>
> > Hi Agus,
> >
> > I just posted some courses I did a while ago to understand the variances
> > and covariances of a BM process on trees and time-series (R markdown):
> > https://github.com/JClavel/Examples  >
> >
> > This is also based on the previous mentioned references illustrated with
> > some simulations.
> > Hope it may helps...
> >
> > Best,
> >
> > Julien
> >
> > --
> > *De :* R-sig-phylo  de la part de
> > Andrew Hipp 
> > *Envoyé :* dimanche 26 août 2018 05:36
> > *À :* bome...@utk.edu
> > *Cc :* mailman, r-sig-phylo; Agus Camacho
> > *Objet :* Re: [R-sig-phylo] understanding variance-covariance matrix
> >
> > I'll second Brian's self-citation. O'Meara et al. 2006 is I think one of
> > the best 

Re: [R-sig-phylo] Aligning tree tip labels together in ape

2018-08-27 Thread Carleson, Nick
Hello,

I used the code insertion that Emmanuel provided, and that solved my issue.
Thank you all for the help and discussion!

Pascal, if you're looking for a tutorial, this is the first one I found
when I started:
http://www.phytools.org/eqg/Exercise_3.2/

I've found it *very* helpful. I've also worked through this one, which uses
ggtree like you're looking into:
https://4va.github.io/biodatasci/r-ggtree.html

For specifics, it would help if you came up with a minimum reproducible
example

and shared it (especially code!). You might get a better response from
people.

Cheers



On Sat, Aug 25, 2018 at 11:53 PM, pascal de Clarens 
wrote:

> Hello,
>
> I am using Iramuteq with ape and get the trees with iriba method
> I have not yet understand how to make  a phylogenic tree ... is there a
> tutorail available?
>
> I installed the ggtree package, but when I try to use the Reinert
> classification method I gnow get this message:
>
> None
>
> Warning message:
>
> package ‘Matrix’ was built under R version 3.4.4
>
> There were 42 warnings (use warnings() to see them)
>
> There were 25 warnings (use warnings() to see them)
>
> Warning message:
>
> package ‘ape’ was built under R version 3.4.4
>
> Error in Ntip + Nnode : non-numeric argument to binary operator
>
> Calls: plot.dendropr -> plot.phylo
>
> Execution halted
>
>
> thanks for your help
>
>
> best regards
>
> Le ven. 24 août 2018 à 17:59, Bjørn Tore Kopperud 
> a écrit :
>
>> Hi Nick,
>>
>>
>> There is a fantastic package for visualizing trees, the "ggtree" package:
>>
>>
>> https://github.com/GuangchuangYu/ggtree
>>
>>
>> Here is a vignette with several examples on how to display trees,
>> including your circular phylogram visualization:
>>
>>
>> https://bioconductor.org/packages/devel/bioc/vignettes/ggtree/inst/doc/
>> treeVisualization.html#phylogram-and-cladogram
>>
>>
>> You can read the documentation to figure out how to plot tip labels, I'm
>> sure it's possible. The ggtree package is very powerful but also different
>> in comparison with ape, as it is built on top of the "grammar of graphics"
>> ggplot package.
>>
>>
>> Best,
>>
>> Bjørn Tore Kopperud
>>
>>
>> G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for
>> visualization and annotation of phylogenetic trees with their covariates
>> and other associated data. *Methods in Ecology and Evolution*. 2017,
>> 8(1):28-36.​
>>
>>
>>
>> --
>> *From:* R-sig-phylo  on behalf of
>> Carleson, Nick 
>> *Sent:* 24 August 2018 17:04
>> *To:* r-sig-phylo@r-project.org
>> *Subject:* [R-sig-phylo] Aligning tree tip labels together in ape
>>
>> Hello all,
>>
>> I'm using the R package 'ape' to make non-ultrametric phylogenetic trees
>> . I want to align tip labels together when drawing a tree with
>> plot.phylo(), and also add on more labels using the tiplabels()
>> function. But, I can't get additional tip labels from tiplabels aligned
>> properly with those from plot.phylo. When I call tiplabels, the labels
>> are being drawn at the true edge length instead of neatly around the plot
>> with the tip labels drawn by plot.phylo. So, in the plot below, I want
>> the tip labels (circles) to be aligned adjacent to the tip labels (names)
>> drawn by plot.phylo.
>>
>> Good: tips like t30, t31, and t2
>> Bad: tips like t1, t20, and t21
>>
>>
>>
>>
>> Can anyone help me out?
>>
>> Below is the code to produce the tree above. I'm using ape version 5.1
>> and R version 3.4.3.
>>
>> library(ape)
>> set.seed(31)
>> sim_tree <- rlineage(0.1, 0.05)
>> plot.phylo(sim_tree, type = "fan", align.tip.label = TRUE)
>> tiplabels(pch = 19, col = rainbow(3), offset = 6)
>>
>> Thanks all!
>>
>>
>> *Nick Carleson *
>>
>> PhD Student
>> * | Oregon State University *Graduate Research Assistant | *Botany and
>> Plant Pathology*
>> ___
>> R-sig-phylo mailing list - R-sig-phylo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
>> Searchable archive at http://www.mail-archive.com/r-
>> sig-ph...@r-project.org/
>>
>
>
> --
> Pascal de Clarens
> 06 07 85 22 54
>



-- 


*Nick Carleson*

PhD Student
* | Oregon State University *Graduate Research Assistant | *Botany and
Plant Pathology*

[[alternative HTML version deleted]]

___
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/


Re: [R-sig-phylo] understanding variance-covariance matrix

2018-08-27 Thread Agus Camacho
Many thanks to all for your very helpful references, commands and examples.

For the sake of future readers, a summary of the off-list discussions and
further reading.

Andrew Hipp provided a very didactic way to look at the vcv matrix as a
triangular distance matrix

library(geiger)
tr <- sim.bdtree(n = 100)
C = as.dist(vcv(tr))
C

Now, it made sense that for n species where a trait X has been measured,
Cov[xi,xj] is an nxn matrix with species coordinates, which for any pair of
tip values Xi and Xj, represents the shared distances of these tips from
the root, multiplied for a rate of evolution, or matrix of rates. The
results of such multiplication constitute the *expected *covariances among
values at the tips.

Under the case of phylo independence, all off-diagonal values of Cov[xi,xj]
are expected to become zero (because of shared history=0, and is a
multiplicative term in the covariance formula). At the diagonal, each trait
covariance with itself consists in the squared distance from the tip to the
root of the tree multiplied by the rate of evolution (or rates, if they are
not homogeneous). That can be represented by a unity matrix multiplied by
the squared term "sigma", which represents the rate of evolution, or a
matrix of rates of evolution along the tree.

Under the case of phylo dependence, all off-diagonal values are expected to
be non zero (because of shared history>0 and is a multiplicative term in
the covariance formula). The rest of Cov [xi,xj] is similar to a case of
phylo independence.

Thus, during a PGLS model fit procedure, R calculates  Cov [xi,xj] for a
given model of evolution over the residuals of the OLS regression. These
residuals should contain phylogenetic dependence coming from shared
evolution of trait values in X and Y. That is because the OLS regression
does not account for such dependence. The residuals of an OLS do not need
to be one unity matrix, but the dependence in residuals should look like it
to assume phylo independence in trait values. Finally, the PGLS procedure
modifies the predictive and predicted variables accordingly, to avoid a
case of phylo dependence under the specified model of evolution, and
finally performs an OLS.

Many thanks again to the refs pointed by Brian, and Liam's 2010 paper on
phylo signal. Matterial from Andrew, Julen and Diogo Provete were also
super didactic.

Hope that help others too,
Cheers

Dr. Agustín Camacho Guerrero. Universidade de São Paulo.
http://www.agustincamacho.com
Laboratório de Comportamento e Fisiologia Evolutiva, Departamento de
Fisiologia,
Instituto de Biociências, USP.Rua do Matão, trav. 14, nº 321, Cidade
Universitária,
São Paulo - SP, CEP: 05508-090, Brasil.



El dom., 26 ago. 2018 a las 21:55, Julien Clavel ()
escribió:

> Hi Agus,
>
> I just posted some courses I did a while ago to understand the variances
> and covariances of a BM process on trees and time-series (R markdown):
> https://github.com/JClavel/Examples 
>
> This is also based on the previous mentioned references illustrated with
> some simulations.
> Hope it may helps...
>
> Best,
>
> Julien
>
> --
> *De :* R-sig-phylo  de la part de
> Andrew Hipp 
> *Envoyé :* dimanche 26 août 2018 05:36
> *À :* bome...@utk.edu
> *Cc :* mailman, r-sig-phylo; Agus Camacho
> *Objet :* Re: [R-sig-phylo] understanding variance-covariance matrix
>
> I'll second Brian's self-citation. O'Meara et al. 2006 is I think one of
> the best introductions to the phylogenetic covariance matrix, and I often
> direct students to it.
>
> Brian's point about the relationship between observed and expected
> covariance is illustrated here in a brief note I wrote up for students this
> spring:
>
>
> https://github.com/andrew-hipp/PCM-2018/blob/master/R-tutorials/2018-PCM-covarianceMatrixRuminations.ipynb
>
> It might be helpful, or it might not. I hope so!
>
> Take care,
> Andrew
>
> On Sat, Aug 25, 2018 at 1:33 PM, Brian O'Meara 
> wrote:
>
> > Hi, Agus. The variance-covariance matrix comes from the tree and the
> > evolutionary model, not the data. Each entry between taxa A and B in the
> > VCV is how much covariance I should expect between data for taxa A and B
> > simulated up that tree using that model. I don't want to be *that guy*,
> but
> > O'Meara et al. (2006)
> > https://onlinelibrary.wiley.com/doi/10./j.0014-3820.2006.tb01171.x
> has
> > a fairly accessible explanation of this (largely b/c I was just learning
> > about VCVs when working on that paper). Hansen and Martins (1996)
> > https://onlinelibrary.wiley.com/doi/10./j.1558-5646.1996.tb03914.x
> > have
> > a much more detailed description of how you get these covariance matrices
> > from microevolutionary processes.
> >
> > Typically, ape::vcv() is how you get a variance covariance for a
> phylogeny,
> > assuming Brownian motion and no measurement error. It just basically
> takes
> > the history two taxa share to create the covariance (or variance, if