Matrix question

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

Matrix question

Albert-Jan Roskam
Hi list,

I just started using the MATRIX command for the first
time and I have a question about this.

I want to subtract to matrices/files (say file X and
file Y) which have an identical layout (numbers of
rows and colunms are the same). All variables are of
the numerical type. Missing values are coded as
'99999999'. Of course, I don't want to calculate the
difference when either of the cells is a missing
value. The syntax below calculates the difference
matrix, but something goes wrong with the missing
values. Can anyone help me correct this syntax? Or
should I just rephrase this question and say "Martha,
could you help me with this MATRIX question"? ;-)

Thank you in advance for your replies!

Albert-Jan

dataset activate filex.
matrix.
get m_filex / missing = 99999999.
get m_filey / file = 'd:\temp\filey.sav' / missing =
   99999999.
loop n = 1 to nrow(m_filex).
loop i = 1 to ncol (m_filex).
loop m = 1 to nrow(m_filey).
loop j = 1 to ncol (m_filey).
do if (m_filex(n,i) <> 99999999 and m_filey(m,j) <>
 99999999).
compute d = m_filex - m_filey.
end if.
end loop.
end loop.
end loop.
end loop.
save d / outfile = 'd:\temp\difference_matrix.sav'.
print d.
end matrix.



Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



____________________________________________________________________________________
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front
Reply | Threaded
Open this post in threaded view
|

Re: Matrix question

bdates
Albert,

Try this.  I tested it with some of my own data, and it works.  Please let
me know if you have any difficulty.

dataset activate filex.
matrix.
get m_filex / missing = 99999999.
get m_filey / file = 'd:\temp\filey.sav' / missing =
   99999999.
compute d=make(nrow(m_filex),ncol(m_filex),0) .
loop n = 1 to nrow(m_filex).
loop i = 1 to ncol (m_filex).
loop m = 1 to nrow(m_filey).
loop j = 1 to ncol (m_filey).
do if (n=m and i=j and m_filex(n,i)<>99999999 and m_filey(m,j)<>99999999).
compute d(n,i)=m_filex(n,i)-m_filey(m,j) .
end if.
end loop.
end loop.
end loop.
end loop.
loop i=1 to nrow(d) .
loop j=1 to ncol(d) .
do if d(i,j)=0 .
compute d(i,j)=99999999 .
end if .
end loop .
end loop .
print d.
save d / outfile = 'd:\temp\difference_matrix.sav'.
end matrix.



Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Matrix question

bdates
In reply to this post by Albert-Jan Roskam
Albert,

I just noticed that my final matrix procedure produced some bad results.
I'll work on it a little longer.  Sorry.

Brian


Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Matrix question

Marta Garcia-Granero
In reply to this post by Albert-Jan Roskam
Hi Albert-jan,

Con fecha martes, 26 de junio de 2007, 15:14:37, escribió:

AjR> I just started using the MATRIX command for the first
AjR> time and I have a question about this.

Wellcome to the dark side, my "padawan" (did you see the Star Wars
trilogies?)

AjR> I want to subtract to matrices/files (say file X and
AjR> file Y) which have an identical layout (numbers of
AjR> rows and colunms are the same). All variables are of
AjR> the numerical type. Missing values are coded as
AjR> '99999999'. Of course, I don't want to calculate the
AjR> difference when either of the cells is a missing
AjR> value. The syntax below calculates the difference
AjR> matrix, but something goes wrong with the missing
AjR> values. Can anyone help me correct this syntax? Or
AjR> should I just rephrase this question and say "Martha,
AjR> could you help me with this MATRIX question"? ;-)

MATRIX.
* Sample data, replace by your own *.
COMPUTE  m_filex={1,2,3,99999999;
                  5,6,7,8;
                  9,10,11,99999999}.
COMPUTE m_filey={11,10,9,99999999;
                  7,6,5,4;
                  3,2,1,99999999}.
* Since m_filex and m_filey are conformant, you just need to know the number
  of rows and columns of one of them *.
