| Libgretl Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
enum MMissingCode; gretl_vector * gretl_vector_from_array (const double *x, int n, GretlMatrixMod mod); gretl_vector * gretl_vector_from_series (const double *x, int t1, int t2); gretl_matrix * gretl_matrix_from_2d_array (const double **X, int rows, int cols); gretl_matrix * gretl_matrix_from_scalar (double x); gretl_matrix * gretl_vcv_matrix_from_model (MODEL *pmod, const char *select, int *err); gretl_vector * gretl_coeff_vector_from_model (const MODEL *pmod, const char *select, int *err); gretl_matrix * gretl_covariance_matrix_from_varlist (const int *list, const double **Z, const DATAINFO *pdinfo, gretl_matrix **means, int *errp); int gretl_matrix_row_to_array (const gretl_matrix *m, int i, double *x); gretl_matrix * gretl_matrix_data_subset_masked (const int *list, const double **Z, int t1, int t2, const char *mask, int *err); gretl_matrix * gretl_matrix_data_subset (const int *list, const double **Z, int t1, int t2, int missop, int *err); DATAINFO * gretl_dataset_from_matrix (gretl_matrix *m, const int *list, double ***pZ, int *err); int gretl_plotfit_matrices (const double *yvar, const double *xvar, FitType fit, int t1, int t2, gretl_matrix **py, gretl_matrix **pX); int gretl_matrix_delete_columns (gretl_matrix *X, int *list); gretl_matrix * gretl_matrix_read_from_text (const char *fname, int *err); int gretl_matrix_write_as_text (gretl_matrix *A, const char *fname); void gretl_matrix_print_to_prn (const gretl_matrix *m, const char *msg, PRN *prn); void gretl_packed_matrix_print (const gretl_matrix *m, const char *msg); void debug_print_matrix (const gretl_matrix *m, const char *msg); void gretl_matrix_print_with_col_heads (const gretl_matrix *m, const char *title, const char **heads, PRN *prn); void gretl_matrix_print_with_format (const gretl_matrix *m, const char *fmt, int wid, int prec, PRN *prn); int gretl_matrix_cut_rows (gretl_matrix *m, const char *mask); int gretl_matrix_cut_rows_cols (gretl_matrix *m, const char *mask); char * gretl_matrix_zero_row_mask (const gretl_matrix *m, int *err); char * gretl_matrix_rank_mask (const gretl_matrix *m, int *err); int gretl_matrix_mp_ols (const gretl_vector *y, const gretl_matrix *X, gretl_vector *b, gretl_matrix *vcv, gretl_vector *uhat, double *s2);
typedef enum {
M_MISSING_OK,
M_MISSING_ERROR,
M_MISSING_SKIP,
M_MISSING_TRIM
} MMissingCode;
gretl_vector * gretl_vector_from_array (const double *x, int n, GretlMatrixMod mod);
x : |
pointer to array of elements. |
n : |
number of elements. |
mod : |
modifier flag: either GRETL_MOD_NONE, or GRETL_MOD_SQUARE
to use the squares of the elements of x.
|
| Returns : | pointer to a newly allocated gretl_vector containing
the elements of x (or their squares), or NULL on failure.
Missing valies in x are skipped.
|
gretl_vector * gretl_vector_from_series (const double *x, int t1, int t2);
x : |
series from data array. |
t1 : |
starting observation. |
t2 : |
ending observation. |
| Returns : | a newly allocated gretl_vector containing the values
of the given data series for the given range, or NULL on failure.
|
gretl_matrix * gretl_matrix_from_2d_array (const double **X, int rows, int cols);
X : |
two-dimensional array of doubles. |
rows : |
number of rows in target matrix. |
cols : |
number of columns in target matrix. |
| Returns : | allocated gretl_matrix, the elements of which are set to
the values in X, or NULL on allocation failure.
|
gretl_matrix * gretl_vcv_matrix_from_model (MODEL *pmod, const char *select, int *err);
Produces all or part of the covariance matrix for pmod
in the form of a gretl_matrix. Storage is allocated, to be freed
by the caller. If select is not NULL, it should be an array
with non-zero elements in positions corresponding to the
desired rows (and columns), and zero elements otherwise.
gretl_vector * gretl_coeff_vector_from_model (const MODEL *pmod, const char *select, int *err);
Produces all or part of the coefficient vector for pmod
in the form of a gretl column vector. Storage is allocated, to be freed
by the caller. If select is non-NULL, it should be an array
with non-zero elements in positions corresponding to the
desired rows and zero elements otherwise.
gretl_matrix * gretl_covariance_matrix_from_varlist (const int *list, const double **Z, const DATAINFO *pdinfo, gretl_matrix **means, int *errp);
list : |
list of variables by ID number. |
Z : |
data array. |
pdinfo : |
pointer to data information struct. |
means : |
pointer to pick up vector of means, or NULL to discard.
|
errp : |
pointer to receive non-zero error code in case of
failure, or NULL.
|
| Returns : | the variance-covariance matrix of the listed variables
(over the currently defined data sample), or NULL in case of
failure.
|
int gretl_matrix_row_to_array (const gretl_matrix *m, int i, double *x);
Copies the values from row i of matrix m into the array
x, which should already be allocated to the correct size.
m : |
source matrix. |
i : |
the row from which values should be copied. |
x : |
array of doubles large enough to hold a row from m.
|
| Returns : | 0 on sucess, 1 if the row is out of bounds. |
gretl_matrix * gretl_matrix_data_subset_masked (const int *list, const double **Z, int t1, int t2, const char *mask, int *err);
Creates a gretl matrix holding the subset of variables from
Z specified by list, over the sample range t1 to t2,
inclusive. Variables are in columns. mask should be an
array of char of length (t2 - t1 + 1) with 1s in the positions
of observations to exclude from the subset and zeros elsewhere.
This apparatus can be used to exclude missing observations.
gretl_matrix * gretl_matrix_data_subset (const int *list, const double **Z, int t1, int t2, int missop, int *err);
Creates a gretl matrix holding the subset of variables from
Z specified by list, over the sample range t1 to t2,
inclusive. Variables are in columns. The missop flag
can be M_MISSING_OK to indicate that it's OK to include
missing values in the matrix (these become NaNs),
M_MISSING_ERROR (it's an error of any missing values are
found), or M_MISSING_SKIP (observations with any missing
values are omitted from the matrix).
list : |
list of variable to process. |
Z : |
data array. |
t1 : |
starting observation. |
t2 : |
ending observation. |
missop : |
how to handle missing observations. |
err : |
location to receive error code. |
| Returns : | allocated matrix or NULL on failure.
|
DATAINFO * gretl_dataset_from_matrix (gretl_matrix *m, const int *list, double ***pZ, int *err);
Creates a gretl dataset from matrix m, either using the
columns specified in list or using all columns if list
is NULL.
int gretl_plotfit_matrices (const double *yvar,
const double *xvar,
FitType fit,
int t1,
int t2,
gretl_matrix **py,
gretl_matrix **pX);
Creates a vector y and matrix X based on the input yvar,
xvar and fit, using the given sample range. An observation
is skipped if either yvar or xvar is missing at that
observation.
yvar : |
the y variable. |
xvar : |
the x variable. |
fit : |
type of fit sought. |
t1 : |
starting observation. |
t2 : |
ending observation. |
py : |
location to receive y vector. |
pX : |
location to receive X matrix. |
| Returns : | 0 on success, non-zero code on error. |
int gretl_matrix_delete_columns (gretl_matrix *X, int *list);
X : |
|
list : |
|
| Returns : |
gretl_matrix * gretl_matrix_read_from_text (const char *fname, int *err);
Reads a matrix from a text file by the name fname; the column
separator must be space or tab. It is assumed that the dimensions of
the matrix (number of rows and columns) are found on the first line
of the csv file, so no heuristics are necessary. In case of error,
an empty matrix is returned and err is filled appropriately.
fname : |
name of text file. |
err : |
location to receive error code. |
| Returns : | The matrix read from file, or NULL.
|
int gretl_matrix_write_as_text (gretl_matrix *A, const char *fname);
A : |
|
fname : |
|
| Returns : |
void gretl_matrix_print_to_prn (const gretl_matrix *m, const char *msg, PRN *prn);
Prints the matrix m to prn.
m : |
matrix to print. |
msg : |
accompanying message text (or NULL if no message is wanted).
|
prn : |
pointer to gretl printing struct. |
void gretl_packed_matrix_print (const gretl_matrix *m, const char *msg);
Prints the symmetric matrix m (packed as lower triangle)
to stderr.
m : |
packed matrix to print. |
msg : |
accompanying message text (or NULL if no message is wanted).
|
void debug_print_matrix (const gretl_matrix *m, const char *msg);
Prints the matrix m to stderr, as with gretl_matrix_print(), but
appends the address of the matrix struct.
m : |
matrix to print. |
msg : |
accompanying message text (or NULL if no message is wanted).
|
void gretl_matrix_print_with_col_heads (const gretl_matrix *m, const char *title, const char **heads, PRN *prn);
Prints the matrix m to prn, with column headings given
by heads.
m : |
matrix to print. |
title : |
accompanying title (or NULL if no title is wanted).
|
heads : |
array of strings to identify the columns. |
prn : |
pointer to gretl printing struct. |
void gretl_matrix_print_with_format (const gretl_matrix *m, const char *fmt, int wid, int prec, PRN *prn);
m : |
|
fmt : |
|
wid : |
|
prec : |
|
prn : |
int gretl_matrix_cut_rows (gretl_matrix *m, const char *mask);
In-place reduction of m based on mask: the masked rows
are cut out of m.
m : |
matrix to process. |
mask : |
character array of length equal to the rows of m,
with 1s indicating rows to be cut, 0s for rows to be
retained.
|
| Returns : | 0 on success, non-zero on error. |
int gretl_matrix_cut_rows_cols (gretl_matrix *m, const char *mask);
In-place reduction of m based on mask: the masked rows
and columns are cut out of m.
m : |
square matrix to process. |
mask : |
character array of length equal to the dimension
of m, with 1s indicating rows and columns to be cut, 0s
for rows/columns to be retained.
|
| Returns : | 0 on success, non-zero on error. |
char * gretl_matrix_zero_row_mask (const gretl_matrix *m, int *err);
Checks matrix m for rows that are all zero. If there are
any such rows, constructs a mask of length equal to the
number of rows in m, with 1s indicating zero rows, 0s
elsewhere. If there are no such rows, returns NULL.
E_ALLOC is written to err in case a mask should have
been constructed but allocation failed.
m : |
matrix to process. |
err : |
location to receive error code. |
| Returns : | allocated mask or NULL.
|
char * gretl_matrix_rank_mask (const gretl_matrix *m, int *err);
Performs a QR decomposition of matrix m and uses this
to assess the rank of m. If m is not of full rank,
constructs a mask of length equal to the numbers of
columns in m, with 1s in positions corresponding
to diagonal elements of R that are effectively 0, and
0s elsewhere. If m is of full column rank, NULL is
returned.
E_ALLOC is written to err in case a mask should have
been constructed but allocation failed.
m : |
matrix to process. |
err : |
location to receive error code. |
| Returns : | allocated mask or NULL.
|
int gretl_matrix_mp_ols (const gretl_vector *y, const gretl_matrix *X, gretl_vector *b, gretl_matrix *vcv, gretl_vector *uhat, double *s2);
Computes OLS estimates using Cholesky factorization, via
the GMP multiple-precision library, and puts the
coefficient estimates in b. Optionally, calculates the
covariance matrix in vcv and the residuals in uhat.
y : |
dependent variable vector. |
X : |
matrix of independent variables. |
b : |
vector to hold coefficient estimates. |
vcv : |
matrix to hold the covariance matrix of the coefficients,
or NULL if this is not needed.
|
uhat : |
vector to hold the regression residuals, or NULL if
these are not needed.
|
s2 : |
pointer to receive residual variance, or NULL. Note:
if s2 is NULL, the "vcv" estimate will be plain (X'X)^{-1}.
|
| Returns : | 0 on success, non-zero error code on failure. |