コード例 #1
0
        def build_dict():
            d = {}

            for effect in BACK_CALCULATABLE_DIAGNOSTIC_EFFECTS:    
                est,lower,upper = self.ma_unit.get_effect_and_ci(effect,
                                                                 self.group_str,
                                                                 self.mult)
                conv_to_disp_scale = lambda x: meta_py_r.diagnostic_convert_scale(x, effect, convert_to="display.scale")
                d_est,d_lower,d_upper = [conv_to_disp_scale(x) for x in [est,lower,upper]]
                for i,Rsubkey in enumerate(["",".lb",".ub"]):
                    try:
                        d["%s%s" % (effect.lower(), Rsubkey)] = float([d_est,d_lower,d_upper][i])
                    except:
                        pass
            
            x = self.getTotalSubjects()
            d["total"] = float(x) if is_a_float(x) else None

            x = self.prevalence_txt_box.text()
            d["prev"] = float(x) if is_a_float(x) else None

            d["conf.level"] = self.global_conf_level
    
            # now grab the raw data, if available
            d.update(self.get_raw_diag_data())
            
            return d
コード例 #2
0
    def val_changed(self, val_str):
        # Backup form state
        old_ma_unit, old_table = self._save_ma_unit_and_table_state(
                                table = self.two_by_two_table,
                                ma_unit = self.ma_unit, 
                                use_old_value=False)
        old_prevalence = self.current_prevalence
        
        new_text = self._get_txt_from_val_str(val_str)
        
        no_errors, display_scale_val = self._text_box_value_is_between_bounds(val_str, new_text)
        if no_errors is False: # There are errors
            self.restore_ma_unit_and_table(old_ma_unit,old_table, old_prevalence)
            calc_fncs.block_signals(self.entry_widgets, True)
            if val_str == "est":
                self.effect_txt_box.setFocus()
            elif val_str == "lower":
                self.low_txt_box.setFocus()
            elif val_str == "upper":
                self.high_txt_box.setFocus()
            elif val_str == "prevalence":
                self.prevalence_txt_box.setFocus()
            calc_fncs.block_signals(self.entry_widgets, False)
            return
        
        # If we got to this point it means everything is ok so far        
        try:
            if display_scale_val not in EMPTY_VALS:
                display_scale_val = float(display_scale_val)
            else:
                display_scale_val = None
        except ValueError:
            # a number wasn't entered; ignore
            # should probably clear out the box here, too.
            print "fail."
            return None
        

        calc_scale_val = meta_py_r.diagnostic_convert_scale(display_scale_val,
                                        self.cur_effect, convert_to="calc.scale")
        
        if val_str == "est":
            self.ma_unit.set_effect(self.cur_effect, self.group_str, calc_scale_val)
        elif val_str == "lower":
            self.ma_unit.set_lower(self.cur_effect, self.group_str, calc_scale_val)
        elif val_str == "upper":
            self.ma_unit.set_upper(self.cur_effect, self.group_str, calc_scale_val)
        elif val_str == "prevalence":
            pass

        new_ma_unit, new_table = self._save_ma_unit_and_table_state(
                table = self.two_by_two_table, ma_unit = self.ma_unit,
                use_old_value=False)
        new_prevalence = self._get_prevalence_str()
        restore_old_f = lambda: self.restore_ma_unit_and_table(old_ma_unit, old_table, old_prevalence)
        restore_new_f = lambda: self.restore_ma_unit_and_table(new_ma_unit, new_table, new_prevalence)
        command = calc_fncs.CommandFieldChanged(restore_new_f=restore_new_f, restore_old_f=restore_old_f, parent=self)
        self.undoStack.push(command)
        
        self.current_prevalence = new_prevalence
