SAS Macro Programs for Statistical Graphics: TWOWAY

$Version: 1.8 (17 Nov 2003)
Michael Friendly
York University



TWOWAY macro ( [download] get twoway.sas)

The TWOWAY macro carries out analysis of two-way experimental design data with one observation per cell, including Tukey's 1 degree of freedom test for non-additivity as described in "Section 7.6". Two plots may be produced: a graphical display of the fit and residuals for the additive model, and a diagnostic plot for removable non-additivity.

The original version of this macro required that the columns of the data table be stored as a set of variables in the input dataset. In this arrangment (table format), use the VAR= argument to specify this list of variables and the ID= variable to specify an additional variable whose values are labels for the rows. In this case, the RESPONSE= option is simply a character label for the response variable in the two-way plot.

Assume a dataset of reaction times to 4 topics in 3 experimental tasks, in a SAS dataset like this:

     TASK   TOPIC1   TOPIC2   TOPIC3   TOPIC4
	  Easy     2.43     3.12     3.68     4.04
	  Medium   3.41     3.91     4.07     5.10
	  Hard     4.21     4.65     5.87     5.69
For this arrangment, the macro would be invoked as follows:
	     
   %twoway(var=topic1 topic2 topic3 topic4, id=task, 
           response=Reaction Time);
Note that the VAR= list cannot be abbreviated to TOPIC1-TOPIC4 here.

The present verion also allows the dataset to contain all response values in a single variable, with two additional variables to specify the row and column class variables, as is done with PROC GLM and PROC PLOT (plot format). In this case, DO NOT specify an ID= variable, use the VAR= argument to specify the two row and column class variables, and specify the name of response variable as RESPONSE=. The same data in this format would have 12 observations, and look like:

	     
 		TASK  TOPIC    RT
		Easy    1     2.43
		Easy    2     3.12
		Easy    3     3.68
		...
		Hard    4     5.69
For this arrangment, the macro would be invoked as follows:
	     
   %twoway(var=topic task, response=RT);
In this arrangement, the order of the VAR= variables does not matter. The columns of the two-way table are determined by the variable which varies most rapidly in the input dataset (topic, in the example).

Parameters

DATA=_LAST_
Name of the data set to be analyzed. One factor in the design is specified by the list of variables in the VAR= parameter. The other factor is defined by the observations in the data set.
VAR=
Table format: specify the list of variables (columns of the table) to identify the levels of the first factor.
Plot format: specify the names of the two class variables for the rows and columns of the table.
ID=
Table format: Row identifier, a character variable to identify the levels of the second factor.
Plot format: Do not specify an ID= variable.
RESPONSE=Response
Table format: specify a label for the response variable on the vertical axis of the two-way FIT plot.
Plot format: specify the name of the response variable in the input dataset.
PLOT=FIT DIAGNOSE
Specifies the plots to be done. The PLOT parameter can contain one or more of the keywords FIT, DIAGNOSE and PRINT. FIT requests a high-resolution plot of fitted values and residuals for the additive model. DIAGNOSE requests a high-resolution diagnostic plot for removable non-additivity. PRINT produces both of these plots in printed form.
HTEXT=
Height for text labels in the high-resolution FIT plot.
NAME=
The name assigned to the graphs in the graphic catalog.
GOUT=
Specifies the name of the graphics catalog used to save the output for later replay. The default is WORK.GSEG, which is erased at the end of your session. To save graphs in a permanent catalog, use a two-part name.

GOPTIONS

You should adjust the HSIZE= and VSIZE= values on the GOPTIONS statement to equate the data units in the horizontal and vertical axes of the FIT plot so that the corners are square.