PoissonRegression
Guide & worked example · Source
PoissonRegression(optimizer=None, maxiter=5000, tol=0.0001, device=None)Poisson Regression for count data with MLE estimation.
Estimates the relationship between count outcomes and covariates using the log link function. Assumes the conditional mean equals the conditional variance: E[y|X] = Var[y|X] = exp(X’β).
Examples: >>> model = PoissonRegression(maxiter=1000, tol=1e-6) >>> X = torch.randn(500, 4) >>> true_beta = torch.tensor([1.0, -0.5, 0.8, 0.3]) >>> y = torch.poisson(torch.exp(X @ true_beta)) >>> model.fit(X, y) >>> model.summary()
Attributes
| Name | Description |
|---|---|
device |
|
history |
|
maxiter |
|
optimizer_class |
|
params |
|
tol |
Methods
| Name | Description |
|---|---|
| fit | Fit the model using maximum likelihood estimation. |
| predict | Predict expected counts E[y|X] = exp(X’β). |
| summary | Print a formatted summary of model estimation results. |
| to | Move model parameters and fitted data to device. |
fit
PoissonRegression.fit(
X,
y,
init_params=None,
verbose=False,
fe=None,
fe_design=None,
hdfe_index=None,
offset=None,
batch_size=None,
stderr=True,
)Fit the model using maximum likelihood estimation.
Optimizes the model parameters to minimize the negative log-likelihood using the specified PyTorch optimizer. After convergence, computes standard errors via the Fisher information matrix.
Args: X: Design matrix of shape (n_samples, n_features). Assumes X includes an intercept column if desired. y: Target vector of shape (n_samples,). init_params: Initial parameter values. For FE-aware GLMs, may be a packed parameter vector or a dict with coef and fe_coef. verbose: If True, prints convergence information. fe: Optional list of 1D fixed-effect ID vectors. fe_design: Optional list of sparse fixed-effect incidence matrices. hdfe_index: Optional index of the FE block to use for fast inference. offset: Optional offset vector added to the linear predictor. batch_size: Optional mini-batch size for first-order optimizers. stderr: Whether to compute standard errors.
Returns: Self (fitted estimator) with populated params dictionary.
Examples: >>> model = LogisticRegression() >>> model.fit(X_train, y_train, verbose=True) >>> print(model.params[“coef”])
predict
PoissonRegression.predict(X, fe=None, fe_design=None, offset=None)Predict expected counts E[y|X] = exp(X’β).
Args: X: Design matrix of shape (n_samples, n_features). fe: Optional FE inputs for FE-aware models. fe_design: Optional sparse FE design inputs for FE-aware models. offset: Optional offset vector for FE-aware models.
Returns: Predicted expected counts of shape (n_samples,).
summary
PoissonRegression.summary(alpha=0.05)Print a formatted summary of model estimation results.
Displays a comprehensive table including parameter estimates, standard errors, t-statistics, p-values, and confidence intervals (if standard errors are available).
Args: alpha: Significance level for confidence intervals (default: 0.05 for 95% confidence intervals).
Examples: >>> model.fit(X, y) >>> model.summary(alpha=0.01) # 99% confidence intervals
to
PoissonRegression.to(device)Move model parameters and fitted data to device.