Saturday, September 21, 2019

Casio fx-CG50 and TI-84 Plus CE: Multilinear Regression with Correlation

Casio fx-CG50 and TI-84 Plus CE: Multilinear Regression with Correlation

Introduction



The program MULT2LIN calculates multiple linear regression with 2 independent variables x_1 and x_2 and correlation of the data.  The data will be used to fit the plane:

y = b + a_1 * x_1 + a_2 * x_2

by least squares.

The correlation is a calculated by:

R = √(( Y^2 + Z^2 - 2 * X * Y * Z) / (1 - X^2))

where:

Y = correlation between x_1 and y
Z = correlation between x_2 and y
X = correlation between x_1 and x_2

The general correlation between two variables (x,y) is calculated by:

r = ( n * Σxy - Σx * Σy ) / √( (n * Σx^2 - (Σx)^2) - (n * Σy^2 - (Σy)^2) )

Casio fx-CG 50 Program MULT2LIN

This is the text version (MULT2LIN.txt)

'ProgramMode:RUN
"EWS 2019-08-07"
"MULTILINEAR"
"REGRESSION"
"LIST X1: "?->List 2
"LIST X2: "?->List 3
"LIST Y: "?->List 1

If Dim List 1<>Dim List 2 Or Dim List 1<>Dim List 3
Then 
"UNEQUAL LENGTH"DispsStop
IfEnd

LinearReg(a+bx) List 2,List 1
Regression_r->Y
LinearReg(a+bx) List 3,List 1
Regression_r->Z
LinearReg(a+bx) List 2,List 3
Regression_r->X
Sqrt((Y^<2>+Z^<2>-2*X*Y*Z)/(1-X^<2>))->R
"CORRELATION: "RDisps
Dim List 1->Dim List 4
Fill(1,List 4)
List->Mat(List 4,List 2,List 3)->Mat X
List->Mat(List 1)->Mat Y
(Trn Mat X*Mat X)^<-1>*Trn Mat X*Mat Y->Mat B
"_Mat _B:"DispsMat B

Notes:

<>  is ≠

Disps is ⊿

Sqrt is √

Regression_r can be found by [ VARS ] , (STAT), (GRAPH), ( > ), ( r ).   The character r is in bold font. 

fx-CG 50 syntax:

LinearReg(a+bx) y data, x data

List->Mat(column list, column list, ... )

This is what it would look like on the calculator:

"MULTILINEAR"
"REGRESSION"
"LIST X1: "?->List 2
"LIST X2: "?->List 3
"LIST Y: "?->List 1

If Dim List 1 ≠ Dim List 2 Or Dim List 1 ≠ Dim List 3
Then 
"UNEQUAL LENGTH"⊿
Stop
IfEnd

LinearReg(a+bx) List 2,List 1
r->Y
LinearReg(a+bx) List 3,List 1
r->Z
LinearReg(a+bx) List 2,List 3
r->X
√((Y²+Z²-2*X*Y*Z)/(1-X²))->R
"CORRELATION: " ⊿
Dim List 1->Dim List 4
Fill(1,List 4)
List->Mat(List 4,List 2,List 3)->Mat X
List->Mat(List 1)->Mat Y
(Trn Mat X*Mat X)⁻¹*Trn Mat X*Mat Y->Mat B
"_Mat _B:"⊿
Mat B

TI-84 Plus CE Program MULT2LIN

* Can be used on all of the TI-84 and TI-83 family
* This program needs to be typed in

"EWS 2019-08-07"
Disp "MULTLINEAR",
"REGRESSION"
Input "LIST X1: ", L1
Input "LIST X2: ", L2
Input "LIST Y: ", L3
If (dim(L1) ≠ dim(L2)) or (dim(L1) ≠ dim(L3))
Then
Disp "UNEQUAL LENGTH"
Stop
End
LinReg(ax+b) L1, L3
r → Y
LinReg(ax+b) L2, L3
r → Z
LinReg(ax+b) L1, L2
r → X
√( ( Y² + Z² - 2*X*Y*Z ) / (1 - X²) ) → R
Disp "CORRELATION:"
Pause R
dim(L1) → dim(L4)
Fill(1, L4)
List>matr(L4,L1,L2,[A])
List>matr(L3,[C])
([A]^T * [A])⁻¹ * [A]^T * [C] → [B]
Disp "[B] ="
Pause [B]

Notes:

^T is the transpose

TI-84 Syntax:

LinReg(ax+b) x list, y list

List>Mat(column list, column list, column list, .... , matrix)

The output of MULT2LIN

R: correlation of the mutilinear data

A 3 x 1 matrix that represents the coefficients for  b + a_1 * x_1 + a_2 * x_2:

[ [ b ]
  [ a_1 ]
  [ a_2 ] ]

Example

A hiring firm collects data on six potential employees based on the criteria:

* Number of years of education (12 = High School Graduate, 16 = 4-Year Degree, 18 = Masters Degree, 20 = Ph.D)
* Number of years of work experience, including part-time and full-time
* Starting salary at a professional firm

Are education and work experience factors to predicting starting salary?  Data from 7 employees are taken below:



X1 Data: {12, 12, 14, 16, 15, 18, 20}
X2 Data: {0.5, 2, 1.5, 2, 3, 3.5, 5}
Y Data: {30000, 35000, 35000, 50000, 52000, 64000, 100000}

Results:

Correlation:  R = 0.9650583083

Coefficient Matrix:
[ [ -24932.24299 ]
 [ 3539.719626 ]
 [ 9042.056075 ] ]

The estimate equation is:
y = -24932.24299 + 3539.719626 * x1 + 9042.056075 * x2
x1 = Number of years of education
x2 = Number of years of work experience

Source:

Higgins, Jim Ed. D.  "Chapter 4: Introduction to Multiple Regression" Excerpt from the Radical Statistician 2005.  http://www.biddle.com/documents/bcg_comp_chapter4.pdf  Retrieved August 6, 2019

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...