Pearson correlation graph between variables

Hi
There are 6 variables (10,000 of each) which I am importing from excel and then using these, I am calculating a new variable let us say, Y (again, 10,000 iterations). How do I plot Pearson correlelation coeffcient between Y and each of 6 variables as tornado plots?
Thanks in advance

 採用された回答

Shubham
Shubham 2024 年 8 月 30 日
編集済み: Shubham 2024 年 8 月 30 日

0 投票

Hi Sunil,
To create a tornado plot of Pearson Correlation Coefficients between a dependent variable ( Y ) and six independent variables, follow these steps:
  1. Use the "corr" function to calculate correlation between ( Y ) and each independent variable. Below is the MATLAB code snippet to achieve this:
% List of variable names
variables = {'Var1', 'Var2', 'Var3', 'Var4', 'Var5', 'Var6'};
correlations = zeros(1, length(variables));
% Calculate correlations
for i = 1:length(variables)
correlations(i) = corr(data.(variables{i}), Y);
end
2. Use the "barh" function to create a horizontal bar chart for the tornado plot.
barh(correlations, 'FaceColor', [0.5, 0.7, 1]);
Refer to the following MathWorks documentation link for more information on "corr":
Hope this helps.

4 件のコメント

Sunil
Sunil 2024 年 8 月 30 日
Hi Shubham
Thanks for reply. Suppose out of 6, I want to plot the correlation of output "Y" with any 3-4, then how can I do that?
Thanks
Sunil
Sunil 2024 年 9 月 2 日
When I run the suggested program, I get the eroor:
Unable to resolve the name 'data.C'.
Error in MC_inputdist (line 156)
correlations(i) = corr(data.(variables{i}), HI);
what could be reason for this?
Thanks
Shubham
Shubham 2024 年 9 月 3 日
Hi Sunil,
This issue may be due to Field Names mismatch. Ensure that your "data" structure actually contains a field named "C".
You can check the fields of "data" using:
fieldnames(data)
Hope this helps.
Sunil
Sunil 2024 年 9 月 4 日
Hi Shubham
Thanks a lot! It worked.

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

その他の回答 (1 件)

KSSV
KSSV 2024 年 8 月 30 日

0 投票

clc; clear ;
R = zeros(6,1) ;
for i = 1:6
X = rand(100,1) ;
y = rand(100,1) ;
R(i) = regression(X',y') ;
end
barh(R)

1 件のコメント

Sunil
Sunil 2024 年 8 月 30 日
I want to find Pearson correlation not regression relationships. Thanks

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

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

質問済み:

2024 年 8 月 30 日

コメント済み:

2024 年 9 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by