Search in sources :

Example 11 with Regression

use of dr.stats.Regression in project beast-mcmc by beast-dev.

the class TemporalRooting method findGlobalRoot.

private Tree findGlobalRoot(final Tree source, final double[] dates, RootingFunction rootingFunction, boolean forcePositiveRate) {
    FlexibleTree bestTree = new FlexibleTree(source);
    double minF = findLocalRoot(bestTree, dates, rootingFunction, forcePositiveRate);
    double minDiff = Double.MAX_VALUE;
    totalRootBranches = source.getNodeCount();
    for (currentRootBranch = 0; currentRootBranch < source.getNodeCount(); currentRootBranch++) {
        FlexibleTree tmpTree = new FlexibleTree(source);
        NodeRef node = tmpTree.getNode(currentRootBranch);
        if (!tmpTree.isRoot(node)) {
            double length = tmpTree.getBranchLength(node);
            tmpTree.changeRoot(node, length * 0.5, length * 0.5);
            double f = findLocalRoot(tmpTree, dates, rootingFunction, forcePositiveRate);
            if (useTargetRate) {
                Regression r = getRootToTipRegression(tmpTree);
                if (Math.abs(r.getGradient() - targetRate) < minDiff) {
                    minDiff = Math.abs(r.getGradient() - targetRate);
                    bestTree = tmpTree;
                }
            } else {
                if (f < minF) {
                    minF = f;
                    bestTree = tmpTree;
                }
            }
        }
    }
    return bestTree;
}
Also used : Regression(dr.stats.Regression)

Example 12 with Regression

use of dr.stats.Regression in project beast-mcmc by beast-dev.

the class RegressionPlot method setData.

/**
     * Set data
     */
public void setData(List<Double> xData, List<Double> yData) {
    super.setData(xData, yData);
    regression = new Regression(this.xData, this.yData);
}
Also used : Regression(dr.stats.Regression)

Example 13 with Regression

use of dr.stats.Regression in project beast-mcmc by beast-dev.

the class RegressionPlot method setData.

/**
     * Set data
     */
public void setData(Variate.N xData, Variate.N yData) {
    super.setData(xData, yData);
    regression = new Regression(this.xData, this.yData);
}
Also used : Regression(dr.stats.Regression)

Example 14 with Regression

use of dr.stats.Regression in project beast-mcmc by beast-dev.

the class TempestPanel method writeDataFile.

public void writeDataFile(Writer writer) {
    PrintWriter pw = new PrintWriter(writer);
    String[] labels = temporalRooting.getTipLabels(currentTree);
    double[] yValues = temporalRooting.getRootToTipDistances(currentTree);
    if (temporalRooting.isContemporaneous()) {
        double meanY = DiscreteStatistics.mean(yValues);
        pw.println("tip\tdistance\tdeviation");
        for (int i = 0; i < yValues.length; i++) {
            pw.println(labels[i] + "\t" + "\t" + yValues[i] + "\t" + (yValues[i] - meanY));
        }
    } else {
        double[] xValues = temporalRooting.getTipDates(currentTree);
        Regression r = temporalRooting.getRootToTipRegression(currentTree);
        double[] residuals = temporalRooting.getRootToTipResiduals(currentTree, r);
        pw.println("tip\tdate\tdistance\tresidual");
        for (int i = 0; i < xValues.length; i++) {
            pw.println(labels[i] + "\t" + xValues[i] + "\t" + yValues[i] + "\t" + residuals[i]);
        }
    }
}
Also used : Regression(dr.stats.Regression) PrintWriter(java.io.PrintWriter)

Example 15 with Regression

use of dr.stats.Regression in project beast-mcmc by beast-dev.

the class TemporalRooting method findGlobalRoot.

private Tree findGlobalRoot(final Tree source, final double[] dates, RootingFunction rootingFunction, boolean forcePositiveRate) {
    FlexibleTree bestTree = new FlexibleTree(source);
    double minF = findLocalRoot(bestTree, dates, rootingFunction, forcePositiveRate);
    double minDiff = Double.MAX_VALUE;
    totalRootBranches = source.getNodeCount();
    for (currentRootBranch = 0; currentRootBranch < source.getNodeCount(); currentRootBranch++) {
        FlexibleTree tmpTree = new FlexibleTree(source);
        NodeRef node = tmpTree.getNode(currentRootBranch);
        if (!tmpTree.isRoot(node)) {
            double length = tmpTree.getBranchLength(node);
            tmpTree.changeRoot(node, length * 0.5, length * 0.5);
            double f = findLocalRoot(tmpTree, dates, rootingFunction, forcePositiveRate);
            if (useTargetRate) {
                Regression r = getRootToTipRegression(tmpTree);
                if (Math.abs(r.getGradient() - targetRate) < minDiff) {
                    minDiff = Math.abs(r.getGradient() - targetRate);
                    bestTree = tmpTree;
                }
            } else {
                if (f < minF) {
                    minF = f;
                    bestTree = tmpTree;
                }
            }
        }
    }
    return bestTree;
}
Also used : Regression(dr.stats.Regression)

Aggregations

Regression (dr.stats.Regression)17 NodeRef (dr.evolution.tree.NodeRef)3 NexusExporter (dr.app.tools.NexusExporter)2 FlexibleTree (dr.evolution.tree.FlexibleTree)2 Variate (dr.stats.Variate)2 NumberFormatter (dr.util.NumberFormatter)2 PrintWriter (java.io.PrintWriter)2 Node (jebl.evolution.graphs.Node)2 Taxon (jebl.evolution.taxa.Taxon)2 RootedTree (jebl.evolution.trees.RootedTree)2 MultivariateTraitTree (dr.evolution.tree.MultivariateTraitTree)1 TreeUtils (dr.evolution.tree.TreeUtils)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 SphericalPolarCoordinates (dr.geo.math.SphericalPolarCoordinates)1