Tuesday, July 18, 2017

Expanding Linear Regression

Expanding Linear Regression


Introduction – Linear Regression

All scientific calculators that have two-variable dimensions has curve fitting.  The most (and universal) curve fitting mode is linear regression.   Linear regression attempts to model bivariate data ((x,y)) to a line by the equation:

y = a + bx

Where a is the y-intercept (ITC) and b is the slope (SLP).  The correlation coefficient, r, is calculated by:

r = SXY / √(SX2 * SY2) where
SX2 = Σ(x – μx)^2
SY2 = Σ(y – μy)^2
SXY = Σ( (x – μx)*(y – μy) )
μx = mean of x values, μy = mean of y values

Source:  HP 17B II Financial Calculator Owner’s Manual, Corvallis, OR  1989.

The best fits are were |r| = 1, or as close to 1 as we can get.  If r is close to 0, the first is not good.  Note that the formula for correlation does not involve the slope or intercept.  We can use this to our advantage.

“Linearize” the Equation

If you can “linearize” equation, we can use the linear regression mode to fit a variety of curves.  The ultimate goal is of course:

y = a + bx

Now, most calculators use the form for linear equations.  However, some switch the a and b around and use the form, like the TI-30X IIS, 

y = ax + b

Hewlett Packard calculators has the b for the intercept and m for slope. 

For clarity, I will use the form Y = ITC + SLP*X. 

  
Calculator Comparison

To demonstrate how we can use the linear regression to fit a variety of curves, I use two calculators:



Sharp EL-W516T which offers 7 regressions.

TI-30X IIS which offers just linear regression.  I use the TI-30X IIS to use the linearized form.

[screen shot of the calcs] 

Sharp EL-W516T
TI-30X IIS
SLP
B
a
ITC
A
b
Linear Regression Equation
y = a + bx
y = ax + b

Screen shots are generated from a Casio fx-CG50. 


Logarithmic Regression:  y = a + b ln x



Translation to Linear:  This is pretty simple, we already have the form that we need, except we note that we have ln x instead of x.  Set the following variables as such:

X = ln x, Y = y, a = ITC, b = SLP

Example data set:
x
y
X = ln x  (8 decimal places)
1.0
2.00
0
1.3
3.00
0.2623643
1.7
4.15
0.5306283
2.3
5.34
0.8329091
2.8
6.10
1.0296194
3.5
7.00
1.252763

To use the linear regression mode, enter the data as such:  (ln x, y).  Everything else remains the same.

Logarithmic Regression Results:
ITC = a = 1.990614146
SLP = b = 4.003372076
r = 0.99905634

Comparing results between using the Logarithmic regression with the Sharp EL-W516T and the Linear regression with the TI-30X IIS, I get the same results.




Exponential Regression:  y  = a*e^(b*x)



Translation to linear: 

y = a*e^(b*x)
ln y = ln (a*e^(b*x))
ln y = ln a + ln(e^(b*x))
ln y = ln a + b*x

We got our form of Y = ITC + SLP*X where:
X = x, Y = ln y, a = e^ITC, b = SLP

When using the linear regression mode, enter data as (x, ln y).  When calculating a, note that

ITC = ln a
e^ITC = a

Example data set:
X
y
Y = ln y  (8 decimal places)
1.0
109.2
4.693181
1.3
363.0
5.8944028
1.7
1795.6
7.4930945
2.3
19794.3
9.8931493
2.8
146260.8
11.893147
3.5
2405208.5
14.693147

Results:
ITC = 0.693829923;  a = 2.001365951
SLP = b = 3.99773169
r = 0.999999992

Inverse Regression: y = a + b/x



Translation to Linear:  Like logarithmic regression, we pretty much have the equation pretty much set, with the exception of 1/x instead of x.  Hence:

X = 1/x, Y = y, a = ITC, b = SLP


 When using the linear regression mode, enter data as (1/x, y). Everything else remains.

Example data set:
X
y
X = 1/x  (8 decimal places)
1.0
6.00
1
1.3
5.55
0.7692308
1.7
5.16
0.5882353
2.3
4.86
0.4347826
2.8
4.73
0.3571429
3.5
4.58
0.2857143

Results:
a = ITC = 4.005529472
b = SLP = 1.993191341
r = 0.999733184

Power Regression:  y = a*x^b



Translation to Linear:  X = ln x, Y = ln y, A = e^a, b

y = a*x^b
ln y = ln (a*x^b)
ln y = ln a + ln(x^b)
ln y = ln a + b * ln x

So we have the following: X = ln x, Y = ln y, ITC = ln a, SLP = b.

In the linear regression mode, enter data as (ln x, ln y). Also, a = e^ITC. 

Example data set:
x
y
X = ln x
Y = ln y
1.0
3.95
0
1.3737156
1.3
6.76
0.2623643
1.9110229
1.7
11.56
0.5306283
2.4475509
2.3
21.09
0.8329091
3.048799
2.8
31.40
1.0296194
3.4468079
3.5
49.00
1.252763
3.8918203

Results:
ITC = 1.379195052; a = e^ITC = 3.971703326
SLP = b = 2.007158681
CORR = r = 0.999991481
   

Table of Linear Regression Equivalents to Curve Fitting


Regression
X
Y
ITC
SLP
Logarithmic: y = a + b * ln x
ln x
y
a
b
Exponential: y = a*e^(b*x)
x
ln y
e^a
b
Inverse: y = a + b/x
1/x
y
a
b
Power: y = a*x^b
ln x
ln y
e^a
b
General Exponential: y = a * b^x
x
ln y
e^a
e^b
Simple Logistic: y = 1/(a + b*e^(-x))
e^(-x)
1/y
a
b
Square Root Linear: y = √(a + b*x)
x
y^2
a
b
Cosine: y = a + b*cos(ω(x – ϕ))
With
ϕ = the point (x) nearest to zero where the trough or peak begins
ω = (2*π)/period (radians) or
ω = 360°/period (degrees)
cos(ω(x – ϕ))
y
a
b


Eddie


This blog is property of Edward Shore, 2016

  Casio fx-7000G vs Casio fx-CG 50: A Comparison of Generating Statistical Graphs Today’s blog entry is a comparison of how a hist...