Change in default behavior of np.polyfit

Hi, in [1] the scaling factor for the covariance matrix of `np.polyfit` was discussed. The conclusion was, that it is non-standard and a patch might be in order to correct this. Pull request [2] changes the factor from chisq(popt)/(M-N-2) to chisq(popt)/(M-N) (with M=number of point, N=number of parameters) essentially removing the "-2". Clearly, this changes the result for the covariance matrix (but not the result for the polynomial coefficients) and therefore the current behavior if `cov=True` is set. It should be noted, that `scipy.optimize.curve_fit` also uses the chisq(popt)/(M-N) as scaling factor (without "-2"). Therefore, the change would remove a discrepancy. Additionally, patch [2] adds an option that sets the scaling factor of the covariance matrix to 1 . This can be useful in occasions, where the weights are given by 1/sigma with sigma being the (known) standard errors of (Gaussian distributed) data points, in which case the un-scaled matrix is already a correct estimate for the covariance matrix. Best, Andreas [1] http://numpy-discussion.10968.n7.nabble.com/Inconsistent-results-for-the-cov... [2] https://github.com/numpy/numpy/pull/11197

Hi Andreas, Thanks for noticing and correcting this unexpected scaling! The addition to get the unscaled version is also very welcome. All the best, Marten

Hi Andreas, Thanks for noticing and correcting this unexpected scaling! The addition to get the unscaled version is also very welcome. All the best, Marten
participants (2)
-
Andreas Nußbaumer
-
Marten van Kerkwijk