static int finalize_midas_model (MODEL *pmod, const int *list, const char *param, const DATASET *dset, midas_info *minfo, int nmidas, int *xlist, int ldepvar, int hfslopes) { int type0, mixed = 0; int i, err = 0; gretl_model_set_string_as_data(pmod, "midas_spec", gretl_strdup(param)); if (pmod->ci == OLS) { /* @pmod is the result of OLS estimation */ int vi; gretl_model_allocate_param_names(pmod, pmod->ncoeff); for (i=0; i<pmod->ncoeff; i++) { vi = pmod->list[i+2]; gretl_model_set_param_name(pmod, i, dset->varname[vi]); } gretl_model_set_int(pmod, "umidas", 1); } else { /* @pmod is the result of NLS estimation */ free(pmod->depvar); pmod->depvar = gretl_strdup(dset->varname[list[1]]); free(pmod->list); pmod->list = gretl_list_copy(list); } pmod->ci = MIDASREG; /* record list of low-frequency regressors */ gretl_model_set_list_as_data(pmod, "lfxlist", xlist); if (ldepvar) { gretl_model_set_int(pmod, "dynamic", 1); } /* record the (common) type of MIDAS term? */ type0 = minfo[0].type; if (nmidas > 1) { for (i=1; i<nmidas; i++) { if (minfo[i].type != type0) { mixed = 1; break; } } } if (!mixed && type0 > 0) { gretl_model_set_int(pmod, "midas_type", type0); } if (nmidas == 1) { /* Record the "gross" MIDAS coefficients, to enable drawing of a plot? We'll do this only if we have a single MIDAS term, which is probably the most most common case. Otherwise it becomes too hard to get the plot right. */ int nx = list[0] - 1; const double *b = pmod->coeff + nx; add_midas_plot_matrix(pmod, &minfo[0], b); } if (!err) { err = model_add_minfo_array(pmod, minfo, nmidas); } return err; }
static int transcribe_duration_results (MODEL *pmod, duration_info *dinfo, const DATASET *dset, int fncount, int grcount, int use_bfgs, int censvar, gretlopt opt) { int np = dinfo->npar; int j, v, err = 0; pmod->ci = DURATION; if (dinfo->dist == DUR_EXPON) { pmod->opt |= OPT_E; } else if (dinfo->dist == DUR_LOGLOG) { pmod->opt |= OPT_L; } else if (dinfo->dist == DUR_LOGNORM) { pmod->opt |= OPT_Z; } else { pmod->opt |= OPT_W; /* Weibull */ } if (censvar > 0) { gretl_model_set_int(pmod, "cens_var", censvar); } if (use_bfgs) { gretl_model_set_int(pmod, "fncount", fncount); gretl_model_set_int(pmod, "grcount", grcount); } else { gretl_model_set_int(pmod, "iters", fncount); } if (!err) { err = gretl_model_allocate_param_names(pmod, np); if (!err) { for (j=0; j<dinfo->k; j++) { v = pmod->list[j+2]; gretl_model_set_param_name(pmod, j, dset->varname[v]); } if (dinfo->dist != DUR_EXPON) { gretl_model_set_param_name(pmod, np-1, "sigma"); } } } if (dinfo->dist == DUR_EXPON) { pmod->sigma = 1.0; } else { pmod->sigma = dinfo->theta[np-1]; } err = gretl_model_write_coeffs(pmod, dinfo->theta, np); if (!err) { err = duration_model_add_vcv(pmod, dinfo, dset, opt); } if (!err) { duration_set_predictions(pmod, dinfo, dset, opt); pmod->lnL = dinfo->ll; mle_criteria(pmod, 0); /* mask invalid statistics */ pmod->fstt = pmod->chisq = NADBL; pmod->rsq = pmod->adjrsq = NADBL; pmod->ess = NADBL; /* but add overall LR test if possible */ if (np > 1 + (dinfo->dist != DUR_EXPON)) { duration_overall_LR_test(pmod, dinfo, use_bfgs); } } return err; }