## How to show confidence interval value on Box Cox transformation?

Solved
Occasional Contributor
Posts: 7

# How to show confidence interval value on Box Cox transformation?

Hei all.. I need help to show confidence interval value on Box Cox transformation.
I dont know source code for do it. hope someone can help me.

thanks.

Accepted Solutions
Solution
‎01-18-2017 07:59 AM
SAS Super FREQ
Posts: 3,839

## Re: How to show confidence interval value on Box Cox transformation?

Okay, the best way I can think of is to copy the Stat.Transreg.Graphics.BoxCoxPlot2

template and add a legend entry for the LOWER and UPPER bounds. The details are in the SAS/STAT documentation, in the chapter on "Statistical Graphics Using ODS".  For even more details, see the chapter "Graph Template Modification" in Warren Kuhfeld's free e-book Basic ODS Graphics Examples.

I'll break the task into steps:

1. Use PROC TEMPLATE to see the template used by the BoxCoxPlot:

``````proc template;
source Stat.Transreg.Graphics.BoxCoxPlot2;
run;``````

2. Copy that definition from the SAS log into a PROC TEMPLAE; ... RUN; block.

3. Modify the GTL so that the DYNAMIC variables LOWER and UPPER appear in a legend.  In the following example, I moved the inset from the lower plot (where there isn't much room) into the upper plot where there is more room:

``````/* for debugging:
ods path (prepend) work.template(update); */
proc template;
define statgraph Stat.Transreg.Graphics.BoxCoxPlot2;
notes "Log Likelihood and t Square Plot";
dynamic
var 'Box-Cox variable name'
lab 'Box-Cox variable label'
varorlab 'label or name when no label'
p05 't or t**2 at p=0.05'
p01 't or t**2 at p=0.01'
p001 't or t**2 at p=0.001'
lower best upper yaxislabel ci head actuallambda legend
footernote legendtitle _byline_ _bytitle_ _byfootnote_;
begingraph;
layout lattice / columndatarange=union rowgutter=0 rows=2
shrinkfonts=true rowweights=(0.6 0.4);
layout overlay / xaxisopts=(display=none) yaxisopts=(
label=YAXISLABEL);
bandplot y=TORF limitlower=LOWER limitupper=UPPER /
legendlabel=CI fillattrs=GRAPHCONFIDENCE extend=
true;
seriesplot y=TORF x=UPPERLAMBDA / group=PARAMETER
index=INDEXVAR includemissinggroup=false tip=(y
x group) name="Parameter" primary=true;
seriesplot y=TORF x=UPPERLAMBDA / group=EFFECT
index=INDEXVAR includemissinggroup=false tip=(y
x group);
referenceline x=LOWER;
referenceline x=BEST;
referenceline x=UPPER;
/* EDIT: Here is new GTL which adds an inset */
layout gridded / autoalign=(topright topleft
bottomright bottomleft right left top bottom)
rows=4;
entry "Selected " { Unicode LAMBDA } " = " ACTUALLAMBDA;
entry "Lower " { Unicode LAMBDA } " = " LOWER;
entry "Upper " { Unicode LAMBDA } " = " UPPER;
discretelegend "band" / halign=right border=false;
endlayout;
endlayout;
layout overlay / xaxisopts=(label="Lambda") yaxisopts=
(label="Log Likelihood" shortlabel="Log Like");
bandplot y=LOGLIKE limitlower=LOWER limitupper=
UPPER / name="band" legendlabel=CI fillattrs=
GRAPHCONFIDENCE extend=true;
seriesplot y=LOGLIKE x=LAMBDA / primary=true tip=(y
x);
referenceline x=LOWER;
referenceline x=BEST;
referenceline x=UPPER;
/* EDIT: Old inset used to be here */
if (LEGEND)
discretelegend "Parameter" / title=LEGENDTITLE;
endif;
endlayout;
endlayout;
if (^LEGEND)
entryfootnote FOOTERNOTE;
endif;
if (_BYTITLE_)
entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else
if (_BYFOOTNOTE_)
entryfootnote halign=left _BYLINE_;
endif;
endif;
endgraph;
end;
run;``````

4. The previous steps only need to be completed one time. Now every time that you run PROC TRANSREG, the new template will be used to layout the graph:

``````/* Example from TRANSREG docuemtnation */
proc format;
value a -1 =   8 0 =   9 1 =  10;
value l -1 = 250 0 = 300 1 = 350;
value o -1 =  40 0 =  45 1 =  50;
run;

data yarn;
input Fail Amplitude Length Load @@;
format amplitude a. length l. load o.;
label fail = 'Time in Cycles until Failure';
datalines;
674 -1 -1 -1    370 -1 -1  0    292 -1 -1  1    338  0 -1 -1
266  0 -1  0    210  0 -1  1    170  1 -1 -1    118  1 -1  0
90  1 -1  1   1414 -1  0 -1   1198 -1  0  0    634 -1  0  1
1022  0  0 -1    620  0  0  0    438  0  0  1    442  1  0 -1
332  1  0  0    220  1  0  1   3636 -1  1 -1   3184 -1  1  0
2000 -1  1  1   1568  0  1 -1   1070  0  1  0    566  0  1  1
1140  1  1 -1    884  1  1  0    360  1  1  1
;

ods graphics on;
proc transreg details data=yarn;
model BoxCox(fail / convenient lambda=-2 to 2 by 0.05) = identity(length);
run;
``````

All Replies
SAS Super FREQ
Posts: 3,839

## Re: How to show confidence interval value on Box Cox transformation?

[ Edited ]

If you use PROC TRANSREG, you get the interval and graph for free. See the documentation for PROC TRANSREG. For details, see the details section "Box-Cox Transformations."

Occasional Contributor
Posts: 7

## Re: How to show confidence interval value on Box Cox transformation?

I have to use proc transreg, source code below:

proc transreg data=VARIMAX details;
title2 'Defaults';
model boxcox(Ekspor / lambda=-3 to 3 by 0.01) = identity(z);
run;

SAS Super FREQ
Posts: 3,839

## Re: How to show confidence interval value on Box Cox transformation?

Can you post what you want it to look like?  For example, do you want an inset with the lower95 and upper95 values?

Occasional Contributor
Posts: 7

## Re: How to show confidence interval value on Box Cox transformation?

yes, I want to inset lower95 and upper95 values.

Solution
‎01-18-2017 07:59 AM
SAS Super FREQ
Posts: 3,839

## Re: How to show confidence interval value on Box Cox transformation?

Okay, the best way I can think of is to copy the Stat.Transreg.Graphics.BoxCoxPlot2

template and add a legend entry for the LOWER and UPPER bounds. The details are in the SAS/STAT documentation, in the chapter on "Statistical Graphics Using ODS".  For even more details, see the chapter "Graph Template Modification" in Warren Kuhfeld's free e-book Basic ODS Graphics Examples.

I'll break the task into steps:

1. Use PROC TEMPLATE to see the template used by the BoxCoxPlot:

``````proc template;
source Stat.Transreg.Graphics.BoxCoxPlot2;
run;``````

2. Copy that definition from the SAS log into a PROC TEMPLAE; ... RUN; block.

3. Modify the GTL so that the DYNAMIC variables LOWER and UPPER appear in a legend.  In the following example, I moved the inset from the lower plot (where there isn't much room) into the upper plot where there is more room:

``````/* for debugging:
ods path (prepend) work.template(update); */
proc template;
define statgraph Stat.Transreg.Graphics.BoxCoxPlot2;
notes "Log Likelihood and t Square Plot";
dynamic
var 'Box-Cox variable name'
lab 'Box-Cox variable label'
varorlab 'label or name when no label'
p05 't or t**2 at p=0.05'
p01 't or t**2 at p=0.01'
p001 't or t**2 at p=0.001'
lower best upper yaxislabel ci head actuallambda legend
footernote legendtitle _byline_ _bytitle_ _byfootnote_;
begingraph;
layout lattice / columndatarange=union rowgutter=0 rows=2
shrinkfonts=true rowweights=(0.6 0.4);
layout overlay / xaxisopts=(display=none) yaxisopts=(
label=YAXISLABEL);
bandplot y=TORF limitlower=LOWER limitupper=UPPER /
legendlabel=CI fillattrs=GRAPHCONFIDENCE extend=
true;
seriesplot y=TORF x=UPPERLAMBDA / group=PARAMETER
index=INDEXVAR includemissinggroup=false tip=(y
x group) name="Parameter" primary=true;
seriesplot y=TORF x=UPPERLAMBDA / group=EFFECT
index=INDEXVAR includemissinggroup=false tip=(y
x group);
referenceline x=LOWER;
referenceline x=BEST;
referenceline x=UPPER;
/* EDIT: Here is new GTL which adds an inset */
layout gridded / autoalign=(topright topleft
bottomright bottomleft right left top bottom)
rows=4;
entry "Selected " { Unicode LAMBDA } " = " ACTUALLAMBDA;
entry "Lower " { Unicode LAMBDA } " = " LOWER;
entry "Upper " { Unicode LAMBDA } " = " UPPER;
discretelegend "band" / halign=right border=false;
endlayout;
endlayout;
layout overlay / xaxisopts=(label="Lambda") yaxisopts=
(label="Log Likelihood" shortlabel="Log Like");
bandplot y=LOGLIKE limitlower=LOWER limitupper=
UPPER / name="band" legendlabel=CI fillattrs=
GRAPHCONFIDENCE extend=true;
seriesplot y=LOGLIKE x=LAMBDA / primary=true tip=(y
x);
referenceline x=LOWER;
referenceline x=BEST;
referenceline x=UPPER;
/* EDIT: Old inset used to be here */
if (LEGEND)
discretelegend "Parameter" / title=LEGENDTITLE;
endif;
endlayout;
endlayout;
if (^LEGEND)
entryfootnote FOOTERNOTE;
endif;
if (_BYTITLE_)
entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else
if (_BYFOOTNOTE_)
entryfootnote halign=left _BYLINE_;
endif;
endif;
endgraph;
end;
run;``````

4. The previous steps only need to be completed one time. Now every time that you run PROC TRANSREG, the new template will be used to layout the graph:

``````/* Example from TRANSREG docuemtnation */
proc format;
value a -1 =   8 0 =   9 1 =  10;
value l -1 = 250 0 = 300 1 = 350;
value o -1 =  40 0 =  45 1 =  50;
run;

data yarn;
input Fail Amplitude Length Load @@;
format amplitude a. length l. load o.;
label fail = 'Time in Cycles until Failure';
datalines;
674 -1 -1 -1    370 -1 -1  0    292 -1 -1  1    338  0 -1 -1
266  0 -1  0    210  0 -1  1    170  1 -1 -1    118  1 -1  0
90  1 -1  1   1414 -1  0 -1   1198 -1  0  0    634 -1  0  1
1022  0  0 -1    620  0  0  0    438  0  0  1    442  1  0 -1
332  1  0  0    220  1  0  1   3636 -1  1 -1   3184 -1  1  0
2000 -1  1  1   1568  0  1 -1   1070  0  1  0    566  0  1  1
1140  1  1 -1    884  1  1  0    360  1  1  1
;

ods graphics on;
proc transreg details data=yarn;
model BoxCox(fail / convenient lambda=-2 to 2 by 0.05) = identity(length);
run;
``````
Occasional Contributor
Posts: 7

## Re: How to show confidence interval value on Box Cox transformation?

thanks Sir. but when I use identity is variable z where z is zero, that can't show lower and upper tail. I use z is zero because my case is Box Cox transformation to time series data. Please correct me if i'm wrong.

my code,

```proc transreg data=VARIMAX details;
title2 'Defaults';
model boxcox(Ekspor / convenient lambda=-3 to 3 by 0.25) = identity(z);
run;```

SAS Super FREQ
Posts: 3,839

## Re: How to show confidence interval value on Box Cox transformation?

Sorry, but I do not understand what you are saying about the z variable. Is z always zero? Is Z discrete?

By the way, from your image the CI is obviously [-0.25, 1].

I have shown you how to create the plow you want.  If you are running an old version of SAS, your ODS template might have a different name or contents, but the process is the same.  I think I have answered your original question.

Occasional Contributor
Posts: 7

## Re: How to show confidence interval value on Box Cox transformation?

as far as I know, box cox transformation for univariate (ex: Ekspor variable), then use zero variable for identity.

Occasional Contributor
Posts: 7

## Re: How to show confidence interval value on Box Cox transformation?

yes Sir. you have that. thanks for your help.

☑ This topic is solved.