static int qr_make_cluster_vcv (MODEL *pmod, int ci, const DATASET *dset, gretl_matrix *XX, gretlopt opt) { gretl_matrix *cvals = NULL; gretl_matrix *V = NULL; const char *cname; int cvar, n_c = 0; int err = 0; if (pmod->ci != OLS && pmod->ci != IVREG) { /* relax this? */ return E_NOTIMP; } cname = get_optval_string(ci, OPT_C); if (cname == NULL) { return E_PARSE; } cvar = current_series_index(dset, cname); if (cvar < 1 || cvar >= dset->v) { err = E_UNKVAR; } if (!err) { cvals = cluster_var_values(dset->Z[cvar], pmod, &err); if (!err) { n_c = gretl_vector_get_length(cvals); if (n_c < 2) { err = E_DATA; } } } #if CDEBUG fprintf(stderr, "qr_make_cluster_vcv: err = %d\n", err); fprintf(stderr, "cluster var = %s (%d)\n", cname, cvar); gretl_matrix_print(cvals, "cvals"); #endif if (!err) { V = cluster_vcv_calc(pmod, cvar, cvals, XX, dset, &err); } if (!err) { err = gretl_model_write_vcv(pmod, V); } if (!err) { gretl_model_set_vcv_info(pmod, VCV_CLUSTER, cvar); gretl_model_set_int(pmod, "n_clusters", n_c); } gretl_matrix_free(V); gretl_matrix_free(cvals); return err; }
int matrix_freq_driver (const int *list, int *graph, gretlopt opt, PRN *prn) { gretl_matrix *m = NULL; DATASET *mdset = NULL; const char *mname; int err = 0; if (list[0] != 1) { return E_PARSE; } mname = get_optval_string(FREQ, OPT_X); if (mname != NULL) { m = get_matrix_by_name(mname); } if (gretl_is_null_matrix(m)) { err = E_DATA; } else { mdset = gretl_dataset_from_matrix(m, list, OPT_B, &err); } if (!err) { err = freqdist(1, mdset, graph, opt, prn); } destroy_dataset(mdset); return err; }
int list_summary_driver (const int *list, const DATASET *dset, gretlopt opt, PRN *prn) { int wtvar = 0; int err = 0; if (opt & OPT_W) { const char *wname = get_optval_string(SUMMARY, OPT_W); if (wname == NULL) { err = E_DATA; } else { wtvar = current_series_index(dset, wname); if (wtvar < 0) { err = E_UNKVAR; } } } if (!err) { err = list_summary(list, wtvar, dset, opt, prn); } return err; }
int graph_page_parse_line (const char *line, gretlopt opt) { const char *outfile = NULL; char cmdword[16]; int gotcmd = 0; int err = 0; if (sscanf(line, "%*s %15s", cmdword) == 1) { gotcmd = 1; } if (gotcmd && (opt & OPT_O)) { /* the --output option rules out the various command words */ return E_PARSE; } else if (opt & OPT_O) { /* --output="filename" */ outfile = get_optval_string(GRAPHPG, OPT_O); if (outfile == NULL) { return E_PARSE; } else { return print_graph_page_direct(outfile, opt); } } else if (!gotcmd) { return E_PARSE; } if (!strcmp(cmdword, "add")) { err = graph_page_add_last_graph(); } else if (!strcmp(cmdword, "show")) { err = display_graph_page(NULL); } else if (!strcmp(cmdword, "free")) { if (gpage.ngraphs > 0) { clear_graph_page(0); } } else if (!strcmp(cmdword, "fontscale")) { const char *s = strstr(line, "fontscale"); err = graph_page_set_font_scale(s + 9); } return err; }
int matrix_command_driver (int ci, const int *list, const char *param, const DATASET *dset, gretlopt opt, PRN *prn) { gretl_matrix *m = NULL; DATASET *mdset = NULL; int *collist = NULL; const char *mname; int err = 0; mname = get_optval_string(ci, OPT_X); if (mname != NULL) { m = get_matrix_by_name(mname); } if (gretl_is_null_matrix(m)) { err = E_DATA; } else if (ci == SCATTERS) { /* note: this is a special case, for now */ return matrix_scatters(m, list, dset, opt); } else if (list != NULL && list[0] == 0) { /* use all columns of the matrix */ mdset = gretl_dataset_from_matrix(m, NULL, OPT_B, &err); } else if (list != NULL && list[0] == 1 && ci == SUMMARY) { /* summary stats for a single specified column */ mdset = gretl_dataset_from_matrix(m, list, OPT_B | OPT_N, &err); } else { /* note that a NULL list is OK here */ mdset = gretl_dataset_from_matrix(m, list, OPT_B, &err); } if (!err) { dataset_set_matrix_name(mdset, mname); collist = gretl_consecutive_list_new(1, mdset->v - 1); if (collist == NULL) { err = E_ALLOC; } } if (!err) { opt &= ~OPT_X; if (ci == BXPLOT) { err = boxplots(collist, param, mdset, opt); } else if (ci == GNUPLOT) { err = gnuplot(collist, param, mdset, opt); } else if (ci == SUMMARY) { err = list_summary(collist, 0, mdset, opt, prn); } else { err = E_DATA; } } destroy_dataset(mdset); free(collist); return err; }