Skip to content

Commit 06c1f74

Browse files
committed
Optional argument for variation()
Added `corrected=true/false` for variation Added test for the above addition
1 parent 9f08f3a commit 06c1f74

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/scalarstats.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ a precomputed mean `m`. The coefficient of variation is the ratio of the
411411
standard deviation to the mean.
412412
"""
413413
variation(x, m) = stdm(x, m) / m
414-
variation(x) = ((m, s) = mean_and_std(x); s/m)
414+
variation(x; corrected::Bool=true) = ((m, s) = mean_and_std(x; corrected=corrected); s/m)
415415

416416
# Standard error of the mean: std / sqrt(len)
417417
# Code taken from var in the Statistics stdlib module

test/scalarstats.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ z2 = [8. 2. 3. 1.; 24. 10. -1. -1.; 20. 12. 1. -2.]
164164

165165
@test variation([1:5;]) 0.527046276694730
166166
@test variation(skipmissing([missing; 1:5; missing])) 0.527046276694730
167+
@test isnan(variation(a))
168+
@test variation(1; corrected = false) == 0
167169

168170
@test @inferred(sem([1:5;])) 0.707106781186548
169171
@test @inferred(sem(skipmissing([missing; 1:5; missing]))) 0.707106781186548

0 commit comments

Comments
 (0)