Skip to content

Commit

Permalink
fixed roc forced choice accuracy
Browse files Browse the repository at this point in the history
Former-commit-id: e93b492
  • Loading branch information
ljchang committed Nov 6, 2017
1 parent 00809d9 commit 4a386db
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions nltools/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def calculate(self, input_values=None, binary_outcome=None,
forced_choice: index indicating position for each unique subject
(default=None)
balanced_acc: balanced accuracy for single-interval classification
(bool)
(bool). THIS IS NOT COMPLETELY IMPLEMENTED BECAUSE
IT AFFECTS ACCURACY ESTIMATES, BUT NOT P-VALUES OR
THRESHOLD AT WHICH TO EVALUATE SENS/SPEC
**kwargs: Additional keyword arguments to pass to the prediction
algorithm
Expand Down Expand Up @@ -199,9 +201,16 @@ def plot(self, plot_method = 'gaussian', balanced_acc=False, **kwargs):
diff_scores = np.array(diff_scores)
mn_diff = np.mean(diff_scores)
d = mn_diff / np.std(diff_scores)
pooled_sd = np.std(diff_scores) / np.sqrt(2);
pooled_sd = np.std(diff_scores) / np.sqrt(2)
d_a_model = mn_diff / pooled_sd

expected_acc = 1 - norm.cdf(0, d, 1)
self.sensitivity = expected_acc
self.specificity = expected_acc
self.ppv = self.sensitivity / (self.sensitivity +
1 - self.specificity)
self.auc = norm.cdf(d_a_model / np.sqrt(2))

x = np.arange(-3, 3, .1)
self.tpr_smooth = 1 - norm.cdf(x, d, 1)
self.fpr_smooth = 1 - norm.cdf(x, -d, 1)
Expand All @@ -219,6 +228,7 @@ def plot(self, plot_method = 'gaussian', balanced_acc=False, **kwargs):
self.tpr_smooth = 1 - (norm.cdf(x, z_true, 1))
self.fpr_smooth = 1 - (norm.cdf(x, z_false, 1))

self.aucn = auc(self.fpr_smooth, self.tpr_smooth)
fig = roc_plot(self.fpr_smooth, self.tpr_smooth)

elif plot_method == 'observed':
Expand Down

0 comments on commit 4a386db

Please sign in to comment.