Module Expr Str Import alias identifier ImportFrom alias ImportFrom alias ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad NameLoad Str body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad If UnaryOpNot CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareLt AttributeLoad NameLoad attr Num body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr BinOpDiv Num NameLoad orelse Raise Call NameLoad Str orelse Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Return Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Pass decorator_list FunctionDef arguments args NameParam defaults body Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body If CompareIs NameLoad NameLoad body If CompareIs AttributeLoad NameLoad attr NameLoad body Return BinOpSub AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad orelse Assign NameStore AttributeLoad NameLoad attr Return BinOpMult NameLoad BinOpSub AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad BinOpPow Call AttributeLoad NameLoad attr NameLoad Num attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad NameLoad kwarg body If UnaryOpNot CompareIs NameLoad NameLoad body Assign NameStore NameLoad orelse Assign NameStore Call AttributeLoad NameLoad attr If UnaryOpNot CompareIs NameLoad NameLoad body Pass orelse If UnaryOpNot CompareIs NameLoad NameLoad body Assign NameStore BinOpMult Num Call AttributeLoad NameLoad attr NameLoad orelse Raise Call NameLoad BinOpAdd Str Str Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad keyword Num NameLoad Assign TupleStore NameStore NameStore NameStore NameStore NameStore NameLoad If CompareNotIn NameLoad ListLoad Num Num Num Num body Assign NameStore BinOpAdd Str NameLoad Raise Call NameLoad NameLoad Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore AttributeLoad NameLoad attr If BoolOpAnd CompareGt Call NameLoad NameLoad Call NameLoad NameLoad CompareIsNot NameLoad NameLoad body Assign NameStore BinOpDiv Call AttributeLoad BinOpPow NameLoad Num attr BinOpSub Call NameLoad NameLoad Call NameLoad NameLoad Assign NameStore BinOpMult NameLoad NameLoad orelse Assign NameStore NameLoad Assign AttributeStore NameLoad attr BinOpSub Call NameLoad NameLoad Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign NameStore Call NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr NameLoad ImportFrom alias Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore Call NameLoad NameLoad NameLoad keyword AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad keyword Num NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Num NameLoad NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore AttributeLoad NameLoad attr If CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr keyword Num keyword Num keyword TupleLoad NameLoad NameLoad orelse Assign NameStore Call NameLoad keyword TupleLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr ListComp SubscriptLoad AttributeLoad NameLoad attr Index TupleLoad Call AttributeLoad NameLoad attr NameLoad NameLoad comprehension NameStore NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str ImportFrom alias Assign NameStore Call NameLoad NameLoad AttributeLoad NameLoad attr Return NameLoad decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam defaults body Assign NameStore AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore NameStore NameLoad Return BinOpAdd BinOpMult NameLoad Call AttributeLoad NameLoad attr BinOpMult UnaryOpUSub NameLoad NameLoad NameLoad decorator_list decorator_list If CompareEq NameLoad Str body FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Return BinOpAdd BinOpMult NameLoad Call AttributeLoad NameLoad attr BinOpMult UnaryOpUSub NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign TupleStore NameStore NameStore NameStore NameLoad Return BinOpAdd BinOpMult NameLoad Call AttributeLoad NameLoad attr BinOpMult UnaryOpUSub NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Return BinOpSub NameLoad Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Return BinOpPow BinOpSub NameLoad Call NameLoad NameLoad NameLoad Num decorator_list Assign NameStore Call AttributeLoad NameLoad attr Num Num Num Assign NameStore Call AttributeLoad NameLoad attr ListLoad Num Num Num Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore BinOpAdd NameLoad BinOpMult Num Call AttributeLoad AttributeLoad NameLoad attr attr keyword Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad keyword TupleLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Print SubscriptLoad NameLoad Index Num Print NameLoad Print AttributeLoad NameLoad attr Print NameLoad Print AttributeLoad NameLoad attr
N/A N/A Non-linear least squares



