Top |
enum | ArmaFlags |
typedef | CoeffIntervals |
struct | CoeffIntervals_ |
enum | VCVMajorType |
enum | MLVCVType |
enum | HACKernel |
enum | PanelVCVType |
enum | RQVCVType |
enum | VCVFlags |
typedef | VCVInfo |
struct | VCVInfo_ |
enum | ModelTestType |
MODEL *
gretl_model_new (void
);
Allocates memory for a gretl MODEL struct and initializes the struct,
using gretl_model_init()
.
void gretl_model_init (MODEL *pmod
,const DATASET *dset
);
Initializes a gretl MODEL, including setting its pointer members
to NULL
. This initialization should be done if the caller has
declared a MODEL struct directly, rather than obtaining a pointer to
MODEL using gretl_model_new()
(in which case the initialization is
done automatically).
int
gretl_model_allocate_storage (MODEL *pmod
);
Allocates space for coefficients and standard errors,
residuals and fitted values in pmod
. The sizes of
the arrays are based on the ncoeff
and full_n
members of pmod
, which must be set first. The
residuals and fitted values are initialized to
gretl's missing value.
MODEL **
gretl_model_array_new (int n
);
Allocates memory for an array of n
gretl MODEL structs and
initializes each model using gretl_model_init()
.
MODEL *
allocate_working_model (void
);
Allocates memory for gretl MODEL struct and initializes it. The model is "protected" against deletion.
void gretl_model_array_destroy (MODEL **models
,int n
);
Frees all resources associated with an array of models, which
should have been obtained via gretl_model_array_new()
.
void gretl_model_smpl_init (MODEL *pmod
,const DATASET *dset
);
Records the start and end of the current sample range in
the model pmod
, which may be necessary for future reference
if a hypothesis test is to be performed. Note that this
sample range may not be the same as the data range over
which the model is actually estimated (for example, in the
case of autoregressive models where observations have to
be dropped to allow for lags).
void impose_model_smpl (const MODEL *pmod
,DATASET *dset
);
Sets on dset
the sample range (starting and ending
observations) that was in effect when pmod
was estimated.
This is not always the same as the data range over which
pmod
was actually estimated (e.g. in case of
autoregressive models, where observations are dropped
to allow for lags).
void gretl_model_set_auxiliary (MODEL *pmod
,ModelAuxCode aux
);
Sets an auxiliary code on pmod
, which may be relevant
for how the model is printed.
void
clear_model (MODEL *pmod
);
Clears a gretl MODEL, freeing all allocated storage and setting
pointer members to NULL
. Also frees any data pointers attached
via gretl_model_set_data()
. The model pointer itself is not
freed, so this function may be called on a MODEL which has been
declared directly by the caller; in that case the caller should
pass the address of the MODEL in question.
void
gretl_model_free (MODEL *pmod
);
Free allocated content of pmod
then the pointer itself.
void
gretl_model_free_on_exit (MODEL *pmod
);
Free allocated content of pmod
then the pointer itself,
without regard to the model's reference count.
int gretl_model_set_data_with_destructor (MODEL *pmod
,const char *key
,void *ptr
,GretlType type
,size_t size
,void (*destructor) (void *)
);
Attaches data to pmod
: the data can be retrieved later using
gretl_model_get_data()
. Note that the data are not "physically"
copied to the model; simply, ptr
is recorded on the model.
This means that the data referenced by the pointer now in
effect belong to pmod
. When pmod
is cleared with clear_model()
,
destructor
will be invoked with ptr
as its single argument.
If a simple "free" is OK for freeing the data, you can use
gretl_model_set_data()
instead.
The size
is needed in case the model is copied with
copy_model()
, in which case the target of the copying
operation receives a newly allocated copy of the data in
question.
pmod |
pointer to MODEL. |
|
key |
key string for data, used in retrieval. |
|
ptr |
data-pointer to be attached to model. |
|
type |
type of data to set. |
|
size |
size of data in bytes. |
|
destructor |
pointer to function that should be used to free the data-pointer in question. |
int gretl_model_set_data (MODEL *pmod
,const char *key
,void *ptr
,GretlType type
,size_t size
);
Attaches data to pmod
: the data can be retrieved later using
gretl_model_get_data()
. Note that the data are not "physically"
copied to the model; simply, ptr
is recorded on the model.
This means that the data referenced by the pointer now in
effect belong to pmod
. The data pointer will be freed when
pmod
is cleared with clear_model()
. If the data has deep
structure that requires special treatment on freeing, use
gretl_model_set_data_with_destructor()
instead.
The size
is needed in case the model is copied with
copy_model()
, in which case the target of the copying
operation receives a newly allocated copy of the data in
question.
pmod |
pointer to MODEL. |
|
key |
key string for data, used in retrieval. |
|
ptr |
data-pointer to be attached to model. |
|
type |
type of the data to set. |
|
size |
size of data in bytes. |
int gretl_model_set_matrix_as_data (MODEL *pmod
,const char *key
,gretl_matrix *m
);
Attaches m
to pmod
as data, recoverable via the key key
using gretl_model_get_data()
.
int gretl_model_set_list_as_data (MODEL *pmod
,const char *key
,int *list
);
Attaches list
to pmod
as data, recoverable via the key key
using gretl_model_get_list()
. Note that the model takes
ownership of the supplied list.
int gretl_model_set_string_as_data (MODEL *pmod
,const char *key
,char *str
);
Attaches str
to pmod
as data, recoverable via the key key
using gretl_model_get_data()
.
int gretl_model_set_array_as_data (MODEL *pmod
,const char *key
,gretl_array *A
);
Attaches A
to pmod
as data, recoverable via the key key
using gretl_model_get_data()
.
int gretl_model_destroy_data_item (MODEL *pmod
,const char *key
);
Looks up the data pointer, attached to pmod
, that is
identified by key
, and if a pointer is found, frees
it (or applies the destructor function that was set for
the item, if any) and removes it from the model's list of
data items. If you want to remove the item from the
model's list without freeing the underlying data pointer,
use gretl_model_detach_data_item()
.
int gretl_model_detach_data_item (MODEL *pmod
,const char *key
);
Looks up the data item, attached to pmod
, that is
identified by key
, and if an item is found, removes
it from the model's list of such items. The data
pointer associated with key
is not touched. If you
want the underlying resources associated with key
to be
freed, use gretl_model_destroy_data_item()
.
int gretl_model_set_int (MODEL *pmod
,const char *key
,int val
);
Records an integer value on a model: the value can be retrieved
later using gretl_model_get_int()
, using the appropriate key
.
int gretl_model_set_double (MODEL *pmod
,const char *key
,double val
);
Records a floating-point value on pmod
: the value can be
retrieved later using gretl_model_get_double()
with the
appropriate key
.
int gretl_model_set_full_vcv_info (MODEL *pmod
,int vmaj
,int vmin
,int order
,int flags
,double bw
);
void * gretl_model_get_data_full (const MODEL *pmod
,const char *key
,GretlType *type
,int *copied
,size_t *sz
);
pmod |
pointer to model. |
|
key |
key string. |
|
copied |
location to receive flag indicating whether the return value is an allocated copy of the original data. |
|
type |
location to receive data type. |
|
sz |
location to receive the size of the data. |
the data pointer identified by key
, or NULL
on failure.
If a non-zero value is written to copied
this indicates that the
return value is a copy of the original (and therefore it is the
caller's responsibility to free the data when it is no longer
required).
double gretl_model_get_double_default (const MODEL *pmod
,const char *key
,double deflt
);
char * gretl_model_get_param_name (const MODEL *pmod
,const DATASET *dset
,int i
,char *targ
);
Writes the appropriate parameter name into targ
, which
should be at least VNAMELEN bytes long. Usually this is
the name of a variable in the dataset, but sometimes it is
a special string (e.g. for nonlinear models).
gretl_array * gretl_model_get_param_names (const MODEL *pmod
,const DATASET *dset
,int *err
);
int gretl_model_get_param_number (const MODEL *pmod
,const DATASET *dset
,const char *s
);
CoeffIntervals * gretl_model_get_coeff_intervals (const MODEL *pmod
,const DATASET *dset
,gretlopt opt
);
Save the 95 percent confidence intervals for the parameter
estimates in pmod
.
int reset_coeff_intervals (CoeffIntervals *cf
,double alpha
);
Recomputes the intervals in cf
using the given value
of alpha
.
const char * gretl_model_get_depvar_name (const MODEL *pmod
,const DATASET *dset
);
int *
gretl_model_get_x_list (const MODEL *pmod
);
an allocated copy of the list of independent
variables included in pmod
, or NULL
on failure.
int *
gretl_model_get_y_list (const MODEL *pmod
);
Retrieve an allocated copy of the list of dependent variables
for pmod
: in almost all cases this will have a single
element; an exception is biprobit.
int *
gretl_model_get_secondary_list (const MODEL *pmod
);
Retrieve an allocated copy of the secondary list from
pmod
: e.g. the list of instruments in the case of IVREG
, or
the selection equation list for HECKIT
.
int arma_model_AR_MA_coeffs (const MODEL *pmod
,gretl_vector **phi_star
,gretl_vector **theta_star
,gretlopt opt
);
Creates consolidated versions of the AR and MA coefficient vectors
from pmod
. If pmod
includes seasonal ARMA terms, the vectors are
suitably expanded to include the interactions between seasonal and
non-seasonal terms. If OPT_I is given and the dependent variable
has been differenced, the AR coefficients are integrated to account
for the differencing. These are the \Phi^* and \Theta^* as used by
Box and Jenkins for forecasting.
int regarma_model_AR_coeffs (const MODEL *pmod
,double **phi0
,int *pp
);
Creates a consolidated version of the AR coefficients from pmod
.
If pmod
includes seasonal AR terms the vector is suitably expanded
to include the interactions between seasonal and non-seasonal
terms, but it is not integrated with respect to any differencing of
the dependent variable.
const double *
arma_model_get_x_coeffs (const MODEL *pmod
);
pointer to the array of coefficients on the exogenous
regressors in pmod
, or NULL
if the model is not ARMA or if there
are no such regressors.
int regarima_model_get_AR_coeffs (const MODEL *pmod
,double **phi0
,int *pp
);
int * arima_delta_coeffs (int d
,int D
,int s
);
gretl_matrix * arma_spectrum_plot_data (const MODEL *pmod
,const DATASET *dset
,int *err
);
gretl_matrix * gretl_model_ahat_vec (const MODEL *pmod
,int *err
);
If pmod
was estimated on panel data via fixed or random
effects, provides a column vector holding the "ahat" values
or estimated individual effects for the individuals
included in the active dataset when the model was estimated.
Some of these values may be NA if some units were not
actually included in estimation.
int gretl_model_set_coeff_separator (MODEL *pmod
,const char *s
,int pos
);
Arranges for the insertion of the given string (or a blank line if
s
is NULL
) at the given position in the array of coefficients,
when the model is printed. The extra line is printed before
coefficient pos
, where pos
is interpreted as a zero-based
index.
pmod |
pointer to model. |
|
s |
informative string (or |
|
pos |
position in the array of coefficients. |
int gretl_model_get_coeff_separator (const MODEL *pmod
,char **ps
,int *ppos
);
Retrieves information that has been set on pmod
regarding the
insertion of an extra line when printing the coefficients, if any.
int gretl_model_new_vcv (MODEL *pmod
,int *nelem
);
Allocates space for a packed coefficient covariance matrix
in pmod
(if such space is not already allocated). Sets
all entries in the array to zero.
pmod |
pointer to model. |
|
nelem |
pointer to receive number of elements in
the packed array, or |
int gretl_model_write_vcv (MODEL *pmod
,const gretl_matrix *V
);
Write the covariance matrix V
into the model pmod
, using the
special packed format that is required by the MODEL struct,
and set the standard errors to the square root of the diagonal
elements of this matrix.
int gretl_model_add_QML_vcv (MODEL *pmod
,int ci
,const gretl_matrix *H
,const gretl_matrix *G
,const DATASET *dset
,gretlopt opt
,gretl_matrix **pV
);
Write a QML covariance matrix into the model pmod
, and set
the standard errors to the square root of the diagonal
elements of this matrix. The ci
argument, specifying the
estimator for pmod
, is required only if opt
includes
OPT_C; otherwise it is ignored.
pmod |
pointer to model. |
|
ci |
command index for model. |
|
H |
inverse of the (negative) Hessian, k x k. |
|
G |
score matrix, T x k. |
|
dset |
pointer to dataset (can be NULL if not doing clustering). |
|
opt |
may include OPT_C for cluster-robust variant. |
|
pV |
location to receive the full covariance matrix, or NULL. |
int gretl_model_add_hessian_vcv (MODEL *pmod
,const gretl_matrix *H
);
Write H
into the model pmod
as its covariance matrix, and
set the standard errors to the square roots of the diagonal
elements of this matrix.
int gretl_model_add_OPG_vcv (MODEL *pmod
,const gretl_matrix *G
,gretl_matrix **pV
);
Compute (G'G)^{-1}, write this into pmod
as its covariance matrix,
and set the standard errors to the square roots of the diagonal
elements of this matrix.
VMatrix * gretl_model_get_vcv (MODEL *pmod
,const DATASET *dset
);
Supplies the caller with a copy of the variance-covariance
matrix for the parameter estimates in pmod
, in a format
suitable for printing. See also free_vcv()
. To get the
covariance matrix as a gretl_matrix, see
gretl_vcv_matrix_from_model()
.
double gretl_model_get_vcv_element (const MODEL *pmod
,int i
,int j
,int np
);
int gretl_model_write_coeffs (MODEL *pmod
,double *b
,int k
);
Write the coefficients b
into the model pmod
, whose
coefficient array is resized appropriately if need be.
int gretl_model_add_arinfo (MODEL *pmod
,int nterms
);
Performs initial setup for structure to hold info on autoregressive coefficients.
MODEL *
gretl_model_copy (MODEL *pmod
);
Does a deep copy of pmod
: allocates a new MODEL pointer
which has its own allocated copies of all the pointer
members of pmod
. The only feature of pmod
that is
not duplicated is the reference count, which is set
to zero in the copy.
void swap_models (MODEL *targ
,MODEL *src
);
Swaps the content of the two model pointers.
int command_ok_for_model (int test_ci
,gretlopt opt
,const MODEL *pmod
);
Check to see if the model-related command in question is
meaningful and acceptable in the context of the estimator
associated with pmod
. Note, though, that this function may
give a "false positive": to be quite sure, we may need to
know more about the model (e.g. specific options used).
See also model_test_ok()
.
int model_test_ok (int ci
,gretlopt opt
,const MODEL *pmod
,const DATASET *dset
);
A more rigorous version of command_ok_for_model()
. Use
this function if the extra information is available.
int maybe_add_test_to_model (MODEL *pmod
,ModelTest *test
);
Adds a ModelTest to pmod
, if the test in question has
not already been performed and recorded. Note that this
function takes care of freeing test
.
void model_test_set_crit_and_alpha (ModelTest *test
,double crit
,double alpha
);
void gretl_model_test_print_direct (const ModelTest *test
,int heading
,PRN *prn
);
void
gretl_model_destroy_tests (MODEL *pmod
);
Clears any hypothesis test structs that have been attached
to pmod
.
int highest_numbered_var_in_model (const MODEL *pmod
,const DATASET *dset
);
int gretl_model_allocate_param_names (MODEL *pmod
,int k
);
Allocate an array of k
strings to hold the names given to
the associated coefficients, in a model where these strings
are not simply given by the names of the independent variables.
int gretl_model_set_param_name (MODEL *pmod
,int i
,const char *name
);
int gretl_model_add_arma_varnames (MODEL *pmod
,const DATASET *dset
,int yno
,int p
,int q
,const char *pmask
,const char *qmask
,int P
,int Q
,int r
);
Composes a set of names to be given to the regressors in an ARMA model.
pmod |
pointer to target model. |
|
dset |
dataset information. |
|
yno |
ID number of dependent variable. |
|
p |
non-seasonal (max) AR order. |
|
q |
non-seasonal (max) MA order. |
|
pmask |
for masking out specific AR lags. |
|
qmask |
for masking out specific MA lags. |
|
P |
seasonal AR order. |
|
Q |
seasonal MA order. |
|
r |
number of exogenous regressors (excluding the constant). |
int gretl_model_add_panel_varnames (MODEL *pmod
,const DATASET *dset
,const int *ulist
);
Composes a set of names to be given to the regressors in an panel model.
void gretl_model_add_allocated_varnames (MODEL *pmod
,char **vnames
);
Attaches an allocated set of variable names to be used
when printing model results, for use in special cases
where we can't just reference names from the list of
regressors attached to the model. The number of strings
must match the number of coefficients, given by the
ncoeff
member of pmod
.
Note that pmod
"takes charge" of the array vnames
:
this will be freed when the model is destroyed.
int gretl_model_add_y_median (MODEL *pmod
,const double *y
);
Calculates the median of y
using the valid observations
with the model's sample range and attaches the median
to the model as data under the key ymedian
.
char * gretl_model_get_fitted_formula (const MODEL *pmod
,int xvar
,const DATASET *dset
);
If pmod
is a simple linear, quadratic or logistic model,
and if xvar
is in fact the "x" variable from the model,
returns a string representing the formula for generating the
fitted values as a function of x. This formula may be used
in the context of a fitted versus actual plot.
void gretl_model_set_name (MODEL *pmod
,const char *name
);
Sets the name of the given model; this is used in
printing the model and in displaying it in the
gretl GUI. Note that a model's name must be no more
than MAXSAVENAME bytes in length, including the
terminating NUL byte; name
is truncated if it is
too long.
double gretl_model_get_scalar (MODEL *pmod
,ModelDataIndex idx
,DATASET *dset
,int *err
);
Retrieves a specified scalar statistic from pmod
:
idx
must be less than M_SCALAR_MAX
.
pmod |
pointer to target model. |
|
idx |
index for the scalar value that is wanted. |
|
dset |
dataset struct. |
|
err |
location to receive error code (required). |
the requested statistic, or NADBL on failure,
in which case err
will contain a non-zero error code.
int gretl_model_get_series (double *x
,MODEL *pmod
,const DATASET *dset
,ModelDataIndex idx
);
Retrieves from pmod
a copy of a specified series (for
example, regression residuals); idx
must be greater than
M_SCALAR_MAX
and less than M_SERIES_MAX
.
gretl_matrix * gretl_model_get_matrix (MODEL *pmod
,ModelDataIndex idx
,int *err
);
Retrieves from pmod
a copy of a specified matrix (for
example, regression residuals); idx
must be greater than
M_SERIES_MAX
and less than M_MATRIX_MAX
.
pmod |
pointer to target model. |
|
idx |
index for the matrix that is wanted. |
|
err |
location to receive error code (required). |
the allocated matrix, or NULL
on failure,
in which case err
will contain a non-zero error code.
double gretl_model_get_data_element (MODEL *pmod
,int idx
,const char *s
,const DATASET *dset
,int *err
);
int gretl_model_serialize (const MODEL *pmod
,SavedObjectFlags flags
,PRN *prn
);
MODEL * gretl_model_from_XML (xmlNodePtr node
,xmlDocPtr doc
,const DATASET *dset
,int *err
);
Reads info on a gretl model from the given XML node
and doc
, and reconstitutes the model in memory.
struct CoeffIntervals_ { int asy; int ncoeff; double alpha; double t; char **names; double *coeff; double *maxerr; int df; gretlopt opt; };
struct VCVInfo_ { int vmaj; /* general type of VCV */ int vmin; /* HC variant, etc. */ int order; /* for use with HAC */ VCVFlags flags; /* includes prewhitening */ double bw; /* for use with QS HAC kernel */ };