tab_float (t, 6, 1, 0, pval, 10, 2);
for (j = 1; j <= c->n_indeps; j++)
{
- v = pspp_linreg_coeff_get_var (c->coeff[j], 0);
+ v = pspp_coeff_get_var (c->coeff[j], 0);
label = var_to_string (v);
/* Do not overwrite the variable's name. */
strncpy (tmp, label, MAX_STRING);
for that value.
*/
- val = pspp_linreg_coeff_get_value (c->coeff[j], v);
+ val = pspp_coeff_get_value (c->coeff[j], v);
val_s = value_to_string (val, v);
strncat (tmp, val_s, MAX_STRING);
}
tab_text (t, 1, 1, TAB_CENTER | TAT_TITLE, _("Covariances"));
for (i = 1; i < c->n_coeffs; i++)
{
- const struct variable *v = pspp_linreg_coeff_get_var (c->coeff[i], 0);
+ const struct variable *v = pspp_coeff_get_var (c->coeff[i], 0);
label = var_to_string (v);
tab_text (t, 2, i, TAB_CENTER, label);
tab_text (t, i + 2, 0, TAB_CENTER, label);
size_t j;
int n_vars = 0;
struct variable **varlist;
- struct pspp_linreg_coeff *coeff;
+ struct pspp_coeff *coeff;
const struct variable *v;
union value *val;
for (i = 1; i < c->n_indeps; i++) /* c->coeff[0] is the intercept. */
{
coeff = c->coeff[i];
- v = pspp_linreg_coeff_get_var (coeff, 0);
+ v = pspp_coeff_get_var (coeff, 0);
if (v->type == ALPHA)
{
if (!reg_inserted (v, varlist, n_vars))
reg_print_depvars (FILE * fp, pspp_linreg_cache * c)
{
int i;
- struct pspp_linreg_coeff *coeff;
+ struct pspp_coeff *coeff;
const struct variable *v;
fprintf (fp, "char *model_depvars[%d] = {", c->n_indeps);
for (i = 1; i < c->n_indeps; i++)
{
coeff = c->coeff[i];
- v = pspp_linreg_coeff_get_var (coeff, 0);
+ v = pspp_coeff_get_var (coeff, 0);
fprintf (fp, "\"%s\",\n\t\t", v->name);
}
coeff = c->coeff[i];
- v = pspp_linreg_coeff_get_var (coeff, 0);
+ v = pspp_coeff_get_var (coeff, 0);
fprintf (fp, "\"%s\"};\n\t", v->name);
}
static void
for (i = 1; i < c->n_coeffs; i++)
{
- v = pspp_linreg_coeff_get_var (c->coeff[i], 0);
+ v = pspp_coeff_get_var (c->coeff[i], 0);
if (v->type == ALPHA)
{
return 1;
int n_quantiles = 100;
double increment;
double tmp;
- struct pspp_linreg_coeff *coeff;
+ struct pspp_coeff *coeff;
if (export)
{
and store pointers to the variables that correspond to the
coefficients.
*/
- pspp_linreg_coeff_init (models[k], X);
+ pspp_coeff_init (models[k], X);
/*
Find the least-squares estimates and other statistics.
2006-05-19 Jason Stover <jhs@math.gcsu.edu>
+ * coefficient.h: Renamed pspp_linreg_coeff to pspp_coeff.
+
* coefficient.c: Moved to src/math.
* coefficient.h: Moved to src/math.
/*
- lib/linreg/coefficient.c
+ src/math/coefficient.c
Copyright (C) 2005 Free Software Foundation, Inc. Written by Jason H Stover.
};
void
-pspp_linreg_coeff_free (struct pspp_linreg_coeff *c)
+pspp_coeff_free (struct pspp_coeff *c)
{
free (c->v_info);
free (c);
coefficient structures for the linear model.
*/
void
-pspp_linreg_coeff_init (pspp_linreg_cache * c, struct design_matrix *X)
+pspp_coeff_init (pspp_linreg_cache * c, struct design_matrix *X)
{
size_t i;
size_t j;
int n_vals = 1;
- struct pspp_linreg_coeff *coeff;
+ struct pspp_coeff *coeff;
c->coeff = xnmalloc (X->m->size2 + 1, sizeof (*c->coeff));
c->coeff[0] = xmalloc (sizeof (*c->coeff[0]));
}
}
void
-pspp_linreg_coeff_set_estimate (struct pspp_linreg_coeff *c, double estimate)
+pspp_coeff_set_estimate (struct pspp_coeff *c, double estimate)
{
c->estimate = estimate;
}
void
-pspp_linreg_coeff_set_std_err (struct pspp_linreg_coeff *c, double std_err)
+pspp_coeff_set_std_err (struct pspp_coeff *c, double std_err)
{
c->std_err = std_err;
}
Return the estimated value of the coefficient.
*/
double
-pspp_linreg_coeff_get_est (const struct pspp_linreg_coeff *c)
+pspp_coeff_get_est (const struct pspp_coeff *c)
{
if (c == NULL)
{
Return the standard error of the estimated coefficient.
*/
double
-pspp_linreg_coeff_get_std_err (const struct pspp_linreg_coeff *c)
+pspp_coeff_get_std_err (const struct pspp_coeff *c)
{
if (c == NULL)
{
How many variables are associated with this coefficient?
*/
int
-pspp_linreg_coeff_get_n_vars (struct pspp_linreg_coeff *c)
+pspp_coeff_get_n_vars (struct pspp_coeff *c)
{
if (c == NULL)
{
0 unless the coefficient refers to an interaction term.
*/
const struct variable *
-pspp_linreg_coeff_get_var (struct pspp_linreg_coeff *c, int i)
+pspp_coeff_get_var (struct pspp_coeff *c, int i)
{
if (c == NULL)
{
Which value is associated with this coefficient/variable combination?
*/
const union value *
-pspp_linreg_coeff_get_value (struct pspp_linreg_coeff *c,
+pspp_coeff_get_value (struct pspp_coeff *c,
const struct variable *v)
{
int i = 0;
}
while (i < c->n_vars)
{
- candidate = pspp_linreg_coeff_get_var (c, i);
+ candidate = pspp_coeff_get_var (c, i);
if (v->index == candidate->index)
{
return (c->v_info + i)->val;
Which coefficient is associated with V? The VAL argument is relevant
only to categorical variables.
*/
-const struct pspp_linreg_coeff *
+const struct pspp_coeff *
pspp_linreg_get_coeff (const pspp_linreg_cache * c,
const struct variable *v, const union value *val)
{
int i = 1;
- struct pspp_linreg_coeff *result = NULL;
+ struct pspp_coeff *result = NULL;
const struct variable *tmp = NULL;
if (c == NULL)
}
result = c->coeff[i];
- tmp = pspp_linreg_coeff_get_var (result, 0);
+ tmp = pspp_coeff_get_var (result, 0);
while (tmp->index != v->index && i < c->n_coeffs)
{
result = c->coeff[i];
- tmp = pspp_linreg_coeff_get_var (result, 0);
+ tmp = pspp_coeff_get_var (result, 0);
i++;
}
if (i > c->n_coeffs)
matches the VAL.
*/
while (tmp->index != v->index && i < c->n_coeffs
- && compare_values (pspp_linreg_coeff_get_value (result, tmp),
+ && compare_values (pspp_coeff_get_value (result, tmp),
val, v->width))
{ /* FIX THIS */
i++;
result = c->coeff[i];
- tmp = pspp_linreg_coeff_get_var (result, 0);
+ tmp = pspp_coeff_get_var (result, 0);
}
if (i == c->n_coeffs)
{
/*
- lib/linreg/coefficient.c
+ src/math/coefficient.c
Copyright (C) 2005 Free Software Foundation, Inc. Written by Jason H Stover.
storage. Therefore non-essential members of the struct will be
allocated only when requested.
*/
-struct pspp_linreg_coeff
+struct pspp_coeff
{
double estimate; /* Estimated coefficient. */
double std_err; /* Standard error of the estimate. */
};
-void pspp_linreg_coeff_free (struct pspp_linreg_coeff *);
+void pspp_coeff_free (struct pspp_coeff *);
/*
Initialize the variable and value pointers inside the
coefficient structures for the linear model.
*/
-void pspp_linreg_coeff_init (pspp_linreg_cache *, struct design_matrix *);
+void pspp_coeff_init (pspp_linreg_cache *, struct design_matrix *);
void
-pspp_linreg_coeff_set_estimate (struct pspp_linreg_coeff *, double estimate);
+pspp_coeff_set_estimate (struct pspp_coeff *, double estimate);
void
-pspp_linreg_coeff_set_std_err (struct pspp_linreg_coeff *, double std_err);
+pspp_coeff_set_std_err (struct pspp_coeff *, double std_err);
/*
Accessor functions for matching coefficients and variables.
/*
Return the estimated value of the coefficient.
*/
-double pspp_linreg_coeff_get_est (const struct pspp_linreg_coeff *);
+double pspp_coeff_get_est (const struct pspp_coeff *);
/*
Return the standard error of the estimated coefficient.
*/
-double pspp_linreg_coeff_get_std_err (const struct pspp_linreg_coeff *);
+double pspp_coeff_get_std_err (const struct pspp_coeff *);
/*
How many variables are associated with this coefficient?
*/
-int pspp_linreg_coeff_get_n_vars (struct pspp_linreg_coeff *);
+int pspp_coeff_get_n_vars (struct pspp_coeff *);
/*
Which variable does this coefficient match? The int argument is usually
0, unless the coefficient refers to an interaction.
*/
-const struct variable *pspp_linreg_coeff_get_var (struct pspp_linreg_coeff *,
+const struct variable *pspp_coeff_get_var (struct pspp_coeff *,
int);
/*
Which value is associated with this coefficient/variable comination?
*/
-const union value *pspp_linreg_coeff_get_value (struct pspp_linreg_coeff *,
+const union value *pspp_coeff_get_value (struct pspp_coeff *,
const struct variable *);
-const struct pspp_linreg_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache
+const struct pspp_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache
*,
const struct variable
*,
pspp_linreg_get_vars (const void *c_, struct variable **v)
{
const pspp_linreg_cache *c = c_;
- struct pspp_linreg_coeff *coef = NULL;
+ struct pspp_coeff *coef = NULL;
const struct variable *tmp;
int i;
int result = 0;
/*
Start at c->coeff[1] to avoid the intercept.
*/
- v[result] = (struct variable *) pspp_linreg_coeff_get_var (c->coeff[1], 0);
+ v[result] = (struct variable *) pspp_coeff_get_var (c->coeff[1], 0);
result = (v[result] == NULL) ? 0 : 1;
for (coef = c->coeff[2]; coef < c->coeff[c->n_coeffs]; coef++)
{
- tmp = pspp_linreg_coeff_get_var (coef, 0);
+ tmp = pspp_coeff_get_var (coef, 0);
assert (tmp != NULL);
/* Repeated variables are likely to bunch together, at the end
of the array. */
gsl_matrix_free (c->cov);
for (i = 0; i < c->n_coeffs; i++)
{
- pspp_linreg_coeff_free (c->coeff[i]);
+ pspp_coeff_free (c->coeff[i]);
}
free (c);
return true;
#include <gsl/gsl_matrix.h>
struct variable;
-struct pspp_linreg_coeff;
+struct pspp_coeff;
union value;
enum
const struct variable *depvar;
gsl_vector *residuals;
- struct pspp_linreg_coeff **coeff;
+ struct pspp_coeff **coeff;
int method; /* Method to use to estimate parameters. */
/*
Means and standard deviations of the variables.
const pspp_linreg_cache *c = c_;
int i;
int j;
- const struct pspp_linreg_coeff **found;
- const struct pspp_linreg_coeff *coe;
+ const struct pspp_coeff **found;
+ const struct pspp_coeff *coe;
double result;
double tmp;
if (i < c->n_coeffs)
{
found[i] = coe;
- tmp = pspp_linreg_coeff_get_est (coe);
+ tmp = pspp_coeff_get_est (coe);
if (predictors[j]->type == NUMERIC)
{
tmp *= vals[j]->f;