Scatter plot and curve fitting?

Hello every one,
I have two set of vectors
X=[2,3,2,2,1,4,1,1,1,1,2,4,3,4,3,3,2,2,3,2,3,1];
Y=[9.14,38.66,0.72,0.79,1.96,0.68,7.58,0.83,2.37,3.44,2.17,1.6,21.98,5.19,0.71,25.35,17.65,7.78,14.38,4.77,2.5,29.26];
To find the correlation between X and Y, we have used Spearman rank correlation coefficient
[RHO]=corr(X.',Y.','type','spearman');
For fitting line to the data points, we have used polynomial of degree 1,
p=polyfit(X,Y,1);%This will generate the coefficients of polynomial of degree(1)
y=polyval(p,X);% This will give the fitted values for the desired values.
scatter(X,Y,'*');% This will create a scatter plot
hold on;
plot(X,y,'k-');% This will plot regression line.
The Spearman rank correlation coefficient has negative value, but the regression line seems to represent positive correlation between X and Y. Any help regarding this issue will be highly appreciated.
Thanks

4 Commenti

what is the significance of coor between x and y? They are different parameters right? X is your independent variable and y is your dependent variable? The following makes a sense:
RHO=corr(Y.',y','type','spearman');
@KSSV ,
X and Y are different parameters. X is independent variable and y is your dependent variable. The correlation coefficient is non significant with P value of 0.96. I want to find the correlation between X and Y, not between Y and the fitted values. Thats why
RHO=corr(Y.',y','type','spearman');
doen't make sence to me.
My main problem is that the correlation is negative but the regression seems to show positve correlation.
Thanks
Rik
Rik il 15 Gen 2019
They are both fairly close to 0. It wouldn't surprise me if there is a lot of overlap between the two confidence intervals.
Rik
Rik il 17 Mag 2019
Comment mistakenly posted as answer by Wen Wen:
I had similar problem. I guess it's because the spearman corrlation which transformed the orignial data into ranks while the polyfit function finds the best linear fit based the original data. If this assumption is correct, my question would be how could we plot the fitting line for spearman correlation in matlab.

Accedi per commentare.

Risposte (0)

Categorie

Tag

Richiesto:

il 15 Gen 2019

Commentato:

Rik
il 17 Mag 2019

Community Treasure Hunt

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

Start Hunting!

Translated by