/******************************************************************************************************************************************************************************************************************. /*This macro produces Multinomial Logistic Regression with split-sample validation /*Always the last dependent category is a reference category in model /*Parameters: /*CROSSVALID dependent_variable |FACTORS= list_of_factors_in_NomReg |COVARIATES= list_of_covariates_in_NOMREG |TRAIN= value_in_percentage_for_training_sample. /* Author: Maciek Lobinski 2007/09/10 . /******************************************************************************************************************************************************************************************************************. define crossvalid (!positional= !charend('|') /FACTORS= !charend('|') /COVARIATES=!charend('|') /TRAIN=!default(0.75) !charend('|')). !if (!covariates=!null) !then !let !cov=''. !else !let !cov=!concat(' WITH ', !covariates). !ifend. !if (!factors=!null) !then !let !fac=''. !else !let !fac=!concat(' BY ', !factors) !ifend. compute los_=uniform(1)0 or index(Var2,'Intercept')<>0 . compute res1=concat('compute ',Var1,'=',string(b,f15.5),'.'). end if. do if index(Var2,'=')=0 and index(Var2,'Stała')=0 and index(Var2,'Intercept')=0 . compute res1=concat('compute ',Var1,'=',Var1,'+',var2,'*',string(b,f15.5),'.'). end if. do if index(Var2,'=')<>0. compute var2=replace(var2,']',''). compute res1=concat('if ',replace(var2,'[',''),var1,'=',var1,'+',string(b,f15.5),'.'). end if. compute res1=replace(res1,',','.'). write outfile ='C:\TEMP\model.sps' /res1. exe. compute id_=\$casenum. if (lag(var1)=var1) dubel=1. select if miss(dubel). compute res1=concat('compute ',Var1,'=','exp(',Var1,').'). write outfile ='C:\TEMP\cross1.sps' /res1. exe. do if \$casenum=1. compute res1=concat('compute maxim=sum(',Var1,' to reference_).'). else. compute res1=''. end if. write outfile ='C:\TEMP\cross2.sps' /res1. exe. compute res1=concat('compute ',Var1,'=',var1,'/maxim.'). write outfile ='C:\TEMP\cross3.sps' /res1. exe. do if \$casenum=1. compute res1=concat('compute maxim=max(',Var1,' to reference_).'). else. compute res1=''. end if. write outfile ='C:\TEMP\cross4.sps' /res1. exe. compute res1=concat('if ',Var1,'=maxim PredCross="',rtrim(var1),'".'). write outfile ='C:\TEMP\cross5.sps' /res1. exe. GET FILE='C:\TEMP\analyx.sav'. insert file ='C:\TEMP\model.sps'. compute reference_=1. exe. insert file ='C:\TEMP\cross1.sps'. insert file ='C:\TEMP\cross2.sps'. insert file ='C:\TEMP\cross3.sps'. compute reference_=reference_/maxim. insert file ='C:\TEMP\cross4.sps'. string PredCross (a120). insert file ='C:\TEMP\cross5.sps'. if reference_=maxim predcross='REFERENCE CATEGORY'. exe. recode los_ (0=2). var lab los_ 'Sample'. val lab /los_ 2'test sample' 1'training sample'. var lab !1 'Observed'. var lab PredCross 'Predicted'. CROSSTABS /TABLES=!1 BY PredCross BY los_ /FORMAT= AVALUE TABLES /CELLS= COUNT TOTAL /COUNT ROUND CELL . del var maxim. !enddefine. /******************************************************************************************************************************************************************************************************************. *example. GET FILE='C:\Program Files\SPSS\Tutorial\sample_files\telco.sav'. crossvalid custcat |FACTORS= retire gender ed |COVARIATES= age income employ |TRAIN=.70.