*
* Box-Cox Transformation
*
SET LENGTH=NONE.
SET MXLOOP = 100000000.
MATRIX.
*GET W/VARIABLES=all/FILE=*/missing=OMIT.
GET W/VARIABLES=all/FILE='D:\数学建模\1.sav'/missing=omit.
COMPUTE NR =NROW(W).
COMPUTE NC =NCOL(W).
COMPUTE Y = MAKE(NR,1,0).
COMPUTE PI=4*ARTAN(1).
COMPUTE XX=MAKE(NR,NC,1).
COMPUTE YLAM=MAKE(NR,1,1).
COMPUTE BOXCOX=MAKE(61,2,0).
COMPUTE YTEMP=0.
LOOP II=1 TO NR.
COMPUTE Y(II,1)=W(II,1).
LOOP JJ=1 TO NC-1.
COMPUTE XX(II,JJ+1)=W(II,JJ+1).
END LOOP.
COMPUTE YTEMP=YTEMP+LN(Y(II)).
END LOOP.
LOOP TEMP=1 TO 61.
COMPUTE LAMBDA=-3.1 + TEMP * 0.1.
DO IF LAMBDA=0.
COMPUTE YLAM(:)=LN(Y(:)).
ELSE.
COMPUTE YLAM(:)=(Y(:)&**LAMBDA -1)/LAMBDA.
END IF.
COMPUTE BETA=INV(T(XX)*XX)*T(XX)*YLAM.
COMPUTE MSE = T(YLAM-XX*BETA)*(YLAM-XX*BETA)/NR.
COMPUTE LOGLIKE= -1*NR/2*LN(2*PI)-NR/2*LN(MSE)-1/2+(LAMBDA-1)*YTEMP.
COMPUTE BOXCOX(TEMP,1)= LAMBDA.
COMPUTE BOXCOX(TEMP,2)= LOGLIKE.
END LOOP.
SAVE BOXCOX /OUTFILE=*.
END MATRIX.
RENAME VARIABLES COL1= LAMBDA COL2= LOGLIKE.
GRAPH
/SCATTERPLOT(BIVAR)=LAMBDA WITH LOGLIKE /MISSING=LISTWISE
/TITLE= 'Log-Likelihood versus lambda'.
Box-Cox变换 SPSS代码
最新推荐文章于 2024-09-09 11:24:23 发布