## Two variable regressions for Palm's RPN calculator

regressions.rpn implements linear, logarithmic, exponential and power two variable regressions for Palm's RPN calculator.

### Models

The following regression models are supported:
 linear model expected_y = a x + b logarithmic model expected_y = a ln x + b exponential model expected_y = b exp(a x) power model expected_y = b x**a regressions.rpn sums up the expressions x, x**2, y, y**2, x y, 1, ln x, (ln x)**2, y ln x, ln y, (ln y)**2, x lny, lnx lny. If any of the logarithmic models can't be supported due to negative values, then it will be disabled (correlation returns zero in this case). The user can also manually disable the logarithmic models.

### Functions

 [+] Sum up the expressions needed for the regression calculations. Returns the new n. [-] Subtract expressions. This lets you correct entries made with `[+]`. Returns the new n. clr Clear sums. sum Calculate sums. Returns sum(x), sum(y) mean Calculate mean values. Returns mean(x), mean(y) wm Calculate the weighted mean. Returns wmean(x) where the yi are the weights. sdev Calculate standard deviations. Returns sdev(x), sdev(y). Requires at least two sets of values. Model Regression model chose dialog: `best lin log exp pwr`. `best` calculates all possible regression models and choses the one with the highest correlation-square. Returns the index of the chosen model. x Calculate xf (forecast) from y. y Calculate yf (forecast) from x. a Slope parameter. Zero if the chosen model is illegal (because of negative values). b Offset parameter. r Correlation. Between -1 and 1. Values far from zero are better.

### Sample

To calculate statistics and regressions on the following data sets, enter:

 xi yi 2 11 3 13 5 17 7 19
clr
11 Enter 2 [+]
13 Enter 3 [+]
17 Enter 5 [+]
19 Enter 7 [+]

Statistics results:

 function tab result(s) sum sum 17.0000 60.0000 mean mean 4.2500 15.0000 weighted mean wm 4.6500 standard deviation sdev 2.2174 3.6515

Regressions results:

 model a b r yf(11) xf(23) lin 1.6271 8.0847 0.9881 25.9831 9.1667 log 6.5833 6.1996 0.9964 21.9856 12.8325 exp 0.1099 9.1903 0.9781 30.7775 8.3489 pwr (best) 0.4494 8.0395 0.9972 23.6178 10.3699

### Math used

 The regression parameters a and b are optimized for least squares. The two partial differentials produce a system of equations from which a and b can be calculated. The correlation can be calculated from variances and covariance. See any good math textbook for more information. ### Software

Note: The program is free software; you can redistribute it and/or modify it. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

source: regressions.rpn
source stripped of comments and blanks, to fit into Palm's clipboard: regressions-s.rpn

### Installation

2. Create a new MemoPad entry from the regressions-s.rpn data. Note: the annotated source regressions.rpn won't fit into Palm's clipboard.
3. Hotsync.
4. Copy the transfered memo into Palm's clipboard.
5. Switch to RPN.
6. Import the script by "Add Set".

### Known problems

• With only two pairs of values, the exponential model is returned rather than the linear model when the `best` model is chosen. This is not a bug since with two value pairs, all four models achieve the same correlation 1.