COMPUTE k=NROW(m_filex).
COMPUTE m=NCOL(m_filex).
* Initialize empty difference matrix with missing values *.
COMPUTE d=MAKE(k,m,99999999).
* Now, elementwise inspection of every element to replace value in difference
  matrix only if no value is missing in m_filex/y *.
LOOP i = 1 TO k.
. LOOP j=1 TO m.
.  DO IF (m_filex(i,j) NE 99999999) AND (m_filey(i,j) NE  99999999).
* Compute a single element, not the whole matrix *.
.   COMPUTE d(i,j) = m_filex(i,j) - m_filey(i,j).
.  END IF.
. END LOOP.
END LOOP.
* save d / outfile = 'd:\temp\difference_matrix.sav'.
PRINT d.
END MATRIX.

Best regrads,
Marta
Reply | Threaded
Open this post in threaded view
|

Re: Matrix question

Albert-Jan Roskam
Hi Marta & Brian,

You taught me well, Jedi master ;-)

Thanks a lot! It's a fascinating, and very useful
command! I wouldn't have been able to come up with
your solution myself.

Best wishes,
Albert-Jan

--- Marta Garcia-Granero <[hidden email]>
wrote:

> Hi Albert-jan,
>
> Con fecha martes, 26 de junio de 2007, 15:14:37,
> escribió:
>
> AjR> I just started using the MATRIX command for the
> first
> AjR> time and I have a question about this.
>
> Wellcome to the dark side, my "padawan" (did you see
> the Star Wars
> trilogies?)
>
> AjR> I want to subtract to matrices/files (say file
> X and
> AjR> file Y) which have an identical layout (numbers
> of
> AjR> rows and colunms are the same). All variables
> are of
> AjR> the numerical type. Missing values are coded as
> AjR> '99999999'. Of course, I don't want to
> calculate the
> AjR> difference when either of the cells is a
> missing
> AjR> value. The syntax below calculates the
> difference
> AjR> matrix, but something goes wrong with the
> missing
> AjR> values. Can anyone help me correct this syntax?
> Or
> AjR> should I just rephrase this question and say
> "Martha,
> AjR> could you help me with this MATRIX question"?
> ;-)
>
> MATRIX.
> * Sample data, replace by your own *.
> COMPUTE  m_filex={1,2,3,99999999;
>                   5,6,7,8;
>                   9,10,11,99999999}.
> COMPUTE m_filey={11,10,9,99999999;
>                   7,6,5,4;
>                   3,2,1,99999999}.
> * Since m_filex and m_filey are conformant, you just
> need to know the number
>   of rows and columns of one of them *.
> COMPUTE k=NROW(m_filex).
> COMPUTE m=NCOL(m_filex).
> * Initialize empty difference matrix with missing
> values *.
> COMPUTE d=MAKE(k,m,99999999).
> * Now, elementwise inspection of every element to
> replace value in difference
>   matrix only if no value is missing in m_filex/y *.
> LOOP i = 1 TO k.
> . LOOP j=1 TO m.
> .  DO IF (m_filex(i,j) NE 99999999) AND
> (m_filey(i,j) NE  99999999).
> * Compute a single element, not the whole matrix *.
> .   COMPUTE d(i,j) = m_filex(i,j) - m_filey(i,j).
> .  END IF.
> . END LOOP.
> END LOOP.
> * save d / outfile =
> 'd:\temp\difference_matrix.sav'.
> PRINT d.
> END MATRIX.
>
> Best regrads,
> Marta
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



____________________________________________________________________________________
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing.
http://new.toolbar.yahoo.com/toolbar/features/mail/index.php
Reply | Threaded
Open this post in threaded view
|

Re: Matrix question

Marta Garcia-Granero
Hi again Albert-jan,

This is the first time in many days I have a bit of free time to
spend, AND a good Internet connection.

AjR> You taught me well, Jedi master ;-)

:DDD

AjR> Thanks a lot! It's a fascinating, and very useful
AjR> command!

