Function to find the median of a list of transmission scenarios
wiwMedTree(matList, sampled = NULL, weights = NULL)
a list of matrices, each of which is the output of findMRCIs$mrciDepths
a vector of node IDs which corresponds to those nodes which are sampled cases
optional vector of weights to correspond to the entries of matList
Returns three objects:
centre
: the mean of the matList entries, restricted to the sampled cases
distances
: for each entry of matList, its distance from centre
mindist
: the minimum of distances
median
: the number of the median entry of matList, i.e. the one(s) which achieve the mindist
from the centre
.
# create some simple "who infected whom" scenarios:
tree1 <- cbind(Infector=1:5,Infectee=2:6)
tree2 <- cbind(Infector=c(1,5,2,2,3),Infectee=2:6)
tree3 <- cbind(Infector=c(2,2,3,4,5),Infectee=c(1,3,4,5,6))
# create list of the MRCI depth matrices:
matList <- lapply(list(tree1,tree2,tree3), function(x) findMRCIs(x)$mrciDepths)
# median tree, assuming all cases are sampled:
wiwMedTree(matList)
#> $centre
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0.3333333 0 0 0 0 0 0 0.6666667 0.6666667 0.6666667
#> [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19]
#> [1,] 0.6666667 0.6666667 0 0.6666667 2 1.333333 1.666667 2 0
#> [,20] [,21] [,22] [,23] [,24] [,25] [,26] [,27] [,28]
#> [1,] 0.6666667 1.333333 2.333333 2 2 0 0.6666667 1.666667 2
#> [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
#> [1,] 3 3 0 0.6666667 2 2 3 4.333333
#>
#> $distances
#> [1] 3.179797 3.431877 2.962731
#>
#> $mindist
#> [1] 2.962731
#>
#> $median
#> [1] 3
#>
# median tree when cases 1, 2 and 4 are sampled:
wiwMedTree(matList, sampled=c(1,2,4))
#> $centre
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#> [1,] 0.3333333 0 0 0 0.6666667 0.6666667 0 0.6666667 2.333333
#>
#> $distances
#> [1] 0.942809 0.745356 1.374369
#>
#> $mindist
#> [1] 0.745356
#>
#> $median
#> [1] 2
#>