README.md in standard_deviation-0.0.1 vs README.md in standard_deviation-1.0.0
- old
+ new
@@ -16,28 +16,39 @@
$ gem install standard_deviation
## Usage
-Just call `standard_deviation` or `stdev` on a array with numbers.
+Just call `standard_deviation` or `stdev` on an array with numbers:
``` ruby
[1, 2, 3, 4, 5].stdev => 1.5811388300841898
[521.0, BigDecimal("1234.45"), 1_120].standard_deviation => 383.168958598336
```
+For population standard deviation, call `stdevp`:
+``` ruby
+[1, 2, 3, 4, 5].stdevp => 1.4142135623730951
+```
+
+Also, the API exposes the `sample_variance` and `population_variance` calculations:
+``` ruby
+[1, 2, 3, 4, 5].sample_variance => 2.5
+[1, 2, 3, 4, 5].population_variance => 2.0
+```
+
## Benchmarks
``` ruby
# Basic ruby implementation
class Array
def stdev_ruby
total = inject :+
mean = total.to_f / size
- variance = inject(0) { |variance, value| variance + (value - mean) ** 2 }
+ variance = inject(0) { |variance, value| variance + (value - mean) ** 2 } / (size - 1)
- Math.sqrt(variance / (size - 1))
+ Math.sqrt(variance)
end
end
# Running on a 2.4 GHz MacBook Pro
n = 10000