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!
data catch;
input gender $ age count @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
datalines;
F 54 18 M 37 0 F 48 12 M 27 0
M 55 0 M 32 0 F 49 12 F 45 11
M 39 0 F 34 1 F 50 0 M 52 4
M 33 0 M 32 0 F 23 1 F 17 0
F 44 5 M 44 0 F 26 0 F 30 0
F 38 0 F 38 0 F 52 18 M 23 1
F 23 0 M 32 0 F 33 3 M 26 0
F 46 8 M 45 5 M 51 10 F 48 5
F 31 2 F 25 1 M 22 0 M 41 0
M 19 0 M 23 0 M 31 1 M 17 0
F 21 0 F 44 7 M 28 0 M 47 3
M 23 0 F 29 3 F 24 0 M 34 1
F 19 0 F 35 2 M 39 0 M 43 6
;
1
DATA catch;
2
INPUT gender $ age count @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3
DATALINES;
4
F 5418 M 37 0 F 4812 M 27 0
5
M 55 0 M 32 0 F 4912 F 4511
6
M 39 0 F 341 F 50 0 M 524
7
M 33 0 M 32 0 F 231 F 17 0
8
F 445 M 44 0 F 26 0 F 30 0
9
F 38 0 F 38 0 F 5218 M 231
10
F 23 0 M 32 0 F 333 M 26 0
11
F 468 M 455 M 5110 F 485
12
F 312 F 251 M 22 0 M 41 0
13
M 19 0 M 23 0 M 311 M 17 0
14
F 21 0 F 447 M 28 0 M 473
15
M 23 0 F 293 F 24 0 M 341
16
F 19 0 F 352 M 39 0 M 436
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!
proc hpfmm data=catch;
class gender;
model count = gender*age / dist=Poisson;
run;
1
PROC HPFMMDATA=catch;
2
class gender;
3
model count = gender*age / dist=Poisson;
4
RUN;
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!
proc hpfmm data=catch;
class gender;
model count = gender*age / dist=Poisson ;
model + / dist=Constant;
run;
1
PROC HPFMMDATA=catch;
2
class gender;
3
model count = gender*age / dist=Poisson ;
4
model + / dist=Constant;
5
RUN;
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!
proc hpfmm data=catch seed=12345;
class gender;
model count = gender*age / dist=Poisson;
model + / dist=constant;
performance nthreads=2;
bayes;
run;
1
PROC HPFMMDATA=catch seed=12345;
2
class gender;
3
model count = gender*age / dist=Poisson;
4
model + / dist=constant;
5
performance nthreads=2;
6
bayes;
7
RUN;
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!
ods graphics on;
ods select TADPanel;
proc hpfmm data=catch seed=12345;
class gender;
model count = gender*age / dist=Poisson;
model + / dist=constant;
performance nthreads=2;
bayes;
run;
ods graphics off;
1
ods graphics on;
2
ods select TADPanel;
3
PROC HPFMMDATA=catch seed=12345;
4
class gender;
5
model count = gender*age / dist=Poisson;
6
model + / dist=constant;
7
performance nthreads=2;
8
bayes;
9
RUN;
10
ods 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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.