notes11 - Sections 3.9 and 6.8: Transformations Timothy...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sections 3.9 and 6.8: Transformations Timothy Hanson Department of Statistics, University of South Carolina Stat 704: Data Analysis I 1 / 24 Transformations of variables (Section 3.9 & p. 236) Some violations of our model assumptions may be fixed by transforming one or more predictors x1 , . . . , xk or Y . If the only problem is a nonlinear relationship between Y and the predictors, i.e. constant variance seems okay, a transformation of one or more of the x1 , . . . , xk is preferred. If non-constant variance appears in one or more plots of Y versus the predictors, a transformation in Y can help...or make it worse! Data analysis is an art. The best way to learn how to analyze data is to analyze data. A nonlinear relationship could manifest itself the scatterplot matrix of Yi versus xij for j = 1, . . . , k , or the residuals ei versus xij from an initial fit. The chosen transformation should roughly mimic the relationship seen in the plot. 2 / 24 Transformations for xi 1 , . . . , xik Examples of transformations for predictors are: x ∗ = log(x ) √ x∗ = x x ∗ = 1/x x ∗ = exp(x ) or x ∗ = exp(−x ) See Figure 3.13, page 130. 3 / 24 0 50 100 x 150 6 6 q q q qq q qq qq q qq q q qq q qq q qq q q q qq q qq qq q q q qq qq qq q q qq qq q q q qqq q q qq q q qq qq qq q q q qq qq q qq q q q q 1 2 3 log(x) 4 5 4 2 0 2 qq q qq q q q qq q qq q qq q q qq q q qq q q qq q qq q q qq q q q q q q q qq q q q q q q q qq qq qqq qq q qq q q qq q qq qq q qq q q q q q y 4 q y qq qq q qq q q qq qq q qq qq q q qq q q qq q qqq q qq q qq qqq q q q qq q qq q qq qq qq qq qq q q q qq qq qq q q q q q q q q q q 0 0 2 y 4 6 Example 1: transforming a predictor 2 4 6 8 10 sqrt(x) 4 / 24 0.0 1.0 x 2.0 0 1 2 3 x^2 4 5 8 10 6 4 2 qq qq qq qq qq q qq qq qq q q qq q qq q q qq q q qq q q q q qq q q qq q q qq q q qq qq q qq q q qq qq q q q q q qqq qq q q q qq q q q qq q q q qq qq q q y 8 10 6 4 2 qq q q q qq q q q qq q q qq q qq q q q q qq q qq q q q qq qq q qq qq q q qq q qq q qqq qq qq q q q q q q q qq q qq q q q qq q q q qq q q q qq qq q q q y 6 4 2 y 8 10 Example 2: transforming a predictor q qq qq q q qq q q qq qq q q q q q qq qq q q qq q qq q q q q q qq q q qq q q qq q q qq qq q qq q q qq qq q q q qq q q qqq q q q qq q q q qq q qq qq qq qq q 2 4 6 8 10 exp(x) 5 / 24 0.5 1.0 1.5 x 2.0 0.5 1.0 1.5 1/x 2.0 1.5 0.5 q qq q q q q qq q qqq q q q qq q q qq q q q q qq qqq q q qq qq q qq q q q q qq qqq q q qq qq q q q q qq q qq q q qq q qq q q q qq q q q qq qqqqq q qqq q q qqqq q qq q q qqq qq qq q qqq q q qq q qq q q qq q qq q qq q qq q q q q y y q qq q qq qqqq qqq q q qq q q qq qqqq qq qq q qq q q qqqq q q q qq q q qq q q qqqqq qq q q qq q qq q qqqqqq q q qq q q q qqq q q q q q qq q qq qqq q q q q q q q qqq q q qq q q q qq q q q q q q q q qq qqq q q 1.5 q q q q qq qq qq q 0.5 0.5 y 1.5 Example 3: transforming a predictor q q q q q q qq qqq q q q qq qqqq q qq q q q qq qq q qq qq qq qq q q q q q qq qqq q q q qq q qq q q qq q qq qq qq q q qqq q q qq qq q q q qqqq q q q q qqq q q q qq qqqq qqq q qq q qqq q q q qq q qq q q q q qq q q qq q qq q qq q q 0.2 0.4 0.6 exp(−x) 6 / 24 Transforming the response If there is evidence of nonconstant error variance, a transformation of Y can often fix things. Examples include: Y ∗ = log(Y ) √ Y∗ = Y Y ∗ = 1/Y See Figure 3.15, page 132. All of these are included in the Box-Cox family of transformations. For some data, a transformation in Y may be followed by one or more transformations in the xi 1 , . . . , xik . 7 / 24 3.5 q 1.0 1.5 2.0 2.5 2.5 1.5 q qq q q qq q q qq q q qq q qqq q qq q q q q q qqqqqq q qq qqq q qq q q q qq q qq q q q q q q q qq qqq qqq q q qq q q q q q q qq q qq qq q qq q qqq q qq qq q qqq q q qq q q q qq q q q qqq q qq q qqqq qqqqq qq qqqqqq q qqqqqqqqq q qqqq qq q q q q qqq q qq qqq qqq qqq q q q qqq q q q log(y) q 0.5 5 15 y 25 35 Example 4: transforming the response 3.0 q q qq q q q q q qqqq q qqq q q qq q qq q q qqqqqqqqq q qqq q qq qq qq q q q qq q qq q q q q q q q q q q qqq q q q qq qq qq qq q q q q q qq q qqqqq q q q q q q q qqqq q q q qq qq qq qq q qq qq q q q qq q q q q q q qq qq qq q qqq qqq qqqq q qq qq qqq q q qq q qqqq q q q q qq q qq q q qq q q qqq q q q q q qqq q q q 1.0 1.5 2.5 3.0 0.7 x 6 x 2.0 q q 1.0 1.5 2.0 x 2.5 3.0 0.5 0.3 0.1 1/y 4 3 2 sqrt(y) 5 q qq q q q qq q q qq q q qq q qqq q qq q q qq q q q qqqqqq q q qq qq q q q qq qq qq q q q q q qq q q q q qqq qqq q q q q q qq q q q q qq q q q q q q q qqqqq qqq q q q q q q q qqq q q q q qq q qq q q q q q q qq q q qqq q q qqqq qqqq qq qqq q q qq q q qq q q qq q qqqq q q q qqq q qqq q q qqq q q qq q qqq q q q q q q q qqq q q q qq q q q qq q q qq q qq qq q qq qq q q q q qqq qq qqq q q qq qq q qqq qqq qqqq q qq qq q q q qq qq q q qq q qq q qq q q qq qq qq q q qqq qq q qq q qq q qqqqqqqqqqq q q qq q q qq q q q q qq q qq qqqqqqqq q q q q q q q qqqqqqqqq q q q qq q qqqqq qqqqq q qq qqqqqqq q q qq q 1.0 1.5 2.0 2.5 3.0 x 8 / 24 1.0 1.5 2.0 2.5 0.0 −1.0 q q qq q q q q qq q q q q q qq q qq qqq q qq q q q qq q q q qq qq q qqqq q q q q q q qq q q q qq qq q qq qq q q q q q qq q q qqqqqq qq q q q qqq qq q q qq q qqq q q q qqq qq q qqqqqq qqqq qq q qq qqqq qqq q q qq q qqq q q q q qqqqqq q qqqqqq q qqqq q q q q qqqqqqqq q q qq qq qq q qq log(y) y 0.4 0.8 1.2 Example 5: transforming the response 3.0 q qq q q q qq qq q q q q qq q qq qqq q q q q q q qq q q q qq qq q qqqq q q q q q qq q qq q q q qq qq qq qq q q q q qq q q qq qqq q q q q qq q qqq q qq q q q q qq q qq qq q q q q qqq qq q q qq qq qq q q q q qqq qqqq qq qq qq q qqq q qqq qq qq q q qqqqqq q q q q qqqqqq q q qqq qq q qqqqq q qq qq qq q q 1.0 1.5 2.0 2.5 3.0 q q qq q q q q qq q q q q q qq q qq qqq q qq q q q qq q q q qq qq q qqqq q q q q q q qq q q q qq qq q qq qq q q q q q qq q q q q qqqq q qq q q q qqq q qq q q q q q qq q q qq q q q q qq qq qq q q qqqqqqq qq q q qq q qq q qqqqqq qq q q qqqqq qq q qq q q qqqqq q q qq qq q qq qq qq q qqqqq q q qq qqqqq q qq q q qq q qq qqqq qq q qq q q q qq qq q q qqq q q qqqqqq q q q q q qqq qq qq q q qqq qqq q qqqq q qq q qqq qq qq qq qq qqqq q qqq qq q q q qq qq qq q q q q qq q qq q q q q qqqq qq q q q q q q qq q qq qq q q q qq q q q qq qqqq q q q q q qq q q q qq qq qq qq q q q q q qq q q qq q q q qq qq q q qq qq 1.0 1.5 2.0 x 2.5 3.0 1.0 2.0 3.0 x 1/y 1.0 0.8 0.6 sqrt(y) 1.2 x 1.0 1.5 2.0 2.5 3.0 x 9 / 24 Box-Cox transformations Box-Cox transformations are of the type Y∗ = Yλ where λ is estimated from the data, typically −3 ≤ λ ≤ 3. These include λ=2 λ=1 λ=0 λ = −1 λ = −1 Y∗ Y∗ Y∗ Y∗ Y∗ = Y2 =Y no transformation! = log(Y ) by definition = 1/Y reciprocal = 1/Y 2 SAS will help you pick λ automatically in proc transreg. 10 / 24 Interpretation changes with transformed data Note: When working with transformed data, predictions and interpretations of regression coefficients are all in terms of the transformed variables. To state the conclusions in terms of the original variables, we need to do a reverse transformation...carefully. 11 / 24 Example: Electrical components Consider time-to-failure in minutes of n = 50 electrical components. Each component was manufactured using a ratio of two types of materials; this ratio was fixed at 0.1, 0.2, 0.3, 0.4, and 0.5. Ten components were observed to fail at each of these manufacturing ratios in a designed experiment. It is of interest to model the failure-time as a function of the ratio, to determine if a significant relationship exists, and if so to describe the relationship simply. 12 / 24 SAS code: data & plot data elec; input ratio time @@; datalines; 0.5 34.9 0.5 9.3 0.5 0.5 9.0 0.5 19.9 0.5 0.4 16.9 0.4 11.3 0.4 0.4 3.7 0.4 7.2 0.4 0.3 54.7 0.3 13.4 0.3 0.3 35.5 0.3 15.0 0.3 0.2 9.3 0.2 37.6 0.2 0.2 50.5 0.2 40.4 0.2 0.1 373.0 0.1 584.0 0.1 0.1 280.2 0.1 679.2 0.1 ; 6.0 2.3 25.4 18.9 29.3 4.6 21.0 63.1 1080.1 501.6 0.5 0.5 0.4 0.4 0.3 0.3 0.2 0.2 0.1 0.1 3.4 4.1 10.7 2.2 28.9 15.1 143.5 41.1 300.8 1134.3 0.5 0.5 0.4 0.4 0.3 0.3 0.2 0.2 0.1 0.1 14.9 25.0 24.1 8.4 21.1 8.7 21.8 16.5 130.8 562.6 proc sgscatter; plot time*ratio; run; * non-constant variance; proc transreg data=elec; * gets Box-Cox analysis, can use ODS graphics too; model boxcox(time) = identity(ratio); run; Multiple predictors are included with, e.g., identity(ratio temperature) 13 / 24 14 / 24 Box-Cox plot 15 / 24 Box Cox output chooses log(Y ) as “convenient” Box-Cox Transformation Information for time Lambda -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 + 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 R-Square 0.09 0.10 0.11 0.13 0.14 0.17 0.20 0.25 0.31 0.40 0.50 0.59 0.63 0.60 0.53 0.45 0.38 0.33 0.28 0.25 0.22 0.19 0.17 0.16 0.15 Log Like -426.733 -398.478 -370.675 -343.407 -316.779 -290.917 -265.983 -242.186 -219.829 -199.453 -182.292 -171.350 < -171.615 * -184.969 -207.524 -235.373 -266.617 -300.324 -335.898 -372.902 -411.006 -449.964 -489.595 -529.764 -570.371 < - Best Lambda * - 95% Confidence Interval + - Convenient Lambda 16 / 24 Transformed response log(Y ) fixed non-constant variance Add log_time=log(time); in data step and plot again. 17 / 24 Try transforming the predictor using log(x ) Add log_ratio=log(ratio); in data step and plot again. 18 / 24 Try transforming the predictor using √ x Add sqrt_ratio=sqrt(ratio); in data step and plot again. 19 / 24 Diagnostics from regressing log (Y ) on log(x ) 20 / 24 Fit on transformed data 21 / 24 proc reg output Parameter Estimates Variable Intercept log_ratio DF 1 1 Parameter Estimate 0.10974 -2.46441 Standard Error 0.30285 0.20740 t Value 0.36 -11.88 Pr > |t| 0.7187 <.0001 The fitted regression line is log(time) = 0.110 − 2.46 log(ratio). For a ratio of xh = 0.25 we get log(time) = 0.110 − 2.46 log(0.25) = 3.52. Exponentiating both sides we get time = e 3.52 = 33.8 minutes. Question: Is this the estimated mean failure time for the population with ratio xh = 0.25? Is it the estimated median time? 22 / 24 Transforming back... Question: How about a prediction interval? How would you get one? Question: Let g (Y ) ∼ N (µ, σ 2 ) for some g (x ) monotone (and so invertible) function. What is the median of Y ? Question: Let P (a < g (Yh ) < b ) = 0.95 (prediction interval for new g (Yh )). How do you get a prediction interval for Yh ? Question: What can you say about any Box-Cox transformation of the (positive) response (e.g. log, square root, reciprocal)? 23 / 24 Example: Surgical unit example Section 9.2: Surgical unit example (pp. 350–352) x1 = blood-clotting score x2 = prognostic index x3 = enzyme function test score x4 = liver function test score x5 = age (years) x6 = gender (0=male, 1=female) x7 = alcohol use (x7 = 1 indicates moderate) x8 = alcohol use (x8 = 1 indicates severe) Y = survival time (days?) after liver operation For no alcohol use, x7 = x8 = 0 (baseline). 24 / 24 ...
View Full Document

This note was uploaded on 12/14/2011 for the course STAT 704 taught by Professor Staff during the Fall '11 term at South Carolina.

Ask a homework question - tutors are online