499 |
run_regression (const struct casefile *cf, void *cmd_ UNUSED) |
run_regression (const struct casefile *cf, void *cmd_ UNUSED) |
500 |
{ |
{ |
501 |
size_t i; |
size_t i; |
|
size_t k; |
|
502 |
size_t n_data = 0; |
size_t n_data = 0; |
503 |
size_t row; |
size_t row; |
504 |
size_t case_num; |
size_t case_num; |
513 |
struct casereader *r2; |
struct casereader *r2; |
514 |
struct ccase c; |
struct ccase c; |
515 |
struct variable *v; |
struct variable *v; |
516 |
|
struct variable **indep_vars; |
517 |
struct design_matrix *X; |
struct design_matrix *X; |
518 |
gsl_vector *Y; |
gsl_vector *Y; |
519 |
pspp_linreg_cache *lcache; |
pspp_linreg_cache *lcache; |
536 |
Read from the active file. The first pass encodes categorical |
Read from the active file. The first pass encodes categorical |
537 |
variables and drops cases with missing values. |
variables and drops cases with missing values. |
538 |
*/ |
*/ |
539 |
|
j = 0; |
540 |
for (i = 0; i < cmd.n_variables; i++) |
for (i = 0; i < cmd.n_variables; i++) |
541 |
{ |
{ |
542 |
v = cmd.v_variables[i]; |
if (!is_depvar (i)) |
|
if (v->type == ALPHA) |
|
543 |
{ |
{ |
544 |
/* Make a place to hold the binary vectors |
v = cmd.v_variables[i]; |
545 |
corresponding to this variable's values. */ |
indep_vars[j] = v; |
546 |
cat_stored_values_create (v); |
j++; |
547 |
} |
if (v->type == ALPHA) |
548 |
for (r = casefile_get_reader (cf); |
{ |
549 |
casereader_read (r, &c); case_destroy (&c)) |
/* Make a place to hold the binary vectors |
550 |
{ |
corresponding to this variable's values. */ |
551 |
row = casereader_cnum (r) - 1; |
cat_stored_values_create (v); |
552 |
|
} |
553 |
val = case_data (&c, v->fv); |
for (r = casefile_get_reader (cf); |
554 |
cat_value_update (v, val); |
casereader_read (r, &c); case_destroy (&c)) |
|
if (mv_is_value_missing (&v->miss, val)) |
|
555 |
{ |
{ |
556 |
if (!is_missing_case[row]) |
row = casereader_cnum (r) - 1; |
557 |
|
|
558 |
|
val = case_data (&c, v->fv); |
559 |
|
cat_value_update (v, val); |
560 |
|
if (mv_is_value_missing (&v->miss, val)) |
561 |
{ |
{ |
562 |
/* Now it is missing. */ |
if (!is_missing_case[row]) |
563 |
n_data--; |
{ |
564 |
is_missing_case[row] = 1; |
/* Now it is missing. */ |
565 |
|
n_data--; |
566 |
|
is_missing_case[row] = 1; |
567 |
|
} |
568 |
} |
} |
569 |
} |
} |
570 |
} |
} |
572 |
|
|
573 |
Y = gsl_vector_alloc (n_data); |
Y = gsl_vector_alloc (n_data); |
574 |
X = |
X = |
575 |
design_matrix_create (n_indep, (const struct variable **) cmd.v_variables, |
design_matrix_create (n_indep, (const struct variable **) indep_vars, |
576 |
n_data); |
n_data); |
577 |
lcache = pspp_linreg_cache_alloc (X->m->size1, X->m->size2); |
lcache = pspp_linreg_cache_alloc (X->m->size1, X->m->size2); |
578 |
lcache->indep_means = gsl_vector_alloc (X->m->size2); |
lcache->indep_means = gsl_vector_alloc (X->m->size2); |
586 |
case_destroy (&c)) |
case_destroy (&c)) |
587 |
/* Iterate over the cases. */ |
/* Iterate over the cases. */ |
588 |
{ |
{ |
|
k = 0; |
|
589 |
case_num = casereader_cnum (r2) - 1; |
case_num = casereader_cnum (r2) - 1; |
590 |
if (!is_missing_case[case_num]) |
if (!is_missing_case[case_num]) |
591 |
{ |
{ |
625 |
design_matrix_set_numeric (X, row, v, val); |
design_matrix_set_numeric (X, row, v, val); |
626 |
} |
} |
627 |
|
|
|
indep_vars[k] = i; |
|
|
k++; |
|
628 |
lopts.get_indep_mean_std[i] = 1; |
lopts.get_indep_mean_std[i] = 1; |
629 |
} |
} |
630 |
} |
} |