Tuesday, January 27, 2009

Matlab: Coefficient of correlation and determination

Both coefficients are used to measure the relationship between two variables. For example lets assume that we want to check whether there is a correlation between the size of the store (in thousands of square feet) (X variable) and annual sales (in million dollars) (Y variable):

X=[1.7 1.6 2.8 5.6 1.3 2.2 1.3 1.1 3.2 1.5 5.2 4.6 5.8 3.0]
Y=[3.7 3.9 6.7 9.5 3.4 5.6 3.7 2.7 5.5 2.9 10.7 7.6 11.8 4.1]

Using Matlab/Octave we can calculate Coefficient of correlation (r) and Coefficient of determination (r2) in a following way:

c=corrcoef([X' Y']);
r=c(1,2);
r2=r^2;

In our example we get r=0.95088 and r2=0.90418.
Now what does it mean? Coefficient of determination measures the proportion of variation in Y that is explained by the X. In other words, we can say that 90.4% of the change in Y can be explained by the change in X. In our case we can conclude that 90.4% of change in annual sales is explained by the change in store size. The rest (9.6%) depends on the other factors like localization, staff, management, etc.

Bellow scatter plot of X and Y:



The above scatter plot can be generated in Matlab/Octave by:
figure;
plot(X,Y,'+r');
title('Scatter plot');

3 comments:

  1. Anonymous2:30 AM

    When I initially left a comment I seem to have clicked the
    -Notify me when new comments are added- checkbox and from
    now on whenever a comment is added I receive 4 emails with the
    exact same comment. Perhaps there is a way you are able to remove me
    from that service? Kudos!

    Feel free to surf to my website ... calories burned walking calculator

    ReplyDelete
  2. Anonymous6:44 PM

    Hello There. I found your blog using msn. This is
    an extremely well written article. I will make sure to
    bookmark it and come back to read more of your useful information.
    Thanks for the post. I'll definitely comeback.

    Here is my homepage ... Diets That Work

    ReplyDelete
  3. Anonymous12:26 PM

    You should be a part of a contest for one of the best blogs on the net.
    I am going to recommend this blog!

    My weblog weblink

    ReplyDelete