4.1 Transforming Data

Download Report

Transcript 4.1 Transforming Data

Transforming Relationships

AP Statistics Practice of Statistics Section 4.1

What You’ll Learn

  Recognize when the relationship between two variables is either an exponential relationship or a power relationship Perform the appropriate transformation to “linearize” the data, find the LSRL on the transformed points, “untransform” to find a model for the original data

Not everything in Linear!

   We’ve looked at several sets of data in which the relationships are linear in nature What about those relationships that exhibit a different “nonlinear” pattern?

Consider for a moment gypsy moths.

 An outbreak of gypsy moths in Massachusetts from 1978 to 1981 resulted in many acres of defoliated land. The acreages are listed in the following table.

Gypsy Moths

 The data and graph depict the number of acres defoliated by gypsy moths in Massachusetts between 1978 and 1981.

Years Acres of Defoliated land 1978 63042 1979 1980 1981 226260 907075 2826095

 regression on the data, remembering to check residual plot.

Simple Linear Regression Simple linear regression results:

Dependent Variable: Acres Independent Variable: Year Acres = -1.7746007E9 + 896997.4 (Year) Sample size: 4 R (correlation coefficient) = 0.9136 R-sq = 0.8347045 Estimate of error standard deviation: 631139.44

Well a visual of the line doesn’t look too bad, and that’s a great correlation coefficient. (remember though, sometimes “r” is deceptive---be sure to check the residuals!)

The Residuals

 A check of the residuals indicates that a linear model seen!)

So, what type of relationship is this?

Remember from linear regression that when the relationship is linear, the response variable increases (or decreases) by a constant amount.

Years Since 1977 Acres of defoliated land Difference in Acres 1 63042 2 226260 163218 3 907075 680815 4 2826095 1919020 •Notice that the difference between number of acres is not constant •With this in mind and the problem with the residual plot, let’s consider another type of relationship.

Exponential Relationships

  In an exponential relationship, the response variable increases by a fixed percentage of the previous total. In other words, we should be able to multiply the previous value by some constant to get the next one.

from 1990-1993 and only look at the increases for 1-year intervals.

Years Since 1977 Acres of defoliated land Ratio (Next/Prev) 1 63042 2 226260 3.5890

3 907075 4.0090

4 2826095 3.1156

•Notice that although the ratio is not exactly the same (we wouldn’t expect it to be exact with “real” data) that there does appear to be a pretty consistent ratio value.

So How Do We Create the Model?

 If the relationship is an exponential one, we can use a mathematical transformation to “linearize” the data, find the LSRL of the transformed data, then “untransform” to find the model that will fit the original data.

 Ok, so let’s take all of that step by step

Finding the Model

Step 1: Use a mathematical model to “linearize” (create a new data set whose relationship is linear)  If the original data is exponential, find the logarithm (either common log or natural log) of each of the response values.

 When working with years it is also helpful to “code” the year data so our calculators can handle the values (most computer programs are capable of creating models using the full year) To do this we will take each year and subtract 1977 (this way all of our values are > 0) Years Acres of Defoliated land Years Since 1977 Log 10 (acres) 1978 63042 1 4.7996

1979 226260 2 5.3546

1980 907075 3 5.9576

1981 2826095 4 6.4512

Finding the Model

Now, let’s check a scatterplot of the transformed data Notice the change in the pattern from our original data to the transformed data. The logarithm transformation really “straightened our data”. (Using the natural logarithm would have had the same effect, our values would have just been different)

Finding the Model

Step 2: Find the LSRL for the transformed data (remember to check the “r” and the residuals!)

Simple Linear Regression Simple linear regression results:

Dependent Variable: log10(Acres) Independent Variable: Year-1977 log 10 (Acres) = 4.2513404 + 0.5557706 (Year-1977) Sample size: 4 R (correlation coefficient) = 0.9993 R-sq = 0.9985874 Estimate of error standard deviation: 0.033050213

This model looks promising, but remember to check the residuals.

Finding the Model

A check of the residuals confirms that an exponential model is appropriate.

  

“Untransforming” to find the model for our original data

Remember that our goal was to find a model that we could use for prediction of the number of defoliated acres of land for a given year.

The linear model we have would predict the common logarithm of acres. In order for our model to be useful, we need to reverse the transformation to create the model that fits the original data.

Although many transformations are easier to “untransform” after evaluating, we can use the properties of logarithms with both exponential and power (we’ll look at those next) to find the model for our original data.

Properties of Logarithms

 Before we try to “untransform”, let’s review the properties of logarithms you learned in Algebra (yes, you really did learn these!)  Log b xy = log b x + log b y (Addition rule)    Log b Log b x b m n = mlog = n b x (Power rule) (Same base) Log b (x/y) = log b  x – log b y (Subtraction rule) Since any subtraction can be changed to an addition equation, we will not use this last rule much!

 

“Untransforming” exponential expressions

An exponential function takes the form:  y = ab x , where a, b are constants  (This is the form we want to end up with) So, let’s get started log 10 10 log 10 (Acres) = 4.2513404 + 0.5557706 (Year-1977) (Acres) = 10 4.2513404 + 0.5557706 (Year-1977) Acres = 10 4.2513404

(10 .5557706(Year-1977) ) Acres = 17837.7634 (3.5956

(Year-1977) ) Linear regression of the transformed data Raise both sides using power of 10 (same base) Same base law and multiplication law for exponents.

Simplify the constants This is now in the form of y=ab x , where a=17837.7634 and b = 3.5956

Notice that “b” is approximately the average of the ratios (next/prev) we calculated when we began looking for a model.

So, does it fit our original data?

Since our original goal was to find a model that would allow us to predict the number of acres of defoliated land if we knew the year, we need to check to see if our model actually fits the data.

