Post Reply 
Gompertz curve
03-30-2015, 03:09 PM (This post was last modified: 04-02-2015 07:09 AM by salvomic.)
Post: #1
Gompertz curve
hi all,
using a very useful tutorial in "Prime tutorial" (tnx Eddie!) I wrote a little program to get the Gompertz Curve (see here):

Code:

EXPORT Gompertz_curve()
BEGIN
LOCAL cr, cg, cb, I;
LOCAL control:=1;

REPEAT
INPUT({A, B, C},
"Gompertz ae^(-be^(-ct))", {"asymptote A","displacement B","growth rate C" }, {"Asymptote", "Displacement along x", "Growth rate (y scaling)" }, {0,1,1},
{A, B, C});
CASE
IF (B <= 0) THEN MSGBOX ("B must be > 0"); control:=1; B:=1; END;
IF (C <= 0) THEN MSGBOX ("C must be > 0"); control:=1; C:=1; END;
DEFAULT control:=0;
END; // case
UNTIL control < 1;

// Colors
CHOOSE(I, "Choose a Color",
"Red", "Blue", "Orange", "Green");
cr := {255, 0, 255, 0};
cg := {0, 0, 127, 255};
cb := {0, 255, 0, 0};

STARTAPP("Advanced Graphing");
V1 := "Y=A*e^(-B*e^(-C*X))";
V1(COLOR) := RGB(cr(I), cg(I), cb(I));
CHECK(1);
// Plot View
STARTVIEW(1, 1);
END;

Please, feel free to suggest improvements or criticism Smile

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-30-2015, 06:36 PM (This post was last modified: 03-30-2015 06:40 PM by salvomic.)
Post: #2
RE: Gompertz curve
However, about this curve I need help for the "inverse" problem: to use regression (interpolation) for that formula (Y=A*e^(-B*e^(-C*X))) with Statistic 2var (or otherwise).

I have a series of values for X (t, years) and Y (population):
X: 1,2,3,4,5,6,7,8,9
Y: 146583, 150203, 161475, 169182, 177619, 183054, 189431, 193082, 195687
I would get an estimation for A, B, C. (Then predict future values...)

I set in Symb -> Type: "User Defined" and Fit: "A*e^(-B*e^(-C*X))", but I'm not able to get plot and the values of estimated A, B, C, as I would like to have...
Any hints?

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-30-2015, 07:44 PM (This post was last modified: 03-30-2015 08:05 PM by Marcio.)
Post: #3
RE: Gompertz curve
(03-30-2015 06:36 PM)salvomic Wrote:  However, about this curve I need help for the "inverse" problem: to use regression (interpolation) for that formula (Y=A*e^(-B*e^(-C*X))) with Statistic 2var (or otherwise).

I have a series of values for X (t, years) and Y (population):
X: 1,2,3,4,5,6,7,8,9
Y: 146583, 150203, 161475, 169182, 177619, 183054, 189431, 193082, 195687
I would get an estimation for A, B, C. (Then predict future values...)

I set in Symb -> Type: "User Defined" and Fit: "A*e^(-B*e^(-C*X))", but I'm not able to get plot and the values of estimated A, B, C, as I would like to have...
Any hints?

The Prime can't do that. To use customized functions, you can't put unknowns in there, meaning you have to provide values for A, B and C if you want to see data plotted against an equation. The manual discusses this a little bit.

What you could do is try to adjust the customized function to one of the options the Prime gives you. Try to make them equivalent to each other. I often do that. Quite fun.

Alternatively, if you are in a hurry or REALLY need this, I have a program that will fit data to customized functions. It's not fully integrated to the apps just yet but it will work just fine, meaning it will only work on the terminal environment. Shouldn't take more than 1 second to give the results back, provided you enter good initial values.

BTW, you will have to normalize your data before using any (or most) parameter estimation program or app.

Just like this:
Y:=Y/max(Y). That should only change the value of A, which will have to be multiplied by max(Y) after you get the results back. The values of B and C should and will not be affected by this little trick.

