Hello
Everything plots/charts/works just fine when I use the GUI, but when I call
corrgram(.......) using the api in C++ it does not show the graph. The function does
compute and display the LAG ACF PACF Q-stat. [p-value], but it
does not show the ACF and PACF charts.
I have also tired correlogram_plot (...), I get the following "Gnuplot is broken or
too old: must be >= version 5.0", but as you see below my Gnuplot is >= 5.0 and
when I use the GUI it plots the ACF and PACF just fine.
GNU Plot Version 5.2 patchlevel 8 last modified 2019-12-01.
OS = Ubuntu 18
GCC = version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
Below is the c++ code that calls the corrgram(...). There are 3 separate functions
involved. The first two functions on this page are helper functions and the final function
at the end is were I call corrgram(...).
Thank you for your help
Riley
template<typename T>
void ToGretl(std::vector<T> &data, DATASET *gretl_data_set, int pd, int
structure, std::string variable_name){
/*
typedef struct {
int v; number of variables
int n; number of observations
int pd; periodicity or frequency of data
int structure; time series, cross section or whatever
double sd0; float representation of stobs
int t1, t2; start and end of current sample
char stobs[OBSLEN]; string representation of starting obs (date)
char endobs[OBSLEN]; string representation of ending obs
double **Z; data array
char **varname; array of names of variables
VARINFO **varinfo; array of specific info on vars
char markers; NO_MARKERS (0), REGULAR MARKERS or DAILY_DATE_STRINGS
char modflag; binary flag for dataset modified or not
char **S; to hold observation markers
char *descrip; to hold info on data sources etc.
char *submask; subsampling mask
char *restriction; record of sub-sampling restriction
char *padmask; record of padding to re-balance panel data
unsigned int rseed; resampling seed
int auxiliary; = 0 for regular dataset, 1 for aux dataset
char *pangrps; panel-only: name of series holding group names
int panel_pd; panel-only: panel time-series frequency
double panel_sd0; panel-only: time-series start
} DATASET;
*/
int nobs = data.size();
gretl_data_set->pd = pd;
gretl_data_set->structure = structure;//1=time series
//gretl_data_set = create_new_dataset (1,nobs, 0);
gretl_data_set->v = 1;//# of vars +1 becuase the dataset requires a constant
gretl_data_set->n = nobs;
gretl_data_set->t1 = 0;//this should be the same as i in for loop below;
gretl_data_set->t2 = nobs;//data.size();//this should be the same as i in for loop
below;
//char f_[] = variable_name.c_str();
gretl_data_set->varname = (char **) malloc(sizeof(char *));//malloc(f_* sizeof(f_));
*gretl_data_set->varname = (char *) malloc(sizeof(char));//malloc(f_* size
strcpy(*gretl_data_set->varname, const_cast<char*>(variable_name.c_str()));
allocate_Z(gretl_data_set, OPT_B);
if(gretl_data_set != NULL){
int size_ = sizeof(gretl_data_set->Z)/sizeof(double);
for(int i = 0; i<nobs;++i){
gretl_data_set->Z[0][i] = data[i];
std::cout<<gretl_data_set->Z[0][i]<<std::endl;
}
}
}
template void ToGretl<double>(std::vector<double> &, DATASET *, int , int
, std::string );
int CorrgramGretl(int varno, int order, int nparam, DATASET *dset, gretlopt opt, PRN
*prn){
int err = 0;
err = corrgram (varno, order, nparam, dset, opt, prn);
return 0;
}
void DataEDA(){
for(auto it:cat_id_by_day){
Stats::Histogram hist_st;
auto cat_id = all_data.cat_id_map.find(it.first);
if(cat_id != all_data.cat_id_map.end()){
std::cout<<"Cat_Id "<<cat_id->second<<std::endl;
Stats::CalcSimpleStats(it.second, hist_st, 10, true);
//Stats::PlotLine()
libgretl_init();
DATASET *gretl_data_set;
PRN *prn;
MODEL *model;
gretl_data_set = datainfo_new();
//gretl_data_set->stobs = all_data.calendar_data.begin()->first.copy();
char* p2 = const_cast<char*>(all_data.calendar_data.begin()->first.c_str());
strcpy(gretl_data_set->stobs, p2);
char* p3 =
const_cast<char*>(all_data.calendar_data.rbegin()->first.c_str());
strcpy( gretl_data_set->endobs, p3);
MyData::ToGretl(it.second,gretl_data_set,7,1, "test");
int err=0;
prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
if (err) {
errmsg(err, prn);
exit(EXIT_FAILURE);
}
gretlopt opt = OPT_R;
// err = gnuplot_graph_wanted (PLOT_CORRELOGRAM, opt);
if (err) {
errmsg(err, prn);
}
std::cout<<"GNU Plot version
"<<gnuplot_version()<<std::endl;
gretl_matrix *acf_mat;//const gretl_matrix *PM
// acf_mat = gretl_matrix_alloc(m, 100);
acf_mat = acf_matrix(gretl_data_set->Z[0], 100, gretl_data_set,
gretl_data_set->n,&err);
const char *vname = "V2";
const double *acf=const_cast<const double* >( &acf_mat->val[0]);
const double *pacf=const_cast<const double* >( &acf_mat->val[1]);
int m = 30;
double pm = 1.0;
// err = correlogram_plot (vname,acf,pacf,acf_mat,m, pm,opt);
if (err) {
errmsg(err, prn);
}
err = Stats::CorrgramGretl(0, 100, 0, gretl_data_set, opt, prn);
if (err) {
errmsg(err, prn);
}
// err = Stats::ArmaEstimateGretl(gretl_data_set, prn, model, 1,1,1,0);
destroy_dataset(gretl_data_set);
gretl_print_destroy(prn);
libgretl_cleanup();
// working got putting arma_estimate into Stat.cpp function
// cleaning this funtion up and moving thing to their respective function
}
}
}