home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2398 / nlmdl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  5.2 KB  |  160 lines

  1. /* ---------------------------------------------------------------------------
  2.  
  3. nlmdl: nlmdl.h
  4.  
  5. nlmdl is a C++ implementation of the statistical methods in A. Ronald 
  6. Gallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
  7. 1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
  8. with it.  The header files nlmdl.h and realmat.h describe the use of the 
  9. program and matrix class, respectively.  
  10.  
  11. Copyright (C) 1990.
  12.  
  13. A. Ronald Gallant
  14. P.O. Box 5513 
  15. Raleigh NC 27650-5513 
  16. USA   
  17.  
  18. Permission to use, copy, modify, and distribute this software and its 
  19. documentation for any purpose and without fee is hereby granted, provided 
  20. that the above copyright notice appear in all copies and that both that 
  21. copyright notice and this permission notice appear in supporting 
  22. documentation.  
  23.  
  24. This software is provided "as is" without any expressed or implied warranty.
  25.  
  26. ----------------------------------------------------------------------------- 
  27.  
  28. This header describes the program nlmdl.cc for estimating theta of the model 
  29. e=q(t,theta).  The user supples a file named starting.dat whose contents are 
  30. described by the template:
  31.  
  32.   switches This line is passed to class model as a string.
  33.   method   What estimation method?  Code SUR, TSLS, or GMM.
  34.   n        Number of observations, t = 1, ..., n.
  35.   M        Number of equations in the system, i.e. dimension of e.
  36.   K        Number of instruments, i.e. dimension of Z, code K=0 with SUR.
  37.   p        Number of parameters, i.e. dimension of theta.
  38.   itheta   Upper limit on Gauss-Newton iterations.
  39.   ivar     Number of var iterates, ivar=0 means none.
  40.   vartype  Code homoskedastic or heteroskedastic.
  41.   MA       Number of moving average terms for var estimate, code MA=0 if e iid.
  42.   weights  Code none or Parzen, coding none when MA>0 is asking for trouble.
  43.   tol      Convergence tolerance, tol=1.0e-8 is reasonable.
  44.   eps      Inversion tolerance, eps=1.0e-13 is reasonable.
  45.   detail   How much output?  Code none, minimal, or full.
  46.            Blank line.
  47.            Blank line.
  48.            Blank line.
  49.            Blank line.
  50.            Blank line.
  51.   theta(1) Starting values for theta.  These must be supplied.
  52.            
  53.     to
  54.  
  55.   theta(p) 
  56.   var(1)   Starting values for variance estimate.  These can be omitted.  
  57.            Matrix is stored columnwise.  If method = SUR or TSLS then then 
  58.     to     l=M and var corresponds to C(e,e').  If method = GMM then l=M*K 
  59.            and var corresponds to the variance of sum on t of e Kronecker 
  60.   var(l*l) product Z.  
  61.  
  62.  
  63. See class status for more detail, especially status::from.  The file 
  64. starting.dat must contain at least the first line, switches.  The user also 
  65. supplies the class model as files model.h and model.cc.  The class model is 
  66. declared in model.h which should match the following template:
  67.  
  68.  
  69.    #include "status.h"
  70.    external status s;
  71.  
  72.    class model
  73.    {   
  74.    protected:
  75.      //...
  76.  
  77.    public:
  78.             model();
  79.             ~model();
  80.    int      initialize();
  81.    int      terminate();
  82.    realmat  e(INTEGER t);      // e is M by 1
  83.    realmat  dele(INTEGER t);   // dele is M by p
  84.    realmat  Z(INTEGER t);      // Z is K by 1
  85.    }
  86.  
  87. For SUR, code the function Z as follows:
  88.  
  89.    realmat model::Z(INTEGER t)
  90.    {
  91.      realmat z(1,1);
  92.      z.elem(1,1)=1.0;
  93.      return z;
  94.    }
  95.  
  96. In writing the class model, the relevant facts regarding program flow in 
  97. nlmdl.cc are as follows: 
  98.  
  99.   1. First, s is tentatively filled in by reading starting.dat using 
  100.  
  101.        status s;
  102.        s.from(s.starting);
  103.  
  104.      The primary purpose of this read is to get the first line from 
  105.      starting.dat so as to make it available to model as the string 
  106.      s.switches.  Nonetheless, everything in starting.dat is read and 
  107.      put in s.  
  108.  
  109.   2. Next, initialize() of class model is called.  The function initialize() 
  110.      can read starting.dat, can read other data, etc.  Since all of class 
  111.      status's data is public, any of it can be filled in or changed by 
  112.      initialize().  One could, for example, fill in all of class status's 
  113.      data and write it using 
  114.  
  115.        s.to(s.starting);
  116.  
  117.      One could also switch to a different starting status file using 
  118.  
  119.        s.starting="filename";
  120.  
  121.      or a different ending status file using 
  122.  
  123.        s.ending="filename";
  124.  
  125.      If initialize() returns 0, execution stops.
  126.  
  127.   3. Then, class status's data is definitively filled in by the call
  128.  
  129.        s.from(s.starting);
  130.  
  131.      and estimation proceeds using these settings.  
  132.  
  133.   4. Finally, terminate() of class model is called; terminate() can read data, 
  134.      write data, etc.  If terminate() returns 0 execution stops, otherwise 
  135.      initialize() is called again and the cycle repeats (from Step 2).  One 
  136.      can use this feature to loop over a grid of starting values.
  137.  
  138.  
  139. Reference:
  140.  
  141. Gallant, A. Ronald (1987), "Nonlinear Statistical Models,"  New York: John 
  142. Wiley and Sons. ISBN 0-471-80260-3.
  143.  
  144. --------------------------------------------------------------------------- */
  145.  
  146.  
  147. #ifndef __FILE_NLMDL_H_SEEN__
  148. #pragma once
  149. #define __FILE_NLMDL_H_SEEN__ 1
  150.  
  151. #include "usual.h"      //This header is also in status.h
  152. #include "realmat.h"    //This header is also in status.h
  153. #include "tools.h"      //This header is also in status.h
  154.  
  155. #include "status.h"
  156. #include "model.h"
  157.  
  158. #endif
  159.  
  160.