| Libgretl Reference Manual |
|---|
nlsnls — |
nlspec;
double (*BFGS_CRIT_FUNC) (const double*,
void*);
int (*BFGS_GRAD_FUNC) (double*,
double*,
...,
BFGS_CRIT_FUNC,
void*);
double* (*BFGS_SCORE_FUNC) (const double*,
...,
void*);
nlspec* nlspec_new (int ci,
const DATAINFO *pdinfo);
void nlspec_destroy (nlspec *spec);
int nlspec_add_param_with_deriv (nlspec *spec,
const char *dstr,
const double **Z,
const DATAINFO *pdinfo);
int nlspec_add_param_list (nlspec *spec,
const int *list,
const double **Z,
const DATAINFO *pdinfo);
int nlspec_set_regression_function (nlspec *spec,
const char *fnstr,
const DATAINFO *pdinfo);
void nlspec_set_t1_t2 (nlspec *spec,
int t1,
int t2);
int nls_parse_line (int ci,
const char *line,
const double **Z,
const DATAINFO *pdinfo,
PRN *prn);
MODEL nls (double ***pZ,
DATAINFO *pdinfo,
gretlopt opt,
PRN *prn);
MODEL model_from_nlspec (nlspec *spec,
double ***pZ,
DATAINFO *pdinfo,
gretlopt opt,
PRN *prn);
double get_default_nls_toler (void);
int BFGS_max (double *b,
int n,
int maxit,
double reltol,
int *fncount,
int *grcount,
BFGS_CRIT_FUNC cfunc,
int crittype,
BFGS_GRAD_FUNC gradfunc,
void *data,
gretlopt opt,
PRN *prn);
int BFGS_numeric_gradient (double *b,
double *g,
int n,
BFGS_CRIT_FUNC func,
void *data);
gretl_matrix* build_OPG_matrix (double *b,
int k,
int T,
BFGS_SCORE_FUNC scorefun,
void *data,
int *err);
double* numerical_hessian (double *b,
int n,
BFGS_CRIT_FUNC func,
void *data,
int *err);
double user_BFGS (gretl_matrix *b,
const char *fncall,
double ***pZ,
DATAINFO *pdinfo,
PRN *prn,
int *err);
gretl_matrix* fdjac (gretl_matrix *theta,
const char *fncall,
double ***pZ,
DATAINFO *pdinfo,
int *err);
typedef struct {
int ci; /* NLS, MLE or GMM */
int mode; /* derivatives: numeric or analytic */
gretlopt opt; /* can include OPT_V for verbose output; if ci = MLE
can also include OPT_H (Hessian) or OPT_R (QML)
to control the estimator of the variance matrix
*/
int dv; /* ID number of dependent variable (NLS) */
char lhname[VNAMELEN]; /* name of LHS var in criterion function */
int lhv; /* ID number of LHS variable in function being
minimized or maximized... */
gretl_matrix *lvec; /* or LHS vector */
char *nlfunc; /* string representation of function,
expressed in terms of the residuals (NLS,
GMM) or the log-likelihood (MLE)
*/
int nparam; /* number of parameters */
int ncoeff; /* number of coefficients (allows for vector params) */
int nvec; /* number of vector parameters */
int naux; /* number of auxiliary commands */
int ngenrs; /* number of variable-generating formulae */
int iters; /* number of iterations performed */
int fncount; /* number of function evaluations (ML, GMM) */
int grcount; /* number of gradient evaluations (ML, GMM) */
int t1; /* starting observation */
int t2; /* ending observation */
int nobs; /* number of observations used */
double crit; /* criterion (minimand or maximand) */
double tol; /* tolerance for stopping iteration */
parm *params; /* array of information on function parameters
(see the parm_ struct above) */
doublereal *coeff; /* coefficient estimates */
double *hessvec; /* vech representation of negative inverse of
Hessian */
char **aux; /* auxiliary commands */
GENERATOR **genrs; /* variable-generation pointers */
double ***Z; /* pointer to data array */
DATAINFO *dinfo; /* pointer to dataset info */
PRN *prn; /* printing aparatus */
ocset *oc; /* orthogonality info (GMM) */
} nlspec;
int (*BFGS_GRAD_FUNC) (double*,
double*,
...,
BFGS_CRIT_FUNC,
void*);
Param1 : |
|
Param2 : |
|
... : |
|
Param4 : |
|
Param5 : |
|
| Returns : |
double* (*BFGS_SCORE_FUNC) (const double*,
...,
void*);
Param1 : |
|
... : |
|
Param3 : |
|
| Returns : |
nlspec* nlspec_new (int ci, const DATAINFO *pdinfo);
ci : |
NLS, MLE or GMM.
|
pdinfo : |
information on dataset. |
| Returns : | a pointer to a newly allocated nls specification,
or NULL on failure.
|
void nlspec_destroy (nlspec *spec);
Frees all resources associated with spec, and frees the
pointer itself.
spec : |
pointer to nls specification. |
int nlspec_add_param_with_deriv (nlspec *spec, const char *dstr, const double **Z, const DATAINFO *pdinfo);
Adds an analytical derivative to spec. This pointer must
have previously been obtained by a call to nlspec_new().
The required format for dstr is "varname = formula", where
varname is the name of the (scalar) variable holding the parameter
in question, and formula is an expression, of the sort that
is fed to gretl's genr command, giving the derivative of the
regression function in spec with respect to the parameter.
The variable holding the parameter must be already present in
the dataset.
spec : |
pointer to nls specification. |
dstr : |
string specifying a derivative with respect to a parameter of the regression function. |
Z : |
data array. |
pdinfo : |
information on dataset. |
| Returns : | 0 on success, non-zero error code on error. |
int nlspec_add_param_list (nlspec *spec, const int *list, const double **Z, const DATAINFO *pdinfo);
Adds to spec a list of (scalar) parameters to be estimated, as
given in list. For an example of use see arma.c in the
gretl plugin directory.
spec : |
nls specification. |
list : |
list of variables by ID number. |
Z : |
data array. |
pdinfo : |
information on dataset. |
| Returns : | 0 on success, non-zero error code on error. |
int nlspec_set_regression_function (nlspec *spec, const char *fnstr, const DATAINFO *pdinfo);
Adds the regression function to spec. This pointer must
have previously been obtained by a call to nlspec_new().
The required format for fnstr is "varname = formula", where
varname is the name of the dependent variable and formula
is an expression of the sort that is fed to gretl's genr command.
The dependent variable must be already present in the
dataset.
spec : |
pointer to nls specification. |
fnstr : |
string specifying nonlinear regression function. |
pdinfo : |
information on dataset. |
| Returns : | 0 on success, non-zero error code on error. |
void nlspec_set_t1_t2 (nlspec *spec, int t1, int t2);
Sets the sample range for estimation of spec. This pointer must
have previously been obtained by a call to nlspec_new().
spec : |
pointer to nls specification. |
t1 : |
starting observation. |
t2 : |
ending observation. |
int nls_parse_line (int ci,
const char *line,
const double **Z,
const DATAINFO *pdinfo,
PRN *prn);
This function is used to create the specification of a
nonlinear regression function, to be estimated via nls.
It should first be called with a line containing a
string specification of the regression function. Optionally,
it can then be called one or more times to specify
analytical derivatives for the parameters of the regression
function.
The format of line should be that used in the genr function.
When specifying the regression function, the formula may
optionally be preceded by the string nls. When specifying
a derivative, line must start with the string deriv. See
the gretl manual for details.
ci : |
either NLS or MLE (docs not finished on this)
|
line : |
specification of regression function or derivative of this function with respect to a parameter. |
Z : |
data array. |
pdinfo : |
information on dataset. |
prn : |
gretl printing struct (for warning messages). |
| Returns : | 0 on success, non-zero error code on failure. |
MODEL nls (double ***pZ, DATAINFO *pdinfo, gretlopt opt, PRN *prn);
Computes estimates of a model via nonlinear least squares. The model must have been specified previously, via calls to the function nls_parse_line.
pZ : |
pointer to data array. |
pdinfo : |
information on dataset. |
opt : |
may include OPT_V for verbose output, OPT_R
for robust covariance matrix.
|
prn : |
printing struct. |
| Returns : | a model struct containing the parameter estimates and associated statistics. |
MODEL model_from_nlspec (nlspec *spec, double ***pZ, DATAINFO *pdinfo, gretlopt opt, PRN *prn);
Computes estimates of the model specified in spec, via nonlinear
least squares. The spec must first be obtained using nlspec_new(), and
initialized using nlspec_set_regression_function(). If analytical
derivatives are to be used (which is optional but recommended)
these are set using nlspec_add_param_with_deriv().
spec : |
nls specification. |
pZ : |
pointer to data array. |
pdinfo : |
information on dataset. |
opt : |
may include OPT_V for verbose output, OPT_A to
treat as an auxiliary model, OPT_C to produce coefficient
estimates only (don't bother with GNR to produce standard
errors).
|
prn : |
printing struct. |
| Returns : | a model struct containing the parameter estimates and associated statistics. |
double get_default_nls_toler (void);
| Returns : | the default value used in the convergence criterion for estimation of models using nonlinear least squares. |
int BFGS_max (double *b,
int n,
int maxit,
double reltol,
int *fncount,
int *grcount,
BFGS_CRIT_FUNC cfunc,
int crittype,
BFGS_GRAD_FUNC gradfunc,
void *data,
gretlopt opt,
PRN *prn);
Obtains the set of values for b which jointly maximize the
criterion value as calculated by cfunc. Uses the BFGS
variable-metric method. Based on Pascal code in J. C. Nash,
"Compact Numerical Methods for Computers," 2nd edition, converted
by p2c then re-crafted by B. D. Ripley for gnu R. Revised for
gretl by Allin Cottrell.
b : |
array of adjustable coefficients. |
n : |
number elements in array b.
|
maxit : |
the maximum number of iterations to allow. |
reltol : |
relative tolerance for terminating iteration. |
fncount : |
location to receive count of function evaluations. |
grcount : |
location to receive count of gradient evaluations. |
cfunc : |
pointer to function used to calculate maximand. |
crittype : |
code for type of the maximand/minimand: should
be C_LOGLIK, C_GMM or C_OTHER. Used only in printing
iteration info.
|
gradfunc : |
pointer to function used to calculate the
gradient, or NULL for default numerical calculation.
|
data : |
pointer that will be passed as the last
parameter to the callback functions cfunc and gradfunc.
|
opt : |
may contain OPT_V for verbose operation.
|
prn : |
printing struct (or NULL). Only used if opt
includes OPT_V.
|
| Returns : | 0 on successful completion, non-zero error code on error. |
int BFGS_numeric_gradient (double *b,
double *g,
int n,
BFGS_CRIT_FUNC func,
void *data);
b : |
|
g : |
|
n : |
|
func : |
|
data : |
|
| Returns : |
gretl_matrix* build_OPG_matrix (double *b, int k, int T, BFGS_SCORE_FUNC scorefun, void *data, int *err);
b : |
|
k : |
|
T : |
|
scorefun : |
|
data : |
|
err : |
|
| Returns : |
double* numerical_hessian (double *b,
int n,
BFGS_CRIT_FUNC func,
void *data,
int *err);
b : |
|
n : |
|
func : |
|
data : |
|
err : |
|
| Returns : |
double user_BFGS (gretl_matrix *b, const char *fncall, double ***pZ, DATAINFO *pdinfo, PRN *prn, int *err);
b : |
|
fncall : |
|
pZ : |
|
pdinfo : |
|
prn : |
|
err : |
|
| Returns : |
gretl_matrix* fdjac (gretl_matrix *theta, const char *fncall, double ***pZ, DATAINFO *pdinfo, int *err);
theta : |
|
fncall : |
|
pZ : |
|
pdinfo : |
|
err : |
|
| Returns : |
| << tsls | system >> |