1 |
/* PSPP - linear regression. |
/* PSPP - Binary encodings for categorical variables. |
2 |
Copyright (C) 2005 Free Software Foundation, Inc. |
Copyright (C) 2005 Free Software Foundation, Inc. |
3 |
Written by Jason H Stover <jason@sakla.net>. |
Written by Jason H Stover <jason@sakla.net>. |
4 |
|
|
31 |
sub-row of a matrix, we need to know which sub-row corresponds to |
sub-row of a matrix, we need to know which sub-row corresponds to |
32 |
the variable 'cat_var'. |
the variable 'cat_var'. |
33 |
|
|
|
The data structures defined here will be placed in the variable |
|
|
structure in the future. When that happens, the useful code |
|
|
in this file will be that which refers to design matrices. |
|
34 |
*/ |
*/ |
35 |
|
|
36 |
#ifndef CAT_H |
#ifndef CAT_H |
37 |
#define CAT_H 1 |
#define CAT_H |
38 |
|
#define CAT_VALUE_NOT_FOUND -2 |
|
#include <gsl/gsl_matrix.h> |
|
39 |
#include <stdbool.h> |
#include <stdbool.h> |
40 |
|
#include "val.h" |
41 |
|
#include "var.h" |
42 |
/* |
/* |
43 |
This structure contains the observed values of a |
This structure contains the observed values of a |
44 |
categorical variable. |
categorical variable. |
53 |
values stored. |
values stored. |
54 |
*/ |
*/ |
55 |
}; |
}; |
|
|
|
|
/* |
|
|
There are usually multiple categorical variables to recode. Get rid |
|
|
of this structure immediately when the variable structure has been |
|
|
modified to contain the binary encoding. |
|
|
*/ |
|
|
struct recoded_categorical_array |
|
|
{ |
|
|
struct recoded_categorical **a; |
|
|
size_t n_vars; |
|
|
}; |
|
|
/* |
|
|
The design matrix structure holds the design |
|
|
matrix and an array to tell us which columns |
|
|
correspond to which variables. This structure |
|
|
is not restricted to categorical variables, and |
|
|
perhaps should be moved to its own module. |
|
|
*/ |
|
|
|
|
|
struct design_matrix_var |
|
|
{ |
|
|
int first_column; /* First column for this variable in |
|
|
the design_matix. If this variable |
|
|
is categorical, its values are |
|
|
stored in multiple, contiguous |
|
|
columns, as dictated by its vector |
|
|
encoding in the variable's struct |
|
|
recoded_categorical. |
|
|
*/ |
|
|
int last_column; |
|
|
const struct variable *v; |
|
|
}; |
|
|
struct design_matrix |
|
|
{ |
|
|
gsl_matrix *m; |
|
|
struct design_matrix_var *vars; /* Element i corresponds to |
|
|
the variable whose values |
|
|
are stored in at least one |
|
|
column of m. If that |
|
|
variable is categorical |
|
|
with more than two |
|
|
categories, its values are |
|
|
stored in multiple, |
|
|
contiguous columns. The |
|
|
variable's values are then |
|
|
stored in the columns |
|
|
first_column through |
|
|
last_column of the |
|
|
design_matrix_var |
|
|
structure. |
|
|
*/ |
|
|
size_t n_vars; |
|
|
}; |
|
|
union value *cat_vector_to_value (const gsl_vector *, struct variable *); |
|
|
|
|
|
void cat_stored_values_create (struct variable *); |
|
|
|
|
|
void cat_value_update (struct variable *, const union value *); |
|
|
|
|
|
int cat_free_recoded_array (struct recoded_categorical_array *); |
|
|
|
|
|
struct recoded_categorical_array *cr_recoded_cat_ar_create (int, |
|
|
struct variable |
|
|
*[]); |
|
|
|
|
|
void cat_recoded_categorical_create (struct variable *); |
|
|
|
|
|
void cat_create_value_matrix (struct variable *); |
|
|
|
|
|
struct recoded_categorical *cat_var_to_recoded_categorical (const struct |
|
|
variable *, |
|
|
struct |
|
|
recoded_categorical_array |
|
|
*); |
|
|
|
|
|
struct design_matrix *design_matrix_create (int, const struct variable *[], |
|
|
const size_t); |
|
|
|
|
|
void design_matrix_destroy (struct design_matrix *); |
|
|
|
|
|
void design_matrix_set_categorical (struct design_matrix *, size_t, |
|
|
const struct variable *, |
|
|
const union value *); |
|
|
|
|
|
void design_matrix_set_numeric (struct design_matrix *, size_t, |
|
|
const struct variable *, const union value *); |
|
|
|
|
|
size_t design_matrix_var_to_column (const struct design_matrix *, |
|
|
const struct variable *); |
|
|
|
|
|
struct variable *design_matrix_col_to_var (const struct design_matrix *, |
|
|
size_t); |
|
|
|
|
|
void |
|
|
design_matrix_set (struct design_matrix *, size_t, |
|
|
const struct variable *, const union value *, |
|
|
struct recoded_categorical *); |
|
|
|
|
|
void cat_stored_values_destroy (struct variable *); |
|
|
|
|
56 |
#endif |
#endif |