1 | package de.uka.ipd.sdq.statistics.estimation; |
2 | |
3 | /** |
4 | * Represents a confidence interval. Whether one confidence interval contains |
5 | * another can be checked by using the {@link #contains(ConfidenceInterval)} |
6 | * method. |
7 | * |
8 | * @author Philipp Merkle |
9 | * |
10 | */ |
11 | public class ConfidenceInterval { |
12 | |
13 | private double lowerBound; |
14 | |
15 | private double upperBound; |
16 | |
17 | private double mean; |
18 | |
19 | private double level; |
20 | |
21 | /** |
22 | * Constructs a confidence interval around the specified mean, having bounds |
23 | * lowerBound and upperBound. |
24 | * |
25 | * @param mean |
26 | * the center of the confidence interval |
27 | * @param lowerBound |
28 | * the confidence interval's lower bound |
29 | * @param upperBound |
30 | * the confidence interval's upper bound |
31 | * @param level |
32 | * the confidence level. Use values between 0 and 1. For instance |
33 | * use 0.95 to estimate the 95% confidence interval. |
34 | * @param noOfObservations |
35 | * the number of observations this confidence interval is constructed from |
36 | */ |
37 | public ConfidenceInterval(double mean, double lowerBound, double upperBound, double level) { |
38 | this.mean = mean; |
39 | this.lowerBound = lowerBound; |
40 | this.upperBound = upperBound; |
41 | this.level = level; |
42 | } |
43 | |
44 | /** |
45 | * Constructs a confidence interval around the specified mean having width |
46 | * (2 * mean * halfWidth). |
47 | * |
48 | * @param mean |
49 | * the center of the confidence interval |
50 | * @param halfWidth |
51 | * the relative half-width. Use values between 0 and 1. For |
52 | * instance use 0.1 in order to specify a 10% half-width. |
53 | */ |
54 | public ConfidenceInterval(double mean, double halfWidth, double level) { |
55 | this(mean, mean - mean * halfWidth, mean + mean * halfWidth, level); |
56 | } |
57 | |
58 | public double getLowerBound() { |
59 | return lowerBound; |
60 | } |
61 | |
62 | public void setLowerBound(double lowerBound) { |
63 | this.lowerBound = lowerBound; |
64 | } |
65 | |
66 | public double getUpperBound() { |
67 | return upperBound; |
68 | } |
69 | |
70 | public void setUpperBound(double upperBound) { |
71 | this.upperBound = upperBound; |
72 | } |
73 | |
74 | public double getMean() { |
75 | return mean; |
76 | } |
77 | |
78 | public void setMean(double mean) { |
79 | this.mean = mean; |
80 | } |
81 | |
82 | |
83 | public double getLevel() { |
84 | return level; |
85 | } |
86 | |
87 | /** |
88 | * Checks, whether the specified confidence interval lies within the bounds |
89 | * of this confidence interval. |
90 | * |
91 | * @param ci |
92 | * the confidence interval |
93 | * @return true if this confidence interval contains the specified one; |
94 | * false else. |
95 | */ |
96 | public boolean contains(ConfidenceInterval ci) { |
97 | return ci != null |
98 | && this.lowerBound <= ci.getLowerBound() |
99 | && this.upperBound >= ci.getUpperBound(); |
100 | } |
101 | |
102 | } |