MATLAB Answers

correlation of nonlinear variables

5 ビュー (過去 30 日間)
Ameen Bassam
Ameen Bassam 2021 年 7 月 27 日
回答済み: John D'Errico 2021 年 7 月 31 日
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 ?

回答 (3 件)

Image Analyst
Image Analyst 2021 年 7 月 27 日
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 2021 年 7 月 28 日
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.
  3 件のコメント
Ameen Bassam
Ameen Bassam 2021 年 7 月 31 日
Thank you for your reply. I think distance correlation can be helpful in my case

サインインしてコメントする。


John D'Errico
John D'Errico 2021 年 7 月 31 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by