|
Size: 2199
Comment:
|
Size: 2368
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| Line 4: | Line 3: |
| The syntax below uses dummy data of one binary variable (y) and a continuous predictor, x and is an adaptation of code from Adam W taken from [[http://stackoverflow.com/questions/24216574/how-to-do-leave-one-out-cross-validation-in-spss ! here]] for cross validating using the leaving-one-out approach for a linear regression model. | The syntax below uses dummy data of one binary variable (y) and a continuous predictor, x and is an adaptation of code from Andy W taken from [[http://stackoverflow.com/questions/24216574/how-to-do-leave-one-out-cross-validation-in-spss | here]] for cross validating using the leaving-one-out approach for a linear regression model. |
| Line 23: | Line 22: |
| The macro then produces the classification table of predicted by true group for the single omitted data point. | We can save this file into a file dummy.sav in U:/My Documents folder. The macro below can then be used to produce the classification table of predicted by true group for the single omitted data point. |
| Line 46: | Line 45: |
| Line 47: | Line 47: |
| /TABLE = 'Sim' | /TABLE = 'U:/My Documents/dummy.sav' |
| Line 49: | Line 49: |
#MATCH FILES FILE = * # /TABLE = 'Sim' # /BY Id. |
The leaving one out error rate in SPSS for logistic regression
The syntax below uses dummy data of one binary variable (y) and a continuous predictor, x and is an adaptation of code from Andy W taken from here for cross validating using the leaving-one-out approach for a linear regression model.
INPUT PROGRAM. LOOP Id = 1 TO 100. END CASE. END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME Sim. COMPUTE X = RV.NORMAL(10,5). COMPUTE YS = 3 + 0.2*(X) + RV.NORMAL(0,0.2). RECODE YS (Lowest thru 4.5=0) (4.5 thru Highest=1) INTO Y. COMPUTE YCOPY=Y. FORMATS Id (F2.0) X Y YCOPY (F4.2). EXECUTE.
We can save this file into a file dummy.sav in U:/My Documents folder. The macro below can then be used to produce the classification table of predicted by true group for the single omitted data point.
DEFINE !LOOE (!POS !TOKENS(1)
/!POS !TOKENS(1)
/!POS !CMDEND)
COMPUTE YCOPY=!2.
INPUT PROGRAM.
COMPUTE #Cases = !1.
LOOP #Id = 1 TO #Cases.
LOOP #Iter = 1 TO #Cases.
COMPUTE L1O = #Iter.
COMPUTE Id = #Id.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME LeaveOneOut.
*Merging in original data.
MATCH FILES FILE = *
/TABLE = 'U:/My Documents/dummy.sav'
/BY Id.
#MATCH FILES FILE = *
# /TABLE = 'Sim'
# /BY Id.
*Set missing to
IF L1O = Id !2 = $SYSMIS.
SORT CASES BY L1O.
SPLIT FILE BY L1O.
*You can replace the logistic regression with whatever procedure you are.
*interested in.
LOGISTIC REGRESSION VARIABLES !2
/METHOD=ENTER !3
/SAVE=PRED (pred) PGROUP (pgp)
/CRITERIA=PIN(.05) POUT(.10) ITERATE(20) CUT(.5).
SPLIT FILE OFF.
*This shows the original leave one out stats.
*And new stats are the same besides some floating.
*point differences (tested for linear regresison)
.
*COMPUTE Test = (CVFit2 - (PredAll-CVFit)).
TEMPORARY.
SELECT IF (L1O = Id).
*FREQ Y pgp.
CROSSTABS
/TABLES=YCOPY BY pgp
/FORMAT=AVALUE TABLES
/CELLS=COUNT
/COUNT ROUND CELL.
EXECUTE.
!ENDDEFINE.We can now run the macro
* ARGUMENTS ARE THE NUMBER OF ROWS OF DATA (SAMPLE SIZE), THE NAME OF THE OUTCOME VARIABLE AND A LIST OF PREDICTORS !LOOE 100 Y X.
