Skip to content

Correlation matrices should probably not use oneunit #198

@Deduction42

Description

@Deduction42

Correlation matrices divide each column by the unit, so they are by definition dimensionless. However, the oneunit function is used here.

C[j,j] = oneunit(T)

I can't think of an example where this would work. This won't work with Unitful.jl, because the covariance matrix can only have a single unit; if you try to use cor2cov! the type will change, because it has to be unitless.

X = randn(10,3) .*u"m"

julia> cov(X)
3×3 Matrix{Quantity{Float64, 𝐋^2, Unitful.FreeUnits{(m^2,), 𝐋^2, nothing}}}:
  1.09164 m^2    0.289683 m^2  -0.139717 m^2
  0.289683 m^2   0.481522 m^2  -0.150258 m^2
 -0.139717 m^2  -0.150258 m^2   1.2722 m^2

julia> cor(X)
ERROR: DimensionError: m^2 and 0.3995548704289101 are not dimensionally compatible.

I can't see this working for Dates either. The oneunit function should be switched to the one function, because the diagonals of correlation matrices are multiplicative identities. If the return type of one(S[i]) cannot be converted to the element type of the covariance matrix S, there's no way to produce the correlation matrix through in-place modification of S anyway. It's best to just construct a new matrix using the element type of one(S[i]).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions