matrix_extra

matrix_extra —

Synopsis




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);
gretl_vector* gretl_coeff_vector_from_model (const MODEL *pmod,
                                             const char *select);
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      (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             const char *mask);
gretl_matrix* gretl_matrix_data_subset_no_missing
                                            (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             int *err);
gretl_matrix* gretl_matrix_data_subset_skip_missing
                                            (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             int *err);
int         gretl_plotfit_matrices          (int yno,
                                             int xno,
                                             FitType fit,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             gretl_matrix **py,
                                             gretl_matrix **pX);

Description

Details

gretl_vector_from_array ()

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_from_series ()

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_from_2d_array ()

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_from_scalar ()

gretl_matrix* gretl_matrix_from_scalar      (double x);

x : scalar to be "promoted".
Returns : allocated 1x1 gretl_matrix, the single element of which is set to x, or NULL on allocation failure or if x = NADBL.

gretl_vcv_matrix_from_model ()

gretl_matrix* gretl_vcv_matrix_from_model   (MODEL *pmod,
                                             const char *select);

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.

pmod : pointer to model
select : char array indicating which rows and colums to select (or NULL for the full matrix).
Returns : the covariance matrix, or NULL on error.

gretl_coeff_vector_from_model ()

gretl_vector* gretl_coeff_vector_from_model (const MODEL *pmod,
                                             const char *select);

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.

pmod : pointer to model
select : char array indicating which rows to select (or NULL for the full vector).
Returns : the coefficient vector, or NULL on error.

gretl_covariance_matrix_from_varlist ()

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.

gretl_matrix_row_to_array ()

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_data_subset ()

gretl_matrix* gretl_matrix_data_subset      (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             const char *mask);

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. If mask is not NULL then it 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.

list : list of variable to process.
Z : data array.
t1 : starting observation.
t2 : ending observation.
mask : missing observations mask, or NULL.
Returns : allocated matrix or NULL on failure.

gretl_matrix_data_subset_no_missing ()

gretl_matrix* gretl_matrix_data_subset_no_missing
                                            (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             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. If any missing values are encountered this constitutes an error.

list : list of variable to process.
Z : data array.
t1 : starting observation.
t2 : ending observation.
err : location to receive error code.
Returns : allocated matrix or NULL on failure.

gretl_matrix_data_subset_skip_missing ()

gretl_matrix* gretl_matrix_data_subset_skip_missing
                                            (const int *list,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             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. If there is a missing value for any variable on a given row, that row is skipped.

list : list of variable to process.
Z : data array.
t1 : starting observation.
t2 : ending observation.
err : location to receive error code.
Returns : allocated matrix or NULL on failure.

gretl_plotfit_matrices ()

int         gretl_plotfit_matrices          (int yno,
                                             int xno,
                                             FitType fit,
                                             const double **Z,
                                             int t1,
                                             int t2,
                                             gretl_matrix **py,
                                             gretl_matrix **pX);

Creates a vector y and matrix X based on the input yno, xno and fit, using the given sample range. An observation is skipped if any of the variables in list are missing at that observation.

yno : ID number of the y variable.
xno : ID number of the y variable.
fit : type of fit sought.
Z : data array.
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.