필터 지우기
필터 지우기

How to create a scatter plot of partial rank correlation

조회 수: 24 (최근 30일)
Takashi Fukushima
Takashi Fukushima 2021년 2월 21일
댓글: 俊荣 韩 2022년 3월 25일
Hello,
I have a question regarding a partial rank correlation.
I would like to use "partialcorr" function to find correlation between X and Y after controlling for Z and visualize it on a scatter plot. As far as I understood the calculation, I can plot it as below.
X = variable 1
Y = variable 2
Z = Confounder
mdl_Z_X = fitlm(Z,X);
mdl_Z_Y = fitlm(Z,Y);
plot(mdl_Z_X.Residuals.Raw,mdl_Z_Y.Residuals.Raw);
I calculated the correlation in both ways to make sure they match each other
R1 = partialcorr(X,Y,Z,"type","Pearson")
R2 = corr(mdl_Z_X.Residuals.Raw, mdl_Z_Y.Residuals.Raw, "type", "Pearson")
And they were matched (R1 = R2). However, When I switched it to "Spearman", the correlation coefficient did not match. What I mean is ...
R1 = partialcorr(X,Y,Z,"type","Spearman")
R2 = corr(mdl_Z_X.Residuals.Raw, mdl_Z_Y.Residuals.Raw, "type", "Spearman")
R1 and R2 were a different value. I also tried to convert X and Y variables into rank variables as if ...
X = [2.5 3.1 6.5 1.2]
Xrank = [2 3 4 1]
The conversion seemed working somewhat as the correlation coefficient became closer to the coefficient from the "partialcorr" function, but it still did not match. Since the algorithm of a built-in function is hidden by MATLAB, I would really appreciate if someone knows how I can create a scatter plot of partial rank correlation.
Thank you in advance.
  댓글 수: 1
俊荣 韩
俊荣 韩 2022년 3월 25일
hello,
Thank you for your example shown here, and I got a lot of help. I tried your code and did a bit of improvement
"R1 and R2 were a different value. I also tried to convert X and Y variables into rank variables as if ...
X = [2.5 3.1 6.5 1.2]
Xrank = [2 3 4 1]"
The rank of X should be descended when conducting Spearman. It's ascending in your example.
And the R2 calculation with resduals of X and Y should use Pearson,
R2 = corr(mdl_Z_X.Residuals.Raw, mdl_Z_Y.Residuals.Raw, "type", "Pearson")
Then, the R1 and R2 were the same.

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

답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by