estimation.Fepois
estimation.Fepois(self, Y, X, fe, weights, coefnames, drop_singletons, collin_tol, maxiter=25, tol=1e-08, fixef_tol=1e-08, solver='np.linalg.solve', weights_name=None, weights_type=None)
Estimate a Poisson regression model.
Non user-facing class to estimate a Poisson regression model via Iterated Weighted Least Squares (IWLS).
Inherits from the Feols class. Users should not directly instantiate this class, but rather use the fepois() function. Note that no demeaning is performed in this class: demeaning is performed in the FixestMulti class (to allow for caching of demeaned variables for multiple estimation).
The method implements the algorithm from Stata’s ppmlhdfe
module.
Attributes
Name | Type | Description |
---|---|---|
Y | np.ndarray | Dependent variable, a two-dimensional numpy array. |
X | np.ndarray | Independent variables, a two-dimensional numpy array. |
fe | np.ndarray | Fixed effects, a two-dimensional numpy array or None. |
weights | np.ndarray | Weights, a one-dimensional numpy array or None. |
coefnames | list[str] | Names of the coefficients in the design matrix X. |
drop_singletons | bool | Whether to drop singleton fixed effects. |
collin_tol | float | Tolerance level for the detection of collinearity. |
maxiter | Optional[int], default=25 | Maximum number of iterations for the IRLS algorithm. |
tol | Optional[float], default=1e-08 | Tolerance level for the convergence of the IRLS algorithm. |
solver | (str, default is np.linalg.solve) | Solver to use for the estimation. Alternative is ‘np.linalg.lstsq’. |
fixef_tol | float, default = 1e-08. | Tolerance level for the convergence of the demeaning algorithm. |
solver | ||
weights_name | Optional[str] | Name of the weights variable. |
weights_type | Optional[str] | Type of weights variable. |
Methods
Name | Description |
---|---|
get_fit | Fit a Poisson Regression Model via Iterated Weighted Least Squares (IWLS). |
predict | Return predicted values from regression model. |
get_fit
estimation.Fepois.get_fit()
Fit a Poisson Regression Model via Iterated Weighted Least Squares (IWLS).
Returns
Type | Description |
---|---|
None |
Attributes
Name | Type | Description |
---|---|---|
beta_hat | np.ndarray | Estimated coefficients. |
Y_hat | np.ndarray | Estimated dependent variable. |
u_hat | np.ndarray | Estimated residuals. |
weights | np.ndarray | Weights (from the last iteration of the IRLS algorithm). |
X | np.ndarray | Demeaned independent variables (from the last iteration of the IRLS algorithm). |
Z | np.ndarray | Demeaned independent variables (from the last iteration of the IRLS algorithm). |
Y | np.ndarray | Demeaned dependent variable (from the last iteration of the IRLS algorithm). |
predict
estimation.Fepois.predict(newdata=None, type='link')
Return predicted values from regression model.
Return a flat np.array with predicted values of the regression model. If new fixed effect levels are introduced in newdata
, predicted values for such observations will be set to NaN.
Parameters
Name | Type | Description | Default |
---|---|---|---|
newdata |
Union[None, pd.DataFrame] | A pd.DataFrame with the new data, to be used for prediction. If None (default), uses the data used for fitting the model. | None |
type |
str | The type of prediction to be computed. Can be either “response” (default) or “link”. If type=“response”, the output is at the level of the response variable, i.e., it is the expected predictor E(Y|X). If “link”, the output is at the level of the explanatory variables, i.e., the linear predictor X @ beta. | 'link' |
Returns
Type | Description |
---|---|
np.ndarray | A flat array with the predicted values of the regression model. |