kerry kerry - 24 days ago 8
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?


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`;