StatsBase.jl
StatsBase.jl copied to clipboard
Missing method for cor(x::Vector, y::Vector, w::Weights)
Currently there is no method available for:
StatsBase.cor(x::AbstractVector, y::AbstractVector, w::AbstractWeights)
Is there a reason this method is missing?
A possible implementation (nevermind the types):
function wcor(x::AbstractVector, y::AbstractVector, w::AbstractVector)
@assert length(x) == length(y) == length(w)
w_ = w ./ sum(w)
x_ = x .- sum(w_ .* x)
y_ = y .- sum(w_ .* y)
return sum(w_ .* x_ .* y_) ./ sqrt(sum(w_ .* x_.^2) * sum(w_ .* y_.^2))
end
+1 for adding the method, and also methods for cov, scattermat and mean_and_cov. Though the implementation will have to be more efficient than that.
What do you suggest to make it more efficient @nalimilan ?
Have a look at how it's done in cov.jl (and in Statistics's covzm_unscaled). The method taking a matrix can probably be adapted without too much difficulty.