I agree. MATRIX is considered by a lot of SPSS users as an "ugly
duckling", but, once you learn some tricks, it's a powerful tool. I
use it a lot in conjuntion with OMS (I use standard SPSS procedures to
tabulate data and compute some statistics, and then I open the
exported tables in MATRIX to  run some complex calculations,
impossible (or more difficult at the very least) outside MATRIX. See
two nice macros below with that mixed approach (calculations exported
with OMS and passed to MATRIX as input data).

If you really want to learn MATRIX, you should dedicate some time to
study MATRIX algebra. I have a nice little book called "Calcul Matriciel"
by Jacques Bouteloup, one of those old books from the fifties-sixties.
I use it a lot when I don't remember exactly how to multiply two
matrices. I suppose there must be some good online resources (like
this one I use sometimes: http://www.sosmath.com/matrix/matrix.html).

Once you start to think "MATRIX", then your programming will be very
easy, and you'll discover you can do things that can't be done easily
in data editor (like multiplying a row of data by a column of other
data...).

Regards,
Marta

Now, the promised two examples of code:

1) A better Kappa .

 ******************************
/*          KAPPAPLUS         */
 ******************************
 * (C) M García-Granero, 2007 *
 * [hidden email]     *
 ******************************

**********************************************************************
* For good references (both used for this MACRO), see:               *
**********************************************************************
* 1) Julius Sim, Chris C Wright "The Kappa Statistic in Reliability  *
*    Studies: Use, Interpretation, and Sample Size Requirements"     *
*    Physical Therapy 2005;85:257-268.                               *
* 2) Joseph J Fleiss "Statistical Methods for Rates and Proportions" *
*    2nd Ed. Wiley Interscience. (Chapter 13)                        *
**********************************************************************
* Accuracy of the MACRO checked with WinPepi (www.brixtonhealth.com) *
**********************************************************************

* MACRO DEFINITION *.
DEFINE KAPPAPLUS(!POS=!TOKENS(3)).
* Taking advantage of CROSSTABS & OMS to simplify tabulation *.
OMS
 /SELECT TABLES
 /IF COMMANDS = 'Crosstabs'
     SUBTYPES = 'Case Processing Summary'
 /DESTINATION VIEWER = NO.
OMS
 /SELECT TABLES
 /IF COMMANDS = 'Crosstabs'
     SUBTYPES = 'Crosstabulation'
 /DESTINATION FORMAT = SAV
             OUTFILE = 'C:\Temp\CrosstabData.sav'.
CROSSTABS /TABLES=!1.
OMSEND.
* MATRIX code *.
MATRIX.
PRINT /TITLE='      ******* AGREEMENT: KAPPA  **********'.
* Read OMS data *.
GET TabData /VAR=ALL
            /FILE='C:\Temp\CrosstabData.sav'
            /NAMES=Vnames
            /MISSING=ACCEPT /SYSMIS=0.
* Extract relevant info *.
COMPUTE CrossTab=TabData(1:(NROW(TabData)-1),7:(NCOL(Tabdata)-1)).
COMPUTE CatNames={Vnames(7:(NCOL(Tabdata)-1)),'Total'}.
* Report input data *.
PRINT {CrossTab,      RSUM(CrossTab);
       CSUM(CrossTab),MSUM(CrossTab)}
 /FORMAT='F8.0'
 /CNAME=CatNames
 /RNAME=CatNames
 /TITLE='Input data'.
* Common data calculation *.
COMPUTE n=MSUM(CrossTab).
COMPUTE Ncat=NROW(CrossTab).
COMPUTE Pij=CrossTab/n.
COMPUTE Pidot=RSUM(Pij).
COMPUTE Pdotj=CSUM(Pij).
PRINT {Pij,Pidot;
       Pdotj,1}
 /FORMAT='F8.3'
 /CNAME=CatNames
 /RNAME=CatNames
 /TITLE='Observed relative frequencies'.
