# How can I find correlation between two variables X & Y which I have obtained experimentally?

61 views (last 30 days)
Raunak Khandelwal on 11 Mar 2020
Edited: Raunak Khandelwal on 11 Mar 2020
I want to know how X (the concentration in ppm) changes with respect to Y (paramater observed during experimentation).
The values of X are 1000, 500, 100.
The values of Y are 970762, 431389, 334401.
I want to find correlation between these values.

Peter on 11 Mar 2020
Three points will give you a line, but I'd be hesitant to call it a trend. In general, linear regression of X and Y gives you a line of best fit and an r^2 value. The closer the r-squared value is to 1, the more linear the data is (y = mx+b is a good representation). Wikipedia has a nice explanation on it.
In MATLAB, you can get r-squared using corrcoef(X), where X is a matrix containing rows of observations and columns of data (Concentration, Parameter). The output is a matrix with 1's on the diagonal (because Data1 is always correlated with Data1, and Data2 is always correlated with Data2). We care about 2 on 1, or 1 on 2. In the matrix, this is R(2,1) or R(1,2). It's symmetric.
conc = [1000;500;100];
param = [970762; 431389; 334401];
X = [conc, param]; % 3x2
R = corrcoef(X)
rsq = R(2,1)^2
0.9025
Generally, people like slightly stronger r^2 vals (>0.95), but for 3 points, it's not terrible. The line of best fit is obtained by solving an overdetermined system:
% param = m*conc + b
mb = [conc, ones(size(conc,1),1)]\param
m=mb(1)
b=mb(2)