Scatter Plot Gypsy Moth Outbreak 3000000 The model looks pretty good, but as with any model we need to use caution when predicting outside our original data range.

2500000 2000000 1500000 1000000 500000 0 Acres = 1.0

1.5

2.0

2.5

3.0

YearsSince1977 Y earsSince1977 3.5

4.0

4.5

Power Models

   Another important transformation used in modeling is the power model.

Power models have the form  Y = ax b where a and b are constants taking the logarithms for both the response regression for the transformed data, then  “untransform” Let’s look at an example

Fishing Tournament

   In a fishing tournament that you are in charge of you need to find a way to record the weight of each fish caught without destroying or killing the fish.

Since it is easier to measure the length of the fish rather than it’s weight, we must find a way to convert the length to weight.

The local marine research lab has been gracious enough to provide you with the data for the average length and weight at different ages for Atlantic Ocean rockfish which model most fish species growing under normal feeding conditions.

Age (yr) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Length (cm) 5.2

8.5

11.5

14.3

16.8

19.2

21.3

23.3

25.0

26.7

28.2

29.6

30.8

32.0

33.0

34.0

34.9

36.4

37.1

37.7

Weight (g) 2 8 21 38 69 117 148 190 264 293 318 371 455 504 518 537 651 719 726 810

The Data

•Since length is one dimensional and weight is three dimensional we should be able to find a reasonable model using power model (the residuals for a regression on the original data confirms that the variables are NOT linearly related—but we already knew that!) •As before we need to first transform our data but we have to perform transformations on both length and weight

Age (yr) 1 2 3 4 8 9 5 6 7 10 11 12 13 14 15 16 17 18 19 20

Transforming the Data

Length (cm) Log 10 (length) Weight (g) Log 10 (weight) 5.2

8.5

.7160

.9294

2 8 .3010

.9031

33.0

34.0

34.9

36.4

37.1

37.7

11.5

14.3

16.8

19.2

21.3

23.3

25.0

26.7

28.2

29.6

30.8

32.0

1.0607

1.1553

1.2253

1.2833

1.3284

1.3674

1.3979

1.4265

1.4502

1.4713

1.4886

1.5052

1.5315

1.5428

1.5611

1.5694

1.5763

1.5763

518 537 651 719 726 810 21 38 69 117 148 190 264 293 318 371 455 504 1.3222

1.5798

1.8388

2.0682

2.1703

2.2788

2.4216

2.4669

2.5024

2.5694

2.6580

2.7024

2.7143

2.7300

2.8136

2.8567

2.8609

2.9085

This scatterplot indicates that a linear regression on the logarithms of both variables is certainly one to consider.

Linear Regression on the transformed data

Simple linear regression results:

Dependent Variable: log10(Weight(g)) Independent Variable: log10(Length(cm)) log 10 (Weight(g)) = -1.8993973 + 3.049418 log 10 Sample size: 20 R (correlation coefficient) = 0.9993 R-sq = 0.9985228 (Length(cm)) A check of the correlation coefficient is certainly promising (r=.9993), the scatterplot of the transformed data indicates the line fits very well, and most importantly-----look at those residuals!!! Yes, statisticians get very excited when they see residuals that look that good!

“Untransforming” a power model

log 10 (Weight(g)) = -1.8993973 + 3.049418 log 10 (Length(cm)) Linear equation of the transformed data 10 log 10 (Weight(g)) = 10 -1.8993973 + 3.049418 log 10 (length(cm)) Weight = 10 -1.8993973

(10 3.049418log

10 (length(cm)) ) Weight = 10 -1.8993973

(10 log 10 (length(cm)) 3.049418

) Raise both sides using a base of 10 Same base and Multiplication law for exponents Power rule for logarithms Weight = 10 -1.8993973

(length(cm)) 3.049418

) Same base Weight = .01261 (length(cm)) 3.049418

Simplify constants Last check: plot the new model on the original data.

Looks like we’ve got a model that will be very useful for estimating the weight of a fish if we know its length!

Atlantic Ocean Rockfish 900 800 700 600 500 400 300 200 100 0 5 Weight = 10 15 20 25 Length Length Scatter Plot 30 35 40

Are there Other Possibilities?

   There are many other possibilities to transform data in order to find a model. If either an exponential or power model is not appropriate you may try:  Square the response or explanatory variable   Take the square root of either variable Take the reciprocal of either variable The possibilities are endless, but for now we will concentrate mostly on either an exponential or power model.

Transforming on the TI

   There are a couple of different ways to find both an exponential and power regression model on your TI-calculator Using lists to transform Using the built in regression models

Using lists to transform

 We’ll use the Gypsy Moth data first.

Enter in lists 1 & 2 L 1 : years since 1977 L 2 : acres of defoliated land Take the common log of the values in list 2 and put the new values in list 3 L 3 : log (L 2 ) Now do a linear regression on lists 1 & 3 You can check residuals just like we did before to verify this regression.

Now “untransform” as we did before to get the exponential Note: for a power model create another list for the logarithm of the explanatory variable and do the linear regression on these two lists.

  

Using the Regression Models

The TI family of calculators has both an exponential and power model built into the stat calc menus.

Create a list for the explanatory variable and one for the response variable From the home screen  STAT   CALC 0:ExpReg (A:PwrReg) L 1 , L 2   untransforming the residuals from the

How to decide which model

    Creating mathematical models for real data involves a lot of trial and error.

One strategy:  Try a linear model first ( residuals)  Then try an exponential model ( residuals) Then try a power model ( residuals)  If all residuals show a pattern, you can continue to try different transformations or choose the one with the best correlation Remember, no model is perfect, some models are useful…..we wish to find a useful model.