Published on :
Statistical CREATION_INTERNE

Zero-Inflated Poisson Regression with PROC HPFMM

This code is also available in: Deutsch Español Français
Awaiting validation
This script demonstrates several facets of PROC HPFMM. It begins by creating a 'catch' data table containing demographic variables and a 'count' variable. Then, it progressively applies more complex models: a basic Poisson model, a 'zero-inflated' Poisson mixture model to account for an excess of zeros, and finally a Bayesian analysis of this last model. The script also shows how to optimize execution (nthreads) and generate specific graphs (ODS Graphics).
Data Analysis

Type : CREATION_INTERNE


The data is entirely generated and contained within the script via a DATA step with a DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'catch' table from internal data. The 'input' statement reads the 'gender', 'age', and 'count' variables. The double 'at' ( @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json) instructs SAS to read multiple observations from the same data line.
Copied!
1DATA catch;
2 INPUT gender $ age count @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3 DATALINES;
4 F 54 18 M 37 0 F 48 12 M 27 0
5 M 55 0 M 32 0 F 49 12 F 45 11
6 M 39 0 F 34 1 F 50 0 M 52 4
7 M 33 0 M 32 0 F 23 1 F 17 0
8 F 44 5 M 44 0 F 26 0 F 30 0
9 F 38 0 F 38 0 F 52 18 M 23 1
10 F 23 0 M 32 0 F 33 3 M 26 0
11 F 46 8 M 45 5 M 51 10 F 48 5
12 F 31 2 F 25 1 M 22 0 M 41 0
13 M 19 0 M 23 0 M 31 1 M 17 0
14 F 21 0 F 44 7 M 28 0 M 47 3
15 M 23 0 F 29 3 F 24 0 M 34 1
16 F 19 0 F 35 2 M 39 0 M 43 6
17;
2 Code Block
PROC HPFMM
Explanation :
This block executes a first simple Poisson regression model. The 'count' variable is modeled as a function of the interaction between 'gender' and 'age'.
Copied!
1PROC HPFMM DATA=catch;
2 class gender;
3 model count = gender*age / dist=Poisson;
4RUN;
3 Code Block
PROC HPFMM
Explanation :
This block fits a two-component mixture model, known as a 'zero-inflated' (ZI) Poisson model. The first MODEL statement specifies the Poisson component, and the second MODEL with 'dist=Constant' adds a component that models the excess of zeros.
Copied!
1PROC HPFMM DATA=catch;
2 class gender;
3 model count = gender*age / dist=Poisson ;
4 model + / dist=Constant;
5RUN;
4 Code Block
PROC HPFMM
Explanation :
This block performs a Bayesian analysis of the 'zero-inflated' Poisson model. The 'BAYES' statement requests Bayesian inference for the model parameters. 'PERFORMANCE NTHREADS=2' is used to accelerate the computation by using two threads.
Copied!
1PROC HPFMM DATA=catch seed=12345;
2 class gender;
3 model count = gender*age / dist=Poisson;
4 model + / dist=constant;
5 performance nthreads=2;
6 bayes;
7RUN;
5 Code Block
PROC HPFMM
Explanation :
This last block re-executes the Bayesian analysis, but by activating graph generation via 'ODS GRAPHICS ON'. 'ODS SELECT TADPanel' filters the output to display only the Bayesian diagnostic graphics panel (Trace, Autocorrelation, Density).
Copied!
1ods graphics on;
2ods select TADPanel;
3PROC HPFMM DATA=catch seed=12345;
4 class gender;
5 model count = gender*age / dist=Poisson;
6 model + / dist=constant;
7 performance nthreads=2;
8 bayes;
9RUN;
10ods graphics off;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y