estimation.fepois_.Fepois
estimation.fepois_.Fepois(self,
FixestFormula,
data,
ssc_dict,
drop_singletons,
drop_intercept,
weights,
weights_type,
collin_tol,
fixef_tol,
lookup_demeaned_data,
tol,
maxiter,='np.linalg.solve',
solver=True,
store_data=True,
copy_data=False,
lean=None,
sample_split_var=None,
sample_split_value=None,
separation_check )
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 | The demeaned dependent variable, a two-dimensional numpy array. |
_X | np.ndarray | The demeaned 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. |
_data | pd.DataFrame | The data frame used in the estimation. None if arguments lean = True or store_data = False . |
Methods
Name | Description |
---|---|
get_fit | Fit a Poisson Regression Model via Iterated Weighted Least Squares (IWLS). |
predict | Return predicted values from regression model. |
prepare_model_matrix | Prepare model inputs for estimation. |
resid | Return residuals from regression model. |
to_array | Turn estimation DataFrames to np arrays. |
get_fit
estimation.fepois_.Fepois.get_fit()
Fit a Poisson Regression Model via Iterated Weighted Least Squares (IWLS).
Returns
Name | 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_.Fepois.predict(=None,
newdata=1e-06,
atol=1e-06,
btoltype='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 |
atol | Float | Stopping tolerance for scipy.sparse.linalg.lsqr(). See https://docs.scipy.org/doc/ scipy/reference/generated/scipy.sparse.linalg.lsqr.html | 1e-6 |
btol | Float | Another stopping tolerance for scipy.sparse.linalg.lsqr(). See https://docs.scipy.org/doc/ scipy/reference/generated/scipy.sparse.linalg.lsqr.html | 1e-6 |
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' |
atol | Float | Stopping tolerance for scipy.sparse.linalg.lsqr(). See https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html | 1e-6 |
btol | Float | Another stopping tolerance for scipy.sparse.linalg.lsqr(). See https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html | 1e-6 |
Returns
Name | Type | Description |
---|---|---|
np.ndarray | A flat array with the predicted values of the regression model. |
prepare_model_matrix
estimation.fepois_.Fepois.prepare_model_matrix()
Prepare model inputs for estimation.
resid
type='response') estimation.fepois_.Fepois.resid(
Return residuals from regression model.
Parameters
Name | Type | Description | Default |
---|---|---|---|
type | str | The type of residuals to be computed. Can be either “response” (default) or “working”. | 'response' |
Returns
Name | Type | Description |
---|---|---|
np.ndarray | A flat array with the residuals of the regression model. |
to_array
estimation.fepois_.Fepois.to_array()
Turn estimation DataFrames to np arrays.