Program to fit data to normal distribution function
|
11-12-2023, 07:37 PM
(This post was last modified: 11-13-2023 08:41 AM by rawi.)
Post: #1
|
|||
|
|||
Program to fit data to normal distribution function
Program to fit data to normal distribution function.
a) Application: 1. Set calculator in User-Mode. 2. XEQ NFIT (Start of program, deleting all registers and stack, setting statistics registers to Reg05) 3. Put in data: For every data point: X ENTER Y A -> Number of data points so far is shown. Correction of last data point: B 4. Compute results: C. Parameters a, b, c, R² are shown. Show results again: D Whereas a, b, c are the parameters of the following function: Y = a*EXP[(X-b)²/c] and R² is the coefficient of determination. 5. Compute estimate of Y for given X: E -> X? -> Put in given X-value R/S -> Estimated Y Ye b) Example: Data of heights of a group of persons and frequency: Height (X) Frequency in % (Y) 53 6.25 54 6.25 55 6.25 56 12.5 57 18.75 58 18.75 59 12.5 60 12.5 62 6.25 USR XEQ Alpha NFIT Alpha Data Input: 53 ENTER 6.25 A -> 1 54 ENTER 6.25 A -> 2 55 ENTER 6.75 A -> 3 (Error) B -> 2 (The last data point is deleted) 55 ENTER 6.25 A -> 3 (Correct input) 56 ENTER 12.5 A -> 4 57 ENTER 18.75 A ->5 … 62 ENTER 6.25 ->9 Computation: C -> a=15.0203 -> R/S -> b=57.8945 -> R/S -> c=-20.586 – R/S -> R2=0.7477 Fitted normal distribution is Y = a*EXP[(X-b)²/c] The parameters a, b, c, R² are stored in registers 01, 02, 03, 04. Results are shown again by pressing D. Estimate Y for X=61: E -> X? 61 R/S -> Ye= 9.4020 (Estimate for Y) c) Registers used: 01 – 21 01 a / ln Y a=EXP(R21-R20²/4/R19) 02 b / X b=-R20/2/R19 03 c c=1/R19 04 R² R²=(R21*R07+R20*R09+R19*R13-R07²/R10)/(R08-R07²/R10) 05 ∑Xi 06 ∑Xi² 07 ∑ln(Yi) 08 ∑(ln(Yi))² 09 ∑Xi * ln(Yi) 10 n 11 ∑Xi^3 12 ∑Xi^4 13 ∑Xi² * ln(Yi) 14 R06*R10-R05² 15 R10*R13-R06*R07 16 R10*R11-R05*R06 17 R10*R09-R05*R07 18 R10*R12-R06² 19 (R14*R15-R16*R17)/(R14*R18-R16²) 20 (R17-R16*R19)/R14 21 (R07-R20*R05-R19*R06)/R10 d) Program listing (256 Bytes): Code: 01 LBL "NFIT" f) Link to RAW-file https://www.dropbox.com/scl/fo/ri5v9o43r...7b5w9&dl=0 |
|||
11-12-2023, 11:04 PM
Post: #2
|
|||
|
|||
RE: Program to fit data to normal distribution function
Link to .raw file?
Love the program. I remember in the early 80s I wrote several programs that fit data to popular statistical distributions and set them the the Users' Library in Corvallis! Namir |
|||
11-13-2023, 05:30 AM
Post: #3
|
|||
|
|||
RE: Program to fit data to normal distribution function
Hi Namir,
Thank you for your interest and your friendly word. I wanted to attach the raw-file to the post but did not realize that raw-files are not accepted as attachments. So I added a link to a Dropbox at the end of the original post, I hope that works. Furthermore I improved the program and added the possibility to estimate Y for a given X. This is included in the original post. Best Raimund |
|||
11-13-2023, 06:19 AM
Post: #4
|
|||
|
|||
RE: Program to fit data to normal distribution function
Thanks for the link. It worked and I was able to download the .raw file and import it to my HP-41CX emulator. I went ahead and added the following lines (as the last commands in LBL C) to display the values of a, b, c, and R squared using:
Code: "a=" The program woks like a charm! Thank you! Namir |
|||
11-13-2023, 08:01 AM
Post: #5
|
|||
|
|||
RE: Program to fit data to normal distribution function
Hi Namir,
thank you very much. Your suggestion improves the user experience a lot. So I included it in the program. I added another subroutine name D to display results again and the subroutine for the estimation of Y for a given X was renamed E, which is better for estimation. Original post and raw-file were updated accordingly. Best Raimund |
|||
11-13-2023, 12:37 PM
Post: #6
|
|||
|
|||
RE: Program to fit data to normal distribution function
(11-13-2023 05:30 AM)rawi Wrote: Hi Namir, An easy workaround is to simply rename the file as a text file and then you can attach it to a post here. Although you should note in your post that it has been renamed for convenience, it's better to also keep that right in the file's name as a reminder, so for example rename MYFILE.RAW to MYFILE.RAW.TXT. --Bob Prosperi |
|||
11-13-2023, 08:22 PM
Post: #7
|
|||
|
|||
RE: Program to fit data to normal distribution function
To download the .raw file for my slightly enhanced version of the curve fite program click here.
Namir |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)