correlation of nonlinear variables

64 views (last 30 days)
Ameen Bassam
Ameen Bassam on 27 Jul 2021
Answered: John D'Errico on 31 Jul 2021
I have variables with nonlinear relationships and I want to calculate the correlation between them to find which variable affect more than the others.
I have used corr function but it returns the linear correlation coefficient. I can't find a function to calculate correlation coefficients for nonlinear variables. Any hlep please? Or should I use R instead of MATLAB ?

Answers (3)

John D'Errico
John D'Errico on 31 Jul 2021
Correlation does not really make sense in respect to nonlinear variables. Depending on the values of the variables, they will be more or less correlated. So that is meaningless. At best you can talk about a local correlation, where a linear approximation is made, and then correlation could be defined.
So in that context, correlation is simple. You start with the inverse of the local Hessian matrix. Scale that to have unit diagonals, by pre-and post multiplying by the correct diagonal matrix. The off-diagonal terms will be the desired local correlation, as a simple approximation, and valid ONLY locally.

Image Analyst
Image Analyst on 27 Jul 2021
If you want, you can try to fit some model through your data, like an exponential growth or decay if you suspect that is the relationship. Then you can compute the MSE of the residuals. Demos are attached.

Jeff Miller
Jeff Miller on 28 Jul 2021
It isn't really clear what you mean by "correlation coefficients for nonlinear variables", because an infinite number of nonlinear relationships are possible, and each one would give a different correlation value. As indicated by Image Analyst, you can try fitting different nonlinear relationships and see which one fits best.
Alternatively, maybe you are looking for the nonparametric Spearman rank order correlation which checks only for monotonic relationships rather than strictly linear ones. If that is what you are after, you can use
[RHO,PVAL] = corr(x,y,'Type','Spearman'); % May require statistics toolbox?
to get the Spearman correlation.
Ameen Bassam
Ameen Bassam on 31 Jul 2021
Edited: Ameen Bassam on 31 Jul 2021
Thank you for your reply. I think distance correlation can be helpful in my case

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!