/* Custom-made function Overfit */ /* Data from Holton(2003)"Value-at-Risk" */ new; cls; let data[10,2]= 1.1 2.14 1.4 2.60 2.5 1.15 2.7 1.19 3.2 1.88 3.6 1.55 4.1 2.65 4.3 3.80 4.5 4.46 4.9 6.35 ; x=data[.,1]; y=data[.,2]; start={0,0,0}; fn function(b)=b[1]+exp(b[2]*x)+b[3]*x; /* You can set this. */ fn fct(b)=(y-function(b))'(y-function(b)); screen off; { b,f,g,ret }=QNewton( &fct,start ); screen on; print "b=" b; points=1000; xx=seqa(minc(x),(maxc(x)-minc(x))/(points-1),points-1)|maxc(x); /* graph */ library pgraph; graphset; pqgwin auto; begwind; window(1,1,0); scale(-0.05*(maxc(x)-minc(x))+minc(x)|maxc(x)+0.05*(maxc(x)-minc(x)),-0.25*(maxc(y)-minc(y))+minc(y)|maxc(y)+0.25*(maxc(y)-minc(y))); setwind(1); title("nonlinear function"); _plctrl=-1; _pcolor=15; _psymsiz=1; xy(x,y); setwind(1); _plctrl=0; _pcolor=10; x=xx; /* switch data to x's sequence to draw a curve */ xy(xx,function(b)); endwind;