Article View: bit.listserv.stat-l
Article #3568Re: Box-Cox transformation
From: Thomas E. Sabin
Date: Mon, 27 Jan 1992 18:47
Date: Mon, 27 Jan 1992 18:47
72 lines
2778 bytes
2778 bytes
Below is a program from a paper on transformations that I wrote soon to be
incorporated into a book. The program computes the Box-Cox transformation
for the interval from -1 to 1 and plots the result. It is easily adjusted
to compute outside this interval. Text in lower case is to be entered by
the user for their dataset. Any comments are appreciated.
**************************************************************************
* Tom Sabin | sabin@fsl.orst.edu *
* Statistical Consultant \|/ (503) 737-6577 *
* Dept. Forest Science \\|// *
* Oregon State University \\\|/// *
* Corvallis, Oregon 97331 | *
**************************************************************************
DATA GM1;
SET dataset; /* Specify dataset name */
Y = response variable; /* Y is the response variable */
LOGY = LOG(Y);
RUN;
PROC MEANS NOPRINT;
VAR LOGY;
OUTPUT OUT=SUM N=N SUM=;
RUN;
DATA GM2;
SET SUM;
GM=EXP(LOGY/N);
DROP _TYPE_;
RUN;
DATA BOXCOX;
IF _N_=1 THEN SET GM2;
SET GM1;
ARRAY X{17} X1-X17;
ARRAY Z{17} Z1-Z17;
DO I=1 TO 17;
X{I} = 0.125*(I-1) - 1; /* Subtract larger or smaller number
to alter interval */
IF X{I} NE 0 THEN
Z{I} = (Y**X{I} - 1)/(X{I}*(GM**(X{I}-1)));
ELSE Z{I} = GM*LOG(Y);
END;
RUN;
PROC REG OUTEST=RSS DATA=BOXCOX NOPRINT;
/* Specify predictor variables and p = # predictor variables */
MODEL Z1-Z17 = predictor variables / SELECTION=RSQUARE START=p SSE;
RUN;
DATA NEW;
IF _N_=1 THEN SET GM2;
SET RSS;
ARRAY X{17} X1-X17;
DO I=1 TO 17;
X{I} = 0.125*(I-1) - 1; /* Subtract larger or smaller number
to alter interval */
END;
LAMDA = X{_N_};
RSS = _SSE_;
L = -0.5*N*LOG(RSS/N);
RUN;
PROC PRINT NOOBS;
VAR LAMDA RSS L;
RUN;
PROC PLOT;
PLOT L*LAMDA;
RUN;
Technical Details
Message-ID:
<784@ccmail.orst.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!paladin.american.edu!auvm!CCMAIL.ORST.EDU!SABINTShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5efb,4547c624b5248d46 X-Google-Attributes: gidf5efb,public X-Google-ArrivalTime: 1992-01-27 12:08:09 PST Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!paladin.american.edu!auvm!CCMAIL.ORST.EDU!SABINT Message-ID: <784@ccmail.orst.edu> Newsgroups: bit.listserv.stat-l Date: Mon, 27 Jan 1992 11:47:52 PDT Sender: "STATISTICAL CONSULTING" <STAT-L@MCGILL1.BITNET> From: "Thomas E. Sabin" <sabint@CCMAIL.ORST.EDU> Subject: Re: Box-Cox transformation