def computeRegr(aggregate, n):
    """
    Compute the error (mse), the slope and the offset of the linear regression from the terms passed in 'aggregate'
    for a signal slice of length 'n' by using the closed form (i.e. the nromal equation) of the linear regression.

    Parameters
    ----------
    aggregate: 5-tuple of floats
       A tuple of 5 floats containing the terms necessary to compute the regression result in the closed form (normal
       equation): Sx = Sum_i(x[i]), Sy = Sum_i(y[i]), Sxy = Sum_i(x[i]*y[i]), Sxx = Sum_i(x[i]^2), Syy = Sum_i(y[i]^2)
       where x and y are the independent and dependent variables, respectively.
    n: integer
       The number of data points used to compute the terms in the tuple 'aggregate'

    Return
    ------
    A 3-tuple containing the mean squared error (mse), the slope and the offset of the linear regression.

    NOTE
    ----
    See https://en.wikipedia.org/wiki/Simple_linear_regression#Numerical_example
    """
    (Sx, Sy, Sxy, Sxx, Syy) = aggregate
    den = n * Sxx - Sx ** 2

    slope = (n * Sxy - Sx * Sy) / den
    offset = (Sxx * Sy - Sx * Sxy) / den
    err = (1. / n) * (
            Syy - 2 * slope * Sxy - 2 * offset * Sy + (slope ** 2) * Sxx + 2 * slope * offset * Sx) + offset ** 2

    return (err, slope, offset)