Module:RiskRange/doc
Appearance
This is the documentation page for Module:RiskRange
This module converts two probability values into a human-friendly range string with a common denominator, making it easy to compare the low and high estimates.
Usage
From wikitext (via Template:RiskRange):
{{RiskRange|probability1|probability2}}
Direct module invocation:
{{#invoke:RiskRange|convert|probability1|probability2}}
Parameters
| Parameter | Description |
|---|---|
1 |
First probability (decimal between 0 and 1) |
2 |
Second probability (decimal between 0 and 1) |
The module automatically orders the probabilities so the lower risk appears first and higher risk appears second.
Output Format
The module outputs ranges in the format "N to M in D" where:
- N = lower numerator (lower risk)
- M = higher numerator (higher risk)
- D = common denominator
Denominator Selection
- If either probability is ≥ 0.1, the denominator is 10 (e.g., "2 to 6 in 10")
- Otherwise, the denominator is chosen based on the smaller probability, rounded to a "nice" value (10, 20, 50, 100, 200, 500, 1,000, etc.)
Special Cases
| Condition | Output |
|---|---|
| Both probabilities ≤ 0 | "no chance" |
| Both probabilities ≥ 1 | "100% chance" |
| Both probabilities ≥ 0.95 | "almost certain" |
| One is 0, other is 1 | "anywhere from no chance to certain" |
| Probabilities within 5% of each other | Single value, e.g., "about 5 in 10" |
| Lower probability ≈ 0 | "up to about N in D" |
| Higher probability ≥ 1 | "at least N in D" |
Examples
| Input | Output |
|---|---|
{{RiskRange|0.2|0.6}} |
2 to 6 in 10 |
{{RiskRange|0.001|0.01}} |
1 to 10 in 1,000 |
{{RiskRange|0.21|0.6}} |
2 to 6 in 10 |
{{RiskRange|0.33|0.82}} |
3 to 8 in 10 |
{{RiskRange|0.01|0.05}} |
1 to 5 in 100 |
{{RiskRange|0.0001|0.001}} |
1 to 10 in 10,000 |
{{RiskRange|0.5|0.5}} |
about 5 in 10 |
{{RiskRange|0|0.5}} |
up to about 5 in 10 |
Algorithm
- Validate inputs and handle error cases
- Order probabilities (lower first)
- Check for special cases (zero, one, equal, almost certain)
- Select common denominator:
- Use 10 if higher probability ≥ 0.1
- Otherwise use
nice_denominator(1/lower_probability)
- Calculate numerators:
N = probability × denominator - Round numerators to integers
- If both round to same value, try larger denominator
- Format output string
See Also
- Template:RiskRange – Template wrapper for this module
- Template:One_In_X – For single probability values
- Module:ProbabilityFormat – Single probability formatting
- Module:RiskRange/testcases – Unit tests (30 test cases)
- Test/RiskRange – Test runner page