def build_results_list_for_binary_bayes(results_dir, N, num_covs, nphi, cr, is_two_group):
    '''
    Builds and returns a results ArrayList from the BRUGs output (the top level is assumed to be the results_dir parameter).
    This list constructed so as to be ready to be passed off to the ReportGenerator on the C# side. 
    '''
    results = arraylist()
    results.Add(build_overall_table(results_dir, nphi, num_covs, cr, is_two_group))
    
    # now build the posterior control group table -- this is 'pc'
    if is_two_group:
        pc_matrix = System.Array.CreateInstance(float, N, 6)
        pc_rows = build_arrs_from_file(results_dir + "//pc//buffer.txt")
        for i in range(len(pc_rows)):
            insert_arr_into_mat(pc_matrix, i, pc_rows[i])
        results.Add(pc_matrix)
    
    # finally, build the treatment effects table -- this is d.exp
    treat_matrix = System.Array.CreateInstance(float, N, 6)
    treat_rows = None
    mstr = "or"
    if is_two_group and mstr != "rd":
        treat_rows = build_arrs_from_file(results_dir + "//d.exp//buffer.txt")
    else:
        treat_rows = build_arrs_from_file(results_dir + "//p//buffer.txt")
    for i in range(len(treat_rows)):
        insert_arr_into_mat(treat_matrix, i, treat_rows[i])
    results.Add(treat_matrix)
    return results
示例#2
0
def build_results_list_for_binary_bayes(results_dir, N, num_covs, nphi, cr, is_two_group):
    '''
    Builds and returns a results ArrayList from the BRUGs output (the top level is assumed to be the results_dir parameter).
    This list constructed so as to be ready to be passed off to the ReportGenerator on the C# side. 
    '''
    results = arraylist()
    results.Add(build_overall_table(results_dir, nphi, num_covs, cr, is_two_group))
    
    # now build the posterior control group table -- this is 'pc'
    if is_two_group:
        pc_matrix = System.Array.CreateInstance(float, N, 6)
        pc_rows = build_arrs_from_file(results_dir + "//pc//buffer.txt")
        for i in range(len(pc_rows)):
            insert_arr_into_mat(pc_matrix, i, pc_rows[i])
        results.Add(pc_matrix)
    
    # finally, build the treatment effects table -- this is d.exp
    treat_matrix = System.Array.CreateInstance(float, N, 6)
    treat_rows = None
    mstr = "or"
    if is_two_group and mstr != "rd":
        treat_rows = build_arrs_from_file(results_dir + "//d.exp//buffer.txt")
    else:
        treat_rows = build_arrs_from_file(results_dir + "//p//buffer.txt")
    for i in range(len(treat_rows)):
        insert_arr_into_mat(treat_matrix, i, treat_rows[i])
    results.Add(treat_matrix)
    return results
def build_results_list_for_cont_bayes(results_dir, N, num_covs, nphi, cr, is_two_group):
    results = arraylist()
    
    overall_effects = System.Array.CreateInstance(float, nphi, 6)
    vars_for_overall_table = None
    if is_two_group:
        vars_for_overall_table = ["muc", "delta"]
    else:
        vars_for_overall_table = ["Ysum"]
    
    for c in range(num_covs):
        vars_for_overall_table.append("cov%s" % c)   
    
    if cr > 0:
        vars_for_overall_table.append("beta0")
    
    add_tau = ["tau2"]
    if is_two_group:
        add_tau.insert(0, "tauc2")
    vars_for_overall_table.extend(add_tau)
    
    for i in range(len(vars_for_overall_table)):
        insert_arr_into_mat(overall_effects, i, ma_format_arr(get_first_line_arr(results_dir + "//%s//buffer.txt" % vars_for_overall_table[i])))
    results.Add(overall_effects)

    # build the treatment effects table -- this is delta.star
    treat_matrix = System.Array.CreateInstance(float, N, 6)
    treat_rows = None
    if is_two_group:
        treat_rows = build_arrs_from_file(results_dir + "//delta.star//buffer.txt")
    else:
        treat_rows = build_arrs_from_file(results_dir + "//theta//buffer.txt")
    for i in range(len(treat_rows)):
        insert_arr_into_mat(treat_matrix, i, treat_rows[i])
    results.Add(treat_matrix)
    
    # now build the posterior control group table -- this is 'pc'
    if is_two_group:
        pc_matrix = System.Array.CreateInstance(float, N, 6)
        pc_rows = build_arrs_from_file(results_dir + "//theta.c//buffer.txt")
        for i in range(len(pc_rows)):
            insert_arr_into_mat(pc_matrix, i, pc_rows[i])
        results.Add(pc_matrix)

    return results
