Skip to content

Add Pearson correlation (r) to lineal regression #332

@fredyagomez

Description

@fredyagomez

Just checking if this worths a PR. Currently Lineal Regression returns m and b, but you always want to check R square attached to see how well the fit was. I know there is a R-square function but would be handy to have this one returned from the function since all formulas are already there.

Planning to push this one
image

which will translate to something like:

  //Pearson correlation
  r = (dataLength * sumXY - sumX * sumY) / 
    (Math.sqrt(dataLength * sumX2 - sumX * sumX) * Math.sqrt(dataLength * sumY2 - sumY * sumY))

Using the same definitions you have for sumXY, SumY, SumX. I would add sumX2 and sumY2 plus the return value r to the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions