| Date: | Thu, 9 Jun 2005 16:46:01 +0200 |
| Reply-To: | Marta García-Granero
<biostatistics@terra.es> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Marta García-Granero
<biostatistics@terra.es> |
| Organization: | Asesoría Bioestadística |
| Subject: | Cochran-Armitage test (delayed reply) |
| Content-Type: | text/plain; charset=ISO-8859-15 |
Hi
Curious, it seems that a message I sent to the list didn't get through
(?)
In may, someone asked for Cochran-Armitage test with SPSS. I replied,
but, today, trying to recover a lost message of mine from the SPSS
archives at the listserv, I realised my reply wasn't there. I'm sending
it again:
SPSS gives a Linear-by-linear test, quite close, but not exactly the
same.
***********************************
* COCHRAN-ARMITAGE TEST FOR TREND *
***********************************
* Reference:
Alan Agresti (2002), Categorical Data Analysis (2nd Ed), pp 181-2, John Wiley & Sons *.
* Dataset #1: scoring is OK (example provided with SAS at:)
(http://www.id.unizh.ch/software/unix/statmath/sas/sasdoc/stat/chap28/sect40.htm)
* (SAS results):
* Statistic (Z) 4.7918
* Asymptotic Test
* One-sided Pr < Z <.0001
* Two-sided Pr < |Z| <.0001
* Sample Size = 161
DATA LIST LIST/dose adverse count (3 F8.0).
BEGIN DATA
0 1 26
0 2 6
1 1 26
1 2 7
2 1 23
2 2 9
3 1 18
3 2 14
4 1 9
4 2 23
END DATA.
VALUE LABEL adverse 1'No' 2'Yes'.
WEIGHT BY count .
* Using SPSS linear by linear test *.
CROSSTABS
/TABLES=dose BY adverse
/FORMAT= AVALUE TABLES
/CELLS= COUNT ROW EXPECTED
/STATISTIC=CHISQ.
* Cochran-Armitage test with MATRIX *.
* This code assumes the dependent variable is coded 0/1 (No/Yes) *.
TEMPORARY.
COMPUTE adverse=adverse-1.
AGGREGATE
/OUTFILE = 'c:\temp\aggdata.sav'
/BREAK = dose
/pi = MEAN(adverse)
/ni = N.
MATRIX.
PRINT/TITLE='Cochran-Armitage Test for Trend (Agresti 2002)'.
GET pi /VAR=pi /FILE='c:\temp\aggdata.sav'.
GET ni /VAR=ni /FILE='c:\temp\aggdata.sav'.
* Scoring (change if required) *.
COMPUTE xi={0; 1; 2; 3; 4}.
* Reports *.
PRINT {xi,ni&*pi,ni}
/FORMAT='F8.1'
/TITLE='Statistics'
/CLABELS='Score i','Count i','N i'.
PRINT MSUM(ni)
/FORMAT='F8.0'
/TITLE='Total sample size'.
* Calculations *.
COMPUTE p=MSUM(ni&*pi)/MSUM(ni).
COMPUTE x=MSUM(xi&*ni)/MSUM(ni).
COMPUTE num=(xi-x)&*ni&*pi.
COMPUTE den=p*(1-p)*ni&*((xi-x)&**2).
COMPUTE z=MSUM(num)/SQRT(MSUM(den)).
COMPUTE zsig=2*(1-CDFNORM(ABS(z))).
* Final report *.
PRINT {z,z**2,zsig,zsig/2}
/FORMAT='F8.3'
/CLABELS='Z','Z²','2-sig','1-sig'
/TITLE='Statistics & Significance'.
COMPUTE observed={(ni-ni&*pi),ni&*pi}.
COMPUTE expected=RSUM(observed)*CSUM(observed)/MSUM(ni).
COMPUTE chisq=MSUM((observed-expected)&**2/expected).
COMPUTE chisqp=1-CHICDF(chisq,NROW(observed)-1).
COMPUTE reschi=chisq-z**2.
COMPUTE reschip=1-CHICDF(reschi,NROW(observed)-2).
PRINT {chisq,chisqp;reschi,reschip}
/FORMAT='F8.3'
/RLABELS='Pearson','Deviat.'
/CLABELS='Chi²','Sig.'
/TITLE='Pearson-Chi² & Deviation from trend (non-linearity)'.
END MATRIX.
* As you can't specify scores for CROSSTABS, the key is recoding
* the predictor to asign the scores you want. Suppose your data
* don't reflect the scoring you want to give *.
* Dataset #2 (Agresti 2002) *.
DATA LIST LIST /alcohol malform count (3 F8.0).
BEGIN DATA
0 1 48
0 0 17066
1 1 38
1 0 14464
2 1 5
2 0 788
3 1 1
3 0 126
4 1 1
4 0 37
END DATA.
VALUE LABEL alcohol
0 ' 0'
1 '<1'
2 '1-2'
3 '3-5'
4 '>6'.
VALUE LABEL malform 0'Absent' 1'Present'.
WEIGHT BY count .
* Agresti gives the following scores: 0, 0.5, 1.5, 4, 7 *.
* The following will not give the results expected (Z²=6.57 p=0.010): *.
CROSSTABS
/TABLES=alcohol BY malform
/FORMAT= AVALUE TABLES
/CELLS= COUNT ROW
/STATISTIC=CHISQ. /* LxL test is 1.828 (p=0.176)*.
* Recoding and re-running *.
TEMPORARY.
RECODE alcohol (0=0) (1=0.5) (2=1.5) (3=4) (4=7) INTO alcscore .
VARIABLE LABELS alcscore 'Scores for alcohol'.
CROSSTABS
/TABLES=alcscore BY malform
/FORMAT= AVALUE TABLES
/CELLS= COUNT ROW
/STATISTIC=CHISQ. /* LxL is now 6.570 *.
* Cochran-Armitage test with MATRIX *.
* This time, MALFORM takes the correct values (0/1) *.
AGGREGATE
/OUTFILE='c:\temp\aggdata.sav'
/BREAK=alcohol
/pi = MEAN(malform)
/ni=N.
MATRIX.
PRINT/TITLE='Cochran-Armitage Test for Trend (Agresti 2002)'.
GET pi /VAR=pi /FILE='c:\temp\aggdata.sav'.
GET ni /VAR=ni /FILE='c:\temp\aggdata.sav'.
* Scoring (change if required) *.
COMPUTE xi={0; 0.5; 1.5; 4; 7}.
* Reports *.
PRINT {xi,ni&*pi,ni}
/FORMAT='F8.1'
/TITLE='Statistics'
/CLABELS='Score i','Count i','N i'.
PRINT MSUM(ni)
/FORMAT='F8.0'
/TITLE='Total sample size'.
* Calculations *.
COMPUTE p=MSUM(ni&*pi)/MSUM(ni).
COMPUTE x=MSUM(xi&*ni)/MSUM(ni).
COMPUTE num=(xi-x)&*ni&*pi.
COMPUTE den=p*(1-p)*ni&*((xi-x)&**2).
COMPUTE z=MSUM(num)/SQRT(MSUM(den)).
COMPUTE zsig=2*(1-CDFNORM(ABS(z))).
* Final report *.
PRINT {z,z**2,zsig,zsig/2}
/FORMAT='F8.3'
/CLABELS='Z','Z²','2-sig','1-sig'
/TITLE='Statistics & Significance'.
COMPUTE observed={(ni-ni&*pi),ni&*pi}.
COMPUTE expected=RSUM(observed)*CSUM(observed)/MSUM(ni).
COMPUTE chisq=MSUM((observed-expected)&**2/expected).
COMPUTE chisqp=1-CHICDF(chisq,NROW(observed)-1).
COMPUTE reschi=chisq-z**2.
COMPUTE reschip=1-CHICDF(reschi,NROW(observed)-2).
PRINT {chisq,chisqp;reschi,reschip}
/FORMAT='F8.3'
/RLABELS='Pearson','Deviat.'
/CLABELS='Chi²','Sig.'
/TITLE='Pearson-Chi² & Deviation from trend (non-linearity)'.
END MATRIX.
--
Regards,
Marta mailto:biostatistics@terra.es
Marta Garcia-Granero, PhD
Statistician
|