# correlation of nonlinear variables

조회 수: 9(최근 30일)
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 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.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

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표시숨기기 이전 댓글 수: 2
Ameen Bassam 2021년 7월 31일

댓글을 달려면 로그인하십시오.

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.

댓글을 달려면 로그인하십시오.

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by