1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
***This item analysis syntax follows the example from the 
	SPSS White Paper on the same subject.
***Score each record, assuming key is the last record, 
	resulting in an array of 1s and 0s.

* Syntax fixed by Raynald Levesque 2003/01/27.
* (Of course syntax could be automated so that it would work, without 
	any modifications, for any number of questions).

PRESERVE.
GET FILE='c:\\temp\\ItemAnalysisExercise.sav'.
SET TVARS=LABELS /TNUMBERS=LABELS.
COMPUTE ID=$CASENUM. 
SORT CASES BY ID (D). 
DO REPEAT key=#1 TO #10/ q=q1 TO q10. 
+ DO IF $CASENUM=1.
+   COMPUTE key=q. 
+  ELSE.
+   COMPUTE q=(q=key). 
+ END IF.
END REPEAT.
XSAVE OUTFILE  "c:\\temp\\SCORED.sav"/DROP=id.
EXECUTE .
GET FILE="c:\\temp\\SCORED.sav.".

***Delete the record containing the key.
SORT CASES BY name (A).
SELECT IF(name NE 'key').

***Compute the score for each record. 
COMPUTE score=MEAN(q1 to q10)*100. 

***Compute and append the ranking of each score. 
RANK VARIABLES=score (D) /NTILES (3) /PRINT=NO /TIES=MEAN .

***Clean up.
RENAME VARIABLES (nscore=group). 
FORMATS score (f8.0).
VALUE LABELS group 1 'high' 2 'middle' 3 'low'. 
SAVE OUTFILE 'c:\\temp\\scored.sav'.

***run against the resulting scored data to produce the output seen in Figures 3-4.
AGGREGATE OUTFILE=* 
 /BREAK=group 
 /q1 'percentage right q1'=MEAN(q1) 
 /q2 'percentage right q2'=MEAN(q2) 
 /q3 'percentage right q3'=MEAN(q3)
 /q4 'percentage right q4'=MEAN(q4)
 /q5 'percentage right q5'=MEAN(q5)
 /q6 'percentage right q6'=MEAN(q6) 
 /q7 'percentage right q7'=MEAN(q7) 
 /q8 'percentage right q8'=MEAN(q8)
 /q9 'percentage right q9'=MEAN(q9)
 /q10 'percentage right q10'=MEAN(q10).
FLIP VARIABLES=q1 TO q10 /NEWNAMES=group.
RENAME VARIABLES (case_lbl=qnum) (v1=high) (v2=middle) (v3=low).
COMPUTE index=high - low. 
FORMATS high TO index (F4.2).
SUMMARIZE
  /TABLES=qnum high middle low index
  /FORMAT=VALIDLIST NOCASENUM TOTAL
  /TITLE='Index of Discrimination'
  /MISSING=VARIABLE
  /CELLS=NONE.



***Compute - among other things - corrected point biserial correlations.
GET FILE 'c:\\temp\\scored.sav'.
RELIABILITY
/VARIABLES=q1 TO q10 
/FORMAT=NOLABELS
/SCALE(ALPHA)=ALL/MODEL=ALPHA 
/STATISTICS=DESCRIPTIVE CORR 
/SUMMARY=TOTAL MEANS.


*** Produce a table similar to that in figure 5

***Item distracter analysis setup. 
GET FILE='c:\\temp\\ItemAnalysisExercise.sav'. 

SELECT IF name="key".
FORMATS q1 TO q10(F1).

*//////////.
DEFINE !keys(nbq=!TOKENS(1))
/* This macro adds the * after the correct answer number */
WRITE OUTFILE='c:\\temp\\define labels.sps'
!DO !cnt=1 !TO !nbq /!QUOTE(!CONCAT('ADD VALUE LABEL q',!cnt," "))!CONCAT(q,!cnt)'"'!CONCAT(q,!cnt)'*".'
!DOEND.
EXECUTE.
!ENDDEFINE.
*//////////.

SET MPRINT=yes.
!keys nbq=10.


GET FILE='c:\\temp\\ItemAnalysisExercise.sav'. 
SELECT IF (name ne 'key'). 
MATCH FILES/FILE=* 
/FILE='C:\\TEMP\\scored.sav' 
/RENAME (name q1 TO q10= d0 TO d10)
/DROP=d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10. 

VARIABLE LABELS group 'Percentage answering distracter'. 
VALUE LABELS group 1 'high 1/3' 2 'middle 1/3' 3 'low 1/3'. 
INCLUDE 'c:\\temp\\define labels.sps'.
CROSSTABS
/TABLES=group BY q1 TO q10 
/FORMAT=AVALUE TABLES 
/CELLS=ROW.

RESTORE.