+ /* Copy the predictor variables from the temporary location into the
+ final one, dropping any categorical variables which appear there.
+ FIXME: This is O(NxM).
+ */
+ {
+ struct variable_node *vn, *next;
+ struct hmap allvars;
+ hmap_init (&allvars);
+ for (v = x = 0; v < n_pred_vars; ++v)
+ {
+ bool drop = false;
+ const struct variable *var = pred_vars[v];
+ int cv = 0;
+
+ unsigned int hash = hash_pointer (var, 0);
+ struct variable_node *vn = lookup_variable (&allvars, var, hash);
+ if (vn == NULL)
+ {
+ vn = xmalloc (sizeof *vn);
+ vn->var = var;
+ hmap_insert (&allvars, &vn->node, hash);
+ }
+
+ for (cv = 0; cv < lr.n_cat_predictors ; ++cv)
+ {
+ int iv;
+ const struct interaction *iact = lr.cat_predictors[cv];
+ for (iv = 0 ; iv < iact->n_vars ; ++iv)
+ {
+ const struct variable *ivar = iact->vars[iv];
+ unsigned int hash = hash_pointer (ivar, 0);
+ struct variable_node *vn = lookup_variable (&allvars, ivar, hash);
+ if (vn == NULL)
+ {
+ vn = xmalloc (sizeof *vn);
+ vn->var = ivar;
+
+ hmap_insert (&allvars, &vn->node, hash);
+ }
+
+ if (var == ivar)
+ {
+ drop = true;
+ }
+ }
+ }
+
+ if (drop)
+ continue;
+
+ lr.predictor_vars = xrealloc (lr.predictor_vars, sizeof *lr.predictor_vars * (x + 1));
+ lr.predictor_vars[x++] = var;
+ lr.n_predictor_vars++;
+ }
+ free (pred_vars);
+
+ lr.n_indep_vars = hmap_count (&allvars);
+ lr.indep_vars = xmalloc (lr.n_indep_vars * sizeof *lr.indep_vars);
+
+ /* Interate over each variable and push it into the array */
+ x = 0;
+ HMAP_FOR_EACH_SAFE (vn, next, struct variable_node, node, &allvars)
+ {
+ lr.indep_vars[x++] = vn->var;
+ free (vn);
+ }
+ hmap_destroy (&allvars);
+ }
+
+
+ /* logistical regression for each split group */