/[pspp]/pspp/src/regression.q
ViewVC logotype

Diff of /pspp/src/regression.q

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by jstover, Wed Nov 16 21:14:32 2005 UTC revision 1.14 by jstover, Tue Nov 22 22:04:45 2005 UTC
# Line 504  run_regression (const struct casefile *c Line 504  run_regression (const struct casefile *c
504    int n_indep;    int n_indep;
505    int j = 0;    int j = 0;
506    /*    /*
507      Keep track of the missing cases.       Keep track of the missing cases.
508    */     */
509    int *is_missing_case;    int *is_missing_case;
510    const union value *val;    const union value *val;
511    struct casereader *r;    struct casereader *r;
512    struct casereader *r2;    struct casereader *r2;
513    struct ccase c;    struct ccase c;
514    const struct variable *v;    struct variable *v;
   struct recoded_categorical_array *ca;  
   struct recoded_categorical *rc;  
515    struct design_matrix *X;    struct design_matrix *X;
516    gsl_vector *Y;    gsl_vector *Y;
517    pspp_linreg_cache *lcache;    pspp_linreg_cache *lcache;
# Line 536  run_regression (const struct casefile *c Line 534  run_regression (const struct casefile *c
534       Read from the active file. The first pass encodes categorical       Read from the active file. The first pass encodes categorical
535       variables and drops cases with missing values.       variables and drops cases with missing values.
536     */     */
537    ca = cr_recoded_cat_ar_create (cmd.n_variables, cmd.v_variables);    for (i = 0; i < cmd.n_variables; i++)
   for (r = casefile_get_reader (cf);  
        casereader_read (r, &c); case_destroy (&c))  
538      {      {
539        row = casereader_cnum (r) - 1;        v = cmd.v_variables[i];
540        for (i = 0; i < ca->n_vars; i++)        if (v->type == ALPHA)
541          {          {
542            v = (*(ca->a + i))->v;            /* Make a place to hold the binary vectors
543            val = case_data (&c, v->fv);               corresponding to this variable's values. */
544            cr_value_update (*(ca->a + i), val);            cat_stored_values_create (v);
545          }          }
546        for (i = 0; i < cmd.n_variables; i++)        for (r = casefile_get_reader (cf);
547               casereader_read (r, &c); case_destroy (&c))
548          {          {
549            v = cmd.v_variables[i];            row = casereader_cnum (r) - 1;
550    
551            val = case_data (&c, v->fv);            val = case_data (&c, v->fv);
552              cat_value_update (v, val);
553            if (mv_is_value_missing (&v->miss, val))            if (mv_is_value_missing (&v->miss, val))
554              {              {
555                n_data--;                if (!is_missing_case[row])
556                is_missing_case[row] = 1;                  {
557                      /* Now it is missing. */
558                      n_data--;
559                      is_missing_case[row] = 1;
560                    }
561              }              }
562          }          }
563      }      }
564    
565    Y = gsl_vector_alloc (n_data);    Y = gsl_vector_alloc (n_data);
   cr_create_value_matrices (ca);  
566    X =    X =
567      design_matrix_create (n_indep, (const struct variable **) cmd.v_variables,      design_matrix_create (n_indep, (const struct variable **) cmd.v_variables,
568                            ca, n_data);                            n_data);
569    lcache = pspp_linreg_cache_alloc (n_data, n_indep);    lcache = pspp_linreg_cache_alloc (X->m->size1, X->m->size2);
570    lcache->indep_means = gsl_vector_alloc (n_indep);    lcache->indep_means = gsl_vector_alloc (X->m->size2);
571    lcache->indep_std = gsl_vector_alloc (n_indep);    lcache->indep_std = gsl_vector_alloc (X->m->size2);
572    
573    /*    /*
574       The second pass creates the design matrix.       The second pass creates the design matrix.
# Line 581  run_regression (const struct casefile *c Line 584  run_regression (const struct casefile *c
584          {          {
585            for (i = 0; i < cmd.n_variables; ++i) /* Iterate over the variables            for (i = 0; i < cmd.n_variables; ++i) /* Iterate over the variables
586                                                     for the current case.                                                     for the current case.
587                                                  */                                                   */
588              {              {
589                v = cmd.v_variables[i];                v = cmd.v_variables[i];
590                val = case_data (&c, v->fv);                val = case_data (&c, v->fv);
591                /*                /*
592                  Independent/dependent variable separation. The                   Independent/dependent variable separation. The
593                  'variables' subcommand specifies a varlist which contains                   'variables' subcommand specifies a varlist which contains
594                  both dependent and independent variables. The dependent                   both dependent and independent variables. The dependent
595                  variables are specified with the 'dependent'                   variables are specified with the 'dependent'
596                  subcommand. We need to separate the two.                   subcommand. We need to separate the two.
597                */                 */
598                if (is_depvar (i))                if (is_depvar (i))
599                  {                  {
600                    if (v->type != NUMERIC)                    if (v->type != NUMERIC)
601                      {                      {
602                        msg (SE, gettext ("Dependent variable must be numeric."));                        msg (SE,
603                               gettext ("Dependent variable must be numeric."));
604                        pspp_reg_rc = CMD_FAILURE;                        pspp_reg_rc = CMD_FAILURE;
605                        return;                        return;
606                      }                      }
# Line 607  run_regression (const struct casefile *c Line 611  run_regression (const struct casefile *c
611                  {                  {
612                    if (v->type == ALPHA)                    if (v->type == ALPHA)
613                      {                      {
614                        rc = cr_var_to_recoded_categorical (v, ca);                        design_matrix_set_categorical (X, row, v, val);
                       design_matrix_set_categorical (X, row, v, val, rc);  
615                      }                      }
616                    else if (v->type == NUMERIC)                    else if (v->type == NUMERIC)
617                      {                      {
618                        design_matrix_set_numeric (X, row, v, val);                        design_matrix_set_numeric (X, row, v, val);
619                      }                      }
620                      
621                    indep_vars[k] = i;                    indep_vars[k] = i;
622                    k++;                    k++;
623                    lopts.get_indep_mean_std[i] = 1;                    lopts.get_indep_mean_std[i] = 1;
# Line 624  run_regression (const struct casefile *c Line 627  run_regression (const struct casefile *c
627          }          }
628      }      }
629    /*    /*
630      Now that we know the number of coefficients, allocate space       Now that we know the number of coefficients, allocate space
631      and store pointers to the variables that correspond to the       and store pointers to the variables that correspond to the
632      coefficients.       coefficients.
633     */     */
634    lcache->coeff = xnmalloc (X->m->size2 + 1, sizeof (*lcache->coeff));    lcache->coeff = xnmalloc (X->m->size2 + 1, sizeof (*lcache->coeff));
635    for (i = 0; i < X->m->size2; i++)    for (i = 0; i < X->m->size2; i++)

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26