(deltas, confidence = 0.95)
| 153 | // the smallest exact confidence level at or above the requested one; fewer than six |
| 154 | // blocks cannot reach 95%, so they get no interval. |
| 155 | export function signedRankInterval(deltas, confidence = 0.95) { |
| 156 | let walsh = deltas.flatMap((a, i) => deltas.slice(i).map(b => (a + b) / 2)); |
| 157 | let estimate = percentile(walsh, 0.5); |
| 158 | walsh.sort((a, b) => a - b); |
| 159 | let cdf = signedRankCdf(deltas.length); |
| 160 | let trim = 0; |
| 161 | while (cdf[trim] <= (1 - confidence) / 2) { |
| 162 | trim++; |
| 163 | } |
| 164 | if (!trim) { |
| 165 | return {estimate, interval: null, confidence: null}; |
| 166 | } |
| 167 | return { |
| 168 | estimate, |
| 169 | interval: [walsh[trim - 1], walsh[walsh.length - trim]], |
| 170 | confidence: 1 - 2 * cdf[trim - 1] |
| 171 | }; |
| 172 | } |
| 173 | |
| 174 | // Probability of at least `observed` successes in `total` trials with success rate p. |
| 175 | export function binomialTail(observed, total, p) { |
no test coverage detected