Debian Codegraph @

src/dr/app/gui/chart/RegressionPlot.java

raw symbols SCIP
1 /*
2 * RegressionPlot.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.gui.chart;
27
28 import dr.stats.Regression;
29 import dr.stats.Variate;
30
31 import java.awt.*;
32 import java.util.List;
33
34 public class RegressionPlot extends Plot.AbstractPlot {
35
36 private Regression regression;
37
38 /**
39 * Constructor
40 */
41 public RegressionPlot(Regression regression) {
42 super(regression.getXData(), regression.getYData());
43 this.regression = regression;
44 }
45
46 /**
47 * Constructor
48 */
49 public RegressionPlot(Variate.N xData, Variate.N yData, boolean forceOrigin) {
50 super(xData, yData);
51 setForceOrigin(forceOrigin);
52 }
53
54 /**
55 * Constructor
56 */
57 public RegressionPlot(List<Double> xData, List<Double> yData, boolean forceOrigin) {
58 super(xData, yData);
59 setForceOrigin(forceOrigin);
60 }
61
62 /**
63 * Set data
64 */
65 public void setData(List<Double> xData, List<Double> yData) {
66 super.setData(xData, yData);
67 regression = new Regression(this.xData, this.yData);
68 }
69
70 /**
71 * Set data
72 */
73 public void setData(Variate.N xData, Variate.N yData) {
74 super.setData(xData, yData);
75 regression = new Regression(this.xData, this.yData);
76 }
77
78 public void setForceOrigin(boolean forceOrigin) {
79 regression.setForceOrigin(forceOrigin);
80 }
81
82 public double getGradient() {
83 return regression.getGradient();
84 }
85
86 public double getYIntercept() {
87 return regression.getYIntercept();
88 }
89
90 public double getXIntercept() {
91 return regression.getXIntercept();
92 }
93
94 public double getResidualMeanSquared() {
95 return regression.getResidualMeanSquared();
96 }
97
98 public Regression getRegression() {
99 return regression;
100 }
101
102 public String toString() {
103 StringBuffer statString = new StringBuffer("Gradient=");
104 statString.append(Double.toString(getGradient()));
105 statString.append(", Intercept=");
106 statString.append(Double.toString(getYIntercept()));
107 statString.append(", RMS=");
108 statString.append(Double.toString(getResidualMeanSquared()));
109
110 return statString.toString();
111 }
112
113 /**
114 * Paint data series
115 */
116 protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) {
117
118 g2.setPaint(linePaint);
119 g2.setStroke(lineStroke);
120
121 double gradient = getGradient();
122 double intercept = getYIntercept();
123
124 double x1 = xAxis.getMinAxis();
125 double y1 = (gradient * x1) + intercept;
126
127 double x2 = xAxis.getMaxAxis();
128 double y2 = (gradient * x2) + intercept;
129
130 drawLine(g2, x1, y1, x2, y2);
131 }
132 }