| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void setUsingData(Vec data) |
| 149 | { |
| 150 | /* Method of parameter esstimation is more complex than for |
| 151 | * other distirbutions, see |
| 152 | * http://www.qualitydigest.com/jan99/html/body_weibull.html |
| 153 | * for the method used. NOTE the above article has alpha and beta in oposite order |
| 154 | */ |
| 155 | |
| 156 | Vec sData = data.sortedCopy(); |
| 157 | DenseVector ranks = new DenseVector(sData.length()); |
| 158 | for(int i = 0; i < sData.length(); i++) |
| 159 | { |
| 160 | //Get the median rank |
| 161 | double tmp = (i+1.0-0.3)/(sData.length()+0.4); |
| 162 | |
| 163 | tmp = 1/(1-tmp); |
| 164 | |
| 165 | tmp = log(log(tmp)); |
| 166 | |
| 167 | ranks.set(i, tmp); |
| 168 | |
| 169 | sData.set(i, log(sData.get(i))); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | double[] s = SimpleLinearRegression.regres(sData, ranks); |
| 174 | |
| 175 | //The shape parameter is approximatly the slope |
| 176 | |
| 177 | setAlpha(s[1]); |
| 178 | |
| 179 | /* |
| 180 | * We can now compute alpha directly. |
| 181 | * Note the page use y = m x + b, instead of y = b x + a |
| 182 | * |
| 183 | */ |
| 184 | |
| 185 | setBeta(exp(-s[0]/alpha)); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public double mean() |