"Fossies" - the Fresh Open Source Software Archive

Member "gretl-2019c/extra/arma_example.c" (11 Aug 2018, 2158 Bytes) of package /linux/misc/gretl-2019c.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "arma_example.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  *  gretl -- Gnu Regression, Econometrics and Time-series Library
    3  *  Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
    4  * 
    5  *  This program is free software: you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation, either version 3 of the License, or
    8  *  (at your option) any later version.
    9  * 
   10  *  This program is distributed in the hope that it will be useful,
   11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *  GNU General Public License for more details.
   14  * 
   15  *  You should have received a copy of the GNU General Public License
   16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  * 
   18  */
   19 
   20 /* Sample program to estimate an ARMA model via libgretl */
   21 
   22 #include <gretl/libgretl.h>
   23 
   24 int arma_estimate (DATASET *dset, PRN *prn)
   25 {
   26     MODEL *model;
   27     int *list;
   28     int err;
   29 
   30     model = gretl_model_new();
   31     list = gretl_list_new(5);
   32 
   33     list[1] = 1;        /* AR order */
   34     list[2] = 0;        /* order of integration */
   35     list[3] = 1;        /* MA order */
   36     list[4] = LISTSEP;  /* separator */
   37     list[5] = 1;        /* position of dependent variable in dataset */
   38 
   39     *model = arma(list, NULL, dset, OPT_NONE, prn);
   40     err = model->errcode;
   41 
   42     if (err) {
   43     errmsg(err, prn);
   44     } else {
   45     printmodel(model, dset, OPT_NONE, prn);
   46     }
   47 
   48     gretl_model_free(model);
   49     free(list);
   50 
   51     return err;
   52 }
   53 
   54 int main (void)
   55 {
   56     DATASET *dset;
   57     PRN *prn;
   58     int err;
   59 
   60     libgretl_init();
   61 
   62     dset = datainfo_new();
   63     prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
   64 
   65     /* Give the full path to the gretl datafile unless it's 
   66        in the current working directory. Note that PREFIX is
   67        defined in the Makefile 
   68     */
   69     err = gretl_read_native_data(PREFIX "/share/gretl/data/ramanathan/data9-7.gdt", dset);
   70 
   71     if (err) {
   72     errmsg(err, prn);
   73     exit(EXIT_FAILURE);
   74     }
   75 
   76     err = arma_estimate(dset, prn);
   77     
   78     destroy_dataset(dset);
   79     gretl_print_destroy(prn);
   80 
   81     libgretl_cleanup();
   82 
   83     return 0;
   84 }