Esempio n. 1
0
def graphics_check():
    # L'Abbe Plots
    labbe_plot()
    plt.show()
    labbe_plot(r1=[0.25, 0.5], r0=[0.1, 0.2], color='r')
    plt.show()
    labbe_plot(r1=[0.3, 0.5], r0=[0.2, 0.7], scale='additive', marker='+', linestyle='')
    plt.show()
    labbe_plot(r1=[0.3, 0.5], r0=[0.2, 0.7], scale='multiplicative', markersize=10)
    plt.show()

    # 1) Check EffectMeasurePlot
    labs = ['Overall', 'Adjusted', '', '2012-2013', 'Adjusted', '', '2013-2014', 'Adjusted', '', '2014-2015',
            'Adjusted']
    measure = [np.nan, 0.94, np.nan, np.nan, 1.22, np.nan, np.nan, 0.59, np.nan, np.nan, 1.09]
    lower = [np.nan, 0.77, np.nan, np.nan, '0.80', np.nan, np.nan, '0.40', np.nan, np.nan, 0.83]
    upper = [np.nan, 1.15, np.nan, np.nan, 1.84, np.nan, np.nan, 0.85, np.nan, np.nan, 1.44]
    p = EffectMeasurePlot(label=labs, effect_measure=measure, lcl=lower, ucl=upper)
    p.plot(figsize=[7, 4])
    plt.show()

    # 2) Check Functional form plots
    data = load_sample_data(False)
    data['age_sq'] = data['age0']**2
    functional_form_plot(data, 'dead', var='age0', loess=False)
    plt.show()
    functional_form_plot(data, 'dead', var='age0', discrete=True, loess=False)
    plt.show()
    functional_form_plot(data, 'cd40', var='age0', outcome_type='continuous', loess=False)
    plt.show()
    functional_form_plot(data, 'dead', var='age0', points=True, loess=False)
    plt.show()
    functional_form_plot(data, 'dead', var='age0', loess=True, loess_value=0.25, discrete=True)
    plt.show()
    functional_form_plot(data, 'dead', var='age0', f_form='age0 + age_sq', loess=False)
    plt.show()

    # 3) Check P-value plots
    p = pvalue_plot(point=0.23, sd=0.1)
    plt.show()
    pvalue_plot(point=0.23, sd=0.1, fill=False)
    plt.show()
    pvalue_plot(point=0.23, sd=0.1, color='r')
    plt.show()
    pvalue_plot(point=0.23, sd=0.1, null=0.05)
    plt.show()
    pvalue_plot(point=0.23, sd=0.1, alpha=0.05)
    plt.show()

    # 4) Check Spaghetti plot
    df = load_sample_data(timevary=True)
    spaghetti_plot(df, idvar='id', variable='cd4', time='enter')
    plt.show()

    # 5) Check ROC
    df = pd.DataFrame()
    df['d'] = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]
    df['p'] = [0.1, 0.15, 0.1, 0.7, 0.5, 0.9, 0.95, 0.5, 0.4, 0.8, 0.99, 0.99, 0.89, 0.95]
    roc(df, true='d', threshold='p', youden_index=False)
    plt.show()
    roc(df, true='d', threshold='p', youden_index=True)
    plt.show()

    # 6) Check Dynamic Risk Plots
    a = pd.DataFrame([[0, 0], [1, 0.15], [2, 0.25], [4, 0.345]], columns=['timeline', 'riske']).set_index(
                     'timeline')
    b = pd.DataFrame([[0, 0], [1, 0.2], [1.5, 0.31], [3, 0.345]], columns=['timeline', 'riske']).set_index(
                     'timeline')
    dynamic_risk_plot(a, b, loess=False)
    plt.show()
    dynamic_risk_plot(a, b, measure='RR', loess=False)
    plt.show()
    dynamic_risk_plot(a, b, measure='RR', scale='log-transform', loess=False)
    plt.show()
    dynamic_risk_plot(a, b, measure='RR', scale='log', loess=False)
    plt.show()
    dynamic_risk_plot(a, b, loess=True, loess_value=0.4)
    plt.show()
    dynamic_risk_plot(a, b, loess=False, point_color='green', line_color='green')
    plt.show()
Esempio n. 2
0
pvalue_plot(point=-0.049, sd=0.042, color='b', fill=False)
pvalue_plot(point=-0.062, sd=0.0231, color='r', fill=False)
plt.legend(
    [Line2D([0], [0], color='b', lw=2),
     Line2D([0], [0], color='r', lw=2)], ['Our Study', 'Review'])
plt.tight_layout()
plt.savefig("../images/zepid_pvalue3.png", format='png', dpi=300)
plt.close()

######################################
# Spaghetti Plot
from zepid.graphics import spaghetti_plot

df = ze.load_sample_data(timevary=True)

spaghetti_plot(df, idvar='id', variable='cd4', time='enter')
plt.tight_layout()
plt.savefig("../images/zepid_spaghetti.png", format='png', dpi=300)
plt.close()

######################################
# Effect Measure plot
import numpy as np
from zepid.graphics import EffectMeasurePlot

labs = [
    'Overall', 'Adjusted', '', '2012-2013', 'Adjusted', '', '2013-2014',
    'Adjusted', '', '2014-2015', 'Adjusted'
]
measure = [
    np.nan, 0.94, np.nan, np.nan, 1.22, np.nan, np.nan, 0.59, np.nan, np.nan,