Exemplo n.º 1
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)
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)
Exemplo n.º 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)
 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.continuous_convert_scale(res["est"], self.cur_effect, convert_to="display.scale")
     res["display_low"]  = meta_py_r.continuous_convert_scale(res["low"], self.cur_effect, convert_to="display.scale")
     res["display_high"] = meta_py_r.continuous_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"])
Exemplo n.º 5
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)
    def val_changed(self, val_str):
        # Backup form state
        old_ma_unit, old_tables_data = self._save_ma_unit_and_table_states(
                                tables = [self.simple_table,
                                          self.g1_pre_post_table,
                                          self.g2_pre_post_table],
                                ma_unit = self.ma_unit, 
                                use_old_value=False)
        old_correlation = self.current_correlation
        
        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:
            print("There was an error while in val_changed")
            self.restore_ma_unit_and_tables(old_ma_unit,old_tables_data, old_correlation)
            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 == "correlation_pre_post":
                self.correlation_pre_post.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 meta_globals.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.continuous_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 == "correlation_pre_post":
            print "ok -- correlation set to %s" % self.correlation_pre_post.text()
            # Recompute the estimates
            self.impute_pre_post_data(self.g1_pre_post_table, 0)
            self.impute_pre_post_data(self.g2_pre_post_table, 1)
        
        self.impute_data() #### experimental
        

        new_ma_unit, new_tables_data = self._save_ma_unit_and_table_states(
                        tables = [self.simple_table,
                                  self.g1_pre_post_table,
                                  self.g2_pre_post_table],
                        ma_unit = self.ma_unit, 
                        use_old_value=False)
        new_correlation = self._get_correlation_str()
        restore_old_f = lambda: self.restore_ma_unit_and_tables(old_ma_unit, old_tables_data, old_correlation)
        restore_new_f = lambda: self.restore_ma_unit_and_tables(new_ma_unit, new_tables_data, new_correlation)
        command = calc_fncs.CommandFieldChanged(restore_new_f=restore_new_f,
                                                restore_old_f=restore_old_f,
                                                parent=self)
        self.undoStack.push(command)
        
        self.current_correlation = new_correlation
    def val_changed(self, val_str):
        # Backup form state
        old_ma_unit, old_tables_data = self._save_ma_unit_and_table_states(
            tables=[
                self.simple_table, self.g1_pre_post_table,
                self.g2_pre_post_table
            ],
            ma_unit=self.ma_unit,
            use_old_value=False)
        old_correlation = self.current_correlation

        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:
            print("There was an error while in val_changed")
            self.restore_ma_unit_and_tables(old_ma_unit, old_tables_data,
                                            old_correlation)
            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 == "correlation_pre_post":
                self.correlation_pre_post.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.continuous_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 == "correlation_pre_post":
            print "ok -- correlation set to %s" % self.correlation_pre_post.text(
            )
            # Recompute the estimates
            self.impute_pre_post_data(self.g1_pre_post_table, 0)
            self.impute_pre_post_data(self.g2_pre_post_table, 1)

        self.impute_data()  #### experimental

        new_ma_unit, new_tables_data = self._save_ma_unit_and_table_states(
            tables=[
                self.simple_table, self.g1_pre_post_table,
                self.g2_pre_post_table
            ],
            ma_unit=self.ma_unit,
            use_old_value=False)
        new_correlation = self._get_correlation_str()
        restore_old_f = lambda: self.restore_ma_unit_and_tables(
            old_ma_unit, old_tables_data, old_correlation)
        restore_new_f = lambda: self.restore_ma_unit_and_tables(
            new_ma_unit, new_tables_data, new_correlation)
        command = calc_fncs.CommandFieldChanged(restore_new_f=restore_new_f,
                                                restore_old_f=restore_old_f,
                                                parent=self)
        self.undoStack.push(command)

        self.current_correlation = new_correlation