* Get rid of useless data *.
RELEASE TabData,Vnames,CrossTab.
COMPUTE AllData=MAKE(NCat+1,8,0).
********* UNWEIGHTED KAPPA ***********.
PRINT /TITLE=' ** UNWEIGHTED KAPPA **'.
COMPUTE Wij=IDENT(Ncat).
COMPUTE Pew=T(Pidot)*Wij*T(Pdotj).
COMPUTE Pow=MSUM(Pij&*Wij).
COMPUTE K=(Pow-Pew)/(1-Pew).
* SE(0) & SE(k) *.
COMPUTE Widot=Wij*T(Pdotj)).
COMPUTE Wdotj=T(Pidot)*Wij.
COMPUTE cterm=Widot*MAKE(1,Ncat,1)+MAKE(Ncat,1,1)*Wdotj.
COMPUTE SE0K=SQRT(T(Pidot)*((Wij-cterm)&**2)*T(Pdotj)-Pew&**2)/((1-Pew)*SQRT(n)).
COMPUTE SE1K=SQRT(MSUM(Pij&*(Wij-cterm&*(1-K))&**2)-(K-Pew*(1-K))**2)/((1-Pew)*SQRT(n)).
* Tests & CI *.
COMPUTE ZValue=K/SE0K.
COMPUTE ZSig=1-CDFNORM(ABS(ZValue)).
COMPUTE LowCL=K-1.96*SE1K.
COMPUTE UppCL=K+1.96*SE1K.
COMPUTE ZValue4=(K-0.4)/SE1K.
COMPUTE ZSig4=1-CDFNORM(ZValue4).
COMPUTE ZValue6=(K-0.6)/SE1K.
COMPUTE ZSig6=1-CDFNORM(ZValue6).
* Store all infor for condensed report at end *.
COMPUTE Alldata((Ncat+1),:)={K,SE0K,ZSig,SE1K,LowCL,UppCL,ZSig4,ZSig6}.
* Max. attainable Kappa *.
COMPUTE PowExp=0.
LOOP i=1 TO Ncat.
- DO IF Pidot(i) LT Pdotj(i).
-  COMPUTE PowExp=PowExp+Pidot(i).
- ELSE.
-  COMPUTE PowExp=PowExp+Pdotj(i).
- END IF.
END LOOP.
COMPUTE MaxK=(PowExp-Pew)/(1-Pew).
* Reports *.
PRINT {K,SE0K,ZValue,ZSig}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Z value','P-value'
 /TITLE='Unweighted Overall Kappa, SE and significance'.
PRINT {K,SE1K,LowCL,UppCL}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Lower95%','Upper95%'
 /TITLE='Unweighted Overall Kappa & 95%CI'.
PRINT {ZValue4,ZSig4;Zvalue6,Zsig6}
 /FORMAT='F8.3'
 /CLABEL='Z value','P-value'
 /RLABEL='Ko=0.4','Ko=0.6'
 /TITLE='Significantly above 0.4 & 0.6?'.
PRINT MaxK
 /FORMAT='F8.3'
 /RLABEL='Max.Kap.'
 /TITLE='Maximum Atttainable Kappa (ceiling given observed marginal totals)'.
********* WEIGHTED KAPPAS ***********.
PRINT /TITLE=' ** WEIGHTED KAPPAS **'.
* Linear weights *.
COMPUTE Wij=MAKE(Ncat,Ncat,0).
LOOP i=1 TO Ncat.
- LOOP j=1 TO Ncat.
-  COMPUTE Wij(i,j)=1-(ABS(i-j)/(Ncat-1)).
- END LOOP.
END LOOP.
PRINT Wij
 /FORMAT='F8.3'
 /CNAME=CatNames
 /RNAME=CatNames
 /TITLE=' --- Linear weights ---'.
