Skip to content

Commit

Permalink
Per #2887, relatively small changes to drive down SonarQube code smel…
Browse files Browse the repository at this point in the history
…ls. Also, switch from total() to n_pairs() when computing confidence intervals.
  • Loading branch information
JohnHalleyGotway committed Oct 9, 2024
1 parent 940c9e2 commit d7582de
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 254 deletions.
136 changes: 66 additions & 70 deletions src/libcode/vx_stat_out/stat_columns.cc

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/libcode/vx_statistics/compute_ci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ void compute_normal_ci(double v, double alpha, double se,
//
////////////////////////////////////////////////////////////////////////

void compute_proportion_ci(double p, int n, double alpha, double vif,
void compute_proportion_ci(double p, int n_pairs, double alpha, double vif,
double &p_cl, double &p_cu) {

//
// Compute the confidence interval using the Wilson method for all
// sizes of n, since it provides a better approximation
//
compute_wilson_ci(p, n, alpha, vif, p_cl, p_cu);
compute_wilson_ci(p, n_pairs, alpha, vif, p_cl, p_cu);

return;
}
Expand All @@ -81,7 +81,7 @@ void compute_proportion_ci(double p, int n, double alpha, double vif,
//
////////////////////////////////////////////////////////////////////////

void compute_wald_ci(double p, int n, double alpha, double vif,
void compute_wald_ci(double p, int n_pairs, double alpha, double vif,
double &p_cl, double &p_cu) {
double v, cv_normal_l, cv_normal_u;

Expand All @@ -100,7 +100,7 @@ void compute_wald_ci(double p, int n, double alpha, double vif,
//
// Compute the upper and lower bounds of the confidence interval
//
v = vif*p*(1.0-p)/n;
v = vif*p*(1.0-p)/n_pairs;

if(v < 0.0) {
p_cl = bad_data_double;
Expand All @@ -122,10 +122,10 @@ void compute_wald_ci(double p, int n, double alpha, double vif,
//
////////////////////////////////////////////////////////////////////////

void compute_wilson_ci(double p, int n_int, double alpha, double vif,
void compute_wilson_ci(double p, int n_pairs, double alpha, double vif,
double &p_cl, double &p_cu) {
double v, cv_normal_l, cv_normal_u;
long long n = n_int;
long long n = n_pairs;

if(is_bad_data(p)) {
p_cl = p_cu = bad_data_double;
Expand Down
6 changes: 3 additions & 3 deletions src/libcode/vx_statistics/compute_ci.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ static const int wald_sample_threshold = 100;
extern void compute_normal_ci(double x, double alpha, double se,
double &cl, double &cu);

extern void compute_proportion_ci(double p, int n, double alpha,
extern void compute_proportion_ci(double p, int n_pairs, double alpha,
double vif, double &p_cl, double &p_cu);

extern void compute_wald_ci(double p, int n, double alpha,
extern void compute_wald_ci(double p, int n_pairs, double alpha,
double vif, double &p_cl, double &p_cu);

extern void compute_wilson_ci(double p, int n, double alpha,
extern void compute_wilson_ci(double p, int n_pairs, double alpha,
double vif, double &p_cl, double &p_cu);

extern void compute_woolf_ci(double odds, double alpha,
Expand Down
5 changes: 4 additions & 1 deletion src/libcode/vx_statistics/contable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class TTContingencyTable;

class ContingencyTable {

protected:
friend class TTContingencyTable;
friend class Nx2ContingencyTable;

private:

void init_from_scratch();

Expand Down
16 changes: 8 additions & 8 deletions src/libcode/vx_statistics/contable_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ double TTContingencyTable::baser_ci(double alpha,

v = baser();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -60,7 +60,7 @@ double TTContingencyTable::fmean_ci(double alpha,

v = fmean();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -79,7 +79,7 @@ double TTContingencyTable::accuracy_ci(double alpha,

v = accuracy();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ double TTContingencyTable::pod_yes_ci(double alpha,

v = pod_yes();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -131,7 +131,7 @@ double TTContingencyTable::pod_no_ci(double alpha,

v = pod_no();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -157,7 +157,7 @@ double TTContingencyTable::pofd_ci(double alpha,

v = pofd();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -180,7 +180,7 @@ double TTContingencyTable::far_ci(double alpha,

v = far();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand All @@ -203,7 +203,7 @@ double TTContingencyTable::csi_ci(double alpha,

v = csi();

compute_proportion_ci(v, total(), alpha, 1.0, cl, cu);
compute_proportion_ci(v, Npairs, alpha, 1.0, cl, cu);

return v;
}
Expand Down
24 changes: 12 additions & 12 deletions src/libcode/vx_statistics/met_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,21 @@ void CTSInfo::compute_ci() {
// Compute confidence intervals for the scores based on
// proportions
//
compute_proportion_ci(baser.v, cts.total(), alpha[i], baser.vif,
compute_proportion_ci(baser.v, cts.n_pairs(), alpha[i], baser.vif,
baser.v_ncl[i], baser.v_ncu[i]);
compute_proportion_ci(fmean.v, cts.total(), alpha[i], fmean.vif,
compute_proportion_ci(fmean.v, cts.n_pairs(), alpha[i], fmean.vif,
fmean.v_ncl[i], fmean.v_ncu[i]);
compute_proportion_ci(acc.v, cts.total(), alpha[i], acc.vif,
compute_proportion_ci(acc.v, cts.n_pairs(), alpha[i], acc.vif,
acc.v_ncl[i], acc.v_ncu[i]);
compute_proportion_ci(pody.v, cts.total(), alpha[i], pody.vif,
compute_proportion_ci(pody.v, cts.n_pairs(), alpha[i], pody.vif,
pody.v_ncl[i], pody.v_ncu[i]);
compute_proportion_ci(podn.v, cts.total(), alpha[i], podn.vif,
compute_proportion_ci(podn.v, cts.n_pairs(), alpha[i], podn.vif,
podn.v_ncl[i], podn.v_ncu[i]);
compute_proportion_ci(pofd.v, cts.total(), alpha[i], pofd.vif,
compute_proportion_ci(pofd.v, cts.n_pairs(), alpha[i], pofd.vif,
pofd.v_ncl[i], pofd.v_ncu[i]);
compute_proportion_ci(far.v, cts.total(), alpha[i], far.vif,
compute_proportion_ci(far.v, cts.n_pairs(), alpha[i], far.vif,
far.v_ncl[i], far.v_ncu[i]);
compute_proportion_ci(csi.v, cts.total(), alpha[i], csi.vif,
compute_proportion_ci(csi.v, cts.n_pairs(), alpha[i], csi.vif,
csi.v_ncl[i], csi.v_ncu[i]);

//
Expand Down Expand Up @@ -814,7 +814,7 @@ void MCTSInfo::compute_ci() {
// Compute confidence intervals for the scores based on
// proportions
//
compute_proportion_ci(acc.v, cts.total(), alpha[i], acc.vif,
compute_proportion_ci(acc.v, cts.n_pairs(), alpha[i], acc.vif,
acc.v_ncl[i], acc.v_ncu[i]);
} // end for i

Expand Down Expand Up @@ -3293,7 +3293,7 @@ void PCTInfo::compute_ci() {
//
for(i=0; i<n_alpha; i++) {

compute_proportion_ci(baser.v, pct.total(), alpha[i], baser.vif,
compute_proportion_ci(baser.v, pct.n_pairs(), alpha[i], baser.vif,
baser.v_ncl[i], baser.v_ncu[i]);

// Compute brier CI using the VIF
Expand Down Expand Up @@ -3377,11 +3377,11 @@ double PCTInfo::get_stat_pct(const string &stat_name,
col_name = "THRESH_I";
}
else if(check_reg_exp("OY_[0-9]", stat_name.c_str())){
v = (double) pct.event_total_by_row(i);
v = pct.event_total_by_row(i);
col_name = "OY_I";
}
else if(check_reg_exp("ON_[0-9]", stat_name.c_str())) {
v = (double) pct.nonevent_total_by_row(i);
v = pct.nonevent_total_by_row(i);
col_name = "ON_I";
}
else {
Expand Down
Loading

0 comments on commit d7582de

Please sign in to comment.