Correlation between two vectors?

前端 未结 4 1692
轻奢々
轻奢々 2021-02-18 18:54

I have two vectors:

A_1 = 

      10
      200
      7
      150

A_2 = 
      0.001
      0.450
      0.0007
      0.200

I would like to know

4条回答
  •  Happy的楠姐
    2021-02-18 19:48

    To perform a linear regression between two vectors x and y follow these steps:

    [p,err] = polyfit(x,y,1);   % First order polynomial
    y_fit = polyval(p,x,err);   % Values on a line
    y_dif = y - y_fit;          % y value difference (residuals)
    SSdif = sum(y_dif.^2);      % Sum square of difference
    SStot = (length(y)-1)*var(y);   % Sum square of y taken from variance
    rsq = 1-SSdif/SStot;        % Correlation 'r' value. If 1.0 the correlelation is perfect
    

    For x=[10;200;7;150] and y=[0.001;0.45;0.0007;0.2] I get rsq = 0.9181.

    Reference URL: http://www.mathworks.com/help/matlab/data_analysis/linear-regression.html

提交回复
热议问题