Author: Josef Perktold based on scipy.optimize.curve_fit

 N/A numpy np scipy optimize statsmodels.base.model Model Results N/A object N/A N/A just a dummy placeholder for now
    most results from RegressionResults can be used here
     N/A N/A NonlinearLS N/A Model N/A N/A Base class for estimation of a non-linear model with least squares

    This class is supposed to be subclassed, and the subclass has to provide a method
    `_predict` that defines the non-linear function `f(params) that is predicting the endogenous
    variable. The model is assumed to be

    :math: y = f(params) + error

    and the estimator minimizes the sum of squares of the estimated error.

    :math: min_parmas \sum (y - f(params))**2

    f has to return the prediction for each observation. Exogenous or explanatory variables
    should be accessed as attributes of the class instance, and can be given as arguments
    when the instance is created.

    Warning:
    Weights are not correctly handled yet in the results statistics,
    but included when estimating the parameters.

    similar to scipy.optimize.curve_fit
    API difference: params are array_like not split up, need n_params information

    includes now weights similar to curve_fit
    no general sigma yet (OLS and WLS, but no GLS)

    This is currently holding on to intermediate results that are not necessary
    but useful for testing.

    Fit returns and instance of RegressionResult, in contrast to the linear
    model, results in this case are based on a local approximation, essentially
    y = f(X, params) is replaced by y = grad * params where grad is the Gradient
    or Jacobian with the shape (nobs, nparams). See for example Greene

    Examples
    --------

    class Myfunc(NonlinearLS):

        def _predict(self, params):
            x = self.exog
            a, b, c = params
            return a*np.exp(-b*x) + c

    Ff we have data (y, x), we can create an instance and fit it with

    mymod = Myfunc(y, x)
    myres = mymod.fit(nparams=3)

    and use the non-linear regression results, for example

    myres.params
    myres.bse
    myres.tvalues


     __init__ N/A N/A self endog exog weights sigma missing N/A None None None None none N/A N/A N/A self endog endog N/A N/A self exog exog N/A N/A N/A sigma None N/A N/A sigma N/A N/A np asarray sigma N/A N/A N/A sigma ndim 2 N/A N/A N/A self sigma sigma N/A N/A self weights N/A 1.0 sigma N/A N/A N/A ValueError correlated errors are not handled yet N/A N/A N/A self weights None N/A predict N/A N/A self exog params N/A None N/A N/A N/A N/A self _predict params N/A _predict N/A N/A self params N/A N/A N/A N/A start_value N/A N/A self N/A N/A N/A None N/A geterrors N/A N/A self params weights N/A None N/A N/A N/A weights None N/A N/A N/A N/A self weights None N/A N/A N/A N/A self endog N/A N/A self _predict params N/A N/A weights N/A self weights N/A N/A weights N/A N/A self endog N/A N/A self _predict params N/A errorsumsquares N/A N/A self params N/A N/A N/A N/A N/A N/A N/A N/A self geterrors params 2 sum N/A fit N/A N/A self start_value nparams N/A None None kw N/A N/A N/A N/A start_value None N/A N/A p0 start_value N/A N/A p0 N/A N/A self start_value N/A N/A N/A p0 None N/A N/A N/A N/A N/A N/A nparams None N/A N/A p0 N/A 0.1 N/A N/A np ones nparams N/A N/A N/A ValueError N/A need information about start values for optimization N/A func N/A self geterrors N/A res N/A N/A optimize leastsq func p0 full_output 1 kw N/A N/A popt pcov infodict errmsg ier res N/A N/A ier N/A 1 2 3 4 N/A N/A msg N/A Optimal parameters not found:  errmsg N/A N/A RuntimeError msg N/A err N/A infodict N/A fvec N/A ydata N/A self endog N/A N/A N/A N/A len ydata N/A len p0 N/A pcov None N/A N/A s_sq N/A N/A N/A N/A err 2 sum N/A N/A len ydata N/A len p0 N/A pcov N/A pcov s_sq N/A N/A pcov None N/A N/A self df_resid N/A N/A len ydata N/A len p0 N/A N/A self df_model N/A len p0 N/A fitres N/A Results N/A N/A fitres params popt N/A N/A fitres pcov pcov N/A N/A fitres rawres res N/A N/A self wendog N/A self endog N/A N/A self wexog N/A N/A self jac_predict popt N/A pinv_wexog N/A N/A N/A np linalg pinv N/A self wexog N/A N/A self normalized_cov_params N/A N/A np dot pinv_wexog N/A N/A np transpose pinv_wexog statsmodels.regression RegressionResults N/A results RegressionResults N/A beta popt N/A lfit N/A RegressionResults self beta normalized_cov_params N/A self normalized_cov_params N/A N/A lfit fitres fitres N/A N/A self _results lfit N/A lfit N/A fit_minimal N/A N/A self start_value N/A N/A N/A minimal fitting with no extra calculations N/A func N/A self geterrors N/A res N/A N/A optimize leastsq func start_value full_output 0 kw N/A res N/A fit_random N/A N/A self ntries rvs_generator nparams N/A 10 None None N/A N/A fit with random starting values

        this could be replaced with a global fitter

         N/A N/A nparams None N/A N/A nparams N/A self nparams N/A N/A rvs_generator None N/A N/A rvs N/A N/A N/A np random uniform low -10 high 10 size N/A ntries nparams N/A N/A rvs N/A rvs_generator size N/A ntries nparams N/A results N/A N/A np array N/A N/A N/A np r_ N/A N/A N/A N/A self fit_minimal rv rv N/A rv rvs N/A results N/A jac_predict N/A N/A self params N/A N/A N/A jacobian of prediction function using complex step derivative

        This assumes that the predict function does not use complex variable
        but is designed to do so.

         statsmodels.tools.numdiff approx_fprime_cs N/A jaccs_err N/A approx_fprime_cs params N/A self _predict N/A jaccs_err N/A N/A Myfunc N/A NonlinearLS N/A _predict N/A N/A self params N/A N/A N/A x N/A self exog N/A N/A a b c params N/A N/A N/A a N/A N/A np exp N/A N/A b x c N/A N/A N/A N/A __name__ __main__ N/A func0 N/A N/A x a b c N/A N/A N/A N/A N/A a N/A N/A np exp N/A N/A b x c N/A func N/A N/A params x N/A N/A N/A N/A a b c params N/A N/A N/A a N/A N/A np exp N/A N/A b x c N/A error N/A N/A params x y N/A N/A N/A N/A y N/A func params x N/A error2 N/A N/A params x y N/A N/A N/A N/A N/A y N/A func params x 2 N/A N/A x N/A N/A np linspace 0 4 50 N/A params N/A N/A np array N/A 2.5 1.3 0.5 N/A y0 N/A func params x N/A y N/A y0 N/A 0.2 N/A N/A N/A np random normal size N/A len x N/A res N/A N/A optimize leastsq error params args N/A x y full_output True N/A mod N/A Myfunc y x N/A resmy N/A N/A mod fit nparams 3 N/A N/A cf_params cf_pcov N/A N/A optimize curve_fit func0 x y N/A cf_bse N/A N/A np sqrt N/A N/A np diag cf_pcov N/A N/A res N/A 0 N/A cf_params N/A N/A resmy params N/A cf_bse N/A N/A resmy bse