Castillo (2007) introduced a framework for analyzing lineage-pair data via an
extension of a phylogenetic linear mixed model (plmm) in which there are two
random-effect terms, one for the 'species 1' and another for the 'species 2' in
every pair. The model is Y = Xb + Z1u1 + Z1u2 + epsilon, where b is the vector of
coefficients, X is a design matrix, u1 and u2 are vectors of species-specific random
effects that covary according to a phylogenetic covariance matrix C (u1 ~ N(0,C)
and u2 ~ N(0,C)), Z1 and Z2 are design matrices that map the species-specific
effects to the correct species in each pair, and epsilon is residual error (epsilon~N(0,C)).
The C matrix in the model is scaled by parameters that do not come into play here.
This function takes a table containng columsn for species 1 and species 2 for every
pair and a phylogenetic tree and returns the matrices Z1 and Z2 as well as pruned
phylogenetic covariance matrices for u1 and u2. This pruning is sometimes required
because not all species found in the dataset will appear as both 'species 1' and
'species 2'. Z1 and Z2 will therefore have different sizes and u1 and u2 require
different covariance matrices. Note that the matrices themselves are pruned, not
the tree from which they are derived, as the latter could result in the covariance
between two species being different for the 'species 1' and 'species 2' random effects.