CTABLES - computations

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

CTABLES - computations

Robert L
It seems possible to add calculations in CTABLES. However, when I try to add the interquartile range to the quartiles, it doesn't work. Instead of the differences between Q3 and Q1 within groups I get the differences between Q3 and Q1 respectively *between* groups. Some simplified syntax:

DATA LIST LIST/group(F1) hrate(F3).
BEGIN DATA
1 69
1 72
1 75
1 77
2 61
2 66
2 61
2 68
2 77
END DATA.
DATASET NAME heart_rates.

* Custom Tables.
CTABLES /TABLE hrate [PTILE 25, PTILE 75] BY group.

* Custom Tables.
CTABLES
  /PCOMPUTE &iqr=EXPR([2]-[1])
  /PPROPERTIES &iqr LABEL ='IQR'
  /TABLE group BY hrate [PTILE 25, PTILE 75]
  /CATEGORIES VARIABLES=group [1,2,&iqr].

Am I missing something here?

Robert

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: CTABLES - computations

Jon Peck
The PCOMPUTE expression operates on the categories for each statistic, not the statistics for each category.

However, you can do this computation using STATS TABLE CALC (Utilities > Calculate with Pivot table).  Here is the syntax for this particular calculation between the columns of statistics.

STATS TABLE CALC SUBTYPE="customtable" PROCESS=PRECEDING 
/TARGET FORMULA="x[-'Percentile 75'] - x[-'Percentile 25']" 
    LOCATION=1  LABEL="Iqr" MODE=AFTER.

This operates on the immediately preceding table of type "customtable".  By default it works on columns.  The columns are numbered counting from 0, so LOCATION=1 MODE=AFTER means to insert the new column after the second column of the table.

The formula here is expressed in terms of the innermost column labels (Percentile 75 and Percentile 25).  The minus sign inside the brackets says to look to the left of the target column for these labels.  Alternatively, the input columns in the formula can be referred to numerically relative to the target column (before the insertion), in this case as FORMULA="x[0] - x[-1]".

You can see the full syntax for this command by placing the cursor on an instance in the Syntax Editor and pressing F1.

On Thu, Mar 22, 2018 at 6:18 AM, Robert Lundqvist <[hidden email]> wrote:
It seems possible to add calculations in CTABLES. However, when I try to add the interquartile range to the quartiles, it doesn't work. Instead of the differences between Q3 and Q1 within groups I get the differences between Q3 and Q1 respectively *between* groups. Some simplified syntax:

DATA LIST LIST/group(F1) hrate(F3).
BEGIN DATA
1 69
1 72
1 75
1 77
2 61
2 66
2 61
2 68
2 77
END DATA.
DATASET NAME heart_rates.

* Custom Tables.
CTABLES /TABLE hrate [PTILE 25, PTILE 75] BY group.

* Custom Tables.
CTABLES
  /PCOMPUTE &iqr=EXPR([2]-[1])
  /PPROPERTIES &iqr LABEL ='IQR'
  /TABLE group BY hrate [PTILE 25, PTILE 75]
  /CATEGORIES VARIABLES=group [1,2,&iqr].

Am I missing something here?

Robert

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD