Beispiel #1
0
static void
drop_redundant_vars (MODEL *pmod, DATASET *dset, gretl_matrix *R, 
		     int rank, gretlopt opt)
{
    int *droplist = NULL;
    int i, vi, pos, nd;
    double d;

#if REDEBUG
    printlist(pmod->list, "pmod->list, into drop_redundant_vars");
    fprintf(stderr, "rank = %d\n", rank);
#endif

    pos = 2;
    nd = 0;
    for (i=0; i<R->rows; i++) {
	d = gretl_matrix_get(R, i, i);
	if (fabs(d) < R_DIAG_MIN) {
	    vi = pmod->list[pos];
	    gretl_list_append_term(&droplist, vi);
	    fprintf(stderr, "dropping redundant variable %d (%s)\n",
		    vi, dset->varname[vi]);
	    gretl_list_delete_at_pos(pmod->list, pos--);
	    nd++;
	}
	pos++;
    }

    pmod->ncoeff -= nd;
    pmod->dfd = pmod->nobs - pmod->ncoeff;
    pmod->dfn = pmod->ncoeff - pmod->ifc;

    if (droplist != NULL) {
	gretl_model_set_list_as_data(pmod, "droplist", droplist);
    }
}
Beispiel #2
0
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;
}