linefit

linefit(x, y, /, axis=0)[source]

Get linear regression along axis, ignoring NaNs. Uses polyfit.

Parameters
  • x (array-like) – The x coordinates.

  • y (array-like) – The y coordinates.

  • axis (int, optional) – Regression axis

Returns

  • slope (array-like) – The slope estimates. The shape is the same as y but with dimension axis reduced to length 1.

  • stderr (array-like) – The standard errors of the slope estimates. The shape is the same as slope.

  • fit (array-like) – The reconstructed best-fit line. The shape is the same as y.

Examples

>>> import numpy as np
>>> import climopy as climo
>>> state = np.random.RandomState(51423)
>>> x = np.arange(500)
>>> y = state.rand(10, 500) + 0.1 * x
>>> slope, stderr, fit = climo.linefit(x, y, axis=1)
>>> slope
array([[0.10000399],
       [0.09997467],
       [0.09980544],
       [0.10004589],
       [0.10002195],
       [0.09996018],
       [0.10009204],
       [0.09992162],
       [0.10014288],
       [0.10011434]])