Thanks for Emmanual. Kate, I think the original explanation of dummy variables with independent contrasts is here:
Garland Jr. T., P.H. Harvey, and A.R. Ives. 1992. Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41:18–32. Cheers, Ted Theodore Garland, Jr., Professor Department of Biology 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&user=iSSbrhwAAAAJ Director, UCR Institute for the Development of Educational Applications Editor in Chief, Physiological and Biochemical Zoology Fail Lab: Episode One http://testtube.com/faillab/zoochosis-episode-one-evolution http://www.youtube.com/watch?v=c0msBWyTzU0 ________________________________________ From: R-sig-phylo [r-sig-phylo-boun...@r-project.org] on behalf of Emmanuel Paradis [emmanuel.para...@ird.fr] Sent: Friday, March 04, 2016 6:30 AM To: Kate Boyce-Miles; r-sig-phylo@r-project.org Subject: Re: [R-sig-phylo] How to use categorical vectors in package ape for phylogenetic independent contrasts Hi Kate, You can compute PICs for a categorical variable in the same way than you enter it in a linear model, that is by first computing its "contrasts" (this is different from the "P-I-Contrasts", though both have some conceptual similarities). The easiest way to do it is to use the function model.matrix. For instance, we generate a tree (tr) and two variables simulated on that tree, one continuous (x) and one discrete (z) with three levels: tr <- rphylo(50, .1, 0) x <- rTraitCont(tr) z <- rTraitDisc(tr, k = 3) We compute the PICs for x the usual way: pic.x <- pic(x, tr) And for z: Z <- model.matrix(~ z)[, -1] rownames(Z) <- names(z) pic.z <- apply(Z, 2, pic, phy = tr) Note that we drop the column with 1's, so Z is a matrix with 2 columns (number of levels - 1). Thus, pic.z is a matrix with 49 rows (n - 1) and 2 columns. We can now perform a linear regression with the two sets of PICs: lm(pic.x ~ pic.z - 1) This should give you the same coefficients than a PGLS like this: library(nlme) gls(x ~ z, correlation = corBrownian(phy = tr)) A very nice explanation of this can be found in Blomberg et al. (2012, Syst. Biol.). The two columns in pic.z should not be considered separately, in the same way than in an ANOVA where there are 2 df associated with a 3-level factor. HTH Best, Emmanuel Le 04/03/2016 01:07, Kate Boyce-Miles a écrit : > > Hello > > I have been using numeric vectors to perform phylogenetic independent > contrasts of several ecological variables for the cat phylogeny, using the > ape package in r, and I was wondering how this can be done using categorical > values? > > Example of how I have been using numeric values: > > tree <- read.newick("phylogeny.txt") > > tree <- as.phylo(tree) > > tree <- root(tree,1) > > x<-c() # x would vectors, for instance rainfall. One value for each > operational taxonomic unit on the tree, and the same order as they appear in > the newick file. > > pic.rain <- pic(x, tree, scaled = T, var.contrasts = F, rescaled.tree = F) # > To generate the phylogenetic independent contrasts > > cor.test(pic.rain,pic.rain) # To test for a correlation, obviously for rain > and rain it would be 1. > > How can this be done using data such as habitat, i.e grassland/forest/desert, > or activity, i.e. nocturnal, diurnal etc? > > I would be very grateful for any suggestions. > > Kate. > > [[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/ > > > Pour nous remonter une erreur de filtrage, veuillez vous rendre ici : > http://f.security-mail.net/301tdFND1Ht > > _______________________________________________ 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/ _______________________________________________ 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/