arg@ccvr1.cc.ncsu.edu (Ron Gallant) (01/12/91)
Submitted-by: arg@ccvr1.cc.ncsu.edu (Ron Gallant) Posting-number: Volume 16, Issue 63 Archive-name: nlmdl/part01 nlmdl is a C++ implementation of the statistical methods in A. Ronald Gallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 1987, using a matrix class, realmat, that is distributed with it. The matrix class may be of some independent interest. It can estimate univariate nonlinear regression models by least squares, multivariate regression models by generalized least squares, simultaneous equations models by three stage least squares, and dynamic simultaneous equations models by generalized method of moments. Errors can be heteroskedastic or serially correlated in any of these models. # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 1 (of 6)." # Contents: MANIFEST Makefile README ch1eg1 ch1eg1/amstat.dat # ch1eg1/ending.bak ch1eg1/model.cc ch1eg1/model.h # ch1eg1/starting.dat ch5eg1 ch5eg1/electb.dat ch5eg1/model.h # ch5eg1/starting.dat ch6eg1 ch6eg1/README ch6eg1/starting.dat # ch6eg2 ch6eg2/end3l.bak ch6eg2/ending.bak ch6eg2/model.cc # ch6eg2/model.h ch6eg2/start3l.dat ch6eg2/starting.dat dcond.cc # dsweep.cc nlmdl.cc patchlevel.h starbox.cc status.h tools.h # usual.h # Wrapped by arg@sparc on Fri Jan 11 20:14:52 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'MANIFEST' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'MANIFEST'\" else echo shar: Extracting \"'MANIFEST'\" \(1664 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X MANIFEST 1 This shipping list X Makefile 1 X README 1 X ch1eg1 1 X ch1eg1/amstat.dat 1 X ch1eg1/detail.bak 3 X ch1eg1/ending.bak 1 X ch1eg1/model.cc 1 X ch1eg1/model.h 1 X ch1eg1/starting.dat 1 X ch5eg1 1 X ch5eg1/detail.bak 2 X ch5eg1/electa.dat 4 X ch5eg1/electb.dat 1 X ch5eg1/electc1.dat 5 X ch5eg1/electc2.dat 5 X ch5eg1/end3l.bak 2 X ch5eg1/ending.bak 2 X ch5eg1/model.cc 3 X ch5eg1/model.h 1 X ch5eg1/starting.dat 1 X ch6eg1 1 X ch6eg1/README 1 X ch6eg1/detail.bak 6 X ch6eg1/ending.bak 2 X ch6eg1/starting.dat 1 X ch6eg2 1 X ch6eg2/detail.bak 3 X ch6eg2/detail3l.bak 2 X ch6eg2/end3l.bak 1 X ch6eg2/ending.bak 1 X ch6eg2/hansen.dat 3 X ch6eg2/model.cc 1 X ch6eg2/model.h 1 X ch6eg2/start3l.dat 1 X ch6eg2/starting.dat 1 X dcond.cc 1 X display.cc 2 X dsweep.cc 1 X nlmdl.cc 1 X nlmdl.h 2 X nlmdl.opr 3 X patchlevel.h 1 X realmat.cc 4 X realmat.h 2 X starbox.cc 1 X status.cc 4 X status.h 1 X tools.h 1 X usual.h 1 END_OF_FILE if test 1664 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(1692 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' XCC = g++ XCFLAGS = -O XRMDIR = .. XNLDIR = .. XMDLDIR = . XLDFLAGS = -lm X Xnlmdl : nlmdl.o status.o display.o model.o \ X realmat.o dcond.o dsweep.o starbox.o X $(CC) -o nlmdl nlmdl.o status.o display.o model.o \ X realmat.o dcond.o dsweep.o starbox.o $(LDFLAGS) X Xnlmdl.o : $(NLDIR)/nlmdl.cc $(NLDIR)/nlmdl.opr \ X $(MDLDIR)/model.h $(NLDIR)/nlmdl.h $(NLDIR)/status.h \ X $(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(NLDIR)/nlmdl.cc X Xmodel.o : $(MDLDIR)/model.cc \ X $(MDLDIR)/model.h $(NLDIR)/nlmdl.h $(NLDIR)/status.h \ X $(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(MDLDIR)/model.cc X Xstatus.o : $(NLDIR)/status.cc \ X $(NLDIR)/status.h \ X $(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(NLDIR)/status.cc X Xdisplay.o : $(NLDIR)/display.cc \ X $(NLDIR)/status.h \ X $(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(NLDIR)/display.cc X Xrealmat.o : $(RMDIR)/realmat.cc \ X $(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/realmat.cc X Xstarbox.o : $(RMDIR)/starbox.cc \ X $(RMDIR)/usual.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/starbox.cc X Xdcond.o : $(RMDIR)/dcond.cc \ X $(RMDIR)/usual.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/dcond.cc X Xdsweep.o : $(RMDIR)/dsweep.cc \ X $(RMDIR)/usual.h $(RMDIR)/tools.h X $(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/dsweep.cc X Xclean : X rm -f *.o core X Xveryclean : X rm -f *.o core nlmdl detail.dat ending.dat tmp.dat END_OF_FILE if test 1692 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(2849 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' X Xnlmdl is a C++ implementation of the statistical methods in A. Ronald Gallant, X"Nonlinear Statistical Models," New York: John Wiley and Sons, 1987, using a Xmatrix class, realmat, that is distributed with it. The matrix class may be Xof some independent interest. X XThe program computes least squares estimates for a univariate nonlinear Xregression model and generalized least squares estimates for a multivariate Xnonlinear regression model. Use the SUR option for both. Other options can Xbe set to correct variance estimates for heteroskedasticity and/or serial Xcorrelation. For simultaneous nonlinear systems, possibly in implicit form, Xit computes three-stage least-squares estimates, TSLS option, and for nonlinear Xdynamic systems, possibly in implicit form, generalized method-of-moments Xestimates, GMM option. X XThe documentation consists of this file, the two header files nlmdl.h and Xrealmat.h, and the examples in the directories ch1eg1, ch5eg1, ch6eg1, and Xch6eg2. X XAs distributed, the code is set up for use with GNU's 1.37 g++ compiler on a XUnix box. To test the code using one of the examples, e.g. ch1eg1, cd to Xch1eg1 and type make -f ../Makefile. Each directory has a file detail.bak Xcreated using nlmdl > detail.bak that used for comparison. For version 1.35 Xof g++, the #undef and #define for I/O style in usual.h will have to be set to XGNU. The code hasn't been tested with other versions. X XThe code can also be used with Borland's Turbo C++ compiler. To use Turbo C++, Xpermute the #undef and #define for compiler choice in usual.h, copy the Xcontents of, e.g., ch1eg1 to the working directory, and list every file with Xa .cc extension in the .PRJ file. Compile with the large memory option. The Xcode hasn't been tested with other C++ compilers. X XUpdates and bug fixes are available via ftp anonymous at ccvr1.cc.ncsu.edu X(128.109.212.20) in directory pub/arg/nlmdl. X XCopyright (C) 1990 by A. Ronald Gallant. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided that Xthe above copyright notice appear in all copies and that both that copyright Xnotice and this permission notice appear in supporting documentation. X XThis software is provided "as is" without any expressed or implied warranty. X X------------------------------------------------------------------------------- XProfessor A. Ronald Gallant Phone: 919-737-2531 XDepartment of Statistics FAX: 919-737-7591 XNorth Carolina State University e-mail: arg@ccvr1.cc.ncsu.edu XCampus Box 8203 ftp: ccvr1.cc.ncsu.edu (128.109.212.20), XRaleigh NC 27695-8203 USA user: anonymous, directory: pub/arg X------------------------------------------------------------------------------- END_OF_FILE if test 2849 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test ! -d 'ch1eg1' ; then echo shar: Creating directory \"'ch1eg1'\" mkdir 'ch1eg1' fi if test -f 'ch1eg1/amstat.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch1eg1/amstat.dat'\" else echo shar: Extracting \"'ch1eg1/amstat.dat'\" \(1020 characters\) sed "s/^X//" >'ch1eg1/amstat.dat' <<'END_OF_FILE' X 1 0.98610 1 1 6.28 X 2 1.03848 0 1 9.86 X 3 0.95482 1 1 9.11 X 4 1.04184 0 1 8.43 X 5 1.02324 1 1 8.11 X 6 0.90475 0 1 1.82 X 7 0.96263 1 1 6.58 X 8 1.05026 0 1 5.02 X 9 0.98861 1 1 6.52 X10 1.03437 0 1 3.75 X11 0.98982 1 1 9.86 X12 1.01214 0 1 7.31 X13 0.66768 1 1 0.47 X14 0.55107 0 1 0.07 X15 0.96822 1 1 4.07 X16 0.98823 0 1 4.61 X17 0.59759 1 1 0.17 X18 0.99418 0 1 6.99 X19 1.01962 1 1 4.39 X20 0.69163 0 1 0.39 X21 1.04255 1 1 4.73 X22 1.04343 0 1 9.42 X23 0.97526 1 1 8.90 X24 1.04969 0 1 3.02 X25 0.80219 1 1 0.77 X26 1.01046 0 1 3.31 X27 0.95196 1 1 4.51 X28 0.97658 0 1 2.65 X29 0.50811 1 1 0.08 X30 0.91840 0 1 6.11 END_OF_FILE if test 1020 -ne `wc -c <'ch1eg1/amstat.dat'`; then echo shar: \"'ch1eg1/amstat.dat'\" unpacked with wrong size! fi # end of 'ch1eg1/amstat.dat' fi if test -f 'ch1eg1/ending.bak' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch1eg1/ending.bak'\" else echo shar: Extracting \"'ch1eg1/ending.bak'\" \(2523 characters\) sed "s/^X//" >'ch1eg1/ending.bak' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 1, Figure 5, p. 35-36. XSUR What estimation method? Code SUR, TSLS, or GMM. X30 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X0 Number of instruments, i.e. dimension of Z. X4 Number of parameters, i.e. dimension of theta. X50 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. Xnone Code none or Parzen, none when MA>0 is unwise. X1.000000e-13 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-10 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X4 Computed rank of V. Xcorrected Divisor of var, corrected or uncorrected. X Blank line. X Blank line. X Blank line. X -2.5889698083278231e-02 -0.02588970 theta(1) X 1.0156796693196859e+00 1.01567967 theta(2) X -1.1156971398981310e+00 -1.11569714 theta(3) X -5.0490286151154495e-01 -0.50490286 theta(4) X 1.1729052766553795e-03 0.00117291 var(1,1) X 1.5936130118638265e-04 0.00015936 V(1,1) X -7.8715725112262180e-05 -0.00007872 V(2,1) X -1.7710704773277823e-04 -0.00017711 V(3,1) X -4.4094836963940918e-05 -0.00004409 V(4,1) X -7.8715725112262180e-05 -0.00007872 V(1,2) X 9.8762401664581004e-05 0.00009876 V(2,2) X 6.0702486057973514e-04 0.00060702 V(3,2) X -1.8513810538785802e-06 -0.00000185 V(4,2) X -1.7710704773277823e-04 -0.00017711 V(1,3) X 6.0702486057973514e-04 0.00060702 V(2,3) X 2.6745983237711428e-02 0.02674598 V(3,3) X 2.3562119500099977e-03 0.00235621 V(4,3) X -4.4094836963940918e-05 -0.00004409 V(1,4) X -1.8513810538785802e-06 -0.00000185 V(2,4) X 2.3562119500099977e-03 0.00235621 V(3,4) X 6.5829241588721008e-04 0.00065829 V(4,4) X -3.1122653130181253e-13 -0.00000000 D(1) X 1.0666063107489048e-12 0.00000000 D(2) X 4.6999396801498302e-11 0.00000000 D(3) X 4.1405085967972343e-12 0.00000000 D(4) X 2.5999999999999996e+01 26.00000000 obj END_OF_FILE if test 2523 -ne `wc -c <'ch1eg1/ending.bak'`; then echo shar: \"'ch1eg1/ending.bak'\" unpacked with wrong size! fi # end of 'ch1eg1/ending.bak' fi if test -f 'ch1eg1/model.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch1eg1/model.cc'\" else echo shar: Extracting \"'ch1eg1/model.cc'\" \(1660 characters\) sed "s/^X//" >'ch1eg1/model.cc' <<'END_OF_FILE' X#include "model.h" X Xmodel::model() { } X Xmodel::~model() { } X X Xvoid model::e(INTEGER t) X{ X e_t.elem(1,1) X = data.elem(t,2) X - data.elem(t,3)*s.theta.elem(1,1) X - data.elem(t,4)*s.theta.elem(2,1) X - s.theta.elem(4,1)*exp(data.elem(t,5)*s.theta.elem(3,1)); X} X Xvoid model::dele(INTEGER t) X{ X REAL tmp; X X tmp = exp(data.elem(t,5)*s.theta.elem(3,1)); X X dele_t.elem(1,1) = - data.elem(t,3); X dele_t.elem(1,2) = - data.elem(t,4); X dele_t.elem(1,3) = - s.theta.elem(4,1)*data.elem(t,5)*tmp; X dele_t.elem(1,4) = - tmp; X} X X Xint model::initialize() X{ X X#ifdef GNU_GPP_COMPILER X X#ifdef USE_ATT_STYLE_IO_WITH_GNU X filebuf databuf; X if( databuf.open("amstat.dat", input) == 0 ){ X cerr << "Error, model::model, Cannot open amstat.dat\n"; X exit(1); X } X istream dataget(&databuf); X#endif X X#ifdef USE_GNU_STYLE_IO_WITH_GNU X istream dataget("amstat.dat",io_readonly,a_useonly); X if (!dataget) { X cerr << "Error, model::model\n"; X exit(1); X } X#endif X X#endif X X#ifdef TURBO_CPP_COMPILER X ifstream dataget("amstat.dat"); X if (!dataget) { X cerr << "Error, model::model\n"; X exit(1); X } X#endif X X data.resize(30,5); X X double x; X X for (INTEGER i=1; i<=30; i++) { X for (INTEGER j=1; j<=5; j++) { X dataget >> x; X data.elem(i,j) = (REAL)x; X } X } X X if(strcmp(s.detail,"full")==0) cout <<starbox("/data//_")<< data; X X dataget.close(); X X return 1; X} X Xvoid model::Z(INTEGER t) X{ X dele(t); X for (INTEGER i = 1; i<=s.K; i++) X if (i <= s.p) X Z_t[i] = dele_t[i]; // will produce SUR estimates when s.K = s.p X else X Z_t[i]=pow(data.elem(t,5),i-s.p); X} X Xint model::terminate() { return 0; } X X X END_OF_FILE if test 1660 -ne `wc -c <'ch1eg1/model.cc'`; then echo shar: \"'ch1eg1/model.cc'\" unpacked with wrong size! fi # end of 'ch1eg1/model.cc' fi if test -f 'ch1eg1/model.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch1eg1/model.h'\" else echo shar: Extracting \"'ch1eg1/model.h'\" \(455 characters\) sed "s/^X//" >'ch1eg1/model.h' <<'END_OF_FILE' X#ifndef __FILE_MODEL_H_SEEN__ X#pragma once X#define __FILE_MODEL_H_SEEN__ 1 X X#include "status.h" X Xextern status s; X Xclass model X{ X Xprotected: X realmat data; X Xpublic: X model(); X ~model(); X X realmat e_t; X realmat dele_t; X realmat Z_t; X X int initialize(); X int terminate(); X X void e(INTEGER t); X void dele(INTEGER t); X void Z(INTEGER t); X X}; X X#endif END_OF_FILE if test 455 -ne `wc -c <'ch1eg1/model.h'`; then echo shar: \"'ch1eg1/model.h'\" unpacked with wrong size! fi # end of 'ch1eg1/model.h' fi if test -f 'ch1eg1/starting.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch1eg1/starting.dat'\" else echo shar: Extracting \"'ch1eg1/starting.dat'\" \(1097 characters\) sed "s/^X//" >'ch1eg1/starting.dat' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 1, Figure 5, p. 35-36. XSUR What estimation method? Code SUR, TSLS, or GMM. X30 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X0 Number of instruments, i.e. dimension of Z. X4 Number of parameters, i.e. dimension of theta. X50 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. Xnone Code none or Parzen, none when MA>0 is unwise. X1.000000e-13 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-10 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X Blank line. X Blank line. X Blank line. X Blank line. X Blank line. X -0.04866 X 1.03884 X -0.73792 X -0.51362 END_OF_FILE if test 1097 -ne `wc -c <'ch1eg1/starting.dat'`; then echo shar: \"'ch1eg1/starting.dat'\" unpacked with wrong size! fi # end of 'ch1eg1/starting.dat' fi if test ! -d 'ch5eg1' ; then echo shar: Creating directory \"'ch5eg1'\" mkdir 'ch5eg1' fi if test -f 'ch5eg1/electb.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch5eg1/electb.dat'\" else echo shar: Extracting \"'ch5eg1/electb.dat'\" \(612 characters\) sed "s/^X//" >'ch5eg1/electb.dat' <<'END_OF_FILE' X 1 1.06 2.86 3.90 X 2 1.78 2.86 3.90 X 3 1.06 3.90 3.90 X 4 1.78 3.90 3.90 X 5 1.37 3.34 5.06 X 6 1.06 2.86 6.56 X 7 1.78 2.86 6.56 X 8 1.06 3.90 6.56 X 9 1.78 3.90 6.56 END_OF_FILE if test 612 -ne `wc -c <'ch5eg1/electb.dat'`; then echo shar: \"'ch5eg1/electb.dat'\" unpacked with wrong size! fi # end of 'ch5eg1/electb.dat' fi if test -f 'ch5eg1/model.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch5eg1/model.h'\" else echo shar: Extracting \"'ch5eg1/model.h'\" \(465 characters\) sed "s/^X//" >'ch5eg1/model.h' <<'END_OF_FILE' X#ifndef __FILE_MODEL_H_SEEN__ X#pragma once X#define __FILE_MODEL_H_SEEN__ 1 X X#include "status.h" X Xextern status s; X Xclass model X{ X Xprotected: X realmat data; X Xpublic: X model(); X ~model(); X X realmat e_t; // e_t is 2 by 1 X realmat dele_t; // dele_ is 2 by 8 X realmat Z_t; // Z_t is 17 by 1 X X int initialize(); X int terminate(); X X void e(INTEGER t); X void dele(INTEGER t); X void Z(INTEGER t); X X}; X X#endif END_OF_FILE if test 465 -ne `wc -c <'ch5eg1/model.h'`; then echo shar: \"'ch5eg1/model.h'\" unpacked with wrong size! fi # end of 'ch5eg1/model.h' fi if test -f 'ch5eg1/starting.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch5eg1/starting.dat'\" else echo shar: Extracting \"'ch5eg1/starting.dat'\" \(1113 characters\) sed "s/^X//" >'ch5eg1/starting.dat' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 5, Figure 3, p. 324-326 XSUR What estimation method? Code SUR, TSLS, or GMM. X224 Number of observations, t = 1, ..., n. X2 Number of equations, i.e. dimension of e. X0 Number of instruments, i.e. dimension of Z. X8 Number of parameters, i.e. dimension of theta. X50 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. Xnone Code none or Parzen, none when MA>0 is unwise. X1.000000e-13 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-10 Inversion tolerance, eps=1.0e-13 is reasonable Xminimal How much output? Code none, minimal, or full. X Blank line. X Blank line. X Blank line. X Blank line. X Blank line. X -2.90 X -1.30 X 0.82 X 0.36 X -1.50 X -1.00 X -0.03 X -0.47 END_OF_FILE if test 1113 -ne `wc -c <'ch5eg1/starting.dat'`; then echo shar: \"'ch5eg1/starting.dat'\" unpacked with wrong size! fi # end of 'ch5eg1/starting.dat' fi if test ! -d 'ch6eg1' ; then echo shar: Creating directory \"'ch6eg1'\" mkdir 'ch6eg1' fi if test -f 'ch6eg1/README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg1/README'\" else echo shar: Extracting \"'ch6eg1/README'\" \(90 characters\) sed "s/^X//" >'ch6eg1/README' <<'END_OF_FILE' X XDo this to get the missing files: X X cp ../ch5eg1/el*.dat . X cp ../ch5eg1/model.* . X END_OF_FILE if test 90 -ne `wc -c <'ch6eg1/README'`; then echo shar: \"'ch6eg1/README'\" unpacked with wrong size! fi # end of 'ch6eg1/README' fi if test -f 'ch6eg1/starting.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg1/starting.dat'\" else echo shar: Extracting \"'ch6eg1/starting.dat'\" \(1113 characters\) sed "s/^X//" >'ch6eg1/starting.dat' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 1, p. 436. XTSLS What estimation method? Code SUR, TSLS, or GMM. X224 Number of observations, t = 1, ..., n. X2 Number of equations, i.e. dimension of e. X17 Number of instruments, i.e. dimension of Z. X8 Number of parameters, i.e. dimension of theta. X20 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. Xnone Code none or Parzen, none when MA>0 is unwise. X1.000000e-08 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-10 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X Blank line. X Blank line. X Blank line. X Blank line. X Blank line. X -2.98 X -1.16 X 0.787 X 0.353 X -1.51 X -1.0 X 0.054 X -0.474 END_OF_FILE if test 1113 -ne `wc -c <'ch6eg1/starting.dat'`; then echo shar: \"'ch6eg1/starting.dat'\" unpacked with wrong size! fi # end of 'ch6eg1/starting.dat' fi if test ! -d 'ch6eg2' ; then echo shar: Creating directory \"'ch6eg2'\" mkdir 'ch6eg2' fi if test -f 'ch6eg2/end3l.bak' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/end3l.bak'\" else echo shar: Extracting \"'ch6eg2/end3l.bak'\" \(2101 characters\) sed "s/^X//" >'ch6eg2/end3l.bak' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450. XGMM What estimation method? Code SUR, TSLS, or GMM. X238 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X3 Number of instruments, i.e. dimension of Z. X2 Number of parameters, i.e. dimension of theta. X20 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xheteroskedastic Code homoskedastic or heteroskedastic. X3 Number of moving average terms MA for var estimate. XParzen Code none or Parzen, none when MA>0 is unwise. X1.000000e-05 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-13 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X2 Computed rank of V. Xuncorrected Divisor of var, corrected or uncorrected. X Blank line. X Blank line. X Blank line. X -8.5525378703973232e-01 -0.85525379 theta(1) X 9.9804560301317236e-01 0.99804560 theta(2) X 4.3978220854904504e-01 0.43978221 var(1,1) X 4.4050039895600307e-01 0.44050040 var(2,1) X 4.3420956263910121e-01 0.43420956 var(3,1) X 4.4050039895600307e-01 0.44050040 var(1,2) X 4.4122700259798669e-01 0.44122700 var(2,2) X 4.3493663977747488e-01 0.43493664 var(3,2) X 4.3420956263910121e-01 0.43420956 var(1,3) X 4.3493663977747488e-01 0.43493664 var(2,3) X 4.2967081964723475e-01 0.42967082 var(3,3) X 3.6066325678816527e+00 3.60663257 V(1,1) X -7.1576798102674808e-03 -0.00715768 V(2,1) X -7.1576798102674808e-03 -0.00715768 V(1,2) X 2.1170843618445885e-05 0.00002117 V(2,2) X 2.6747016119385693e-06 0.00000267 D(1) X -1.7073275785211286e-08 -0.00000002 D(2) X 1.0861341198092420e+00 1.08613412 obj END_OF_FILE if test 2101 -ne `wc -c <'ch6eg2/end3l.bak'`; then echo shar: \"'ch6eg2/end3l.bak'\" unpacked with wrong size! fi # end of 'ch6eg2/end3l.bak' fi if test -f 'ch6eg2/ending.bak' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/ending.bak'\" else echo shar: Extracting \"'ch6eg2/ending.bak'\" \(2101 characters\) sed "s/^X//" >'ch6eg2/ending.bak' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450. XGMM What estimation method? Code SUR, TSLS, or GMM. X238 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X3 Number of instruments, i.e. dimension of Z. X2 Number of parameters, i.e. dimension of theta. X20 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. XParzen Code none or Parzen, none when MA>0 is unwise. X1.000000e-05 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-13 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X2 Computed rank of V. Xuncorrected Divisor of var, corrected or uncorrected. X Blank line. X Blank line. X Blank line. X -1.0335217392035390e+00 -1.03352174 theta(1) X 9.9825572364240200e-01 0.99825572 theta(2) X 4.0582168346665826e-01 0.40582168 var(1,1) X 4.0643410965960231e-01 0.40643411 var(2,1) X 3.9873658267692480e-01 0.39873658 var(3,1) X 4.0643410965960231e-01 0.40643411 var(1,2) X 4.0705487414860658e-01 0.40705487 var(2,2) X 3.9936326231932223e-01 0.39936326 var(3,2) X 3.9873658267692480e-01 0.39873658 var(1,3) X 3.9936326231932223e-01 0.39936326 var(2,3) X 3.9272327136336027e-01 0.39272327 var(3,3) X 3.5800932072477121e+00 3.58009321 V(1,1) X -7.2126817691390913e-03 -0.00721268 V(2,1) X -7.2126817691390913e-03 -0.00721268 V(1,2) X 2.0603180900457831e-05 0.00002060 V(2,2) X -9.1931859179544446e-08 -0.00000009 D(1) X 1.8525999753608607e-10 0.00000000 D(2) X 1.0569217148505041e+00 1.05692171 obj END_OF_FILE if test 2101 -ne `wc -c <'ch6eg2/ending.bak'`; then echo shar: \"'ch6eg2/ending.bak'\" unpacked with wrong size! fi # end of 'ch6eg2/ending.bak' fi if test -f 'ch6eg2/model.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/model.cc'\" else echo shar: Extracting \"'ch6eg2/model.cc'\" \(1679 characters\) sed "s/^X//" >'ch6eg2/model.cc' <<'END_OF_FILE' X#include "model.h" X Xmodel::model() { } X Xmodel::~model() { } X X Xvoid model::e(INTEGER t) X{ X REAL a,b,yta,yt,xt; X X INTEGER i=t+2; X X yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]); X xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]); X X a=s.theta[1]; X b=s.theta[2]; X X yta = pow(yt,a); X X e_t[1] = b * yta * xt - 1.0; X} X Xvoid model::dele(INTEGER t) X{ X REAL a,b,yta,yt,xt; X X INTEGER i=t+2; X X yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]); X xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]); X X a=s.theta[1]; X b=s.theta[2]; X X yta = pow(yt,a); X X dele_t.elem(1,1) = b * log(yt) * yta * xt; X dele_t.elem(1,2) = yta*xt; X} X X Xint model::initialize() X{ X INTEGER i; X double tmp; X X#ifdef GNU_GPP_COMPILER X#ifdef USE_ATT_STYLE_IO_WITH_GNU X X filebuf cdata_buf; X if (cdata_buf.open("hansen.dat",input) ==0) { X cerr << "Error, model::model, Cannot open hansen.dat.\n"; X exit(1); X } X istream cdata(&cdata_buf); X X#endif X X#ifdef USE_GNU_STYLE_IO_WITH_GNU X X istream cdata("hansen.dat",io_readonly,a_useonly); X if ( !cdata ) { X cerr << "Error, model::model, Cannot open hansen.dat.\n"; X exit(1); X } X X#endif X X#endif X X#ifdef TURBO_CPP_COMPILER X X ifstream cdata("hansen.dat"); X if (!cdata) { X cerr << "Error, model::model, Cannot open hansen.dat.\n"; X exit(1); X } X X#endif X X for (i=1; i<=240; i++) { X cdata >> tmp; nds[i]=(REAL)tmp; X cdata >> tmp; pop[i]=(REAL)tmp; X cdata >> tmp; nyse[i]=(REAL)tmp; X cdata >> tmp; dflat[i]=(REAL)tmp; X } X X return 1; X} X Xvoid model::Z(INTEGER t) X{ X INTEGER i = t+2; X Z_t[1] = 1.0; X Z_t[2] = (nds[i-1]/pop[i-1])/(nds[i-2]/pop[i-2]); X Z_t[3] = (1.0+nyse[i-1])*(dflat[i-2]/dflat[i-1]); X} X Xint model::terminate() { return 0; } X X X X X END_OF_FILE if test 1679 -ne `wc -c <'ch6eg2/model.cc'`; then echo shar: \"'ch6eg2/model.cc'\" unpacked with wrong size! fi # end of 'ch6eg2/model.cc' fi if test -f 'ch6eg2/model.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/model.h'\" else echo shar: Extracting \"'ch6eg2/model.h'\" \(536 characters\) sed "s/^X//" >'ch6eg2/model.h' <<'END_OF_FILE' X#ifndef __FILE_MODEL_H_SEEN__ X#pragma once X#define __FILE_MODEL_H_SEEN__ 1 X X#include "status.h" X Xextern status s; X Xclass model X{ X Xprotected: X REAL nds[256]; X REAL pop[256]; X REAL nyse[256]; X REAL dflat[256]; X Xpublic: X realmat e_t; // e_t is 1 by 1 X realmat dele_t; // dele_t is 1 by 2 X realmat Z_t; // Z_t is 3 by 1 X X model(); X ~model(); X X int initialize(); X int terminate(); X X void e(INTEGER t); X void dele(INTEGER t); X void Z(INTEGER t); X X}; X X#endif END_OF_FILE if test 536 -ne `wc -c <'ch6eg2/model.h'`; then echo shar: \"'ch6eg2/model.h'\" unpacked with wrong size! fi # end of 'ch6eg2/model.h' fi if test -f 'ch6eg2/start3l.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/start3l.dat'\" else echo shar: Extracting \"'ch6eg2/start3l.dat'\" \(1068 characters\) sed "s/^X//" >'ch6eg2/start3l.dat' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450. XGMM What estimation method? Code SUR, TSLS, or GMM. X238 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X3 Number of instruments, i.e. dimension of Z. X2 Number of parameters, i.e. dimension of theta. X20 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xheteroskedastic Code homoskedastic or heteroskedastic. X3 Number of moving average terms MA for var estimate. XParzen Code none or Parzen, none when MA>0 is unwise. X1.000000e-05 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-13 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X Blank line. X Blank line. X Blank line. X Blank line. X Blank line. X-0.4 X 0.9 END_OF_FILE if test 1068 -ne `wc -c <'ch6eg2/start3l.dat'`; then echo shar: \"'ch6eg2/start3l.dat'\" unpacked with wrong size! fi # end of 'ch6eg2/start3l.dat' fi if test -f 'ch6eg2/starting.dat' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ch6eg2/starting.dat'\" else echo shar: Extracting \"'ch6eg2/starting.dat'\" \(1068 characters\) sed "s/^X//" >'ch6eg2/starting.dat' <<'END_OF_FILE' XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450. XGMM What estimation method? Code SUR, TSLS, or GMM. X238 Number of observations, t = 1, ..., n. X1 Number of equations, i.e. dimension of e. X3 Number of instruments, i.e. dimension of Z. X2 Number of parameters, i.e. dimension of theta. X20 Upper limit on Gauss-Newton iterations. X1 Number var iterates, ivar=0 means none. Xhomoskedastic Code homoskedastic or heteroskedastic. X0 Number of moving average terms MA for var estimate. XParzen Code none or Parzen, none when MA>0 is unwise. X1.000000e-05 Convergence tolerance, tol=1.0e-8 is reasonable. X1.000000e-13 Inversion tolerance, eps=1.0e-13 is reasonable Xfull How much output? Code none, minimal, or full. X Blank line. X Blank line. X Blank line. X Blank line. X Blank line. X-0.4 X 0.9 END_OF_FILE if test 1068 -ne `wc -c <'ch6eg2/starting.dat'`; then echo shar: \"'ch6eg2/starting.dat'\" unpacked with wrong size! fi # end of 'ch6eg2/starting.dat' fi if test -f 'dcond.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dcond.cc'\" else echo shar: Extracting \"'dcond.cc'\" \(1599 characters\) sed "s/^X//" >'dcond.cc' <<'END_OF_FILE' X/* XName dcond - Improves the accuracy of dsweep when the diagonal X elements of a are not of the same order of magnitude. X XUsage #include "usual.h" X #include "tools.h" X void dcond(REAL *a, INTEGER n, REAL *s,INTEGER isw) X XPrototype in tools.h X XDescription a is a symmetric, positive definite, n by n matrix stored X columnwise with no unused space and first element in a[0]; i.e., X for (j=1; j<=n; j++) for (i=1; i<=n; i++) aij=a[n*(j-1)+(i-1)]; X will traverse the matrix with aij being the element in the X i-th row and j-th column. s is a work vector of length n. X The intended calling sequence is: X dcond(a,n,s,0); X ier=dsweep(a,n,eps); X dcond(a,n,s,1); X The usage X dcond(a,n,s,0); X will return a correlation matrix in a and the standard errors X in s when a is a variance-covariance matrix. X XRemark dscond.c is dcond.f translated to C++. X XReturn value None. X XFunctions Library: (none) Xcalled Sublib: (none) X*/ X X#include "usual.h" X#include "tools.h" X Xvoid dcond(REAL *a, INTEGER n, REAL *s, INTEGER isw) X{ X INTEGER i; X REAL *si, *sj, *top, *aij; X X if (isw == 1) goto L20; X X for (i = 0; i < n; ++i) X s[i] = sqrt(a[i + i * n]); X X L20: X X sj = s; X top = s + n; X aij = a; X X while (sj < top) { X if (*sj != 0.) { X si = s; X while (si < top) X if (*si != 0.) *aij++ /= (*si++) * (*sj); X } X sj++; X } X X return; X X} END_OF_FILE if test 1599 -ne `wc -c <'dcond.cc'`; then echo shar: \"'dcond.cc'\" unpacked with wrong size! fi # end of 'dcond.cc' fi if test -f 'dsweep.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dsweep.cc'\" else echo shar: Extracting \"'dsweep.cc'\" \(4560 characters\) sed "s/^X//" >'dsweep.cc' <<'END_OF_FILE' X/* XName dsweep - Inverts a positive definite matrix in place by a X diagonal sweep. X XUsage #include "usual.h" X #include "tools.h" X INTEGER dsweep(REAL *a, INTEGER n, REAL eps) X XPrototype in tools.h X XDescription a is a symmetric, positive definite, n by n matrix stored X columnwise with no unused space and first element in a[0]; i.e., X for (j=1; j<=n; j++) for (i=1; i<=n; i++) aij=a[n*(j-1)+(i-1)]; X will traverse the matrix with aij being the element in the X i-th row and j-th column. On return a contains the inverse of a X stored columnwise. eps is an input constant used as a relative X tolerance in testing for degenerate rank. A reasonable value X for eps is 1.e-13. X XRemark dsweep.cc is dsweep.f translated to C++. X XReference Schatzoff, M., R. Tsao, and S. Fienberg (1968) "Efficient X Calculation of all Possible Regressions," Technometrics 10, X 769-779. X XReturn value The return value ier is an error parameter coded as follows: X ier=0, no error, rank of a is n; ier > 0, a is singular, rank X of a is n-ier. If ier > 0 then dsweep returns a g-inverse. X XFunctions Library: (none) Xcalled Sublib: (none) X*/ X X#include "usual.h" X#include "tools.h" X X XINTEGER dsweep(REAL *a, INTEGER n, REAL eps) X{ X INTEGER i, j, k, kk, ier; X REAL test, d, negd, akj, akk, tol; X REAL *p_aij, *p_aji, *p_aik, *p_a1j, *p_akk, *top; X X a--; // Adjust offset to allow Fortran style indexing. X X tol=0.0; X X for (i=1; i<=n; i++) { X test=a[n*(i-1)+i]; X if(test > tol) tol=test; X } X X tol=tol*eps; X ier=0; X X X /* X This is the intention: X X for (k=1; k<=n; k++) { X X kk=n*(k-1)+k; X X akk=a[kk]; X X if (akk < tol) { X X ier=ier+1; X X for (j=k; j<=n; j++) // zero out row k of upper triangle X a[n*(j-1)+k]=0.0; X X for (i=1; i<=k-1; i++) // zero out column k of upper triangle X a[kk-i]=0.0; X X } X else { // sweep X X d=1.0/akk; X X for (j=1 ; j < k; j++) { X akj=-a[n*(k-1)+j]; X for (i=1 ; i <= j; i++) { X aik=a[n*(k-1)+i]; X a[n*(j-1)+i] -= aik*akj*d; X } X } X X for (j=k+1; j <= n; j++) { X akj=a[n*(j-1)+k]; X for (i=1 ; i < k; i++) { X aik=a[n*(k-1)+i]; X a[n*(j-1)+i] -= aik*akj*d; X } X for (i=k+1; i <= j; i++) { X aik=a[n*(i-1)+k]; X a[n*(j-1)+i] -= aik*akj*d; X } X } X X for (j=k; j<=n; j++) X a[n*(j-1)+k] *= d; X X for (i=1; i<k; i++) X a[kk-i] = -a[kk-i]*d; X X a[kk]=d; X X } X } X X // copy the upper triangle to the lower X X for (i=1; i <= n; i++) X for (j=i; j <= n; j++) X a[n*(i-1)+j]=a[n*(j-1)+i]; X X X This is the code with inner loops optimized: X */ X X for (k=1; k<=n; k++) { X X kk=n*(k-1)+k; X X p_akk = &a[kk]; X X akk=*p_akk; X X if (akk < tol) { X X ier=ier+1; X X p_aij = p_akk; X top = &a[n*(n-1)+k+1]; X X while (p_aij < top) { X *p_aij = REAL_ZERO; X p_aij += n; X } X X p_aij = p_akk-k+1; X top = p_akk; X X while (p_aij < top) { X *p_aij++ = REAL_ZERO; X } X X } X else { // sweep X X d=((REAL)1.0)/akk; X negd = -d; X X for (j=1 ; j < k; j++) { X akj=-a[n*(k-1)+j]; X p_aij = &a[n*(j-1)+1]; X X top = p_aij + j; X p_aik = &a[n*(k-1)+1]; X while (p_aij < top) { X *p_aij++ += (*p_aik++)*akj*negd; X } X } X X for (j=k+1; j <= n; j++) { X akj=a[n*(j-1)+k]; X p_a1j = &a[n*(j-1)+1]; X X p_aij = p_a1j; X top = p_aij + k - 1; X p_aik = &a[n*(k-1)+1]; X while (p_aij < top) { X *p_aij++ += (*p_aik++)*akj*negd; X } X X p_aij = p_a1j; X top = p_aij + j; X p_aij = p_aij + k; X p_aik = &a[n*k+k]; X while (p_aij < top) { X *p_aij++ += (*p_aik)*akj*negd; X p_aik += n; X } X X } X X p_aij = p_akk; X top = &a[n*(n-1)+k+1]; X X while (p_aij < top) { X *p_aij *= d; X p_aij += n; X } X X p_aij = p_akk-k+1; X top = p_akk; X X while (p_aij < top) { X *p_aij++ *= negd; X } X X *p_akk=d; X X } X } X X for (j=1; j <= n; j++) { X X top = &a[n*(j-1)+1]; X p_aij = top + j - 1; X p_aji = p_aij; X top += n; X X while (p_aij < top) { X *p_aij++ = *p_aji; X p_aji += n; X } X X } X X return ier; X} X X END_OF_FILE if test 4560 -ne `wc -c <'dsweep.cc'`; then echo shar: \"'dsweep.cc'\" unpacked with wrong size! fi # end of 'dsweep.cc' fi if test -f 'nlmdl.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'nlmdl.cc'\" else echo shar: Extracting \"'nlmdl.cc'\" \(3428 characters\) sed "s/^X//" >'nlmdl.cc' <<'END_OF_FILE' X/* ---------------------------------------------------------------------------- X Xnlmdl: nlmdl.cc X Xnlmdl is a C++ implementation of the statistical methods in A. Ronald XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed Xwith it. The header files nlmdl.h and realmat.h describe the use of the Xprogram and matrix class, respectively. X XCopyright (C) 1990. X XA. Ronald Gallant XP.O. Box 5513 XRaleigh NC 27650-5513 XUSA X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. X XThis software is provided "as is" without any expressed or implied warranty. X X---------------------------------------------------------------------------- */ X#include "nlmdl.h" X Xtypedef void (*ZERO_ARGUMENT_NL_OPR)(); Xtypedef void (*ONE_ARGUMENT_NL_OPR)(int); X Xstatus s; Xmodel m; X XZERO_ARGUMENT_NL_OPR opr_mgn; XZERO_ARGUMENT_NL_OPR opr_obj; XONE_ARGUMENT_NL_OPR opr_var; XZERO_ARGUMENT_NL_OPR opr_V; X X#include "nlmdl.opr" X Xint main() X{ X char msg[MAX_STATUS_LINE]; X X s.from(s.starting); X X repeat: X X if(m.initialize()==0) exit(0); X X s.from(s.starting); X X if(strcmp(s.detail,"none") != 0) { X sprintf(msg,"/nlmdl %s//_",VERSION); X cout << starbox(msg); X s.display(START_UP); X cout << starbox("/Starting theta//_") << s.theta; X } X X if(strcmp(s.method,"SUR") == 0) { X opr_mgn = &SUR_mgn; X opr_obj = &SUR_obj; X opr_var = &SUR_var; X opr_V = &SUR_V; X } X else if(strcmp(s.method,"TSLS") == 0) { X X if ( strcmp(s.vartype,"heteroskedastic") == 0 || s.MA>0 ) { X cerr << "\nError, nlmdl, Use GMM for this case, not TSLS.\n\n"; X exit(1); X } X opr_mgn = &TSLS_mgn; X opr_obj = &TSLS_obj; X opr_var = &SUR_var; X opr_V = &TSLS_V; X X qZ.resize(s.M*s.K,1); X QZ.resize(s.M*s.K,s.p); X } X else if(strcmp(s.method,"GMM") == 0) { X opr_mgn = &GMM_mgn; X opr_obj = &GMM_obj; X opr_var = &GMM_var; X opr_V = &GMM_V; X X qZ.resize(s.M*s.K,1); X QZ.resize(s.M*s.K,s.p); X } X else { X cerr << "Error, nlmdl, s.method set wrong.\n"; X exit(1); X } X X m.e_t.resize(s.M,1); X m.dele_t.resize(s.M,s.p); X if (s.K > 0 ) m.Z_t.resize(s.K,1); X X s.V.resize(s.p, s.p, REAL_ZERO ); X for (INTEGER i = 1; i <= s.p; i++) s.V.elem(i,i) = 1.0; X s.D.resize(s.p, 1, REAL_ZERO ); X X for (INTEGER var_loop = 0; var_loop <= s.ivar; var_loop++) { X X (*opr_var)(var_loop); X X if(strcmp(s.detail,"full") == 0) { X cout << "\nvar_loop " << var_loop << "\n"; X s.display(VAR_ITERATE); X } X X for (INTEGER theta_loop = 0; theta_loop <= s.itheta; theta_loop++) { X X (*opr_mgn)(); X X if(strcmp(s.detail,"full") == 0) { X cout << "\ntheta_loop " << theta_loop << "\n"; X s.display(THETA_ITERATE); X } X X int rv = line_search(&msg[0]); X X if(strcmp(s.detail,"full") == 0) cout << msg; X if(rv != 0) break; X } X } X X (*opr_mgn)(); X (*opr_V)(); X X s.to(s.ending); X X if (strcmp(s.detail,"none") != 0) s.display(TERMINATION); X X if(m.terminate() != 0) goto repeat; X X exit(0); X} END_OF_FILE if test 3428 -ne `wc -c <'nlmdl.cc'`; then echo shar: \"'nlmdl.cc'\" unpacked with wrong size! fi # end of 'nlmdl.cc' fi if test -f 'patchlevel.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'patchlevel.h'\" else echo shar: Extracting \"'patchlevel.h'\" \(1006 characters\) sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE' X/* -------------------------------------------------------------------------- X Xnlmdl: patchlevel.h X Xnlmdl is a C++ implementation of the statistical methods in A. Ronald XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed Xwith it. The header files nlmdl.h and realmat.h describe the use of the Xprogram and matrix class, respectively. X XCopyright (C) 1990. X XA. Ronald Gallant XP.O. Box 5513 XRaleigh NC 27650-5513 XUSA X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. X XThis software is provided "as is" without any expressed or implied warranty. X X------------------------------------------------------------------------- */ X X#define PATCHLEVEL 0 X X END_OF_FILE if test 1006 -ne `wc -c <'patchlevel.h'`; then echo shar: \"'patchlevel.h'\" unpacked with wrong size! fi # end of 'patchlevel.h' fi if test -f 'starbox.cc' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'starbox.cc'\" else echo shar: Extracting \"'starbox.cc'\" \(2486 characters\) sed "s/^X//" >'starbox.cc' <<'END_OF_FILE' X/* XName starbox - puts title in a centered box of stars. X XUsage #include "usual.h" X #include "tools.h" X char* starbox(char *title, char terminator); X XPrototype in tools.h X XDescription title is a character string. The string is made up of X concatonated lines. A line is made up of 0-68 characters X followed by a slash (default). Examples are: X cout << starbox("//line 1/line 2/line 3///"); X cout << starbox("\n\nline 1\nline 2\nline 3\n\n\n",'\n'); X XReturn value Character string. X XFunctions Library: strcat, strchr, strlen Xcalled Tools: (none) X Sublib: (none) X*/ X X#include "usual.h" X#include "tools.h" X Xchar * starbox(char *title, char terminator) X{ X char border[81],tab[81],work[256],middle[81]; X char *line, *begin, *end, *t; X int i,pad,mpad,linesize; X long int length, cum_length; X X char starbox_str_pointer[1024]; X long int starbox_str_length = 1024; X X cum_length = 0; X *starbox_str_pointer = '\0'; X X for (i=0; i<70; i++) X border[i] = '*'; X border[70] = '\n'; border[71] = '\0'; X X ((LINESIZE<72)||(LINESIZE>133)) ? (linesize=133) : (linesize=LINESIZE); X X pad = (linesize-72)/2+1; X for (i=0; i<pad; i++) X tab[i] = ' '; X tab[pad] = '\0'; X X work[0]='\n'; work[1]='\n'; work[2]='\0'; X line = strcat(work,tab); X line = strcat(work,border); X X cum_length += strlen(line); X X if (cum_length < starbox_str_length) X strcat(starbox_str_pointer,line); X else X return "Error, starbox, title too long."; X X begin = title; X while ( (end=strchr(begin,terminator)) != NULL ) { X length = end - begin; X if (length > 68) return "Error, starbox, line too long."; X middle[0] = '*'; X mpad = (68-length)/2+1; X for (i=1; i<=mpad; i++) middle[i] = ' '; X t = &middle[mpad]; X while (begin < end) *t++ = *begin++; X begin++; X for (i=mpad+length; i<=68; i++) middle[i]=' '; X middle[69]='*'; middle[70]='\n'; middle[71]='\0'; X work[0]='\0'; X line = strcat(work,tab); X line = strcat(work,middle); X X X if (cum_length < starbox_str_length) X strcat(starbox_str_pointer,line); X else X return "Error, starbox, title too long."; X X } X X work[0]='\0'; X line = strcat(work,tab); X line = strcat(work,border); X X if (cum_length < starbox_str_length) X strcat(starbox_str_pointer,line); X else X return "Error, starbox, title too long."; X X return starbox_str_pointer; X X} X X X END_OF_FILE if test 2486 -ne `wc -c <'starbox.cc'`; then echo shar: \"'starbox.cc'\" unpacked with wrong size! fi # end of 'starbox.cc' fi if test -f 'status.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'status.h'\" else echo shar: Extracting \"'status.h'\" \(2046 characters\) sed "s/^X//" >'status.h' <<'END_OF_FILE' X/* ---------------------------------------------------------------------------- X Xnlmdl: status.h X Xnlmdl is a C++ implementation of the statistical methods in A. Ronald XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed Xwith it. The header files nlmdl.h and realmat.h describe the use of the Xprogram and matrix class, respectively. X XCopyright (C) 1990. X XA. Ronald Gallant XP.O. Box 5513 XRaleigh NC 27650-5513 XUSA X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. X XThis software is provided "as is" without any expressed or implied warranty. X X---------------------------------------------------------------------------- */ X/* status is a class used by nlmdl */ X X#ifndef __FILE_STATUS_H_SEEN__ X#pragma once X#define __FILE_STATUS_H_SEEN__ 1 X X#include "usual.h" X#include "realmat.h" X#include "tools.h" X X X X#define MAX_STATUS_LINE 256 X#define STARTING_FILENAME "starting.dat" X#define ENDING_FILENAME "ending.dat" X Xenum display_mode {START_UP, VAR_ITERATE, THETA_ITERATE, TERMINATION}; X Xclass status X{ Xpublic: X status(); X ~status(); X X char switches[MAX_STATUS_LINE]; X char method[MAX_STATUS_LINE]; X INTEGER n; X INTEGER M; X INTEGER K; X INTEGER p; X INTEGER itheta; X INTEGER ivar; X char vartype[MAX_STATUS_LINE]; X INTEGER MA; X char weights[MAX_STATUS_LINE]; X REAL tol; X REAL eps; X char detail[MAX_STATUS_LINE]; X INTEGER rank; X char df[MAX_STATUS_LINE]; X realmat theta; X realmat var; X realmat V; X realmat D; X REAL obj; X X char* starting; X char* ending; X X int from(char* filename); X int to(char* filename); X int display(display_mode); X X}; X X#endif X END_OF_FILE if test 2046 -ne `wc -c <'status.h'`; then echo shar: \"'status.h'\" unpacked with wrong size! fi # end of 'status.h' fi if test -f 'tools.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tools.h'\" else echo shar: Extracting \"'tools.h'\" \(290 characters\) sed "s/^X//" >'tools.h' <<'END_OF_FILE' X#ifndef __FILE_TOOLS_H_SEEN__ X#pragma once X#define __FILE_TOOLS_H_SEEN__ 1 X X#include "usual.h" X Xchar* starbox(char *title, char terminator = '/'); X Xvoid dcond(REAL *a, INTEGER n, REAL *s, INTEGER isw); XINTEGER dsweep(REAL *a, INTEGER n, REAL eps); X X#endif /*__FILE_TOOLS_H_SEEN__*/ END_OF_FILE if test 290 -ne `wc -c <'tools.h'`; then echo shar: \"'tools.h'\" unpacked with wrong size! fi # end of 'tools.h' fi if test -f 'usual.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'usual.h'\" else echo shar: Extracting \"'usual.h'\" \(4267 characters\) sed "s/^X//" >'usual.h' <<'END_OF_FILE' X#ifndef __FILE_USUAL_H_SEEN__ X#pragma once X#define __FILE_USUAL_H_SEEN__ 1 X X X#undef TURBO_CPP_COMPILER X#define GNU_GPP_COMPILER 1 X X#define USE_ATT_STYLE_IO_WITH_GNU 1 X#undef USE_GNU_STYLE_IO_WITH_GNU X X X/* ------------------------- References --------------------------------- X XBjarne Stroustrup (1986), The C++ Programming Language. Reading Massachusetts: XAddison-Wesley Publishing Company. X X Header files: X X <complex.h> p. 123, 173 X <ctype.h> p. 77, 237 X <math.h> p. 22, 115 X <signal.h> p. 126 X <stdargs.h> p. 124 X <stream.h> p. 12, 226 X <string.h> p. 111 X <vector.h> p. 35 X X X XKernigham, Brian W., and Dennis M. Ritchie (1988). The C Programming Language, XSecond Edition. Englewood Cliffs, New Jersey: Prentice Hall. X X X Appendix B. Standard Library X X B1 Input and Output: <stdio.h> p. 241 X B2 Character Class Tests: <ctype.h> p. 248 X B3 String Functions: <string.h> p. 249 X B4 Mathematical Functions: <math.h> p. 250 X B5 Utility Functions: <stdlib.h> p. 251 X B6 Diagnostics <assert.h> p. 253 X B7 Variable Argument Lists: <stdarg.h> p. 254 X B8 Non-Local Jumps <setjump.h> p. 254 X B9 Signals: <signal.h> p. 255 X B10 Date and Time Functions <time.h> p. 255 X B11 Implementation-defined Limits: <limits.h> and <float.h> p. 257 X X---------------------------------------------------------------------------*/ X X/*--------------------------- g++ ------------------------------------------- X XGNU's g++ follows Stroustrup. These are the g++ equivalents together with Xtheir dependencies. X X<Complex.h> X <File.h> <builtin.h> <errno.h> <istream.h> <math.h> <math-68881.h> X <ostream.h> <std.h> <stddef.h> <stdio.h> <stream.h> <streambuf.h> X <values.h> X X<ctype.h> X <stdio.h> X X<math.h> X <errno.h> <math-68881.h> <std.h> <stddef.h> <stdio.h> X X<signal.h> X <sys/signal.h> X X<std.h> X <stdio.h> <stddef.h> X X<stream.h> X <File.h> <builtin.h> <errno.h> <istream.h> <math.h> <math-68881.h> X <ostream.h> <std.h> <stddef.h> <stdio.h> <streambuf.h> <values.h> X X<string.h> X <std.h> <stddef.h> <stdio.h> X X<Vec.hP> & <Vec.ccP> X <stream.h> X XThe USE_ATT_STYLE_IO_WITH_GNU option uses the filebuf class which conforms Xto Chapter 8 of Stroustrup. Syntax to open a file: X filebuf f1; X if (f1.open("filename",input) == 0) error("cannot open file"); X istream from(&f1); X //options: input, output, append X XThe USE_GNU_STYLE_IO_WITH_GNU option uses the File class. Syntax to open a Xfile: X istream from("filename",io_readonly,a_useonly); X if (!from) error("cannot open file"); X //options: io_readonly, io_writeonly, io_readwrite, io_appendonly, io_append X //options: a_createonly, a_create, a_useonly, a_use X----------------------------------------------------------------------------*/ X X#ifdef GNU_GPP_COMPILER X#include <stream.h> X#endif X X X/*---------------------------- Turbo C++ ------------------------------------ X XTurbo C++ uses a tiresome mixture of ANSI C headers and Stroustrup headers. XSee page 155 of the Turbo C++ Programmers Guide for a description. X XSyntax to open a file: X ifstream from("filename"); X if (!from) error("cannot open file"); X ofstream to("filename") X if (!to) error("cannot open file"); X----------------------------------------------------------------------------*/ X X#ifdef TURBO_CPP_COMPILER X#include <iostreams.h> X#include <fstream.h> X#include <stdio.h> X#include <string.h> X#include <math.h> X#include <stdlib.h> X#endif X X#define LINESIZE 80 // define linesize for output routines X Xtypedef long int INTEGER; // define precision of integer arithmetic Xtypedef double REAL; // define precision of floating point arithmetic X X#define REAL_ZERO 0.0 // correct type 0 for REAL, 0.0F, 0.0, or 0.0L X Xtypedef void (*ONE_ARG_ERROR_HANDLER_T)(const char*); Xtypedef void (*TWO_ARG_ERROR_HANDLER_T)(const char*, const char*); X X#endif /*__FILE_USUAL_H_SEEN__*/ END_OF_FILE if test 4267 -ne `wc -c <'usual.h'`; then echo shar: \"'usual.h'\" unpacked with wrong size! fi # end of 'usual.h' fi echo shar: End of archive 1 \(of 6\). cp /dev/null ark1isdone MISSING="" for I in 1 2 3 4 5 6 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 6 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.