<?xml version="1.0"?>
<!-- $Id: testCoalescent.xml,v 1.2 2005/07/11 23:22:40 rambaut Exp $ -->
<!-- Tests the coalescent prior -->

<beast>

    <taxa id="taxa1">
        <taxon id="A"/>
        <taxon id="B"/>
        <taxon id="C"/>
        <taxon id="D"/>
    </taxa>

    <!-- create a demographic model and intialize currentPopulationSize parameter -->
    <constantSize id="demo1" units="years">
        <populationSize>
            <parameter id="demo1.pop1" value="10.0"/>
        </populationSize>
    </constantSize>

    <!-- simulate a coalescent tree -->
    <coalescentTree id="tree1">
        <constantSize idref="demo1"/>
        <taxa idref="taxa1"/>
    </coalescentTree>


    <!-- A prior on the distribution node heights defined given                  -->
    <!-- a Yule speciation process (a pure birth process).                       -->
    <yuleModel id="yule" units="substitutions">
        <birthRate>
            <parameter id="yule.birthRate" value="2.0" lower="0.0"
                       upper="100.0"/>
        </birthRate>
    </yuleModel>

    <treeModel id="treeModel1">
        <coalescentTree idref="tree1"/>
        <rootHeight>
            <parameter id="treeModel1.rootHeight"/>
        </rootHeight>
        <nodeHeights rootNode="false" internalNodes="true">
            <parameter id="treeModel1.internalNodeHeights"/>
        </nodeHeights>
        <nodeHeights rootNode="true" internalNodes="true">
            <parameter id="treeModel1.allNodeHeights"/>
        </nodeHeights>
    </treeModel>

    <speciationLikelihood id="speciation">
        <model>
            <yuleModel idref="yule"/>
        </model>
        <speciesTree>
            <treeModel idref="treeModel1"/>
        </speciesTree>
    </speciationLikelihood>

    <treeLengthStatistic name="TL" id="TL">
        <treeModel idref="treeModel1"/>
    </treeLengthStatistic>

    <mcmc id="mcmc1" chainLength="10000000">
        <speciationLikelihood idref="speciation"/>
        <log id="logScreen2" logEvery="100000">
            <column dp="4">
                <speciationLikelihood idref="speciation"/>
                <parameter idref="treeModel1.rootHeight"/>
                <treeLengthStatistic idref="TL"/>
            </column>
        </log>
        <log id="log1" logEvery="10" fileName="yulePrior.log">
            <speciationLikelihood idref="speciation"/>
            <parameter idref="treeModel1.rootHeight"/>
            <treeLengthStatistic idref="TL"/>
        </log>
        <logTree id="logTree1" logEvery="100" nexusFormat="true"
                 fileName="yulePrior.trees">
            <treeModel idref="treeModel1"/>
        </logTree>
        <operators>
            <subtreeSlide weight="1" gaussian="true" size="1">
                <treeModel idref="treeModel1"/>
            </subtreeSlide>
        </operators>
    </mcmc>

    <report>
        Time taken:
        <property name="timer">
            <mcmc idref="mcmc1"/>
        </property>
    </report>

    <traceAnalysis fileName="yulePrior.log" burnIn="1000">
        <!-- expectation of root height for 4 tips and lambda = 2 -->
        <expectation name="treeModel1.rootHeight" value="0.541666"/>
        <!-- expectation of tree length for 4 tips and lambda = 2 -->
        <expectation name="TL" value="1.5"/>
    </traceAnalysis>

    <treeTraceAnalysis fileName="yulePrior.trees"/>

</beast>


