
In statistics, the Box-Cox transformation of the response variable Y is used to make the linear model more appropriate to the data. It can be used to attempt to impose linearity, reduce skewness or stabilize the residual variance. The Box-Cox transformation is defined as:

*
* Box-Cox Transformation
*
SET LENGTH=NONE.
SET MXLOOP = 100000000.
MATRIX.
GET X/VARIABLES=x/MISSING=OMIT.
GET Y/VARIABLE=y /MISSING=OMIT.
COMPUTE NR =NROW(X).
COMPUTE NC =NCOL(X).
COMPUTE PI=4*ARTAN(1).
COMPUTE XX=MAKE(NR,NC+1,1).
COMPUTE YLAM=MAKE(NR,1,1).
COMPUTE BOXCOX=MAKE(61,2,0).
COMPUTE YTEMP=0.
LOOP I=1 TO NR.
COMPUTE XX(I,1)=1.
COMPUTE XX(I,2)=X(I).
COMPUTE YTEMP=YTEMP+LN(Y(I)).
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'.

讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~