KB2
KB2

Reputation: 121

How to use categorical vectors in ape (r) for phylogenetic independent contrasts

I have been performing phylogenetically 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.

Here is how it works using numeric values:

# Load ape
library(ape)

# Simulate data
set.seed(23)
phy <- rcoal(10)
x <- runif(10, 0, 10)
y <- x + rnorm(10)

# Compute correlation of independent contrasts
cor.test(pic(y, phy), pic(x, phy))

How can I do independent contrasts with discrete data?

Upvotes: 2

Views: 1059

Answers (1)

SlowLoris
SlowLoris

Reputation: 1005

Independent contrasts are only for continuous data. To test for correlations between discrete variables while accounting for phylogenetic non-independence, there are two potential avenues.

  1. You can use phylogenetic logistic regression, as implemented the phyloglm package.

  2. You can use continuous time Markov models to test for correlated evolution between a pair of discrete traits. These models are implemented in the standalone software BayesTraits, or you can follow this excellent blog post that demonstrates how to implement the test using the phytools package.

I should mention that concerns have been raised surrounding the ability of these Markov models to deal with phylogenetic pseudoreplication (see this paper), causing me to lean toward the GLM framework.

Upvotes: 1

Related Questions