Utility functions for psy-reg

Classes:

GenericModel(*params, **attrs)

An abstract model for least-squares regression

Functions:

rsquared(sim, obs)

Calculate the R-squared (coefficient of determination, $R^2$)

class psy_reg.utils.GenericModel(*params, **attrs)

Bases: object

An abstract model for least-squares regression

This abstract base class implements a fit and predict and can be subclassed to provide a model for a function that is fitted with the scipy.optimize.curve_fit() function.

Methods:

estimate_p0(x, y, bounds)

fit(x, y, *args, **kwargs)

func_args()

The arguments for the fit function if the method is 'curve_fit'

function(x, *params, **kwargs)

The function that is responsible for the fit

predict(x)

Attributes:

func_kwargs

The arguments for the fit function if the method is 'curve_fit'

pcov

The covariance matrix

rsquared

The coefficient of determination, $R^2$

classmethod estimate_p0(x, y, bounds)
classmethod fit(x, y, *args, **kwargs)
classmethod func_args()

The arguments for the fit function if the method is ‘curve_fit’

property func_kwargs

The arguments for the fit function if the method is ‘curve_fit’

abstract static function(x, *params, **kwargs)

The function that is responsible for the fit

property pcov

The covariance matrix

predict(x)
property rsquared

The coefficient of determination, $R^2$

psy_reg.utils.rsquared(sim, obs)

Calculate the R-squared (coefficient of determination, $R^2$)

$R^2$ is defined as

\[R^2 = 1 - \frac{\sum\,(obs - sim)^2}{\sum(obs - \widebar{obs})^2}\]
Parameters:
  • sim (np.ndarray) – Simulated values

  • obs (np.ndarray) – Observed values (broadcastable to sim)

Returns:

The R squared

Return type:

float