* Linear Weighted Kappa *.
COMPUTE Pew=T(Pidot)*Wij*T(Pdotj).
COMPUTE Pow=MSUM(Pij&*Wij).
COMPUTE WK=(Pow-Pew)/(1-Pew).
* SE(0) & SE(k) *.
COMPUTE Widot=Wij*T(Pdotj)).
COMPUTE Wdotj=T(Pidot)*Wij.
COMPUTE cterm=Widot*MAKE(1,Ncat,1)+MAKE(Ncat,1,1)*Wdotj.
COMPUTE SE0Kw=SQRT(T(Pidot)*((Wij-cterm)&**2)*T(Pdotj)-Pew&**2)/((1-Pew)*SQRT(n)).
COMPUTE SE1Kw=SQRT(MSUM(Pij&*(Wij-cterm&*(1-WK))&**2)-(WK-Pew*(1-WK))**2)/((1-Pew)*SQRT(n)).
* Tests & CI *.
COMPUTE ZValue=WK/SE0Kw.
COMPUTE ZSig=1-CDFNORM(ABS(ZValue)).
COMPUTE LowCLw=WK-1.96*SE1Kw.
COMPUTE UppCLw=WK+1.96*SE1Kw.
COMPUTE ZValue4=(WK-0.4)/SE1Kw.
COMPUTE ZSig4=1-CDFNORM(ZValue4).
COMPUTE ZValue6=(WK-0.6)/SE1Kw.
COMPUTE ZSig6=1-CDFNORM(ZValue6).
* Reports *.
PRINT {WK,SE0Kw,ZValue,ZSig}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Z value','P-value'
 /TITLE='Linear Weighted Kappa, SE and significance'.
PRINT {WK,SE1Kw,LowCLw,UppCLw}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Lower95%','Upper95%'
 /TITLE='Linear Weighted Kappa & 95%CI'.
PRINT {ZValue4,ZSig4;Zvalue6,Zsig6}
 /FORMAT='F8.3'
 /CLABEL='Z value','P-value'
 /RLABEL='Ko=0.4','Ko=0.6'
 /TITLE='Significantly above 0.4 & 0.6?'.
* Quadratic weights *.
COMPUTE Wij=MAKE(Ncat,Ncat,0).
LOOP i=1 TO Ncat.
- LOOP j=1 TO Ncat.
-  COMPUTE Wij(i,j)=1-((i-j)/(Ncat-1))&**2.
- END LOOP.
END LOOP.
PRINT Wij
 /FORMAT='F8.3'
 /CNAME=CatNames
 /RNAME=CatNames
 /TITLE='--- Quadratic weights ---'.
* Quadratic Weighted Kappa *.
COMPUTE Pew=T(Pidot)*Wij*T(Pdotj).
COMPUTE Pow=MSUM(Pij&*Wij).
COMPUTE WK=(Pow-Pew)/(1-Pew).
* SE(0) & SE(k) *.
COMPUTE Widot=Wij*T(Pdotj)).
COMPUTE Wdotj=T(Pidot)*Wij.
COMPUTE cterm=Widot*MAKE(1,Ncat,1)+MAKE(Ncat,1,1)*Wdotj.
COMPUTE SE0Kw=SQRT(T(Pidot)*((Wij-cterm)&**2)*T(Pdotj)-Pew&**2)/((1-Pew)*SQRT(n)).
COMPUTE SE1Kw=SQRT(MSUM(Pij&*(Wij-cterm&*(1-WK))&**2)-(WK-Pew*(1-WK))**2)/((1-Pew)*SQRT(n)).
* Tests & CI *.
COMPUTE ZValue=WK/SE0Kw.
COMPUTE ZSig=1-CDFNORM(ABS(ZValue)).
COMPUTE LowCLw=WK-1.96*SE1Kw.
COMPUTE UppCLw=WK+1.96*SE1Kw.
COMPUTE ZValue4=(WK-0.4)/SE1Kw.
COMPUTE ZSig4=1-CDFNORM(ZValue4).
COMPUTE ZValue6=(WK-0.6)/SE1Kw.
COMPUTE ZSig6=1-CDFNORM(ZValue6).
* Reports *.
PRINT {WK,SE0Kw,ZValue,ZSig}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Z value','P-value'
 /TITLE='Quadratic Weighted Kappa, SE and significance'.
