@@ -171,9 +171,13 @@ def get_signal_model_summary(name: str, all_settings: dict, df: DataFrame) -> di
171
171
"risk_unit" : str (df .risk_unit .values [0 ]),
172
172
}
173
173
summary ["risk_bounds" ] = [float (risk_exposures .min ()), float (risk_exposures .max ())]
174
+ risk_mean = np .vstack (
175
+ [risk_exposures [:, [0 , 1 ]].mean (axis = 1 ), risk_exposures [:, [2 , 3 ]].mean (axis = 1 )]
176
+ )
177
+ risk_mean .sort (axis = 0 )
174
178
summary ["risk_score_bounds" ] = [
175
- float (np .quantile (risk_exposures [:, [ 0 , 1 ]]. mean ( axis = 1 ) , 0.15 )),
176
- float (np .quantile (risk_exposures [:, [ 2 , 3 ]]. mean ( axis = 1 ) , 0.85 )),
179
+ float (np .quantile (risk_mean [ 0 ] , 0.15 )),
180
+ float (np .quantile (risk_mean [ 1 ] , 0.85 )),
177
181
]
178
182
summary ["normalize_to_tmrel" ] = all_settings ["complete_summary" ]["score" ][
179
183
"normalize_to_tmrel"
@@ -379,7 +383,7 @@ def get_linear_model_summary(
379
383
summary ["beta" ] = [float (beta_info [0 ]), float (beta_info [1 ])]
380
384
summary ["gamma" ] = [float (gamma_info [0 ]), float (gamma_info [1 ])]
381
385
382
- # compute the score
386
+ # compute the score and add star rating
383
387
risk = np .linspace (* summary ["risk_bounds" ], 100 )
384
388
signal = get_signal (signal_model , risk )
385
389
beta_sd = np .sqrt (beta_info [1 ] ** 2 + gamma_info [0 ] + 2 * gamma_info [1 ])
@@ -408,10 +412,25 @@ def get_linear_model_summary(
408
412
sign = np .sign (pred )
409
413
if np .any (np .prod (inner_ui [:, index ], axis = 0 ) < 0 ):
410
414
summary ["score" ] = float ("nan" )
415
+ summary ["star_rating" ] = 0
411
416
else :
412
- summary [ " score" ] = float (
417
+ score = float (
413
418
((sign * burden_of_proof )[:, index ].mean (axis = 1 )).min ()
414
419
)
420
+ summary ["score" ] = score
421
+ #Assign star rating based on ROS
422
+ if np .isnan (score ):
423
+ summary ["star_rating" ] = 0
424
+ elif score > np .log (1 + 0.85 ):
425
+ summary ["star_rating" ] = 5
426
+ elif score > np .log (1 + 0.50 ):
427
+ summary ["star_rating" ] = 4
428
+ elif score > np .log (1 + 0.15 ):
429
+ summary ["star_rating" ] = 3
430
+ elif score > 0 :
431
+ summary ["star_rating" ] = 2
432
+ else :
433
+ summary ["star_rating" ] = 1
415
434
416
435
# compute the publication bias
417
436
index = df .is_outlier == 0
@@ -559,7 +578,11 @@ def get_quantiles(
559
578
560
579
561
580
def plot_signal_model (
562
- name : str , summary : dict , df : DataFrame , signal_model : MRBeRT
581
+ name : str ,
582
+ summary : dict ,
583
+ df : DataFrame ,
584
+ signal_model : MRBeRT ,
585
+ show_ref : bool = True ,
563
586
) -> Figure :
564
587
"""Plot the signal model
565
588
@@ -573,6 +596,8 @@ def plot_signal_model(
573
596
Data frame contains training data.
574
597
signal_model
575
598
Fitted signal model for risk curve.
599
+ show_ref
600
+ Whether to show the reference line. Default is `True`.
576
601
577
602
Returns
578
603
-------
@@ -584,7 +609,7 @@ def plot_signal_model(
584
609
fig , ax = plt .subplots (figsize = (8 , 5 ))
585
610
586
611
# plot data
587
- _plot_data (name , summary , df , ax , signal_model = signal_model )
612
+ _plot_data (name , summary , df , ax , signal_model = signal_model , show_ref = show_ref )
588
613
589
614
# plot curve
590
615
risk = np .linspace (* summary ["risk_bounds" ], 100 )
@@ -602,6 +627,7 @@ def plot_linear_model(
602
627
df : DataFrame ,
603
628
signal_model : MRBeRT ,
604
629
linear_model : MRBRT ,
630
+ show_ref : bool = True ,
605
631
) -> Figure :
606
632
"""Plot the linear model
607
633
@@ -617,6 +643,8 @@ def plot_linear_model(
617
643
Fitted signal model for risk curve.
618
644
linear_model
619
645
Fitted linear model for risk curve.
646
+ show_ref
647
+ Whether to show the reference line. Default is `True`.
620
648
621
649
Returns
622
650
-------
@@ -628,7 +656,7 @@ def plot_linear_model(
628
656
fig , ax = plt .subplots (1 , 2 , figsize = (16 , 5 ))
629
657
630
658
# plot data
631
- _plot_data (name , summary , df , ax [0 ], signal_model , linear_model )
659
+ _plot_data (name , summary , df , ax [0 ], signal_model , linear_model , show_ref = show_ref )
632
660
633
661
# plot curve and uncertainty
634
662
beta = summary ["beta" ]
@@ -642,11 +670,11 @@ def plot_linear_model(
642
670
pred = np .outer (
643
671
np .array (
644
672
[
645
- beta [0 ] - 1.645 * outer_beta_sd ,
646
- beta [0 ] - 1.645 * inner_beta_sd ,
673
+ beta [0 ] - 1.96 * outer_beta_sd ,
674
+ beta [0 ] - 1.96 * inner_beta_sd ,
647
675
beta [0 ],
648
- beta [0 ] + 1.645 * inner_beta_sd ,
649
- beta [0 ] + 1.645 * outer_beta_sd ,
676
+ beta [0 ] + 1.96 * inner_beta_sd ,
677
+ beta [0 ] + 1.96 * outer_beta_sd ,
650
678
]
651
679
),
652
680
signal ,
@@ -655,9 +683,12 @@ def plot_linear_model(
655
683
if summary ["normalize_to_tmrel" ]:
656
684
pred -= pred [:, [np .argmin (pred [2 ])]]
657
685
686
+ log_bprf = pred [2 ] * (1.0 - 1.645 * outer_beta_sd / beta [0 ])
687
+
658
688
ax [0 ].plot (risk , pred [2 ], color = "#008080" )
659
689
ax [0 ].fill_between (risk , pred [0 ], pred [4 ], color = "gray" , alpha = 0.2 )
660
690
ax [0 ].fill_between (risk , pred [1 ], pred [3 ], color = "gray" , alpha = 0.2 )
691
+ ax [0 ].plot (risk , log_bprf , color = "red" )
661
692
662
693
# plot funnel
663
694
_plot_funnel (summary , df , ax [1 ])
@@ -672,6 +703,7 @@ def _plot_data(
672
703
ax : Axes ,
673
704
signal_model : MRBeRT = None ,
674
705
linear_model : Optional [MRBRT ] = None ,
706
+ show_ref : bool = True ,
675
707
) -> Axes :
676
708
"""Plot data points
677
709
@@ -690,6 +722,8 @@ def _plot_data(
690
722
the points are plotted reference to original signal model. When linear
691
723
model is provided, the points are plotted reference to the linear model
692
724
risk curve.
725
+ show_ref
726
+ Whether to show the reference line. Default is `True`.
693
727
694
728
Returns
695
729
-------
@@ -718,6 +752,9 @@ def _plot_data(
718
752
if summary ["normalize_to_tmrel" ]:
719
753
risk = np .linspace (* summary ["risk_bounds" ], 100 )
720
754
signal = get_signal (signal_model , risk )
755
+ if linear_model is not None :
756
+ signal *= linear_model .beta_soln [0 ]
757
+ ref_ln_rr -= signal .min ()
721
758
alt_ln_rr -= signal .min ()
722
759
723
760
# plot data points
@@ -738,8 +775,9 @@ def _plot_data(
738
775
alpha = 0.5 ,
739
776
marker = "x" ,
740
777
)
741
- for x_0 , y_0 , x_1 , y_1 in zip (alt_risk , alt_ln_rr , ref_risk , ref_ln_rr ):
742
- ax .plot ([x_0 , x_1 ], [y_0 , y_1 ], color = "#008080" , linewidth = 0.5 , alpha = 0.5 )
778
+ if show_ref :
779
+ for x_0 , y_0 , x_1 , y_1 in zip (alt_risk , alt_ln_rr , ref_risk , ref_ln_rr ):
780
+ ax .plot ([x_0 , x_1 ], [y_0 , y_1 ], color = "#008080" , linewidth = 0.5 , alpha = 0.5 )
743
781
744
782
# plot support lines
745
783
ax .axhline (0.0 , linewidth = 1 , linestyle = "-" , color = "gray" )
0 commit comments