コード例 #3
0
 def f(study_a, study_b):
     ma_unit_A = study_a.get_ma_unit(outcome_name,follow_up)
     ma_unit_B = study_b.get_ma_unit(outcome_name,follow_up)
     
     if outcome_type is BINARY:
         to_display_scale = lambda x: meta_py_r.binary_convert_scale(x, current_effect, convert_to="display.scale")
     elif outcome_type is CONTINUOUS:
         to_display_scale = lambda x: meta_py_r.continuous_convert_scale(x, current_effect, convert_to="display.scale")
     elif outcome_type is DIAGNOSTIC:
         to_display_scale = lambda x: meta_py_r.diagnostic_convert_scale(x, current_effect, convert_to="display.scale")
     
     if outcome_type in (BINARY,CONTINUOUS):
         outcome_data_A = ma_unit_A.get_effect_and_ci(current_effect, group_str, mult)
         outcome_data_B = ma_unit_B.get_effect_and_ci(current_effect, group_str, mult)                    
         outcome_data_A = [to_display_scale(c_val) for c_val in outcome_data_A]
         outcome_data_B = [to_display_scale(c_val) for c_val in outcome_data_B]
     elif outcome_type == DIAGNOSTIC:
         #                                  /\/\/\/\
         (outcome_data_A, outcome_data_B) = ([],[])
         #                                     |
         #                                  \_____/
         for diag_metric in ["Sens","Spec"]: # this order corresponds to the order displayed on the spreadsheet
             est_and_ci_A = ma_unit_A.get_effect_and_ci(diag_metric, group_str, mult)
             est_and_ci_B = ma_unit_B.get_effect_and_ci(diag_metric, group_str, mult)
             est_and_ci_A = [to_display_scale(c_val) for c_val in est_and_ci_A]
             est_and_ci_B = [to_display_scale(c_val) for c_val in est_and_ci_B]
             
             outcome_data_A.extend(est_and_ci_A)
             outcome_data_B.extend(est_and_ci_B)
     study_a_val = outcome_data_A[data_index]
     study_b_val = outcome_data_B[data_index]
     
     return self._meta_cmp_wrapper(study_a, study_b, study_a_val, study_b_val, reverse)
コード例 #4
0
def helper_set_current_effect(ma_unit, txt_boxes, current_effect, group_str, data_type, mult=None):
    '''Fills in text boxes on calculator forms with data from ma unit.
    I noticed all 3 set_current_effect functions in the 3 calculators are
    nearly identical so it makes sense to share the similiar parts'''
    
    if mult is None:
        raise ValueError("mult must be specified")
    
    if data_type == "binary":
        conv_to_disp_scale = lambda x: meta_py_r.binary_convert_scale(x, current_effect, convert_to="display.scale")
    elif data_type == "continuous":
        conv_to_disp_scale = lambda x: meta_py_r.continuous_convert_scale(x, current_effect, convert_to="display.scale")
    elif data_type == "diagnostic":
        conv_to_disp_scale = lambda x: meta_py_r.diagnostic_convert_scale(x, current_effect, convert_to="display.scale")
    else:
        raise Exception("data_type unrecognized")
    effect_tbox, lower_tbox, upper_tbox = [txt_boxes[box_name] for box_name in ("effect","lower","upper")]
    
    (est,lower,upper) = ma_unit.get_effect_and_ci(current_effect, group_str, mult)
    (d_est,d_lower,d_upper) = [conv_to_disp_scale(x) for x in (est,lower,upper)]
    for val, txt_box in zip((d_est,d_lower,d_upper),
                          [effect_tbox, lower_tbox, upper_tbox]):
        txt_box.blockSignals(True)
        if val is not None:
            txt_box.setText(QString("%s" % round(val, CALC_NUM_DIGITS)))
        else:
            txt_box.setText(QString(""))
        txt_box.blockSignals(False)