PRINT {WK,SE1Kw,LowCLw,UppCLw}
 /FORMAT='F8.3'
 /CLABEL='Kappa','SE','Lower95%','Upper95%'
 /TITLE='Quadratic Weighted Kappa & 95%CI'.
PRINT {ZValue4,ZSig4;Zvalue6,Zsig6}
 /FORMAT='F8.3'
 /CLABEL='Z value','P-value'
 /RLABEL='Ko=0.4','Ko=0.6'
 /TITLE='Significantly above 0.4 & 0.6?'.
********** KAPPA FOR INDIVIDUAL CATEGORIES **********.
PRINT /TITLE=' ** KAPPA FOR INDIVIDUAL CATEGORIES **'.
COMPUTE Wij=IDENT(2).
LOOP NKappa=1 TO Ncat.
- COMPUTE Copied=Pij.
- COMPUTE ScrapCol=Copied(:,1).
- COMPUTE Copied(:,1)=Copied(:,Nkappa).
- COMPUTE Copied(:,NKappa)=ScrapCol.
- COMPUTE ScrapRow=Copied(1,:).
- COMPUTE Copied(1,:)=Copied(Nkappa,:).
- COMPUTE Copied(NKappa,:)=ScrapRow(1,:).
- COMPUTE SPij=MAKE(2,2,0).
- COMPUTE SPij(1,1)=Copied(1,1).
- COMPUTE SPij(1,2)=MSUM(Copied(1,2:Ncat)).
- COMPUTE SPij(2,1)=MSUM(Copied(2:Ncat,1)).
- COMPUTE SPij(2,2)=MSUM(Copied(2:Ncat,2:Ncat)).
- COMPUTE SPidot=RSUM(SPij).
- COMPUTE SPdotj=CSUM(SPij).
- COMPUTE Pew=T(SPidot)*Wij*T(SPdotj).
- COMPUTE Pow=MSUM(SPij&*Wij).
- COMPUTE K=(Pow-Pew)/(1-Pew).
- COMPUTE AllData(Nkappa,1)=K.
* SE(0) & SE(k) *.
- COMPUTE Widot=Wij*T(SPdotj)).
- COMPUTE Wdotj=T(SPidot)*Wij.
- COMPUTE cterm=Widot*MAKE(1,2,1)+MAKE(2,1,1)*Wdotj.
- COMPUTE SE0K=SQRT(T(SPidot)*((Wij-cterm)&**2)*T(SPdotj)-Pew&**2)/((1-Pew)*SQRT(n)).
- COMPUTE SE1K=SQRT(MSUM(SPij&*(Wij-cterm&*(1-K))&**2)-(K-Pew*(1-K))**2)/((1-Pew)*SQRT(n)).
- COMPUTE AllData(Nkappa,2)=SE0K.
- COMPUTE AllData(Nkappa,4)=SE1K.
* Tests & CI *.
- COMPUTE ZValue=K/SE0K.
- COMPUTE ZSig=1-CDFNORM(ABS(ZValue)).
- COMPUTE AllData(Nkappa,3)=ZSig.
- COMPUTE LowCL=K-1.96*SE1K.
- COMPUTE UppCL=K+1.96*SE1K.
- COMPUTE AllData(Nkappa,5)=LowCL.
- COMPUTE AllData(Nkappa,6)=UppCL.
- COMPUTE ZValue4=(K-0.4)/SE1K.
- COMPUTE ZSig4=1-CDFNORM(ZValue4).
- COMPUTE ZValue6=(K-0.6)/SE1K.
- COMPUTE ZSig6=1-CDFNORM(ZValue6).
- COMPUTE AllData(Nkappa,7)=ZSig4.
- COMPUTE AllData(Nkappa,8)=ZSig6.
END LOOP.
* Condensed Report *.
PRINT AllData
 /FORMAT='F5.3'
 /RNAMES=CatNames
 /CLABELS='Kappa','SE[H0]','P(K=0)','SE[Ha]','Low95%','Upp95%','P(0.4)','P(0.6)'
 /TITLE='Summary report (individual categories and Overall unweighted Kappa) '.
END MATRIX.
!ENDDEFINE.

