added support for detrending with NaNs and to save coefficients of linear trend