Box-Cox变换 SPSS代码

*
* 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'.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值