countreg

countregFitModel

Description

The countregFitModel action analyzes regression models in which the dependent variable takes nonnegative integer or count values. These models are often used to represent the number of times an event occurs. This action supports various models including Poisson, Negative Binomial (NB1 and NB2), and their zero-inflated versions (ZIP, ZINB, ZICMP), as well as Conway-Maxwell-Poisson (CMP) models. It is suitable for both cross-sectional and panel data.

countreg.countregFitModel { bayes={...}, bounds={...}, class={...}, collection={...}, display={...}, dispmodel={...}, extendparmlength=TRUE | FALSE, freq="variable-name", groupid="variable-name", includeinternalnames=TRUE | FALSE, initialvalues={...}, model={...}, multimember={...}, optimizer={...}, output={...}, outputTables={...}, polynomial={...}, prior={...}, restrictions={...}, selection={...}, spline={...}, store={...}, table={...}, tests={...}, timingReport={...}, weight={...}, zeromodel={...} }
Settings
ParameterDescription
bayesSpecifies the options to use for Bayesian analysis.
boundsImposes simple boundary constraints on the parameter estimates.
classSpecifies the classification variables.
modelSpecifies the dependent variable and independent regressor variables for the regression model.
dispmodelSpecifies the dispersion-related regressors for Conway-Maxwell-Poisson models.
zeromodelSpecifies the zero-inflated regressors that determine the probability of a zero count.
tableSpecifies the input data table.
freqSpecifies the observation frequency variable.
weightSpecifies the observation weight variable.
groupidSpecifies an identification variable for panel data models.
offsetSpecifies the variable to use as an offset in the model.
selectionSpecifies the model selection method (e.g., FORWARD, BACKWARD, LASSO).
storeStores the estimated model to an item store for later use.
outputSpecifies an output data table to contain various statistics like predicted values and residuals.
Data Preparation View data prep sheet
Creating Sample Data for Count Regression

This SAS code generates a sample dataset named 'd_counts' in the 'mycas' caslib. The dataset contains a count variable 'NumInjur' representing the number of injuries, and several explanatory variables ('Sex', 'Age', 'x1', 'x2') that can be used to model the count outcome.

Copied!
1DATA mycas.d_counts;
2 call streaminit(12345);
3 DO i = 1 to 1000;
4 Sex = ifn(rand('UNIFORM') > 0.5, 'F', 'M');
5 Age = 20 + floor(rand('UNIFORM') * 40);
6 x1 = rand('UNIFORM');
7 x2 = rand('NORMAL');
8 lambda = exp(-1 + 0.5 * (Sex='M') + 0.02 * Age + 0.1 * x1 + 0.3 * x2);
9 NumInjur = rand('POISSON', lambda);
10 OUTPUT;
11 END;
12RUN;

Examples

This example performs a simple Poisson regression to model the number of injuries ('NumInjur') based on the predictors 'Sex', 'Age', and 'x1'.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 countreg.countregFitModel /
3 TABLE={name='d_counts'},
4 class={'Sex'},
5 model={
6 depVars={{name='NumInjur'}},
7 effects={{vars={'Sex', 'Age', 'x1'}}}
8 };
9RUN;
Result :
The action will produce several output tables, including 'ModelFitSummary', 'ParameterEstimates', and 'ConvergenceStatus'. The 'ParameterEstimates' table will show the estimated coefficients for the intercept, 'Sex', 'Age', and 'x1', along with their standard errors and p-values.

This example fits a Zero-Inflated Negative Binomial (ZINB) model. The count model for 'NumInjur' includes 'x1' and 'x2'. The zero-inflation model, which models the probability of excess zeros, includes the 'Sex' variable. This is useful when the data has more zeros than a standard Poisson or Negative Binomial model would predict.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 countreg.countregFitModel /
3 TABLE={name='d_counts'},
4 class={'Sex'},
5 model={
6 depVars={{name='NumInjur'}},
7 effects={{vars={'x1', 'x2'}}},
8 modeloptions={modeltype='ZINB'}
9 },
10 zeromodel={
11 effects={{vars={'Sex'}}}
12 },
13 OUTPUT={casout={name='out_zinb', replace=true}, pred='Predicted', probzero='P_Zero'};
14RUN;
Result :
The output will include parameter estimates for both the count model (for 'x1' and 'x2') and the zero-inflation model (for 'Sex'). It will also show the estimated dispersion parameter for the Negative Binomial distribution. An output table 'out_zinb' will be created containing the original data plus the predicted mean counts ('Predicted') and the probability of excess zeros ('P_Zero').

FAQ

What is the purpose of the countreg.countregFitModel action?
What types of count data models can be fitted with this action?
How do I handle datasets with an excess number of zero counts?
What model selection methods are available in the countregFitModel action?
Can this action perform Bayesian analysis?
How can I save the fitted model for future use, such as scoring?
How can I obtain predicted values or other statistics for each observation?