コード例 #5
0
            def f(study_a, study_b):
                ma_unit_A = study_a.get_ma_unit(outcome_name, follow_up)
                ma_unit_B = study_b.get_ma_unit(outcome_name, follow_up)

                if outcome_type is BINARY:
                    to_display_scale = lambda x: meta_py_r.binary_convert_scale(
                        x, current_effect, convert_to="display.scale")
                elif outcome_type is CONTINUOUS:
                    to_display_scale = lambda x: meta_py_r.continuous_convert_scale(
                        x, current_effect, convert_to="display.scale")
                elif outcome_type is DIAGNOSTIC:
                    to_display_scale = lambda x: meta_py_r.diagnostic_convert_scale(
                        x, current_effect, convert_to="display.scale")

                if outcome_type in (BINARY, CONTINUOUS):
                    outcome_data_A = ma_unit_A.get_effect_and_ci(
                        current_effect, group_str, mult)
                    outcome_data_B = ma_unit_B.get_effect_and_ci(
                        current_effect, group_str, mult)
                    outcome_data_A = [
                        to_display_scale(c_val) for c_val in outcome_data_A
                    ]
                    outcome_data_B = [
                        to_display_scale(c_val) for c_val in outcome_data_B
                    ]
                elif outcome_type == DIAGNOSTIC:
                    #                                  /\/\/\/\
                    (outcome_data_A, outcome_data_B) = ([], [])
                    #                                     |
                    #                                  \_____/
                    for diag_metric in [
                            "Sens", "Spec"
                    ]:  # this order corresponds to the order displayed on the spreadsheet
                        est_and_ci_A = ma_unit_A.get_effect_and_ci(
                            diag_metric, group_str, mult)
                        est_and_ci_B = ma_unit_B.get_effect_and_ci(
                            diag_metric, group_str, mult)
                        est_and_ci_A = [
                            to_display_scale(c_val) for c_val in est_and_ci_A
                        ]
                        est_and_ci_B = [
                            to_display_scale(c_val) for c_val in est_and_ci_B
                        ]

                        outcome_data_A.extend(est_and_ci_A)
                        outcome_data_B.extend(est_and_ci_B)
                study_a_val = outcome_data_A[data_index]
                study_b_val = outcome_data_B[data_index]

                return self._meta_cmp_wrapper(study_a, study_b, study_a_val,
                                              study_b_val, reverse)
コード例 #6
0
 def reset_conf_level(self):
     print("Re-scaling est, low, high to standard confidence level")
     
     old_effect_and_ci = self.ma_unit.get_effect_and_ci(self.cur_effect, self.group_str)
     
     argument_d = {"est"  : old_effect_and_ci[0],
                   "low"  : old_effect_and_ci[1],
                   "high" : old_effect_and_ci[2],
                   "orig.conf.level": self.CI_spinbox.value(),
                   "target.conf.level": meta_py_r.get_global_conf_level()}
     
     res = meta_py_r.rescale_effect_and_ci_conf_level(argument_d)
     if "FAIL" in res:
         print("Could not reset confidence level")
         return
     
     res["display_est"]  = meta_py_r.diagnostic_convert_scale(res["est"], self.cur_effect, convert_to="display.scale")
     res["display_low"]  = meta_py_r.diagnostic_convert_scale(res["low"], self.cur_effect, convert_to="display.scale")
     res["display_high"] = meta_py_r.diagnostic_convert_scale(res["high"], self.cur_effect, convert_to="display.scale")
     
     # Save results in ma_unit
     self.ma_unit.set_effect_and_ci(self.cur_effect, self.group_str, res["est"],res["low"],res["high"])
     self.ma_unit.set_display_effect_and_ci(self.cur_effect, self.group_str, res["display_est"],res["display_low"],res["display_high"])
コード例 #7
0
def helper_set_current_effect(ma_unit,
                              txt_boxes,
                              current_effect,
                              group_str,
                              data_type,
                              mult=None):
    '''Fills in text boxes on calculator forms with data from ma unit.
    I noticed all 3 set_current_effect functions in the 3 calculators are
    nearly identical so it makes sense to share the similiar parts'''

    if mult is None:
        raise ValueError("mult must be specified")

    if data_type == "binary":
        conv_to_disp_scale = lambda x: meta_py_r.binary_convert_scale(
            x, current_effect, convert_to="display.scale")
    elif data_type == "continuous":
        conv_to_disp_scale = lambda x: meta_py_r.continuous_convert_scale(
            x, current_effect, convert_to="display.scale")
    elif data_type == "diagnostic":
        conv_to_disp_scale = lambda x: meta_py_r.diagnostic_convert_scale(
            x, current_effect, convert_to="display.scale")
    else:
        raise Exception("data_type unrecognized")
    effect_tbox, lower_tbox, upper_tbox = [
        txt_boxes[box_name] for box_name in ("effect", "lower", "upper")
    ]

    (est, lower, upper) = ma_unit.get_effect_and_ci(current_effect, group_str,
                                                    mult)
    (d_est, d_lower,
     d_upper) = [conv_to_disp_scale(x) for x in (est, lower, upper)]
    for val, txt_box in zip((d_est, d_lower, d_upper),
                            [effect_tbox, lower_tbox, upper_tbox]):
        txt_box.blockSignals(True)
        if val is not None:
            txt_box.setText(QString("%s" % round(val, CALC_NUM_DIGITS)))
        else:
            txt_box.setText(QString(""))
        txt_box.blockSignals(False)