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

Add correlation matrix (Pearson's correlation) #249

Open
lhapp27 opened this issue Nov 12, 2023 · 1 comment
Open

Add correlation matrix (Pearson's correlation) #249

lhapp27 opened this issue Nov 12, 2023 · 1 comment

Comments

@lhapp27
Copy link

lhapp27 commented Nov 12, 2023

Thank you for the package. This is my first time suggesting code changes, sorry if I dont obey common practices.

Maybe it would be useful to some users (e.g. to me it was...) to provide also functionality to calculate the correlation matrix (or more properly: Pearson’s product-moment correlation coefficient: https://en.wikipedia.org/wiki/Correlation#Pearson's_product-moment_coefficient ). This is not difficult to do, as with the covariance matrix and the standard errors all the necessary ingredients are already readily available. But I guess it does not hurt if it is there directly.

function correlation(fit::LsqFitResult; rtol::Real=NaN, atol::Real=0)
    # computes correlation of fit parameters
    covar = vcov(fit)
    std_errors = stderror(fit; rtol=rtol, atol=atol)
    
    corr = covar./(std_errors'.*std_errors)

    return corr
end

Probably one needs some catching of erros, in case std_errors has zeros.

@pkofod
Copy link
Member

pkofod commented Jan 16, 2024

Hm, good question. I think some other statistics and linear algebra packages have other names for it that we should probably obey to.

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

No branches or pull requests

2 participants