ctdcal.fit_ctd.multivariate_fit

ctdcal.fit_ctd.multivariate_fit(y, *args, coef_names=None, const_name='c0')[source]

Least-squares fit data using multiple dependent variables. Dependent variables must be provided in tuple pairs of (data, order) as positional arguments.

If coef_names are defined, coefficients will be returned as a dict. Otherwise, coefficients are return as an array in the order of the dependent variables, sorted by decreasing powers.

Parameters
  • y (array-like) – Indepedent variable to be fit

  • args (tuple) – Pairs of dependent variable data and fit order (i.e., (data, order))

  • coef_names (list-like, optional) – Base names for coefficients (i.e., “a” for 2nd order yields [“a2”, “a1”])

  • const_name (str, optional) – Name for constant offset term

Returns

coefs – Least-squares fit coefficients in decreasing powers

Return type

array-like

Examples

Behavior when coef_names is None:

>>> z = [1, 4, 9]
>>> x = [1, 3, 5]
>>> y = [1, 2, 3]
>>> multivariate_fit(z, (x, 2), (y, 1))
array([0.25, 0.375, 0.25, 0.125])  # [c1, c2, c3, c4]

where z = (c1 * x ** 2) + (c2 * x) + (c3 * y) + c4

Behavior when coef_names is given:

>>> z = [1, 4, 9]
>>> x = [1, 3, 5]
>>> y = [1, 2, 3]
>>> multivariate_fit(z, (x, 2), (y, 1), coef_names=["a", "b"])
{"a2": 0.25, "a1": 0.375, "b1": 0.25, "c0": 0.125}

where z = (a2 * x ** 2) + (a1 * x) + (b1 * y) + c0