Marcio
Find all posts by this user
Quote this message in a reply
03-30-2015, 07:50 PM
Post: #4
RE: Gompertz curve
(03-30-2015 06:36 PM)salvomic Wrote:  However, about this curve I need help for the "inverse" problem: to use regression (interpolation) for that formula (Y=A*e^(-B*e^(-C*X))) with Statistic 2var (or otherwise).

I have a series of values for X (t, years) and Y (population):
X: 1,2,3,4,5,6,7,8,9
Y: 146583, 150203, 161475, 169182, 177619, 183054, 189431, 193082, 195687
I would get an estimation for A, B, C. (Then predict future values...)

I set in Symb -> Type: "User Defined" and Fit: "A*e^(-B*e^(-C*X))", but I'm not able to get plot and the values of estimated A, B, C, as I would like to have...
Any hints?

For this, you could create a system of equations resulting from substituting each pair of X and Y values into the general equation. Then use the generalized Newton's method to determine the least-squares fit. Snorre implemented such a function here:

http://www.hpmuseum.org/forum/thread-455.html#pid24491

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-30-2015, 07:51 PM
Post: #5
RE: Gompertz curve
(03-30-2015 07:44 PM)Marcio Wrote:  The Prime can't do that. To use customized functions, you can't put unknowns in there, meaning you have to provide values for A, B and C if you want to see data plotted against an equation. The manual discusses this a little bit.
I thought that, in fact...
I'm trying to put the unknown but no fit, then...
Quote:What you could do is try to adjust the customized function to one of the options the Prime gives you.
the nearest is surely "logistic regression", but Gompertz is a generalized logistic, not the same thing...
Quote:Alternatively, if you are in a hurry, I have a program that fits data to customized functions, but it's not yet fully integrated to the apps, meaning it will only work on the terminal environment.

Marcio

I could try your solution, if you like to share it...
I was founding a solution in the program suite from Namir (MLRX, BestMLR...) but no one seems to be adapt...

thank you

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-30-2015, 08:08 PM (This post was last modified: 03-30-2015 08:16 PM by salvomic.)
Post: #6
RE: Gompertz curve
(03-30-2015 07:50 PM)Han Wrote:  For this, you could create a system of equations resulting from substituting each pair of X and Y values into the general equation. Then use the generalized Newton's method to determine the least-squares fit. Snorre implemented such a function here:

http://www.hpmuseum.org/forum/thread-455.html#pid24491

thank you Han,
I'm reading the post with the Snorre's method...
but Snorre wrote: «Usage: newton( [f1(x1,...,xn), ..., fm(x1,...,xn)], [x1,...,xn], [xinit1,...,xinitn], thf, thd, kmax )
Prints out the current values of |f(x)| and |d|. Returns x=[x1,...,xn].»
Now, in my case, how to put as xinit1..., thf, thd and kmax?

I tried to use also Solve with 3 equations like you suggest, but perhaps isn't the right method...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-30-2015, 10:07 PM (This post was last modified: 03-31-2015 05:38 PM by salvomic.)
Post: #7
RE: Gompertz curve
(03-30-2015 07:44 PM)Marcio Wrote:  BTW, you will have to normalize your data before using any (or most) parameter estimation program or app.

Just like this:
Y:=Y/max(Y). That should only change the value of A, which will have to be multiplied by max(Y) after you get the results back. The values of B and C should and will not be affected by this little trick.

doing so, I get a logistic as 1.1177/(1+0.6269*e^(-0.1929*X)) and it is very close to the observed data. The asymptote should be about 1.1177 (A)...
This curve seems to fit to my data better than the Gompertz (but a book of mine write that those data are from Gompertz curve...) Smile

manually (empirically) I get for Gompertz A=1.1177, B=0.44, C=.14, but also so, Logistic is a little more close to the data...

