Generalized Linear Models class
GLM inherits from statsmodels.base.model.LikelihoodModel
Parameters: | endog : array-like
exog : array-like
family : family class instance
offset : array-like or None
exposure : array-like or None
freq_weights : array-like
missing : str
|
---|
Notes
Only the following combinations make sense for family and link
+ ident log logit probit cloglog pow opow nbinom loglog logc
Gaussian | x x x
inv Gaussian | x x x
binomial | x x x x x x x x x
Poission | x x x
neg binomial | x x x x
gamma | x x x
Not all of these link functions are currently available.
Endog and exog are references so that if the data they refer to are already arrays and these arrays are changed, endog and exog will change.
Using frequency weights: Frequency weights produce the same results as repeating observations by the frequencies (if those are integers). This is verified for all basic results with nonrobust or heteroscedasticity robust cov_type. Other robust covariance types have not yet been verified, and at least the small sample correction is currently not based on the correct total frequency count. It has not yet been decided whether all the different types of residuals will be based on weighted residuals. Currently, residuals are not weighted.
Attributes
Examples
>>> import statsmodels.api as sm
>>> data = sm.datasets.scotland.load()
>>> data.exog = sm.add_constant(data.exog)
Instantiate a gamma family model with the default link function.
>>> gamma_model = sm.GLM(data.endog, data.exog,
... family=sm.families.Gamma())
>>> gamma_results = gamma_model.fit()
>>> gamma_results.params
array([-0.01776527, 0.00004962, 0.00203442, -0.00007181, 0.00011185,
-0.00000015, -0.00051868, -0.00000243])
>>> gamma_results.scale
0.0035842831734919055
>>> gamma_results.deviance
0.087388516416999198
>>> gamma_results.pearson_chi2
0.086022796163805704
>>> gamma_results.llf
-83.017202161073527
Attributes
df_model | float | p - 1, where p is the number of regressors including the intercept. |
df_resid | float | The number of observation n minus the number of regressors p. |
endog | array | See Parameters. |
exog | array | See Parameters. |
family | family class instance | A pointer to the distribution family of the model. |
freq_weights | array | See Parameters. |
mu | array | The estimated mean response of the transformed variable. |
n_trials | array | See Parameters. |
normalized_cov_params | array | p x p normalized covariance of the design / exogenous data. |
pinv_wexog | array | For GLM this is just the pseudo inverse of the original design. |
scale | float | The estimate of the scale / dispersion. Available after fit is called. |
scaletype | str | The scaling used for fitting the model. Available after fit is called. |
weights | array | The value of the weights after the last iteration of fit. |
Methods
estimate_scale(mu) | Estimates the dispersion/scale. |
estimate_tweedie_power(mu[, method, low, high]) | Tweedie specific function to estimate scale and the variance parameter. |
fit([start_params, maxiter, method, tol, ...]) | Fits a generalized linear model for a given family. |
fit_constrained(constraints[, start_params]) | fit the model subject to linear equality constraints |
fit_regularized([method, alpha, ...]) | Return a regularized fit to a linear regression model. |
from_formula(formula, data[, subset, drop_cols]) | Create a Model from a formula and dataframe. |
get_distribution(params[, scale, exog, ...]) | Returns a random number generator for the predictive distribution. |
hessian(params[, scale, observed]) | Hessian, second derivative of loglikelihood function |
hessian_factor(params[, scale, observed]) | Weights for calculating Hessian |
information(params[, scale]) | Fisher information matrix. |
initialize() | Initialize a generalized linear model. |
loglike(params[, scale]) | Evaluate the log-likelihood for a generalized linear model. |
loglike_mu(mu[, scale]) | Evaluate the log-likelihood for a generalized linear model. |
predict(params[, exog, exposure, offset, linear]) | Return predicted values for a design matrix |
score(params[, scale]) | score, first derivative of the loglikelihood function |
score_factor(params[, scale]) | weights for score for each observation |
score_obs(params[, scale]) | score first derivative of the loglikelihood for each observation. |
score_test(params_constrained[, ...]) | score test for restrictions or for omitted variables |
Methods
estimate_scale(mu) | Estimates the dispersion/scale. |
estimate_tweedie_power(mu[, method, low, high]) | Tweedie specific function to estimate scale and the variance parameter. |
fit([start_params, maxiter, method, tol, ...]) | Fits a generalized linear model for a given family. |
fit_constrained(constraints[, start_params]) | fit the model subject to linear equality constraints |
fit_regularized([method, alpha, ...]) | Return a regularized fit to a linear regression model. |
from_formula(formula, data[, subset, drop_cols]) | Create a Model from a formula and dataframe. |
get_distribution(params[, scale, exog, ...]) | Returns a random number generator for the predictive distribution. |
hessian(params[, scale, observed]) | Hessian, second derivative of loglikelihood function |
hessian_factor(params[, scale, observed]) | Weights for calculating Hessian |
information(params[, scale]) | Fisher information matrix. |
initialize() | Initialize a generalized linear model. |
loglike(params[, scale]) | Evaluate the log-likelihood for a generalized linear model. |
loglike_mu(mu[, scale]) | Evaluate the log-likelihood for a generalized linear model. |
predict(params[, exog, exposure, offset, linear]) | Return predicted values for a design matrix |
score(params[, scale]) | score, first derivative of the loglikelihood function |
score_factor(params[, scale]) | weights for score for each observation |
score_obs(params[, scale]) | score first derivative of the loglikelihood for each observation. |
score_test(params_constrained[, ...]) | score test for restrictions or for omitted variables |
Attributes
endog_names | Names of endogenous variables |
exog_names | Names of exogenous variables |