SDM: Moved the linear regression and calculation of the eigenvalue threshold to a separate function