* Sample dataset, from table 2 (test-retest agreement) of Sim & Wright paper *.
DATA LIST FREE/Test1 Test2 n (3 F8).
BEGIN DATA
1 1 15 1 2  3 1 3  1 1 4  1
2 1  4 2 2 18 2 3  3 2 4  2
3 1  4 3 2  5 3 3 16 3 4  4
4 1  1 4 2  2 4 3  4 4 4 17
END DATA.
VAR LEVEL Test1 Test2 (ORDINAL).
VAL LABEL Test1 Test2
 1'None'
 2'Mild'
 3'Moderate'
 4'Severe'.
VAR LABEL Test1 'Pain at Shoulder Joint (test 1)'/
          Test2 'Pain at Shoulder Joint (test 2)'.
WEIGHT BY n.

* MACRO call *.
KAPPAPLUS Test1 BY Test2.

2) Non parametric skewness and kurtosis index.

* Sample dataset *.
DATA LIST FREE/bilirrubina (F8).
BEGIN DATA
 25 178 15 10  90  30 280  20   58   8
 20  75 85 12 158  10   6  22  103  16
170  28 240  8  16  20  80 420  36  24
 70  22  14  5 130  54  25  22  15  22
 50  24 143 42   4  18  44 220  54  38
135  24  78 24   4 152  68  45  38  18
120  18  30 20 360  26  12  16 310  72
 48  96  32 22  55  12  10  62  46  35
 15 192  20 65  42   6  60  34  14 115
  9 164  12 40  18 530  32 104  28   6
 81  10  26 94  46  40  14  40
END DATA.
VAR LEVEL bilirrubina(SCALE).

* Syntax *.
OMS
 /SELECT TABLES
 /IF COMMANDS = 'Explore'
     SUBTYPES = 'Percentiles'
 /DESTINATION FORMAT = SAV
             OUTFILE = 'C:\Temp\Octiles.sav'.
OMS
 /SELECT TABLES
 /IF COMMANDS = 'Explore'
     SUBTYPES = 'Case Processing Summary'
 /DESTINATION VIEWER = NO.
EXAMINE
  VARIABLES=bilirrubina
  /PLOT BOXPLOT
  /PERCENTILES(12.5,25,37.5,50,62.5,75,87.5) AEMPIRICAL
  /STATISTICS NONE
  /NOTOTAL.
OMSEND.

MATRIX.
* Get octiles *.
GET Ei /VAR=@12.5 TO @87.5 /FILE='C:\Temp\Octiles.sav'
       /MISSING=OMIT.
* Skewness: Bowley's SK2 *.
COMPUTE SK2=(Ei(6)+Ei(2)-2*Ei(4))/(Ei(6)-Ei(2)).
* Kurtosis: Moor's KR2 *.
COMPUTE KR2=(Ei(7)-Ei(5)+Ei(3)-Ei(1))/(Ei(6)-Ei(2))-1.233.
* Reports *.
PRINT Ei(4)
 /FORMAT='F8.1'
 /TITLE='Sample median (used for Wilcoxon signed-rank test of symmetry around the median)'.
PRINT {SK2;KR2}
 /FORMAT='F8.3'
 /RLABEL='SK2','KR2'
 /TITLE="Robust measures of skweness & kurtosis: Bowley's SK2 and Moor's centered KR2".
PRINT/TITLE='SK2 Skewness: range [-1; 1]. -ve skewed to the left, +ve skewed to the right'.
PRINT/TITLE='KR2 Kurtosis: range [-1.233; infinity]. -ve platikurtic, +ve leptokurtic'.
END MATRIX.

* Skewness test (one sample Wilcoxon around the sample median) *.
TEMPORARY.
COMPUTE k=1.
AGGREGATE
  /OUTFILE=*
  MODE=ADDVARIABLES
  /BREAK=k
  /SampleMedian = MEDIAN(bilirrubina).
NPAR TEST
  /WILCOXON=SampleMedian WITH bilirrubina .
DELETE VARIABLES SampleMedian.