`cov` not behaving properly for vector of vectors?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Inspect src/Statistics.jl around unscaled_covzm and the referenced lines near 525 and 557, then reproduce the Julia examples for cov on vectors of vectors. Done means cov(A,B) produces the expected 5×5 covariance for vector-valued observations while preserving the existing behavior for scalar vectors.
Written by the indexing model from the issue text.
Description
I'm not sure if I'm understanding the behavior of cov correctly, but it seems like the current implementation for between two vectors only works on a vector of numbers. It currently gives the dot product between the vectors, which is only equivalent to what the documentation says when the vectors only contain scalars (since it's doing an inner product). At some point before bringing it over from StatsBase.jl, this probably worked according to this comment, but right now it doesn't give the behavior I expect. For example,
julia> N = 1000;
julia> A = [randn(5) for _ in 1:N];
julia> B = [randn(5) for _ in 1:N];
julia> using Statistics
julia> cov(A,B) # This is unexpected
0.15626480407767923
julia> sum((a-mean(A))*(b-mean(B))' for (a,b) in zip(A,B))/(N-1) # This is expected
5×5 Matrix{Float64}:
9.35299e-16 -5.73004e-16 -4.02748e-16 9.26408e-16 -3.28066e-16
-7.09476e-16 1.65189e-15 2.7001e-15 -9.89532e-16 -2.72944e-16
2.08931e-16 3.56516e-16 7.28591e-16 9.61526e-16 -1.33894e-15
3.51182e-16 -1.68034e-16 -1.23136e-16 -2.57385e-16 9.51302e-16
-1.97373e-16 5.99676e-16 2.97838e-16 -1.7159e-16 -1.01532e-15
I'm not saying the above is the best possible implementation, just that it gives the answer I expect. I would propose (and be willing to put up a PR for!) a change where the current implementation of unscaled_covzm is specialized to AbstractVector{<:Number} and there's a different general implementation of it for AbstractVector, similar to what I put up above.
- Dominant language
- Julia
- Stars
- 93
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaStats/Statistics.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
JuliaStats/Statistics.jl#221 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
JuliaStats/Statistics.jl#219 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaStats/Statistics.jl#207 · 1 comment ·
-
Difficulty 3/5 Half a day Newbie friendliness 55/100
JuliaStats/Statistics.jl#220 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
JuliaStats/Statistics.jl#215 · 1 reaction ·
All issues in JuliaStats/Statistics.jl
Similar issues
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
path: splitext treats directory references and leading dots as extensionsPossibly taken @Hiten0305l claimed this today. Open
Difficulty 2/5 Half a day Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
JuliaRegistries/RegistryCI.jl#758 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaParallel/Hwloc.jl#93 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day