MATLAB: Pearson correlation coefficient determination

correlationpearson

Hi,
I am trying to generate the Pearson correlation coefficient for A1 vs. A2, A1 vs. C and A2 vs. C. For all these I get 1.000 which is quite unrealistic. What am I doing wrong here? You can use these numbers to excute the function. Pearson_correlation(100000,10000,25000,1)
function [ Absorbance1,Absorbance2 ] = Pearson_correlation(I0,E1,E2,l)
% A = ECl beer-lambert law
% A = -log T = -log(It/Io)=log(I0)-log(It)
% A = Absorbance
%It = Intensity of Transmitted photons
%I0 = Initial Intensity of photons
C=[0 10 20 30 40 50]; %Concentrations
C1=C*1E-6; %Concentration unit conversion
SD=sqrt(I0); %Standard deviation of excitation photons
%This part of the code generates numbers for A1,A2 and the Pearson
%correlation coeffienct for A1 vs. A2, A1 vs. C and A2 vs.C
I0f=I0+randn(1,1).*SD; %excitation photon fluctuation

A1=E1*C1*l; %Calculation of absorbance
It11=I0f.*10.^(-A1); %Calculation of transmittance
SD21=sqrt(It11);
It12=It11+SD21.*randn(1,1); %transmittance fluctuation
Absorbance1=log(I0f)-log(It12) %calculation of absorbance accounding the fluctuations.
I0f=I0+randn(1,1).*SD; %excitation photon fluctuation
A2=E2*C1*l;
It21=I0f.*10.^(-A2);
SD21=sqrt(It21);
It22=It21+SD21.*randn(1,1);
Absorbance2=log(I0f)-log(It22)
r=corrcoef(Absorbance1, Absorbance2);
Absorbance_correlation=r(2)
s=corrcoef(C,Absorbance1);
Concentration_correlation1=s(2)
t=corrcoef(C,Absorbance2);
Concentration_correlation2=t(2)
% Pearson_correlation(100000,10000,25000,1)

Best Answer

What do you expect? It seems you keep on doing these computations, but then fail to think about the result, not thinking why you get what you did. For example...
corrcoef(Absorbance1, Absorbance2)
ans =
1 0.999999780102625
0.999999780102625 1
The coreelation coefficient is NOT 1. However, it is very near 1. Not exactly so though.
p1 = polyfit(Absorbance1',Absorbance2',1)
p1 =
2.50345381465648 -0.0079603101543761
[Absorbance1'*p1(1) + p1(2), Absorbance2']
ans =
0.00319199569957401 0.00396857486191138
0.580997733409916 0.580941962999683
1.15897081349257 1.15836071715381
1.73713188545425 1.73637553044848
2.31550417871278 2.31518905653607
2.89411383324176 2.8950745980109
So, if we transform Absorbance1 by a linear transformation, we get something virtually identical to Absorbance2.
Likewise, C is a perfectly linear sequence.
C
C =
0 10 20 30 40 50
diff(Absorbance1)
ans =
0.230803434170655 0.230870278772036 0.230945371780708 0.231029743737411 0.231124557258262
As you should see by the differences there, Absorbance1 is nearly so too.
Can you possibly expect to not see nearly unit correlations for each of those comparisons? Two perfectly linear (non-constant) sequences will have a correlation coefficient that is either 1 or -1.
Look at what you get. Don't just compute a number and assume it has any meaning. Think about what you have done. Does what you did make sense?
Related Question