示例#4
0
def build_results_list_for_cont_bayes(results_dir, N, num_covs, nphi, cr, is_two_group):
    results = arraylist()
    
    overall_effects = System.Array.CreateInstance(float, nphi, 6)
    vars_for_overall_table = None
    if is_two_group:
        vars_for_overall_table = ["muc", "delta"]
    else:
        vars_for_overall_table = ["Ysum"]
    
    for c in range(num_covs):
        vars_for_overall_table.append("cov%s" % c)   
    
    if cr > 0:
        vars_for_overall_table.append("beta0")
    
    add_tau = ["tau2"]
    if is_two_group:
        add_tau.insert(0, "tauc2")
    vars_for_overall_table.extend(add_tau)
    
    for i in range(len(vars_for_overall_table)):
        insert_arr_into_mat(overall_effects, i, ma_format_arr(get_first_line_arr(results_dir + "//%s//buffer.txt" % vars_for_overall_table[i])))
    results.Add(overall_effects)

    # build the treatment effects table -- this is delta.star
    treat_matrix = System.Array.CreateInstance(float, N, 6)
    treat_rows = None
    if is_two_group:
        treat_rows = build_arrs_from_file(results_dir + "//delta.star//buffer.txt")
    else:
        treat_rows = build_arrs_from_file(results_dir + "//theta//buffer.txt")
    for i in range(len(treat_rows)):
        insert_arr_into_mat(treat_matrix, i, treat_rows[i])
    results.Add(treat_matrix)
    
    # now build the posterior control group table -- this is 'pc'
    if is_two_group:
        pc_matrix = System.Array.CreateInstance(float, N, 6)
        pc_rows = build_arrs_from_file(results_dir + "//theta.c//buffer.txt")
        for i in range(len(pc_rows)):
            insert_arr_into_mat(pc_matrix, i, pc_rows[i])
        results.Add(pc_matrix)

    return results
def build_results_list_for_diagnostic_bayes(results_dir, metrics, N, num_covs, nphis, cr):
    all_results = arraylist()
    results = arraylist()
    forest_plot_stuff = arraylist()
    outcome_index = 0
    for outcome in metrics:
    is_two_group = False
    if outcome in ["dor", "lrp", "lrn"]:
        is_two_group = True
    cur_outcome_table = build_diagnostic_bayes_outcome_table(results_dir, outcome, N, cr, num_covs, is_two_group)
    results.Add(cur_outcome_table)
    
    #
    # now deal with forest plot stuff
    #
    # this will include: [lowers, means, uppers, overalls]
    stuff_for_this_forest_plot = arraylist() 
        # here we build double[] arrays to hand off for the forest plot. we need lowers, means and uppers, as well
        # as overalls, for each metric. first we add results for each study.
    lowers, means, uppers = System.Array.CreateInstance(float, N), System.Array.CreateInstance(float, N), System.Array.CreateInstance(float, N)
    lower_index, mean_index, upper_index = 0, 2, 4
    for study_i in range(N):
        lowers[study_i] = cur_outcome_table[study_i, lower_index]
        means[study_i] = cur_outcome_table[study_i, mean_index]
        uppers[study_i] = cur_outcome_table[study_i, upper_index]
        
    
    for double_arr in [lowers, means, uppers]:
        stuff_for_this_forest_plot.Add(double_arr)
        
    # now add the overall estimate
    overall = System.Array.CreateInstance(float, 3)
    # the summary statistic is psum if 'one group' model; delta.exp otherwise
    overall_var = "psum"
    if is_two_group:
        overall_var = "delta.exp"
        #overall_var = "delta"
    overall_arr = ma_format_arr(get_first_line_arr(results_dir + outcome + "//%s//buffer.txt" % overall_var))

    overall[0] = overall_arr[2]
    overall[1] = overall_arr[0]
    overall[2] = overall_arr[4]
    stuff_for_this_forest_plot.Add(overall)
    forest_plot_stuff.Add(stuff_for_this_forest_plot)
    outcome_index += 1
    all_results.Add(results)
    all_results.Add(forest_plot_stuff)
    return all_results



