Esempio n. 1
0
static int add_midas_plot_matrix (MODEL *pmod,
				  midas_info *m,
				  const double *b)
{
    gretl_matrix *C = NULL;
    gretl_matrix *theta = NULL;
    gretl_matrix *w = NULL;
    int err = 0;
	
    C = gretl_matrix_alloc(m->nterms, 2);
    err = (C == NULL);

    if (!err && m->type != MIDAS_U) {
	theta = gretl_matrix_alloc(m->nparm, 1);
	err = (theta == NULL);
    }

    if (!err) {
	double ci, hfb = 0;
	int p = m->minlag;
	int i, k = 0;
	
	if (m->type == MIDAS_U) {
	    for (i=0; i<m->nparm; i++) {
		gretl_matrix_set(C, i, 0, b[k++]);
		gretl_matrix_set(C, i, 1, p++);
	    }
	} else {
	    hfb = takes_coeff(m->type) ? b[k++] : 1.0;
	    for (i=0; i<m->nparm; i++) {
		theta->val[i] = b[k++];
	    }		
	    w = midas_weights(m->nterms, theta, m->type, &err);
	    if (!err) {
		for (i=0; i<m->nterms; i++) {
		    ci = hfb * w->val[i];
		    gretl_matrix_set(C, i, 0, ci);
		    gretl_matrix_set(C, i, 1, p++);
		}
	    }
	    gretl_matrix_free(w);
	}
    }

    gretl_matrix_free(theta);

    if (!err) {
	char *cnames[2] = {"coeff", "lag"};
	char **S = strings_array_dup(cnames, 2);

	if (S != NULL) {
	    gretl_matrix_set_colnames(C, S);
	}
	err = gretl_model_set_matrix_as_data(pmod, "midas_coeffs", C);
    } else {
	gretl_matrix_free(C);
    }

    return err;
}
series_table *series_table_copy (series_table *st)
{
    series_table *ret = NULL;

    if (st != NULL) {
	ret = series_table_alloc();
    }

    if (ret != NULL) {
	char **S = strings_array_dup(st->strs, st->n_strs);
	int i;

	if (S == NULL) {
	    series_table_destroy(ret);
	    ret = NULL;
	} else {
	    ret->n_strs = st->n_strs;
	    ret->strs = S;
	    for (i=0; i<ret->n_strs; i++) {
		g_hash_table_insert(ret->ht, (gpointer) ret->strs[i], 
				    GINT_TO_POINTER(i+1));
	    }
	}
    }

    return ret;
}
Esempio n. 3
0
gretl_array *gretl_array_from_strings (char **S, int n,
				       int copy, int *err)
{
    gretl_array *A;

    A = gretl_array_new(GRETL_TYPE_STRINGS, 0, err);

    if (A != NULL) {
	if (copy) {
	    A->data = (void **) strings_array_dup(S, n);
	    if (A->data == NULL) {
		*err = E_ALLOC;
	    }
	} else {
	    A->data = (void **) S;
	}
	if (!*err) {
	    A->n = n;
	}
    }

    return A;
}