kerry kerry - 1 year ago 88
MySQL Question

php or mysql to provide correlation coefficient between two columns

Can anybody point me in the direction of or give me an example of a function in php or query in mysql that will return the correlation coefficient between 2 columns in a mysql table?

Answer Source

Adapted from a similar question found on the interwebs perhaps something like this might be of use?

select ( avg( `col1` * `col2` ) - avg( `col1` ) + avg( `col2` ) ) / ( stddev( `col1` ) * stddev(`col2`) ) as 'correlation'
from `table`;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download