The SPSS Statistics catalog of table types has over 500 entries (and all Custom Tables count as just one), but sometimes the table you need is not available out of the box. This post is about a technique for combining portions of two tables to get the one you really wanted by using multiple procedures, OMS, and the STATS TABLE CALC extension command.

Suppose you have data such as the following consisting of five Likert scale measures and a category variable. (Realistically you would have many more cases).

You are interested in displaying a table of means for each group such as the following, but you would like to include the category significance level for each variable in that table.

Here is the table as it would be produced by CTABLES. It shows the mean score for each variable by category, but you need an ANOVA calculation to get the pvalues.

It's easy to use ONEWAY to calculate the ANOVA statistics. It produces this output.

What you want, though, is the numbers in the last column of that table added as a new column in the custom table. Enter STATS TABLE CALC. This extension command allows you to do calculations with the cells of a table in the Viewer as input and put the results in that table. If you have at least Statistics version 21 these can be in new rows or columns. In earlier versions of Statistics you can replace values in existing cells. TABLE CALC works like post computes in Custom Tables, but it can be used with almost any kind of table, and it has a much more powerful expression language.

Our problem here, though, is that we want the calculations to take values from the ANOVA table and add them to the Custom Table. TABLE CALC can do this by plugging in a small custom function. Here is how you could specify this using the dialog box for TABLE CALC, which is on the Utilities menu once this extension command is installed. I will explain the custom function below.

In the dialog I specified the table to modify by using its OMS subtype and other parameters. Specifying the target column as -1 means to insert it after the last column. The key here is the Formula field, which specifies that the values to be inserted are obtained by calling the function addsig in the module getsigs.py. The parameter "arg" being passed to that function will be automatically filled with information the function needs to do its job.

Before we run TABLE CALC, though, we need to capture the ANOVA table. We do that by using OMS, the Output Management System, to write that table into the XMLWORKSPACE. The sequence of commands is thus OMS, ONEWAY, OMSEND, CTABLES, and finally STATS TABLE CALC. Here is the OMS and ONEWAY code.

Now here is the magical Python function addsig I wrote and saved in the file getsigs.py.

The addsig function is called for each row in the table as the column is being added. arg is a dictionary with various useful variables in it. Details can be displayed by running STATS TABLE CALC /HELP. The code checks to see whether this is the first call for this table. If so, it retrieves the significance column of the anova table from the xmlworkspace where it was written by OMS. Note that it uses the xmlworkspace tag specified in the OMS command to find the table. That list of values is saved in arg so that it will be available each time addsig is called.

The function returns the saved significance value referring to the row (arg["roworcol"]) of the current call. That becomes the cell value for the new cell.

Here is what the table looks like after TABLE CALC completes. TABLE CALC has also set the format to show four decimals in the significance column.

This could be packaged in a custom dialog box with the variables and category variable as controls, but here is the full set of syntax used for this example.

STATS TABLE CALC is included in the current version of the Python Essentials, but it can be downloaded from the Extension Commands Collection on the SPSS Community site. The Python Essentials are either included with the Statistics installation or available through the same site.