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;
}
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);
}
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);
}
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]);
}
}
}
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;
}
Aggregations