Statistics.jl icon indicating copy to clipboard operation
Statistics.jl copied to clipboard

`cov`/`cor` with dims>2 should error?

Open nickrobinson251 opened this issue 5 years ago • 2 comments

I found this a little surprsing. Should this error rather than give NaNs?

> using Statistics
> A = rand(3, 5)
> cov(A, dims=7)
3×3 Array{Float64,2}:
NaN  NaN  NaN
NaN  NaN  NaN
NaN  NaN  NaN

> cor(A, dims=7)
3×3 Array{Float64,2}:
   1.0  NaN    NaN
 NaN      1.0  NaN
 NaN    NaN      1.0

(Julia 1.1.1)

nickrobinson251 avatar Jun 21 '19 12:06 nickrobinson251

On Slack

Milan Bouchet-Valat I guess this behavior is inherited from reductions like sum, where higher dimensions are ignored (they are collapsed, which is a no-op). But I'm not sure it makes sense here. File an issue?

nickrobinson251 avatar Jun 21 '19 12:06 nickrobinson251

It doesn’t help that the ˋcorrected = trueˋ version of ˋcovˋ which is applied multiplies everything with ˋNaN == 1/(n-1)ˋ

mschauer avatar Jun 21 '19 13:06 mschauer