JuliaStats / StatsBase.jl

Basic statistics for Julia
Other
584 stars 191 forks source link

variation() has no optional argument corrected=false / true #777

Open mauricelanghinrichs opened 2 years ago

mauricelanghinrichs commented 2 years ago

Hey all!

I noticed that variation() and potentially other derived methods in StatsBase don't seem to have the "corrected" optional keyword argument. variation() calls std() I guess, where one can optionally switch off correcting for degrees of freedom (division by N or N-1). I wondered if it makes sense to add this option also for variation(), and maybe other methods that rely on std() or similar, too.

In applications I find this particularly relevant when computing coefficients of variations of single-element arrays (as it may happen when array length is itself probabilistic). For example:

using StatsBase

a = [1.0]
variation(a) # NaN
variation(a, corrected=true) # not possible, but should also give NaN
variation(a, corrected=false) # not possible, but should give 0.0

My version is StatsBase v0.33.16.

Best

nalimilan commented 2 years ago

Makes sense. Would you make a pull request to make variation pass corrected when calling mean_and_std?