Now I can see it in Statistic 2var (also if seems don't fit very well)

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-31-2015, 01:54 PM (This post was last modified: 03-31-2015 03:07 PM by Marcio.)
Post: #8
RE: Gompertz curve
(03-30-2015 10:07 PM)salvomic Wrote:  doing so, I get a logistic as 1.1177/(1+0.6269*e^(-0.1929*X)) and it is very close to the observed data. The asymptote should be about 1.1177 (A)...
This curve seems to fit to my data better than the Gompertz (but a book of mine write that those data are from Gompertz curve...) Smile
manually (empirically) I get for Gompertz A=1.1177, B=0.44, C=.14, but also so, Logistic is a little more close to the data...
Now I can see it in Statistic 2var (also if seems don't fit well, but I now can see who rules A,B,C: my program or ...Statistic? in fact they seem to use the same data, A, B, C ...)

The correct values for A, B and C are 1.151, 0.5191 and 0.1509 respectively. For those, R^2 = 0.9916.

Let me know if you still need the program. I will have to edit it to make it more user-friendly.

And yes, the curves are indeed very similar but only for that region your data covers, outside that area the functions behave differently, that means that the estimates you found for A, B and C using the logistic fit might not be the best for extrapolation.

Marcio
Find all posts by this user
Quote this message in a reply
03-31-2015, 02:04 PM (This post was last modified: 03-31-2015 04:10 PM by salvomic.)
Post: #9
RE: Gompertz curve
(03-31-2015 01:54 PM)Marcio Wrote:  The correct values for A, B and C are 1.151, 0.5191 and 0.1509 respectively. For those, R^2 = 0.9916.
thank you. You're right: so the two curves are more close with the range of our data
Quote:Let me know if you still need the program. I will have to edit it to make it more user-friendly.
you're very kind.
Yes, I would like to try it.
We could also make a program with mine and yours functions to treat Gompertz Curve...
Quote:And yes, the curves are indeed very similar but only for that region your data covers, outside of that area the functions behave differently, that means that the estimates you found for A, B and C using the logistic fit might not be the best for extrapolation.

Marcio

yes, indeed.
With those data I can see (in Statistic 2var) they are however enough close also for extrapolation, but generally speaking above the range there is a difference and with Gompertz often the purpose is to predict future values...
In our case Gompertz seems to be below Logistic in the left tail and over it beyond the range of the Y...

However in this case Logistic is always a good approximation.

***
In the image the two curves (orange Gompertz, green Logistic) in Statistics 2var


Attached File(s) Thumbnail(s)
   

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-01-2015, 03:43 AM (This post was last modified: 04-01-2015 03:56 AM by Marcio.)
Post: #10
RE: Gompertz curve
SAlvomic

The code was sent to you via PM with basic instructions and everything. I will be publishing the new version of it on the forum as soon as I finish a few details. However, if anyone else is interested in the basic version, I can share it via PM.

Marcio
Find all posts by this user
Quote this message in a reply
04-01-2015, 07:22 AM (This post was last modified: 04-01-2015 09:38 AM by salvomic.)
Post: #11
RE: Gompertz curve
(04-01-2015 03:43 AM)Marcio Wrote:  SAlvomic

The code was sent to you via PM with basic instructions and everything. I will be publishing the new version of it on the forum as soon as I finish a few details. However, if anyone else is interested in the basic version, I can share it via PM.

Marcio

very kind of you, thanks!

only a curiosity of mine: why the data to analyze go in C7 and C9?, I mean: do you like 7 and 9 and not 7 and 8? Smile ...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-01-2015, 09:55 AM
Post: #12
RE: Gompertz curve
All the rest was filled up.
You can import data from anywhere, spreadsheet, stat2var app, home variable etc.
Marcio
Find all posts by this user
Quote this message in a reply
04-01-2015, 11:41 AM
Post: #13
RE: Gompertz curve
(04-01-2015 09:55 AM)Marcio Wrote:  All the rest was filled up.
You can import data from anywhere, spreadsheet, stat2var app, home variable etc.
Marcio

thank you, Marcio,
I customized two or three lines, for the rest the program for me is already almost ok!

I'm looking forward for your general solution, when you'll publish in the Forum.

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-01-2015, 11:57 AM (This post was last modified: 04-01-2015 11:58 AM by Marcio.)
Post: #14
RE: Gompertz curve
(04-01-2015 11:41 AM)salvomic Wrote:  I customized two or three lines, for the rest the program for me is already almost ok!

I'm looking forward for your general solution, when you'll publish in the Forum.

You know, having to enter the equation or function directly in the code does not bother me as much. I will see what I can do about it though.

Truth is that I much prefer dealing with numbers than letters.

Marcio
Find all posts by this user
Quote this message in a reply
Post Reply 




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