Calculate Linear regression segment I have array of random numbers. How can I calculate linear regression segment? I am interested in finding the exact formula so I be able to use it in my work, please help me finding this formula with the next declarations:


*

*$N$ - the number of random numbers in the array

*$S$ - the sum of the numbers in the array.

*$array_{min}$ - the minimum number in the array

*$array_{max}$ - the maximum number in the array

*$E$ - the average number in the array.


We are looking for $y = mx + c$. So you need to find a formula to represent $m$ and $c$ with the above declarations.
The array of random number are the $Y$. $X$ is just neutral numbers from $0$ to $N$
 A: I've found an easy to follow explanation of the Linear regression method here: Introduction to Linear Regression by David M. Lane.
To check if this is what we need and actually not so complicated as it is on the Wikipedia, I've writen Scilab function (see below for the code and visualization).
The essential part is where $a$ and $b$ for $y'=a x + b$ are calculated.
function _linreg()
    // Based on http://onlinestatbook.com/2/regression/intro.html

    // Sample data set
    X = 1:100   // 1, 2, ..., 100
    // Y is a 45 degree line with noise (see the visualization)
    Y = X + rand(X) .* 50
    // Raw plot, the source data
    plot(X, Y, '+')

    function [r] = scc(X, Y)
        // Sample correlation coefficient
        // http://en.wikipedia.org/wiki/Correlation_and_dependence

        X1 = X - mean(X)
        Y1 = Y - mean(Y)

        r = sum(X1 .* Y1) / sqrt(sum(X1.^2) * sum(Y1.^2))
    endfunction

    a = scc(Y, X) * stdev(Y) / stdev(X)
    b = mean(Y) - a * mean(X)

    // Regression plot
    plot(X, a .* X + b, 'r')
endfunction


