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
* (Q) Do you know of anyone that has written syntax
	to hold out more than one case and do the cross-validation on x number of
	held-out cases; I know the adjusted predicted variables will hold out one
	case, but it would be nice to hold out, say, 5 cases to get a more
	representative assessment of the regression skill...
* (A) rlevesque@videotron.ca 2001/09/01.
*	http://pages.infinit.net/rlevesqu/index.htm


SET MPRINT=no.
*///////////////////////////.
DEFINE !regres( use=!TOKENS(1) 
	/nbcases=!TOKENS(1) 
	/dep=!TOKENS(1)
	/indep=!CMDEND)

COMPUTE caseid=$CASENUM.
/* Calculate the number of regression passes = nbcases - use*/
!LET !nbloop=!LEN(!SUBSTR(!BLANK(!nbcases),!use))

!DO !casebeg=1 !TO !nbloop
/* compute caseid of last case used to compute coefficients */.
!LET !caseend = !LEN(!SUBSTR(!CONCAT( !BLANK(!casebeg),!BLANK(!use)),2))

/* compute the select variable*/.
COMPUTE !CONCAT('svar',!casebeg)=0.
IF RANGE(caseid ,!casebeg, !caseend ) !CONCAT('svar',!casebeg)=1.

REGRESSION
  /SELECT= !CONCAT('svar',!casebeg) EQ 1
  /MISSING LISTWISE
  /STATISTICS COEFF OUTS R ANOVA
  /CRITERIA=PIN(.05) POUT(.10)
  /NOORIGIN
  /DEPENDENT !dep
  /METHOD=ENTER !indep
  /SAVE PRED.
!DOEND

!ENDDEFINE.
*///////////////////////////.

SET MPRINT=yes.

****** Example 1.
GET
  FILE='c:\\Program Files\\SPSS\\Employee data.sav'.
N OF CASES 20.
* Say we want to use 15 cases to do the regression (holdout 5 cases).
!regres use=15 nbcases=20 dep=salary indep=educ jobtime.

****** Example 2.
GET
  FILE='c:\\Program Files\\SPSS\\Employee data.sav'.
N OF CASES 22.
!regres use=16 nbcases=22 dep=salary indep=educ jobtime
.