| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.treestat.statistics; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class Nbar extends AbstractTreeSummaryStatistic { |
| 38 |
|
| 39 |
private Nbar() { } |
| 40 |
|
| 41 |
public double[] getSummaryStatistic(Tree tree) { |
| 42 |
|
| 43 |
double NBar = 0.0; |
| 44 |
for (int i =0; i < tree.getExternalNodeCount(); i++) { |
| 45 |
NodeRef node = tree.getExternalNode(i); |
| 46 |
while (!tree.isRoot(node)) { |
| 47 |
node = tree.getParent(node); |
| 48 |
NBar += 1.0; |
| 49 |
} |
| 50 |
} |
| 51 |
return new double[] { NBar / tree.getExternalNodeCount() }; |
| 52 |
} |
| 53 |
|
| 54 |
public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); } |
| 55 |
public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); } |
| 56 |
public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); } |
| 57 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 58 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 59 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 60 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 61 |
|
| 62 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 63 |
|
| 64 |
public TreeSummaryStatistic createStatistic() { |
| 65 |
return new Nbar(); |
| 66 |
} |
| 67 |
|
| 68 |
public String getSummaryStatisticName() { |
| 69 |
return "N_bar"; |
| 70 |
} |
| 71 |
|
| 72 |
public String getSummaryStatisticDescription() { |
| 73 |
return "The mean number of nodes above an external node."; |
| 74 |
} |
| 75 |
|
| 76 |
public String getSummaryStatisticReference() { |
| 77 |
return "Kirkpatrick & Slatkin (1992)"; |
| 78 |
} |
| 79 |
|
| 80 |
public boolean allowsPolytomies() { return true; } |
| 81 |
|
| 82 |
public boolean allowsNonultrametricTrees() { return true; } |
| 83 |
|
| 84 |
public boolean allowsUnrootedTrees() { return false; } |
| 85 |
|
| 86 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.TREE_SHAPE; } |
| 87 |
}; |
| 88 |
} |