PARMSET Data Type |
A PARMSET is a specialized data type which consists of a list of parameters (a “parameter set”) for non-linear estimation and constraints on them (if any). PARMSETs are constructed and maintained using the instruction NONLIN, and are used by the instructions CVMODEL, DLM, FIND, MAXIMIZE, NLLS, and NLSYSTEM. PARMSETs can be combined using the standard “+” operator. You can set up vectors or matrices of them or pass them as procedure parameters.
The Instruction NONLIN
NONLIN sets up or edits the list of free parameters in the model. In its simplest form, it simply defines a list of free parameters to be estimated by a subsequent instruction, such as NLLS:
nonlin alpha gamma delta
nonlin g b0 b1 b2
NONLIN can accept either single REAL variables as parameters or a complete VECTOR or other real array, or an array of real-valued arrays, such as a VECTOR[VECTOR]. For instance,
declare vector b(5)
nonlin b rho
will create a parameter set which includes the five elements of B plus the single value RHO. A vector used in this way doesn’t have to be dimensioned at the time of the NONLIN instruction, but must be dimensioned before being used for estimation.
The above instructions create an internal PARMSET, which is the one used by the estimation instructions unless you provide a different one.
Managing and Combining PARMSETS
To create a different PARMSET, use the PARMSET option on the NONLIN.
nonlin(parmset=boxcoxparms) sigma lambda
nonlin(parmset=regparms) b
The first of these creates a PARMSET named BOXCOXPARMS which includes the two variables SIGMA and LAMBDA. The second creates REGPARMS. You can combine one PARMSET with another using the “+” operation, either in a COMPUTE instruction or directly on the estimation instruction. For instance,
compute fullparm=boxcoxparms+regparms or
maximize(parmset=boxcoxparms+regparms) ...
The functions %PARMSPEEK and %PARMSPOKE can be used (with a named PARMSET) to move values into and out of a parameter set. For instance, in the last example, %PARMSPEEK(BOXCOXPARMS) will return a vector with elements SIGMA and LAMBDA in order, and %PARMSPOKE(BOXCOXPARMS,V) would make SIGMA=V(1) and LAMBDA=V(2). This can be handy when you wish to parameterize a function using single variable names (which makes it easier to change the function, and read the estimation output), but you also need to be able to move information into and out of the parameter set easily. For instance,
nonlin(parmset=simszha) a12 a21 a23 a24 a31 a36 a41 $
a43 a46 a51 a53 a54 a56
...
compute axbase=%parmspeek(simszha)
...
compute %parmspoke(simszha,axbase+saxx*au)
In the application from which this is taken, it’s necessary to reset the parameters using a matrix operation. However, parameterizing the function as A(13) would have been clumsy, since adding or deleting a parameter would have required a complete rewrite of six lines defining a matrix. By using %PARMSPEEK and %PARMSPOKE, you can set up the PARMSET in the most convenient fashion and still be able to set the elements using matrix operations.
If you need to refer to the default parameter set, use the %PARMSET() function.
Using NONLIN to Impose Constraints
NONLIN is also used to add constraints on the parameters.
nonlin(parmset=base) g b0 b1 b2
nonlin(parmset=constraint) b0>=0.0 b1>=0.0 b2>=0.0
nlls(parmset=base) ...
nlls(parmset=base+constraint) ...
This does NLLS on a model, the first time without constraints imposed, the second with non-negativity constraints on the three “b” parameters. Note that constraints are only obeyed for certain types of non-linear optimization methods. In particular, the simplex and genetic algorithms won’t impose inequality constraints.
Constraints can also apply to all elements of a vector or matrix. For instance, the following creates a PARMSET with the single real variable A and a vector with NLAGS elements B, and constrains the B’s to be positive.
dec vect b(nlags)
nonlin a b b>=0
Even if you’re not actually doing non-linear estimation which requires a PARMSET, you can benefit from using them to organize your statistics. For instance, suppose you’re running a loop and you need to keep track of M1, M2, M3 and M4. If you do
nonlin(parmset=simstats) m1 m2 m3 m4
then the function %PARMSPEEK(SIMSTATS) will return a 4-vector with the current values of the four variables. You can thus do the calculations using statistics on the VECTOR rather than having to program up bookkeeping on the separate variables. When you’re done, you can also use %PARMSLABELS(SIMSTATS) to get the labels for output.
Note that while, in this case, these are all scalars, they could be a mix of scalars and matrices, just like any other PARMSET.
Copyright © 2025 Thomas A. Doan