Hi, Folks,

I am new to gretl. I need to use the gretl libraries within my C++ codes to be able to get ARMA estimations. However, whatever dataset that I try, the model returns an error code of 3 corresponding to finding a singular matrix, or an error code 5. Could someone please help me figure out what I am doing wrong? I am pasting my code here. Thanks in advace.

extern "C" {
    #include </usr/local/include/gretl/libgretl.h>
}

int main ()
{

    char *fname;
    int err;
    MODEL *mymodel=NULL;
    const int *list, *pqlags;
    const double **Z = NULL;
    double **data = NULL;
    DATAINFO *pdinfo;
    gretlopt opt;
    PRN *prn = NULL;
    const char *arma_spec = "1 1 1 ; 0";
    const char *arma_pq_lags = "1 1 1 ; 0";

    fname = "ar1.gdt";
    putenv("GRETL_PLUGIN_PATH=/usr/local/lib/gretl-gtk2/");
    libgretl_init();
    //prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
    pdinfo = datainfo_new();

    list = gretl_list_from_string(arma_spec, &err);
    if(err){
            printf("%dError forming list...\n", err);
    }
    else{
            printf("Successfully formed list...\n");
    }
    pqlags = gretl_list_from_string(arma_pq_lags, &err);
    if(err){
            printf("%dError setting pqlags...\n", err);
    }
    else{
            printf("Successfully set pqlags...\n");
    }
   
    double d[100] = {14.00506,11.88694,15.84804,16.51717,14.55883,18.91454,15.56367,18.95697,21.16984,23.70920,
                     26.51456,25.02122,24.67900,24.57805,27.53288,26.16876,25.97866,28.77978,27.00108,26.31299,
                      23.90812,28.09266,27.59627,28.99814,27.25777,21.54126,24.70151,29.98875,28.83029,30.92882,
                     33.13654,31.92837,32.16757,35.21054,36.53613,35.32862,36.95167,35.64065,33.83243,35.97180,
                     37.06993,40.31979,40.41081,41.82210,41.57343,41.89816,36.40815,37.99717,39.21328,38.22750,
                     39.87281,39.07015,38.82488,41.02295,40.33261,38.38574,34.24121,34.99200,34.66115,36.47538,
                     38.15541,38.16863,36.70234,35.50128,30.94532,30.10700,29.89030,26.38155,28.98603,30.92539,
                     30.58638,34.29289,32.15656,33.86830,37.14510,32.88388,31.34332,34.36881,35.96956,36.14701,
                     37.06460,34.94625,36.38298,37.88554,36.18585,35.67232,38.44046,38.32361,35.27670,39.22223,
                     38.74319,38.24741,38.20142,36.89593,36.60553,39.88735,39.64674,36.07956,34.86294,29.09646};
   
    double *mydataarr[100];
    for(int i = 0; i < 100; i++){
            d[i] = i;
            mydataarr[i] = &d[i];
    }

    Z = (const double **)mydataarr;
    double **pZ = (double **)mydataarr;

    mymodel = gretl_model_new();
    pdinfo = datainfo_new();
    pdinfo = create_new_dataset(&pZ,1,100,1);

    const DATAINFO *info = (const DATAINFO *)pdinfo;

    printf("Before mymodel=%lu\n",mymodel);
    (*mymodel)= arma(list,pqlags,Z,pdinfo,OPT_NONE,NULL);

    if(mymodel->errcode)
    {
        printf("ARMA model error: %d\n", mymodel->errcode);
    }
    else
    {
        printf("%f",mymodel->uhat[0]);
    }

    destroy_dataset(pZ, pdinfo);
    gretl_print_destroy(prn);
    libgretl_cleanup();

    return 0;
}




--
Kahkashan.