qreg() quadratic regression with r
|
12-31-2017, 12:50 AM
(This post was last modified: 12-31-2017 01:21 AM by TheKaneB.)
Post: #1
|
|||
|
|||
qreg() quadratic regression with r
Hi,
I noticed that the HP Prime Statistics 2Var App has got the very useful quadratic regression function, but as I understand it doesn't calculate the correlation coefficient "r" (it just gives NaN). So, I thought it could be a fun exercise to reimplement the quadratic regression from scratch and including the r calculation as well. Code:
example usage Code:
The returned list gives the coefficient for a parabola with the formula f(x) = A + Bx + Cx^2. The order of the coefficient is chosen to be compatible with the built-in function "polynomial_regression". The fourth element in the list L2(4) is the correlation coefficient. You can compare the built-in polynomial_regression(L1, 2) and qreg(L1) and compare the results. From a few, totally non scientific, test that I made the errors seem to be around 1e-10 on average. Sources: Formula used http://keisan.casio.com/exec/system/14059932254941 I believe that the coefficient are correct at least to 8 significant digits, but I'm not 100% sure. Here it is another implementation I did in Python, to check if the algorithm was correct (I find it easier to do a prototype in Python and then translate it to HPPPL later). Code: import math The python version have embedded test data and prints the results. As I said, it's just a quick prototype, not intended for real use, so I didn't bother adding proper argument parsing from the command line. I hope you find it useful, I plan on translating it to the HP 35S later on, if I have time. EDIT: about the example data in the python code. It's a list of measured diameters (in millimeters) and sizes (in GB) of the reflective layer of several DVD-R that I've had around my house. As all of you may know, you can easily see the occupied area of a DVD-R, so I thought I would calculate a formula to get an approximation of the space left on a disk just by measuring the diameter of the written (lighter) area, and since the area grows with the square of the diameter, it seemed appropriate to use a quadratic regression fitting for this task. Software Failure: Guru Meditation -- Antonio IU2KIY |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
qreg() quadratic regression with r - TheKaneB - 12-31-2017 12:50 AM
RE: qreg() quadratic regression with r - TheKaneB - 12-31-2017, 01:22 AM
RE: qreg() quadratic regression with r - Tim Wessman - 12-31-2017, 02:22 AM
RE: qreg() quadratic regression with r - TheKaneB - 12-31-2017, 12:50 PM
RE: qreg() quadratic regression with r - salvomic - 12-31-2017, 01:28 PM
RE: qreg() quadratic regression with r - TheKaneB - 01-01-2018, 12:14 AM
RE: qreg() quadratic regression with r - TheKaneB - 12-31-2017, 12:40 PM
RE: qreg() quadratic regression with r - Tim Wessman - 12-31-2017, 04:22 PM
|
User(s) browsing this thread: 1 Guest(s)