SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
QQPlot.java
1/*
2 * Class: QQPlot
3 * Description: qq-plot
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Richard Simard
9 * @since May 2011
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.charts;
26
27import umontreal.ssj.probdist.ContinuousDistribution;
28import java.util.Arrays;
29
43public class QQPlot extends XYLineChart {
44 private double[][] Q; // data points
45 private double[][] Lin; // line y = x
46
47 private void initLinear(double a, double b) {
48 // line y = x in [a, b] by steps of h
49 int m = 100;
50 double h = (b - a) / m;
51 Lin = new double[2][m + 1];
52 for (int i = 0; i <= m; i++)
53 Lin[0][i] = Lin[1][i] = a + h * i;
54 }
55
56 private void initPoints(ContinuousDistribution dist, double[] data, int numPoints) {
57 int i;
58 double p;
59 Q = new double[2][numPoints]; // q_i = cdf^(-1)(p_i)
60
61 for (i = 0; i < numPoints; i++)
62 Q[1][i] = data[i];
63 Arrays.sort(Q[1]);
64 for (i = 0; i < numPoints; i++) {
65 p = (i + 0.5) / numPoints;
66 Q[0][i] = dist.inverseF(p);
67 }
68 }
69
86 public QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[] X) {
87 this(title, XLabel, YLabel, dist, X, X.length);
88 }
89
103 public QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[] X, int numPoints) {
104 super();
105 initPoints(dist, X, numPoints);
106 initLinear(Q[1][0], Q[1][numPoints - 1]);
107 dataset = new XYListSeriesCollection(Q, Lin);
108 // --- dashed line for y = x
109 ((XYListSeriesCollection) dataset).setDashPattern(1, "dashed");
110 init(title, XLabel, YLabel);
111 }
112
129 public QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[][] data, int r) {
130 this(title, XLabel, YLabel, dist, data[r], data[r].length);
131 }
132}
QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[][] data, int r)
Constructs a new QQPlot instance.
Definition QQPlot.java:129
QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[] X, int numPoints)
Similar to the constructor QQPlot(title, XLabel, YLabel, dist, X) above, except that only the first n...
Definition QQPlot.java:103
QQPlot(String title, String XLabel, String YLabel, ContinuousDistribution dist, double[] X)
Constructs a new QQPlot instance using the points X.
Definition QQPlot.java:86
XYLineChart()
Initializes a new XYLineChart instance with an empty data set.
Classes implementing continuous distributions should inherit from this base class.
double inverseF(double u)
Returns the inverse distribution function .
XYListSeriesCollection()
Stores data used in a XYLineChart or in other related charts, and provides complementary tools to dra...
void setDashPattern(int series, String dashPattern)
Selects dash pattern for a data series.