I have 2 arrays of equal length. The following function attempts to calculate the slope using these arrays. It returns the average of the slope between each points. For the foll
You should be dividing by x_values.length - 1 . Number of slopes is pairwise.
x_values.length - 1
Edit : Wiki example in my comments shows how to calculate the alpha and beta which determines the slope of the linear regression line.