statsmodels.genmod.generalized_linear_model.GLM.fit

GLM.fit(start_params=None, maxiter=100, method='IRLS', tol=1e-08, scale=None, cov_type='nonrobust', cov_kwds=None, use_t=None, full_output=True, disp=False, max_start_irls=3, **kwargs)[source]

Fits a generalized linear model for a given family.

Parameters:
start_paramsarray_like, optional

Initial guess of the solution for the loglikelihood maximization. The default is family-specific and is given by the family.starting_mu(endog). If start_params is given then the initial mean will be calculated as np.dot(exog, start_params).

maxiterint, optional

Default is 100.

methodstr

Default is ‘IRLS’ for iteratively reweighted least squares. Otherwise gradient optimization is used.

tolfloat

Convergence tolerance. Default is 1e-8.

scalestr or float, optional

scale can be ‘X2’, ‘dev’, or a float The default value is None, which uses X2 for Gamma, Gaussian, and Inverse Gaussian. X2 is Pearson’s chi-square divided by df_resid. The default is 1 for the Binomial and Poisson families. dev is the deviance divided by df_resid

cov_typestr

The type of parameter estimate covariance matrix to compute.

cov_kwdsdict-like

Extra arguments for calculating the covariance of the parameter estimates.

use_tbool

If True, the Student t-distribution is used for inference.

full_outputbool, optional

Set to True to have all available output in the Results object’s mle_retvals attribute. The output is dependent on the solver. See LikelihoodModelResults notes section for more information. Not used if methhod is IRLS.

dispbool, optional

Set to True to print convergence messages. Not used if method is IRLS.

max_start_irlsint

The number of IRLS iterations used to obtain starting values for gradient optimization. Only relevant if method is set to something other than ‘IRLS’.

atolfloat, optional

(available with IRLS fits) The absolute tolerance criterion that must be satisfied. Defaults to tol. Convergence is attained when: \(rtol * prior + atol > abs(current - prior)\)

rtolfloat, optional

(available with IRLS fits) The relative tolerance criterion that must be satisfied. Defaults to 0 which means rtol is not used. Convergence is attained when: \(rtol * prior + atol > abs(current - prior)\)

tol_criterionstr, optional

(available with IRLS fits) Defaults to 'deviance'. Can optionally be 'params'.

wls_methodstr, optional

(available with IRLS fits) options are ‘lstsq’, ‘pinv’ and ‘qr’ specifies which linear algebra function to use for the irls optimization. Default is lstsq which uses the same underlying svd based approach as ‘pinv’, but is faster during iterations. ‘lstsq’ and ‘pinv’ regularize the estimate in singular and near-singular cases by truncating small singular values based on rcond of the respective numpy.linalg function. ‘qr’ is only valid for cases that are not singular nor near-singular.

optim_hessian{‘eim’, ‘oim’}, optional

(available with scipy optimizer fits) When ‘oim’–the default–the observed Hessian is used in fitting. ‘eim’ is the expected Hessian. This may provide more stable fits, but adds assumption that the Hessian is correctly specified.

Notes

If method is ‘IRLS’, then an additional keyword ‘attach_wls’ is available. This is currently for internal use only and might change in future versions. If attach_wls’ is true, then the final WLS instance of the IRLS iteration is attached to the results instance as results_wls attribute.


Last update: Oct 03, 2024