Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cov and cor in the presence of missing values #94

Merged
merged 1 commit into from
Oct 27, 2021
Merged

Conversation

nalimilan
Copy link
Member

dot currently (since https://github.com/JuliaLang/Statistics.jl/pull/85) throws when the input contains missing, which is breaking as they were previously accepted.
Use adjoint(y) * x instead of dot(y, x), as the former falls back to the latter for arrays of Numbers but to sum(uu*vv for (uu, vv) in zip(u, v)) for other types.

`dot` currently throws when the input contains `missing`,
which is breaking as they were previously accepted.
Use `adjoint(y) * x` instead of `dot(y, x)`, as the former falls back
to the latter for arrays of `Number`s but to
`sum(uu*vv for (uu, vv) in zip(u, v))` for other types.
@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #94 (b914eab) into master (52998f2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #94   +/-   ##
=======================================
  Coverage   96.91%   96.91%           
=======================================
  Files           1        1           
  Lines         422      422           
=======================================
  Hits          409      409           
  Misses         13       13           
Impacted Files Coverage Δ
src/Statistics.jl 96.91% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52998f2...b914eab. Read the comment docs.

@@ -522,7 +522,7 @@ unscaled_covzm(x::AbstractMatrix, vardim::Int) = (vardim == 1 ? _conj(x'x) : x *
function unscaled_covzm(x::AbstractVector, y::AbstractVector)
(isempty(x) || isempty(y)) &&
throw(ArgumentError("covariance only defined for non-empty vectors"))
return dot(y, x)
return *(adjoint(y), x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use this unnatural style of calling *?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's used below. I've no idea why it was written like this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants