Fit data to normal and lognormal distribution
|
11-14-2023, 02:24 PM
Post: #1
|
|||
|
|||
Fit data to normal and lognormal distribution
This program is 95% the same as the program in the thread "program to fit data to normal distribution." So I could have changed that thread. But it could be that someone wants to fit the normal distribution function but not the lognormal distribution function and prefers the shorter and simpler program. So I decided to present this program in a new thread. In the forum.swissmicros.com you will find the raw-file as an attechment: Here
a) Application: 1. Set calculator in User-Mode. 2. XEQ NLFIT (Start of program, deleting all registers, setting statistics registers to Reg05) You are asked whether you want to fit a normal or a log-normal distribution: Put in 1 for normal and 2 for log-normal distribution. 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 1: Normal Distribution - 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 NLFIT Alpha -> NV=1, LNNV=2? We want to use normal distribution, therefore 1 R/S -> 0 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 … 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) Example 2: Lognormal distribution: Data: X Y 100 330 200 300 300 270 400 240 500 220 USR XEQ Alpha NLFIT Alpha -> NV=1, LNNV=2? We want to use log-normal distribution, therefore 2 R/S -> 0 Data Input (all data have to be greater than zero): 100 ENTER 330 A -> 1 … 500 ENTER 220 A -> 5 Correction can be done as in example for normal distribution. Computation: C -> a=331,3041 -> R/S -> b=4.4288 -> R/S -> c=-7.7372 -> R/S -> R2=0.9992 Fitted log-normal distribution is Y = a*EXP[(ln(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=600: E -> X? -> 600 R/S -> Ye= 200.8183 (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 or ∑ln(Xi) 06 ∑Xi² or ∑(ln(Xi))² 07 ∑ln(Yi) 08 ∑(ln(Yi))² 09 ∑Xi * ln(Yi) or ∑ln(Xi) * ln(Yi) 10 n 11 ∑Xi^3 or ∑(ln(Xi))^3 12 ∑Xi^4 or ∑(ln(Xi))^4 13 ∑Xi² * ln(Yi) or ∑(ln(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 (283 Bytes): Code: 01 LBL “NLFIT” |
|||
11-14-2023, 04:01 PM
Post: #2
|
|||
|
|||
RE: Fit data to normal and lognormal distribution
Your code has nostalgic effect on me! I remember coding probability distributions that can be put in a linearized multiple regression (with 2 terms) form. That was in 1980/1981.
Cool code! Thanks! Namir |
|||
11-15-2023, 08:40 AM
Post: #3
|
|||
|
|||
RE: Fit data to normal and lognormal distribution
Glad to hear that you like it. It was fun for me programming it.
Thank you as well for your helpful suggestions for improvement, which I used. Best Raimund |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)