Clear Filters
Clear Filters

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

116 views (last 30 days)
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.

Answers (2)

Peter O
Peter O 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.
For your data:
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)

Shihab
Shihab on 29 Nov 2022
SC = [3171;2795;2734;2447;2182]; IR = [ 46.23;43.86;39.89;36.76;35.3]; X = [SC,IR] ; % 5×4 R= corrcoef(X) esq= R( 2,1)^2

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!