ericgoolsby / Rphylopars

Phylogenetic Comparative Tools for Missing Data and Within-Species Variation
30 stars 11 forks source link

explained phylogenetic variance #37

Open daskandalis opened 4 years ago

daskandalis commented 4 years ago

What is the reason for calculating the estimated percentage of variance explained by the phylogeny is provided as 100x(1 - phenotypic_variance/raw_variance), where raw_variance is the variance of all observations for a given trait across species?

This result gives, e.g., 80% of the variance in a trait explained by a star phylogeny. But a star phylogeny does not explain any variance in a trait. It seems that the calculation is the unexplained variance, of which the phylogenetic variance is only one part (and is possibly none).

And an actual issue, phylogenetic variance fails with a single trait:

sim_data <- simtraits(ntaxa = 15,ntraits = 1,nreps = 3,nmissing = 10)
PPE <- phylopars(trait_data = sim_data$trait_data,tree = sim_data$tree,
    pheno_error = TRUE,phylo_correlated = TRUE,pheno_correlated = TRUE)
PPE
Phylogenetic trait variance-covariance
         V1
V1 1.193152

Phenotypic trait variance-covariance
           V1
V1 0.06849152

% variance explained by phylogeny
Error in apply(PPE$trait_data[, 1:nvar + 1], 2, function(X) var(X, na.rm = TRUE)) : 
  dim(X) must have a positive length

EDIT: Hit ctrl+enter and posted this sooner than I had time to think all the way through. Oh well.

ericgoolsby commented 2 years ago

Apologies for the years-long delay in responding to this. I agree this isn't a great metric, nor is it explained anywhere -- this was simply a port of the original summary statistics that the original PhyloPars web portal reported. I think it would make much more sense to look at this on a trait-by-trait basis calculated as phylo_var / (pheno_var + phylo_var). I'm going to keep this issue open so when Rphylopars gets a major update (hypothetically in the near future) I can remember to update this and add some documentation clarifying what it means. In any case, thanks for pointing out the single-trait issue! The latest CRAN version resolves that issue at least.