From 5ad828e12325ce9dd6862493e225adaabd7d294c Mon Sep 17 00:00:00 2001 From: Antonio Saragga <47437960+ASaragga@users.noreply.github.com> Date: Tue, 16 Feb 2021 16:24:50 +0000 Subject: [PATCH 1/4] Allow computing the correlation matrix from the covariance matrix only (StatsBase.jl #652) --- src/cov.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cov.jl b/src/cov.jl index a77cd5086..4f68f1d13 100644 --- a/src/cov.jl +++ b/src/cov.jl @@ -131,6 +131,13 @@ deviations `s`. Use `StatsBase.cov2cor!` for an in-place version. """ cov2cor(C::AbstractMatrix, s::AbstractArray) = cov2cor!(copy(C), s) +""" + cov2cor(C) + + Compute the correlation matrix from the covariance matrix `C`. Use `StatsBase.cov2cor!` for an in-place version. + """ + cov2cor(C::AbstractMatrix) = cov2cor!(copy(C)) + """ cor2cov(C, s) From f68e00ef941f2752974dc72c7462e8a7067690f4 Mon Sep 17 00:00:00 2001 From: Antonio Saragga <47437960+ASaragga@users.noreply.github.com> Date: Thu, 18 Feb 2021 03:11:23 +0000 Subject: [PATCH 2/4] Add tests to allow computing the correlation matrix from the covariance matrix only --- test/cov.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/cov.jl b/test/cov.jl index ab310276c..0ffca0f83 100644 --- a/test/cov.jl +++ b/test/cov.jl @@ -122,8 +122,12 @@ weight_funcs = (weights, aweights, fweights, pweights) @testset "cov2cor" begin @test cov2cor(cov(X, dims = 1), std(X, dims = 1)) ≈ cor(X, dims = 1) @test cov2cor(cov(X, dims = 2), std(X, dims = 2)) ≈ cor(X, dims = 2) + @test cov2cor(cov(X, dims = 1)) ≈ cor(X, dims = 1) + @test cov2cor(cov(X, dims = 2)) ≈ cor(X, dims = 2) @test cov2cor(cov1, std1) ≈ cor1 @test cov2cor(cov2, std2) ≈ cor2 + @test cov2cor(cov1) ≈ cor1 + @test cov2cor(cov2) ≈ cor2 end @testset "cor2cov" begin @test cor2cov(cor(X, dims = 1), std(X, dims = 1)) ≈ cov(X, dims = 1) From 25894d26f5f7341e1140c0d91d23c54d4fb43d00 Mon Sep 17 00:00:00 2001 From: Antonio Saragga <47437960+ASaragga@users.noreply.github.com> Date: Fri, 19 Feb 2021 20:38:48 +0000 Subject: [PATCH 3/4] Add tests for cov2cor function --- test/cov.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/cov.jl b/test/cov.jl index 0ffca0f83..cf54d16e7 100644 --- a/test/cov.jl +++ b/test/cov.jl @@ -122,8 +122,6 @@ weight_funcs = (weights, aweights, fweights, pweights) @testset "cov2cor" begin @test cov2cor(cov(X, dims = 1), std(X, dims = 1)) ≈ cor(X, dims = 1) @test cov2cor(cov(X, dims = 2), std(X, dims = 2)) ≈ cor(X, dims = 2) - @test cov2cor(cov(X, dims = 1)) ≈ cor(X, dims = 1) - @test cov2cor(cov(X, dims = 2)) ≈ cor(X, dims = 2) @test cov2cor(cov1, std1) ≈ cor1 @test cov2cor(cov2, std2) ≈ cor2 @test cov2cor(cov1) ≈ cor1 From edeeaf6bc615aa46aa4584e866f90db93f8763a7 Mon Sep 17 00:00:00 2001 From: Antonio Saragga <47437960+ASaragga@users.noreply.github.com> Date: Sat, 20 Feb 2021 13:56:35 +0000 Subject: [PATCH 4/4] Update cov.jl --- test/cov.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/cov.jl b/test/cov.jl index cf54d16e7..ab310276c 100644 --- a/test/cov.jl +++ b/test/cov.jl @@ -124,8 +124,6 @@ weight_funcs = (weights, aweights, fweights, pweights) @test cov2cor(cov(X, dims = 2), std(X, dims = 2)) ≈ cor(X, dims = 2) @test cov2cor(cov1, std1) ≈ cor1 @test cov2cor(cov2, std2) ≈ cor2 - @test cov2cor(cov1) ≈ cor1 - @test cov2cor(cov2) ≈ cor2 end @testset "cor2cov" begin @test cor2cov(cor(X, dims = 1), std(X, dims = 1)) ≈ cov(X, dims = 1)