FAQ/kw/means - CBU statistics Wiki
location: FAQ / kw / means

The SPSS syntax below computes the raw score means with given mean rank (as outputted by !kwpairs). This may be a more intuitive way of expressing the locations of each group. Run immediately after running !kwpairs as the macro assumes the data has been backed up in a file called input.sav which is created by running !kwpairs.

[COPY AND PASTE BELOW SYNTAX INTO A SPSS SYNTAX WINDOW; SELECT ALL AND RUN; EDIT LAST TWO LINES TO SUBSTITUTE OBSERVED MEAN RANKS]

* input a column of scores (y) and group
* run immediately after using !kwpairs macro
* using the outputted mean ranks as input in
* bottom line below; 
* BACKUP DATA BEFORE RUNNING THIS MACRO
*
* outputs in file called output.sav (located in
* My Documents folder) and in output window
* the raw data value in original data with
* corresponding mean rank obtained by
* interpolation

set errors=none.
set mprint=off.

DEFINE RMEAN (!POS !TOKENS(1)).

get file=input.sav.

COMPUTE MR=!1.

RANK
  VARIABLES=y  (A)   /RANK /PRINT=YES
  /TIES=MEAN .
exe.

SORT CASES BY RY(A).

IF (MR GT RY) LR=MIN(ABS(MR-RY)).
IF (MR LT RY) UR=MIN(ABS(MR-RY)).
EXE.

IF (LR GT 0) IND=1.
IF (UR GT 0) IND=2.
EXE.

aggregate outfile=* 
 /break=IND
 /LRY LY=MAX(RY Y)
 /URY UY=MIN(RY Y).

IF (IND EQ 1) LRYY=LRY.
IF (IND EQ 1) LYY=LY.
IF (IND EQ 2) URYY=URY.
IF (IND EQ 2) UYY=UY.
EXE.

COMPUTE dummy=1.
EXE.

aggregate outfile=* 
 /break=dummy
 /RY1 Y1 RY2 Y2=FIRST(LRYY LYY URYY UYY).

COMPUTE MR=!1.
COMPUTE RMN=Y1 + (Y2-Y1) * (MR-RY1) / (RY2-RY1).
EXE.

aggregate outfile=* 
 /break=dummy
 /LY=FIRST(RMN).

save outfile=output.sav /keep = LY.
exe.

GET FILE=OUTPUT.SAV.

compute mr=!1.

formats all (f11.8).
variable labels mr 'Mean Rank' /ly 'Raw mean' .

report format=list automatic align(center)
  /variables=mr ly
  /title "Raw score mean obtained by interpolation having given mean rank".
         
!ENDDEFINE.

* input a single group mean rank as outputted
* by !kwpairs macro: 
* macro outputs raw data value in original data
* with inputted corresponding mean rank

* substitute the two outputted mean ranks
* for 8.5 and 8.0714 given below

RMEAN 8.5.
RMEAN 8.0714.

None: FAQ/kw/means (last edited 2013-03-08 10:17:26 by localhost)