HP Forums

Full Version: Gompertz Model
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Link: http://edspi31415.blogspot.com/2016/04/h...model.html

The program GOMPERTZ fits data {y_1, y_2, y_3, ..., y_m} to the curve y = a * b^c^x

Program:
Code:
EXPORT GOMPERTZ(yl)
BEGIN
LOCAL y,m,n;
// 2nd STEP
y:=SORT(yl);
m:=SIZE(y);
n:=m/3;
LOCAL y1:=SUB(y,1,n);
LOCAL y2:=SUB(y,n+1,2*n);
LOCAL y3:=SUB(y,2*n+1,m);
LOCAL s1:=ΣLIST(LN(y1));
LOCAL s2:=ΣLIST(LN(y2));
LOCAL s3:=ΣLIST(LN(y3));
LOCAL c:=((s3-s2)/(s2-s1))^(1/n);
LOCAL b:=e^((s2-s1)*(c-1)/
(1-c^n)^2);
LOCAL a:=e^(1/n*(s1+(s2-s1)/
(1-c^n)));
LOCAL v:=[[a],[b],[c]];

// Making dmat,ymat
LOCAL dmat,ymat,I,k1,k2,k3,k4;
dmat:=[[0,0,0]];
ymat:=[[0]];
FOR I FROM 0 TO m-1 DO
k1:=b^c^I;
k2:=k1*a/b*c^I;
k3:=k2*LN(b)*I;
k4:=y(I+1)-a*(b^c^I);
dmat:=ADDROW(dmat,[k1,k2,k3],
I+1);
ymat:=ADDROW(ymat,[k4],I+1);
END;
dmat:=DELROW(dmat,I+1);
ymat:=DELROW(ymat,I+1);

// new param
LOCAL vt:=(TRN(dmat)*dmat)*
TRN(dmat)*ymat;
LOCAL v1:=v+vt;
RETURN v1;

END;
Reference URL's