Post Reply 
Simple Linear Regression
05-23-2015, 04:45 PM
Post: #1
Simple Linear Regression
Nothing fancy, just simple linear regression to fill a niche.

Calculates m and b for the equation y=mx+b, as well as the correlation r.

This program assumes the default ΣREG 11, and stores its results in R17-R19. Modify accordingly if you prefer a non-default stat regs location. No modules required.

Usage:
Enter stat data normally, then run LR to compute m, b, and r, which are stored in R17, R18, and R19 respectively, and also placed on the stack in Z, Y, and X. Run LR again to recompute m, b, and r if stat data is modified.

After running LR, run XHAT and YHAT to predict x or y respectively from the value present in the stack X register. The result will be left in X.

If you run XHAT and YHAT frequently, you may wish to insert local alpha labels at the beginning of those subroutines. Good choices would be b and c, since the shifted functions on those keys feature a prominent "y" and "x" character, and they don't interfere with the stat keys.

Code:
01 LBL "LR"
02 MEAN
03 *
04 RCL 16
05 *
06 CHS
07 RCL 15
08 +
09 RCL 11
10 X^2
11 RCL 16
12 /
13 CHS
14 RCL 12
15 +
16 /
17 STO 17
18 MEAN
19 RCL 17
20 *
21 -
22 STO 18
23 MEAN
24 *
25 RCL 16
26 *
27 CHS
28 RCL 15
29 +
30 RCL 16
31 1
32 -
33 ENTER
34 ENTER
35 SDEV
36 *
37 *
38 /
39 STO 19
40 RCL 18
41 RCL 17
42 RTN

43 LBL "XHAT"
44 RCL 18
45 -
46 RCL 17
47 /
48 RTN

49 LBL "YHAT"
50 RCL 17
51 *
52 RCL 18
53 +
54 RTN
55 END
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Simple Linear Regression - Dave Britten - 05-23-2015 04:45 PM



User(s) browsing this thread: 1 Guest(s)