projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
CROSSTABS: Improve error messages and coding style.
[pspp]
/
src
/
language
/
stats
/
logistic.c
diff --git
a/src/language/stats/logistic.c
b/src/language/stats/logistic.c
index 9794ed62c85cf331d1192e7ba76de1d3ce3e2482..75f1d2a13fb4f6a439fb0a6e4428b3cc3a45cec1 100644
(file)
--- a/
src/language/stats/logistic.c
+++ b/
src/language/stats/logistic.c
@@
-227,7
+227,7
@@
predictor_value (const struct ccase *c,
{
/* Values of the scalar predictor variables */
if (index < n_x)
{
/* Values of the scalar predictor variables */
if (index < n_x)
- return case_
data (c, x[index])->f
;
+ return case_
num (c, x[index])
;
/* Coded values of categorical predictor variables (or interactions) */
if (cats && index - n_x < categoricals_df_total (cats))
/* Coded values of categorical predictor variables (or interactions) */
if (cats && index - n_x < categoricals_df_total (cats))
@@
-242,7
+242,7
@@
predictor_value (const struct ccase *c,
/*
/*
- Return the probability beta_hat (that is the estimator logit(y)
)
+ Return the probability beta_hat (that is the estimator logit(y))
corresponding to the coefficient estimator for case C
*/
static double
corresponding to the coefficient estimator for case C
*/
static double
@@
-321,7
+321,7
@@
hessian (const struct lr_spec *cmd,
}
casereader_destroy (reader);
}
casereader_destroy (reader);
- if (
max_w < cmd->min_epsilon)
+ if (max_w < cmd->min_epsilon)
{
*converged = true;
msg (MN, _("All predicted values are either 1 or 0"));
{
*converged = true;
msg (MN, _("All predicted values are either 1 or 0"));
@@
-478,7
+478,7
@@
initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
double weight = dict_get_case_weight (cmd->dict, c, &res->warn_bad_weight);
const union value *depval = case_data (c, cmd->dep_var);
double weight = dict_get_case_weight (cmd->dict, c, &res->warn_bad_weight);
const union value *depval = case_data (c, cmd->dep_var);
- if (var_is_value_missing (cmd->dep_var, depval
, cmd->exclude)
)
+ if (var_is_value_missing (cmd->dep_var, depval
) & cmd->exclude
)
{
missing = true;
}
{
missing = true;
}
@@
-486,7
+486,7
@@
initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
for (v = 0; v < cmd->n_indep_vars; ++v)
{
const union value *val = case_data (c, cmd->indep_vars[v]);
for (v = 0; v < cmd->n_indep_vars; ++v)
{
const union value *val = case_data (c, cmd->indep_vars[v]);
- if (var_is_value_missing (cmd->indep_vars[v], val
, cmd->exclude)
)
+ if (var_is_value_missing (cmd->indep_vars[v], val
) & cmd->exclude
)
{
missing = true;
break;
{
missing = true;
break;
@@
-509,7
+509,7
@@
initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
}
else if (!v1set)
{
}
else if (!v1set)
{
- if (
!value_equal (&res->y0, depval, width))
+ if (!value_equal (&res->y0, depval, width))
{
value_clone (&res->y1, depval, width);
v1set = true;
{
value_clone (&res->y1, depval, width);
v1set = true;
@@
-520,7
+520,7
@@
initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
if (! value_equal (&res->y0, depval, width)
&&
! value_equal (&res->y1, depval, width)
if (! value_equal (&res->y0, depval, width)
&&
! value_equal (&res->y1, depval, width)
-
)
+ )
{
msg (ME, _("Dependent variable's values are not dichotomous."));
case_unref (c);
{
msg (ME, _("Dependent variable's values are not dichotomous."));
case_unref (c);
@@
-640,7
+640,7
@@
run_lr (const struct lr_spec *cmd, struct casereader *input,
work.hessian = gsl_matrix_calloc (work.beta_hat->size, work.beta_hat->size);
/* Start the Newton Raphson iteration process... */
work.hessian = gsl_matrix_calloc (work.beta_hat->size, work.beta_hat->size);
/* Start the Newton Raphson iteration process... */
- for(
i = 0 ; i < cmd->max_iter ; ++i)
+ for(i = 0 ; i < cmd->max_iter ; ++i)
{
double min, max;
gsl_vector *v ;
{
double min, max;
gsl_vector *v ;
@@
-669,7
+669,7
@@
run_lr (const struct lr_spec *cmd, struct casereader *input,
gsl_vector_minmax (delta, &min, &max);
gsl_vector_minmax (delta, &min, &max);
- if (
fabs (min) < cmd->bcon && fabs (max) < cmd->bcon)
+ if (fabs (min) < cmd->bcon && fabs (max) < cmd->bcon)
{
msg (MN, _("Estimation terminated at iteration number %d because parameter estimates changed by less than %g"),
i + 1, cmd->bcon);
{
msg (MN, _("Estimation terminated at iteration number %d because parameter estimates changed by less than %g"),
i + 1, cmd->bcon);
@@
-697,8
+697,8
@@
run_lr (const struct lr_spec *cmd, struct casereader *input,
- if (
! converged)
- msg (MW, _("Estimation terminated at iteration number %d because maximum iterations has been reached"), i
);
+ if (! converged)
+ msg (MW, _("Estimation terminated at iteration number %d because maximum iterations has been reached"), i);
output_model_summary (&work, initial_log_likelihood, log_likelihood);
output_model_summary (&work, initial_log_likelihood, log_likelihood);
@@
-883,7
+883,7
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
}
lr.confidence = lex_number (lexer);
lex_get (lexer);
}
lr.confidence = lex_number (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-917,7
+917,7
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
}
lr.bcon = lex_number (lexer);
lex_get (lexer);
}
lr.bcon = lex_number (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-928,14
+928,14
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
{
if (lex_force_match (lexer, T_LPAREN))
{
{
if (lex_force_match (lexer, T_LPAREN))
{
- if (! lex_force_int
(lexer
))
+ if (! lex_force_int
_range (lexer, "ITERATE", 0, INT_MAX
))
{
lex_error (lexer, NULL);
goto error;
}
lr.max_iter = lex_integer (lexer);
lex_get (lexer);
{
lex_error (lexer, NULL);
goto error;
}
lr.max_iter = lex_integer (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-953,7
+953,7
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
}
lr.lcon = lex_number (lexer);
lex_get (lexer);
}
lr.lcon = lex_number (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-971,7
+971,7
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
}
lr.min_epsilon = lex_number (lexer);
lex_get (lexer);
}
lr.min_epsilon = lex_number (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-982,20
+982,13
@@
cmd_logistic (struct lexer *lexer, struct dataset *ds)
{
if (lex_force_match (lexer, T_LPAREN))
{
{
if (lex_force_match (lexer, T_LPAREN))
{
- if (! lex_force_num (lexer))
- {
- lex_error (lexer, NULL);
- goto error;
- }
+ if (!lex_force_num_range_closed (lexer, "CUT", 0, 1))
+ goto error;
+
cp = lex_number (lexer);
cp = lex_number (lexer);
- if (cp < 0 || cp > 1.0)
- {
- msg (ME, _("Cut point value must be in the range [0,1]"));
- goto error;
- }
lex_get (lexer);
lex_get (lexer);
- if (
! lex_force_match (lexer, T_RPAREN))
+ if (! lex_force_match (lexer, T_RPAREN))
{
lex_error (lexer, NULL);
goto error;
{
lex_error (lexer, NULL);
goto error;
@@
-1312,7
+1305,7
@@
output_model_summary (const struct lr_result *res,
double entries[] = {
-2 * log_likelihood,
cox,
double entries[] = {
-2 * log_likelihood,
cox,
- cox / (
1.0 - exp(initial_log_likelihood * (2 / res->cc)))
+ cox / (1.0 - exp(initial_log_likelihood * (2 / res->cc)))
};
for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
pivot_table_put2 (table, i, 0, pivot_value_new_number (entries[i]));
};
for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
pivot_table_put2 (table, i, 0, pivot_value_new_number (entries[i]));