Re: [R-sig-phylo] phylogenetic correlation analysis
Dear Julien: I tried the attached Rscript with mvMORPH to attain a phylogenetic correlation matrix betwen all pairs of variables O - AQ in the attached csv file (variables B-N are just variables that define the assignment to various subgroups and won't be included in these analyses). The tree is also attached. Howver, when I am running your script under these data, I am always getting various error messages. Maybe, I need to sort the species lists prior to the analysis, so that both data frame and tree show the same sequence, but the problem might be something else. Would you mind to have a short check on my data? Thanks a lot, Oliver Zitat von Julien Clavel : Dear Oliver, Yes, you can use the independent contrasts to estimate the correlations (e.g., assuming BM). Otherwise, you can compute the correlations directly from the models fit in mvMORPH. For instance, under BM you can use: fit_bm <- mvBM(tree, data) cov2cor(fit_bm$sigma) # marginal correlations cor2pcor(fit_bm$sigma) # partial correlations Under OU, you can also retrieve the correlations from the variance-covariance matrix (which depends on both the “sigma” and “alpha” parameters, and can be retrieved with the “stationary” function): fit_ou <- mvOU(tree, data) cov2cor(stationary(fit_ou$sigma)) # marginal correlations cor2pcor(stationary(fit_ou)) # partial correlations Alternatively, you can use the “mvgls” function to do it, e.g.: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="LL") cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations You can for instance use penalized likelihood to obtain a regularized estimate of the evolutionary correlations: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL") # Ridge penalization by default cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations With LASSO penalization, for instance, you can find a sparse estimate for the partial correlations. That is, you can directly select the “significant” partial correlations from the model fit: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL", penalty="LASSO") cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations Best wishes, Julien De : R-sig-phylo de la part de Oliver Betz Envoyé : dimanche 13 juin 2021 14:45 À : r-sig-phylo@r-project.org Objet : [R-sig-phylo] phylogenetic correlation analysis Dear all: I would like to perform a phylogenetic correlation analysis (simlar to PGLS, but correlation instead of regression), so that I get a correlation matrix, where all the Pearson or Spearman correlation coefficients between all of my variables are listed. One solution might be to calculate PICs and do standard correlation analyses on them, but there might be a more direct solution available? Which R package would you recommend for such analysis? Thank you very much, Oliver Betz ___ 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/ #Correlation analysis #Data management to prepare correct data and tree file library(mvMORPH) setwd("c:/temp") tree <- read.tree("DataR/transmitting science course/Own data/Steninae_reduced.nwk") # load eye protrusion versus attack distance towards large springtails data <- read.csv2("DataR/transmitting science course/Own data/Daten Mittelwert für Hauptkomponentenanalyse_Gesamtliste_Original April 2021_data transformed_nur Relativwerte_Phyl.csv", header=T) names(data) <- c("Species","Gattung","Artengruppe", "Untergattung", "Klebpolstertyp", "Tarsustyp","Hoehe_1","Hoehe_2","Hoehe_3","Hoehe_4","Litter","Rocks","Vegetation","Ground","log_Körperlänge","log_Vorderkörper","log_Pronotuml","log_rel_Hinterbeinl","log_rel_Antennenl", "log_rel_Labiuml","LOG_eye_protrusion","log_rel_Haftpolsterfl","log_rel_Anz_Hafth_Klebp","LOG_rel_Anzahl_Haftkont_Klebp","LOG_rel_Breite_4.Vordertarsus", "LOG_rel_Anzahl_Hafthaare_4.Vordertarsus", "LOG_rel_Attachment_force_smooth","LOG_rel_Attachment_force_rough", "LOG_rel_attack_dist_small_Md", "LOG_rel_attack_dist_large_Md", "LOG_rel_attack_dist_small_Lb", "LOG_rel_attack_dist_large_Lb", "ARCSIN_capture_succ_Md_small", "ARCSIN_capture_succ_Md_large", "ARCSIN_capture_succ_Lb_small", "ARCSIN_capture_succ_Lb_large", "Niche_width_elevation","Niche_width_habitat", "Species_freq_Doi_Inth", "Species_freq_Doi_Php", "ARCSIN_selection_index_vertical", "ARCSIN_selection_index_ground", "ARCSIN_selection_index_stones") # rename colums with shorter names, save dataframe as "dat" rownames(data) <- data$Species # use species names to set rownames
Re: [R-sig-phylo] phylogenetic correlation analysis
Rphylopars is an option too (https://github.com/ericgoolsby/Rphylopars) [[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] phylogenetic correlation analysis
Whether one gets them from PGLS directly or from contrasts, one can get correlations by just inferring the covariance matrix and then calculating r(x,y) = Cov(x,y) / (Var(x) Var(y))^(1/2) where of course Var(x) is also Cov(x,x), and so on. You would not need a separate run to get correlations. Joe -- Joe Felsenstein felse...@gmail.com, j...@gs.washington.edu Department of Genome Sciences and Department of Biology, University of Washington, Box 355065, Seattle, WA 98195-5065 USA ___ 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] phylogenetic correlation analysis
I'll just add one note of caution. If you do the independent contrasts calculations, make sure the package you use to compute correlations is actually doing them through the origin. In years past, I ran into stats programs that would give you a regression through the origin (slope) as requested, but would also report a correlation coefficient that was NOT through the origin! As always, trust but verify! Cheers, Ted On Sun, Jun 13, 2021 at 7:04 AM Julien Clavel wrote: > Dear Oliver, > > Yes, you can use the independent contrasts to estimate the > correlations (e.g., assuming BM). Otherwise, you can compute the > correlations > directly from the models fit in mvMORPH. > > For instance, under BM you can use: > > fit_bm <- mvBM(tree, data) > cov2cor(fit_bm$sigma) # marginal correlations > cor2pcor(fit_bm$sigma) # partial correlations > > Under OU, you can also retrieve the correlations from the > variance-covariance matrix > (which depends on both the “sigma” and “alpha” parameters, and can be > retrieved > with the “stationary” function): > fit_ou <- mvOU(tree, data) > cov2cor(stationary(fit_ou$sigma)) # marginal correlations > cor2pcor(stationary(fit_ou)) # partial correlations > > > Alternatively, you can use the “mvgls” function to do it, e.g.: > > fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="LL") > cov2cor(fit_bm2$sigma$Pinv) # marginal correlations > cor2pcor(fit_bm2$sigma$Pinv) # partial correlations > > You can for instance use penalized likelihood to obtain a > regularized estimate of the evolutionary correlations: > > fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL") # Ridge > penalization by default > cov2cor(fit_bm2$sigma$Pinv) # marginal correlations > cor2pcor(fit_bm2$sigma$Pinv) # partial correlations > > With LASSO penalization, for instance, you can find a sparse > estimate for the partial correlations. That is, you can directly select > the “significant” > partial correlations from the model fit: > > fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL", > penalty="LASSO") > cov2cor(fit_bm2$sigma$Pinv) # marginal correlations > cor2pcor(fit_bm2$sigma$Pinv) # partial correlations > > Best wishes, > > Julien > > > > De : R-sig-phylo de la part de Oliver > Betz > Envoyé : dimanche 13 juin 2021 14:45 > À : r-sig-phylo@r-project.org > Objet : [R-sig-phylo] phylogenetic correlation analysis > > Dear all: > > I would like to perform a phylogenetic correlation analysis (simlar to > PGLS, but correlation instead of regression), so that I get a > correlation matrix, where all the Pearson or Spearman correlation > coefficients between all of my variables are listed. One solution > might be to calculate PICs and do standard correlation analyses on > them, but there might be a more direct solution available? > > Which R package would you recommend for such analysis? > > > Thank you very much, > > Oliver Betz > > ___ > 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/ > [[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] phylogenetic correlation analysis
Dear Oliver, Yes, you can use the independent contrasts to estimate the correlations (e.g., assuming BM). Otherwise, you can compute the correlations directly from the models fit in mvMORPH. For instance, under BM you can use: fit_bm <- mvBM(tree, data) cov2cor(fit_bm$sigma) # marginal correlations cor2pcor(fit_bm$sigma) # partial correlations Under OU, you can also retrieve the correlations from the variance-covariance matrix (which depends on both the “sigma” and “alpha” parameters, and can be retrieved with the “stationary” function): fit_ou <- mvOU(tree, data) cov2cor(stationary(fit_ou$sigma)) # marginal correlations cor2pcor(stationary(fit_ou)) # partial correlations Alternatively, you can use the “mvgls” function to do it, e.g.: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="LL") cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations You can for instance use penalized likelihood to obtain a regularized estimate of the evolutionary correlations: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL") # Ridge penalization by default cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations With LASSO penalization, for instance, you can find a sparse estimate for the partial correlations. That is, you can directly select the “significant” partial correlations from the model fit: fit_bm2 <- mvgls(data~1, tree=tree, model="BM", method="PL", penalty="LASSO") cov2cor(fit_bm2$sigma$Pinv) # marginal correlations cor2pcor(fit_bm2$sigma$Pinv) # partial correlations Best wishes, Julien De : R-sig-phylo de la part de Oliver Betz Envoyé : dimanche 13 juin 2021 14:45 À : r-sig-phylo@r-project.org Objet : [R-sig-phylo] phylogenetic correlation analysis Dear all: I would like to perform a phylogenetic correlation analysis (simlar to PGLS, but correlation instead of regression), so that I get a correlation matrix, where all the Pearson or Spearman correlation coefficients between all of my variables are listed. One solution might be to calculate PICs and do standard correlation analyses on them, but there might be a more direct solution available? Which R package would you recommend for such analysis? Thank you very much, Oliver Betz ___ 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/