linear regression

living with the lab
linear regression
exponential and power law relationships
14000
12000
a straight line just doesn’t represent this data very well
y (meters) 10000
8000
6000
4000
2000
0
0
10
20
30
40
x (seconds)
how do we handle cases where x is not linearly related to y?
living with the lab
Class Problem Enter the data below into a spreadsheet, and complete the following activities:
a. Plot y versus x in Excel, and set the title of the plot to “linear y versus linear x”
b. Copy the plot from (a) to another part of your worksheet. Select the vertical axis on the copied plot, right click and select “format axis.” Select logarithmic scale, and change the title of this plot to “log y versus linear x”
c. Copy the plot from (b) to another part of your worksheet. Use a logarithmic axis for the horizontal axis, and change the title of the plot to “log y versus log x”
x
(seconds)
y
(meters)
2
50
6
450
10
1400
14
2600
18
4200
22
6550
www.epa.gov
26
8800
30
11750
2
living with the lab
compare the three plots . . . log y versus linear x
linear y versus linear x
10000
100000
10000
10000
y (meters)
y (meters) 12000
100000
8000
6000
y (meters)
14000
log y versus log x
1000
100
1000
100
4000
10
2000
0
10
1
0
10
20
30
40
1
0
x (seconds)
10
20
30
40
1
x (seconds)
10
100
x (seconds)
do you notice anything special about any of these three plots?
plot
form
equation
physical example
linear versus linear is a straight line
linear
∙
spring: log versus linear is a straight line
exponential
∙
radioactive decay:
log versus log is a straight line
power law
∙
accelerating body:
∙
∙
∙
3
living with the lab
add trendlines & r2 to the previous plots. . . log y versus linear x
linear y versus linear x
100000
14000
y = 418.75x ‐ 2225
R² = 0.9445
10000
y (meters)
y (meters) 10000
8000
6000
4000
2000
100000
y = 123.73e0.1732x
R² = 0.8645
y = 12.457x2.0199
R² = 0.9997
10000
y (meters)
12000
log y versus log x
1000
100
1000
100
10
10
0
‐2000 0
‐4000
10
20
40
1
1
0
x (seconds)

∙
linear
•
•
30
10
20
x (seconds)

∙
exponential
30
40
1
10
100
x (seconds)
∙
power law
which one has the highest r2 value?
a power law relationship best describes the relationship between x and y
what does this mean?
4
living with the lab
math behind power law relationships
∙
log
log ∙
log
log
log
m ∙ log
logarithm rules
take log of both sides
log
log
log
∙
log
log
∙ log
log
plays part of b
“log(y)” plays the part of “y”
x
2
6
10
14
18
22
26
30
y
50
450
1400
2600
4200
6550
8800
11750
log x
0.301
0.778
1.000
1.146
1.255
1.342
1.415
1.477
8.715
∑
∑
“log(x)” plays the part of “x”
log y
1.699
2.653
3.146
3.415
3.623
3.816
3.944
4.070
26.367
2
log x ∙ log y (log x)
0.511
0.091
2.065
0.606
3.146
1.000
3.914
1.314
4.548
1.576
5.123
1.802
5.581
2.002
6.012
2.182
30.901
10.572
2
(log y)
2.886
7.040
9.898
11.662
13.128
14.564
15.559
16.565
91.302
log ∙
.
∙
∑
∑ ∑
∑
.
∙
.
.
26.367
∑
10
12.457 ∙
.
10
.
= 2.020
2.020 ∙ 8.715
8
1.095
12.457
.
5
living with the lab
rewriting equations for power law relationships
equations for linear fits
∑
∑
∑ ∑
∑
∑
∑
replace x with “log x” and y with “log y”
equations for power law fits
∑
log
∙
∑
∑ log
∑ log
∙∑
∑ log
∑ log
10
6
living with the lab
math behind exponential relationships
“ln
∙
logarithm rules
l
l
l ln
l mx ∙ ln
l ” plays the part of “y”
∙
take natural log (ln) of both sides
l l
l l
l ∙l
l
l ln
∙
l
1
plays part of b
equations for exponential fits
∑
∙ ln
∑
∑
∑
∑ ln
∑ ln
ln
∑
7
living with the lab
Class Problem The air that we breathe exerts a significant amount of pressure on objects at sea level (101.3 kPa or 14.7 psi). As we go higher into the atmosphere, the pressure decreases and eventually reaches zero in outer space where there is no air. Pressure measurements were recorded as a function of elevation above sea level resulting in the following table (km = kilometers and kPa = kilopascals):.
altitude
(km)
0.1
5
8
16
33
47
pressure
(kPa)
99.5
50.7
33.8
10.1
1.0
0.1
a)
b)
c)
d)
Hand plot pressure versus elevation using linear‐linear scales.
Hand plot pressure versus elevation using log‐linear scales.
Hand plot pressure versus elevation using log‐log scales.
Based on your hand plots, what type of function is most appropriate (linear, exponential, power law)????
e) Create an Excel spreadsheet, and create a plot of the data along with a trendline showing r2 for linear, exponential and power law functions. Which has the highest r2?
f) If you have time, manually compute m and b for this function using Excel.
equations for exponential fits
∑
∙ ln
∑
∑
∑
∑ ln
∑ ln
ln
∑
8
living with the lab
solution
9