# phylosor.query: Computes the value of the Phylogenetic Sorensen's Similarity... In PhyloMeasures: Fast and Exact Algorithms for Computing Phylogenetic Biodiversity Measures

## Description

Calculates the Phylogenetic Sorensen's Similarity (PhyloSor) given paired sets of tips on a phylogeny. A version of this function that computes the standardised value of the measure is not yet available.

## Usage

 ```1 2``` ```phylosor.query(tree, matrix.a, matrix.b = NULL, query.matrix = NULL) ```

## Arguments

 `tree` A phylo tree object `matrix.a` A matrix with binary (0/1) values, where each row represents a tip set. Each column name in the matrix must match a tip label on the input tree. If not all values in the matrix are binary, we consider two cases; if the matrix contains only non-negative values, all values are coerced to binary ones and a warning message is printed. If the matrix contains at least one negative value, the function throws an error `matrix.b` Optional, a second matrix with a similar format as matrix.a `query.matrix` Optional, a two-column matrix specifying the pairs of rows (tip sets) for which the function computes the PhyloSor values. Each row in query.matrix indicates a pair of tip sets for which we want to compute the PhyloSor value. Let k and r be the values that are stored in the i-th row of query.matrix, where k is the value stored in the first column and r is the value stored in the second column. If matrix.b is given, the function computes the PhyloSor value between the k-th row of matrix.a and the r-th row of matrix.b. If matrix.b is not given, the function computes the PhyloSor value between the k-th and r-th row of matrix.a (default = NULL)

## Details

Queries can be given in four ways. If neither matrix.b nor query.matrix are given, the function computes the PhyloSor values for all pairs of rows (tip sets) in matrix.a . If matrix.b is given but not query.matrix, the function computes the PhyloSor values for all combinations of a row in matrix.a with rows in matrix.b. If query.matrix is given and matrix.b is not, the function returns the PhyloSor values for the pairs of rows in matrix.a specified by query.matrix. If query.matrix and matrix.b are both given, PhyloSor values are computed for the rows in matrix.a specified by the first column of query.matrix against the rows in matrix.b specified in the second column of query.matrix.

## Value

The PhyloSor values for the requested pairs of tip sets. If query.matrix is provided, then the values are returned in an one-dimensional vector. The i-th element of this vector is the PhyloSor value for the pair of tip sets indicated in the i-th row of query.matrix. If query.matrix is not provided, the PhyloSor values are returned in a matrix object; entry [i,j] in the output matrix stores the PhyloSor value between the tip sets specified on the i-th and j-th row of matrix.a (if matrix.b is not specified), or the PhyloSor value between the i-th row of matrix.a and the j-th row of matrix.b (if matrix.b is specified)

## Author(s)

Constantinos Tsirogiannis (tsirogiannis.c@gmail.com) and Brody Sandel (bsandel@scu.edu)

## References

Graham, C.H. and P.V.A. Fine. 2008. Phylogenetic beta diversity: linking ecological and evolutionary processes across space and time. Ecology Letters 11: 1265:1277.

Swenson, N.G. 2011. Phylogenetic beta diversity metrics, trait evolution and inferring functional beta diversity of communities. PLoS ONE: 6: e21264.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19``` ```#Load phylogenetic tree of bird families from package "ape" data(bird.families, package = "ape") #Create 10 random communities with 50 families each comm = matrix(0,nrow = 10,ncol = length(bird.families\$tip.label)) for(i in 1:nrow(comm)) {comm[i,sample(1:ncol(comm),50)] = 1} colnames(comm) = bird.families\$tip.label #Calculate all pairwise PhyloSor values for communities in comm phylosor.query(bird.families,comm) #Calculate pairwise distances from #the first two rows of comm to all rows phylosor.query(bird.families, comm[1:2,],comm) #Calculate the distances from the first two rows #to all rows using the query matrix qm = expand.grid(1:2,1:10) phylosor.query(bird.families,comm,query.matrix = qm) ```

### Example output

```           [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
[1,] 1.0000000 0.5238994 0.4818447 0.4662483 0.4197887 0.4296697 0.4939709
[2,] 0.5238994 1.0000000 0.5821663 0.5518166 0.4957020 0.4859668 0.5390419
[3,] 0.4818447 0.5821663 1.0000000 0.4868452 0.4982865 0.4504721 0.5240900
[4,] 0.4662483 0.5518166 0.4868452 1.0000000 0.4192917 0.4324966 0.4590164
[5,] 0.4197887 0.4957020 0.4982865 0.4192917 1.0000000 0.4894263 0.4875350
[6,] 0.4296697 0.4859668 0.4504721 0.4324966 0.4894263 1.0000000 0.4450926
[7,] 0.4939709 0.5390419 0.5240900 0.4590164 0.4875350 0.4450926 1.0000000
[8,] 0.4772245 0.4664398 0.5055244 0.4975217 0.4139907 0.4271555 0.5717293
[9,] 0.5478610 0.5650999 0.4957103 0.4601460 0.4338314 0.4238221 0.5359883
[10,] 0.4641848 0.4231298 0.4959046 0.4902543 0.4490963 0.4844463 0.5339135
[,8]      [,9]     [,10]
[1,] 0.4772245 0.5478610 0.4641848
[2,] 0.4664398 0.5650999 0.4231298
[3,] 0.5055244 0.4957103 0.4959046
[4,] 0.4975217 0.4601460 0.4902543
[5,] 0.4139907 0.4338314 0.4490963
[6,] 0.4271555 0.4238221 0.4844463
[7,] 0.5717293 0.5359883 0.5339135
[8,] 1.0000000 0.5328399 0.4982960
[9,] 0.5328399 1.0000000 0.4113526
[10,] 0.4982960 0.4113526 1.0000000
[,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
[1,] 1.0000000 0.5238994 0.4818447 0.4662483 0.4197887 0.4296697 0.4939709
[2,] 0.5238994 1.0000000 0.5821663 0.5518166 0.4957020 0.4859668 0.5390419
[,8]      [,9]     [,10]
[1,] 0.4772245 0.5478610 0.4641848
[2,] 0.4664398 0.5650999 0.4231298
 1.0000000 0.5238994 0.5238994 1.0000000 0.4818447 0.5821663 0.4662483
 0.5518166 0.4197887 0.4957020 0.4296697 0.4859668 0.4939709 0.5390419
 0.4772245 0.4664398 0.5478610 0.5650999 0.4641848 0.4231298
```

PhyloMeasures documentation built on May 2, 2019, 6:17 a.m.