new; /* KERNEL.GPR: Nonparametric Kernel Density and Series Estimation of an Unkown Regression Function By Woocheol Kim, Ylae University, April, 1998 */ load a[1500,2]=dat1.asc; library pgraph; graphset; y =a[.,1]; x =a[.,2]; n =1500; s =stdc(x); /** *** Nonparametric Estimation **/ /****************** h =1.5*s*n^(-1/5); inc =1; f ={}; i =1; do until i gt n; p =1/(n*h).*sumc(pdfn((x[i]-x)./h)); fp =1/(n*h).*sumc(y.*pdfn((x[i]-x)./h)); f =f|(fp/p); i =i+inc;i; endo; output file=a:\q8\ker.asc reset; f; output off; ***********************/ load f[]=a:\q8\ker.asc; /*_ptek ="nonpara.tkf"; _pdate =""; _plctrl =-1; _pstype ={1}; _psymsiz={1}; title("Nonparametric Regression(Data2)\LKernel Estimator:"); _plegctl={2,5,1,1}; _plegstr="h=1.5*SD*n^(-1/5)"; xlabel("X"); ylabel("fhat"); xy(x,f);*/ /*** ****Series Estimation ***/ xx=ones(n,1)~x; yh ={}; @place for the estimated values @ mxp =3; @maximum power in the series estimation @ j =2; do until j gt mxp; xx =xx~x^j; b =inv(xx'xx)*xx'y; yh =yh~xx*b; j =j+1; endo; yh=yh[.,2]; /*_plctrl =-1; _ptek ="series.tkf"; title("Series Regression\LUsing Data2"); _plegctl={2,4,1,1}; _plegstr="y=b0+b1*x+b2*x^2+b3*x^3+b4*x^4"; xy(x,yh);*/ load beta=a:\q1&2\q_dat1; yhat = exp( (xx*beta)) ; title("Fig 4:kernel vs Series vs nonlinear Regression\LUsing Data1"); _plctrl =-1; _pstype ={1,3,5}; _psymsiz={0.5,1.5,2.5}; /*_ptek ="compa.tkf";*/ _plegctl={2,4,1,1}; _plegstr="h=1.5*SD*n^(-1/5)\0"\ "y=b0+b1*x+b2*x^2+b3*x^3+b4*x^4\0"\ "y=exp(b0+b1*x+b2*x^2+b3*x^3+b4*x^4)"; xy(x,f~yh~yhat);