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!
data Display;\n input Active $ Passive $ wt @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;\n if Active ne 't';\n if Active eq Passive then wt=.;\n datalines;\nr r 0 r s 1 r t 5 r u 8 r v 9 r w 0\ns r 29 s s 0 s t 14 s u 46 s v 4 s w 0\nt r 0 t s 0 t t 0 t u 0 t v 0 t w 0\nu r 2 u s 3 u t 1 u u 0 u v 38 u w 2\nv r 0 v s 0 v t 0 v u 0 v v 0 v w 1\nw r 9 w s 25 w t 4 w u 6 w v 13 w w 0\n;
1
DATA 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;
6
r r 0 r s 1 r t 5 r u 8 r v 9 r w 0
7
s r 29 s s 0 s t 14 s u 46 s v 4 s w 0
8
t r 0 t s 0 t t 0 t u 0 t v 0 t w 0
9
u r 2 u s 3 u t 1 u u 0 u v 38 u w 2
10
v r 0 v s 0 v t 0 v u 0 v v 0 v w 1
11
w 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!
proc catmod data=Display;\n weight wt;\n model Active*Passive=_response_ /\n missing=structural zero=sampling\n freq pred=freq noparm oneway;\n loglin Active Passive;\n contrast 'Passive, U vs. V' Passive 0 0 0 1 -1;\n contrast 'Active, U vs. V' Active 0 0 1 -1;\n title2 'Test Quasi-Independence for the Incomplete Table';\nquit;
1
PROC CATMODDATA=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';
10
QUIT;
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.