示例#1
0
    ofile.write('Marginal P/LP CP Effect: {0:.3f} ({1:.3f}; {2:.2e})\n'.format(cp_lin_mod_w_pack_years.params['P/LP Carrier'],cp_lin_mod_w_pack_years.bse['P/LP Carrier'],cp_lin_mod_w_pack_years.pvalues['P/LP Carrier']))
    ofile.write('P/LP x Pack-years CP Effect: {0:.3f} ({1:.3f}; {2:.2e})\n'.format(cp_lin_mod_w_pack_years.params['Pack-years x P/LP Carrier'],cp_lin_mod_w_pack_years.bse['Pack-years x P/LP Carrier'],cp_lin_mod_w_pack_years.pvalues['Pack-years x P/LP Carrier']))
    ofile.write('\n'*3)

    global_cp_model=OLS(pack_year_table['Cryptic Phenotype'],exog=sm.tools.add_constant(pack_year_table[['sex','age_normalized','array','Smoking-Pack Years']+['PC{0:d}'.format(i) for i in range(1,11)]+['P/LP Carrier','PGS','PGS x P/LP Carrier']]),hasconst=True).fit()

    ofile.write("#"*5+" Final Model (N={0:d}) ".format(pack_year_table.shape[0])+"#"*5+'\n')
    for param in global_cp_model.params.keys():
        ofile.write('{3:s} Effect: {0:.3f} ({1:.3f}; {2:.2e})\n'.format(global_cp_model.params[param],global_cp_model.bse[param],global_cp_model.pvalues[param],param))
    ofile.write('\n')

    global_cp_model_minus_pgs=OLS(pack_year_table['Cryptic Phenotype'],exog=sm.tools.add_constant(pack_year_table[['sex','age_normalized','array','Smoking-Pack Years']+['PC{0:d}'.format(i) for i in range(1,11)]+['P/LP Carrier']]),hasconst=True).fit()

    global_cp_model_minus_pgs_interaction=OLS(pack_year_table['Cryptic Phenotype'],exog=sm.tools.add_constant(pack_year_table[['sex','age_normalized','array','Smoking-Pack Years']+['PC{0:d}'.format(i) for i in range(1,11)]+['P/LP Carrier','PGS']]),hasconst=True).fit()

    lr_test_all_pgs=global_cp_model.compare_lr_test(global_cp_model_minus_pgs)
    lr_test_pgs_interaction=global_cp_model.compare_lr_test(global_cp_model_minus_pgs_interaction)

    ofile.write('Aggregate PGS Effect P-Value (LR Test): {0:.2e}\n'.format(lr_test_all_pgs[1]))
    ofile.write('PGS Interaction Effects P-Value (LR Test): {0:.2e}\n'.format(lr_test_pgs_interaction[1]))
    ofile.write('\n'*3)

    pack_year_table['CP Residuals (Pack-Year Adj.)']=global_cp_model_minus_pgs.resid
    pack_year_table['PGS Quantiles']=assign_quantiles(pack_year_table,'PGS',3)

    f, axis = plt.subplots(1, 1,figsize=(10,8))
    f.tight_layout(pad=2)
    axis.spines['right'].set_visible(False)
    axis.spines['top'].set_visible(False)
    sns.pointplot(x='PGS Quantiles',y='CP Residuals (Pack-Year Adj.)',data=pack_year_table,hue='Genotype',palette=[color_list[0],color_list[2]],ax=axis,scale=3.0,errwidth=15.0,join=False,markers=['o','^'],dodge=0.25)
    axis.set_ylabel('Cryptic Phenotype\nResiduals (Pack-years Adj.)')