Published on :
Statistics CREATION_INTERNE

Example 5 for PROC CATMOD: Log-Linear Model

This code is also available in: Deutsch Español Français
Awaiting validation
This script analyzes the joint distribution of interactions (active role, passive role) within a population of 6 squirrel monkeys. Data comes from Fienberg (1980). The diagonal of the contingency table consists of structural zeros, as a monkey cannot interact with itself (have both active and passive roles simultaneously). The script uses PROC CATMOD to fit a quasi-independence model, which tests the independence of variables conditionally on the absence of structurally empty cells. Specific contrast tests are also performed to compare the behaviors of certain monkeys.
Data Analysis

Type : CREATION_INTERNE


The data is created directly in the script via a DATA step with a DATALINES statement. Interactions are read, and structural zeros are defined by setting the weight variable (wt) to a missing value when the 'active' and 'passive' monkeys are the same.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block reads the interaction data. The `input` statement with the double at sign (`@@`) allows reading multiple observations on the same data line. The condition `if Active eq Passive then wt=.;` is crucial as it identifies the diagonal cells of the table and assigns a missing value to the `wt` weight, thereby marking them as structural zeros for the subsequent analysis.
Copied!
1DATA Display;
2 INPUT Active $ Passive $ wt @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3 IF Active ne 't';
4 IF Active eq Passive THEN wt=.;
5 DATALINES;
6r r 0 r s 1 r t 5 r u 8 r v 9 r w 0
7s r 29 s s 0 s t 14 s u 46 s v 4 s w 0
8t r 0 t s 0 t t 0 t u 0 t v 0 t w 0
9u r 2 u s 3 u t 1 u u 0 u v 38 u w 2
10v r 0 v s 0 v t 0 v u 0 v v 0 v w 1
11w r 9 w s 25 w t 4 w u 6 w v 13 w w 0
12;
2 Code Block
PROC CATMOD
Explanation :
The CATMOD procedure is used for categorical data analysis. `weight wt;` specifies the frequency variable. The `model` statement defines the complete interaction model. The `missing=structural` option tells the procedure that missing values for `wt` correspond to structural zeros and should be excluded from the analysis, while `zero=sampling` treats other zeros as sampling zeros. `loglin Active Passive;` fits a log-linear model with only main effects, which corresponds to a quasi-independence test. Finally, the `contrast` statements allow performing specific hypothesis tests on the model parameters, here to compare monkeys 'u' and 'v'.
Copied!
1PROC CATMOD DATA=Display;
2 weight wt;
3 model Active*Passive=_response_ /
4 missing=structural zero=sampling
5 freq pred=freq noparm oneway;
6 loglin Active Passive;
7 contrast 'Passive, U vs. V' Passive 0 0 0 1 -1;
8 contrast 'Active, U vs. V' Active 0 0 1 -1;
9 title2 'Test Quasi-Independence for the Incomplete Table';
10QUIT;
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