def generate_model_file_cont(out_path, cr, num_covs, is_two_group, generic):
    out_str = None
    # build string for covariate regression
    cov_str = ""
    if num_covs:
        cov_str = " + " + build_reg_str_for_covs(num_covs)
        
    if is_two_group:
    out_str = cont_bayes_two_group_linear_cr_str
        if cr == "none":
            out_str = out_str.replace("beta0 ~ dnorm(0.0,precnorm)", "")
        if num_covs:
            out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)",  "mu[i] <- delta" +  cov_str)
            out_str +=  build_assignments_for_covs(num_covs)
        else:
            # no control rate, no covariates. 
        out_str = out_str.replace("delta.star[i] ~ dnorm(mu[i], inv.tau2 )", "delta.star[i] ~ dnorm(delta, inv.tau2 )")
        out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)", "mu[i] <- delta")
        else:
        if num_covs:
            out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)", "mu[i] <- delta + beta0 *(theta.c[i] - muc)" + cov_str)
            out_str += build_assignments_for_covs(num_covs)
        
    else:
示例#6
0
def build_results_list_for_diagnostic_bayes(results_dir, metrics, N, num_covs, nphis, cr):
    all_results = arraylist()
    results = arraylist()
    forest_plot_stuff = arraylist()
    outcome_index = 0
    for outcome in metrics:
    is_two_group = False
    if outcome in ["dor", "lrp", "lrn"]:
        is_two_group = True
    cur_outcome_table = build_diagnostic_bayes_outcome_table(results_dir, outcome, N, cr, num_covs, is_two_group)
    results.Add(cur_outcome_table)
    
    #
    # now deal with forest plot stuff
    #
    # this will include: [lowers, means, uppers, overalls]
    stuff_for_this_forest_plot = arraylist() 
        # here we build double[] arrays to hand off for the forest plot. we need lowers, means and uppers, as well
        # as overalls, for each metric. first we add results for each study.
    lowers, means, uppers = System.Array.CreateInstance(float, N), System.Array.CreateInstance(float, N), System.Array.CreateInstance(float, N)
    lower_index, mean_index, upper_index = 0, 2, 4
    for study_i in range(N):
        lowers[study_i] = cur_outcome_table[study_i, lower_index]
        means[study_i] = cur_outcome_table[study_i, mean_index]
        uppers[study_i] = cur_outcome_table[study_i, upper_index]
        
    
    for double_arr in [lowers, means, uppers]:
        stuff_for_this_forest_plot.Add(double_arr)
        
    # now add the overall estimate
    overall = System.Array.CreateInstance(float, 3)
    # the summary statistic is psum if 'one group' model; delta.exp otherwise
    overall_var = "psum"
    if is_two_group:
        overall_var = "delta.exp"
        #overall_var = "delta"
    overall_arr = ma_format_arr(get_first_line_arr(results_dir + outcome + "//%s//buffer.txt" % overall_var))

    overall[0] = overall_arr[2]
    overall[1] = overall_arr[0]
    overall[2] = overall_arr[4]
    stuff_for_this_forest_plot.Add(overall)
    forest_plot_stuff.Add(stuff_for_this_forest_plot)
    outcome_index += 1
    all_results.Add(results)
    all_results.Add(forest_plot_stuff)
    return all_results



def generate_model_file_cont(out_path, cr, num_covs, is_two_group, generic):
    out_str = None
    # build string for covariate regression
    cov_str = ""
    if num_covs:
        cov_str = " + " + build_reg_str_for_covs(num_covs)
        
    if is_two_group:
    out_str = cont_bayes_two_group_linear_cr_str
        if cr == "none":
            out_str = out_str.replace("beta0 ~ dnorm(0.0,precnorm)", "")
        if num_covs:
            out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)",  "mu[i] <- delta" +  cov_str)
            out_str +=  build_assignments_for_covs(num_covs)
        else:
            # no control rate, no covariates. 
        out_str = out_str.replace("delta.star[i] ~ dnorm(mu[i], inv.tau2 )", "delta.star[i] ~ dnorm(delta, inv.tau2 )")
        out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)", "mu[i] <- delta")
        else:
        if num_covs:
            out_str = out_str.replace("mu[i] <- delta + beta0 *(theta.c[i] - muc)", "mu[i] <- delta + beta0 *(theta.c[i] - muc)" + cov_str)
            out_str += build_assignments_for_covs(num_covs)
        
    else: