Пример #1
0
def plot_fits(m):
    # set font
    book_graphics.set_font()
    
    pl.figure(**book_graphics.three_quarter_plus_page_params)
    for ii in range(2):
        pl.subplot(1, 2, ii+1)
        model = m[ii]
        #
        graphics.plot_data_bars(model.input_data, color='grey', label='Simulated data')
        #
        pl.plot(model.ages, model.pi_age_true, 'w-', linewidth=3)
        pl.plot(model.ages, model.pi_age_true, 'k--', label='Truth')
        #
        #pl.plot(model.ages, model.vars['mu_age'].trace().T, '-', color='grey', alpha=.1)
        pl.plot(model.ages, model.vars['mu_age'].stats()['mean'], 'w-', linewidth=4)
        pl.plot(model.ages, model.vars['mu_age'].stats()['mean'], 'k-', linewidth=2, label='Posterior mean')

        pl.plot(model.ages, model.vars['mu_age'].stats()['95% HPD interval'][:,0], 'k-', label='Uncertainty interval')
        pl.plot(model.ages, model.vars['mu_age'].stats()['95% HPD interval'][:,1], 'k-')
        
        #
        if ii == 0:
            pl.legend(fancybox=True, shadow=True, loc='upper center', bbox_to_anchor=(1.15,-.2), ncol=2)
        pl.xlabel('Age (years)')
        pl.ylabel('Rate (per PY)')
        pl.axis([-5, 105, -.05, 1.])
        pl.yticks([0, .25, .5, .75])
        pl.xticks(fontsize='large')
        book_graphics.subtitle('(%s)'%'ab'[ii])

    #pl.subplots_adjust(top=.87, bottom=.44, wspace=.35) # l b r t w h #(top=.93, bottom=.53, wspace=.35)
    pl.subplots_adjust(top=.9, bottom=.3, wspace=.35)
Пример #2
0
def plot_fits(m):
    # set font
    book_graphics.set_font()

    pl.figure(**book_graphics.three_quarter_plus_page_params)
    for ii in range(2):
        pl.subplot(1, 2, ii + 1)
        model = m[ii]
        #
        graphics.plot_data_bars(model.input_data,
                                color='grey',
                                label='Simulated data')
        #
        pl.plot(model.ages, model.pi_age_true, 'w-', linewidth=3)
        pl.plot(model.ages, model.pi_age_true, 'k--', label='Truth')
        #
        #pl.plot(model.ages, model.vars['mu_age'].trace().T, '-', color='grey', alpha=.1)
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['mean'],
                'w-',
                linewidth=4)
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['mean'],
                'k-',
                linewidth=2,
                label='Posterior mean')

        pl.plot(model.ages,
                model.vars['mu_age'].stats()['95% HPD interval'][:, 0],
                'k-',
                label='Uncertainty interval')
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['95% HPD interval'][:, 1], 'k-')

        #
        if ii == 0:
            pl.legend(fancybox=True,
                      shadow=True,
                      loc='upper center',
                      bbox_to_anchor=(1.15, -.2),
                      ncol=2)
        pl.xlabel('Age (years)')
        pl.ylabel('Rate (per PY)')
        pl.axis([-5, 105, -.05, 1.])
        pl.yticks([0, .25, .5, .75])
        pl.xticks(fontsize='large')
        book_graphics.subtitle('(%s)' % 'ab'[ii])

    #pl.subplots_adjust(top=.87, bottom=.44, wspace=.35) # l b r t w h #(top=.93, bottom=.53, wspace=.35)
    pl.subplots_adjust(top=.9, bottom=.3, wspace=.35)
Пример #3
0
    return model

best_model = load_new_model()

output = pandas.read_csv('/home/j/Project/dismod/gbd/data/applications-data_af.csv')

# figure af-data
pl.figure(**book_graphics.half_page_params)

pl.subplot(1,2,1)
dismod3.graphics.plot_data_bars(best_model.get_data('p'))
pl.xlabel('Age (years)')
pl.ylabel('Prevalence (%)')
pl.yticks([0, .05, .1, .15,  .2], [0, 5, 10, 15, 20])
my_axis(.22)
book_graphics.subtitle('(a)')


pl.subplot(1,2,2)
dismod3.graphics.plot_data_bars(best_model.get_data('i'))
pl.xlabel('Age (years)')
pl.ylabel('Incidence (per 1000 PY)')
pl.yticks([0, .001, .002, .003, .004], [0, 1, 2, 3, 4,])
my_axis(.0045)
book_graphics.subtitle('(b)')


pl.subplots_adjust(wspace=.35, top=.99, bottom=.14)

pl.savefig('book/graphics/af-data.pdf')
pl.savefig('book/graphics/af-data.png')
Пример #4
0
        model = dismod3.data.load('/home/j/Project/dismod/dismod_status/prod/dm-37005')
    #model.input_data = model.input_data.drop(['x_health_system_access'], axis=1)
    return model

# figure cirrhosis-data
best_model = load_new_model()

pl.figure(**book_graphics.half_page_params)

pl.subplot(1,2,1)
dismod3.graphics.plot_data_bars(best_model.get_data('p'))
pl.xlabel('Age (years)')
pl.ylabel('Prevalence (%)')
pl.yticks([0, .001, .002, .003, .004], [0, 0.1, 0.2, 0.3, 0.4])
my_axis(.0045)
book_graphics.subtitle('(a)')


pl.subplot(1,2,2)
dismod3.graphics.plot_data_bars(best_model.get_data('pf'))
pl.xlabel('Age (years)')
pl.ylabel('Cause-specific mortality \n (per 10,000 PY)'+'\n\n', ha='center')
pl.yticks([0, .0008, .0016, .0024, .0032], [0, 8, 16, 24, 32])
my_axis(.0035)
pl.subplots_adjust(hspace=.35)
pl.subplots_adjust(wspace=.35)
book_graphics.subtitle('(b)')


pl.subplots_adjust(wspace=.35, top=.99, bottom=.14)
Пример #5
0
best_model = load_new_model()

output = pandas.read_csv(
    '/home/j/Project/dismod/gbd/data/applications-data_af.csv')

# figure af-data
pl.figure(**book_graphics.half_page_params)

pl.subplot(1, 2, 1)
dismod3.graphics.plot_data_bars(best_model.get_data('p'))
pl.xlabel('Age (years)')
pl.ylabel('Prevalence (%)')
pl.yticks([0, .05, .1, .15, .2], [0, 5, 10, 15, 20])
my_axis(.22)
book_graphics.subtitle('(a)')

pl.subplot(1, 2, 2)
dismod3.graphics.plot_data_bars(best_model.get_data('i'))
pl.xlabel('Age (years)')
pl.ylabel('Incidence (per 1000 PY)')
pl.yticks([0, .001, .002, .003, .004], [
    0,
    1,
    2,
    3,
    4,
])
my_axis(.0045)
book_graphics.subtitle('(b)')
Пример #6
0
    mc.MAP(vars).fit(method='fmin_powell', tol=.00001, verbose=0)
    #pl.plot(ages, vars['mu_age'].value, 'w', linewidth=3, **params)
    
    if i == 0:
        ax1 = fig.add_subplot(2,1,i+1)
        ax1.plot(X, Y, 'ks', ms=4, mew=2)
        ax1.plot(ages, vars['mu_age'].value, 'k', linewidth=2, linestyle=params['linestyle'])#, **params)
    else:
        ax2 = fig.add_subplot(2,1,i+1, sharex=ax1)
        ax2.plot(X, Y, 'ks', ms=4, mew=2)
        ax2.plot(ages, vars['mu_age'].value, 'k', linewidth=2, linestyle=params['linestyle'])#, **params)
        pl.xlabel('$a$')
    decorate_figure()
    pl.setp(ax1.get_xticklabels(), visible=False)
    book_graphics.subtitle(params['subt'] + ' ' + params['label'])
pl.subplots_adjust(hspace=.1, top=.99, bottom=.11)
pl.savefig('book/graphics/splines-fig.pdf')

# <codecell>

### @export 'spline_fig'
knots = range(0, 101, 5)
fig1_data = {}

for i, params in enumerate([dict(label=r'$\sigma = 0.5$', subt='(a)', smoothing=.5),
                            dict(label=r'$\sigma = 0.05$', subt='(b)', smoothing=.05),
                            dict(label=r'$\sigma = 0.005$', subt='(c)', smoothing=.005)]):
    
    vars = age_pattern.age_pattern('t', ages=ages, knots=knots, smoothing=params.pop('smoothing'))
    vars['mu_pred'] = mc.Lambda('mu_pred', lambda mu_age=vars['mu_age'], X=X : mu_age[X])
Пример #7
0
    pl.plot(pl.arange(101),
            pl.array(output['1k_' + params['type']]),
            'k--',
            linewidth=3,
            label='{35}')
    pl.plot(pl.arange(101),
            pl.array(output['2k_' + params['type']]),
            'k-',
            linewidth=3,
            label='{31, 35}')

    pl.xlabel('Age (years)')
    pl.ylabel(params['ylabel'] + '\n\n', ha='center')
    pl.yticks(*params.get('yticks', ([0, .025, .05], [0, 2.5, 5])))
    pl.axis(params.get('axis', [-5, 105, -.005, .06]))
    book_graphics.subtitle(params['title'])

pl.subplots_adjust(top=.99, bottom=.14, wspace=.35, hspace=.25)

pl.legend(bbox_to_anchor=(.42, 0, .3, .53),
          bbox_transform=pl.gcf().transFigure,
          fancybox=True,
          shadow=True,
          title='Additional knots at:')
pl.savefig('book/graphics/oa_knee-knots.pdf')
pl.savefig('book/graphics/oa_knee-knots.png')

# figure oa_knee-i_prior
pl.figure(**book_graphics.three_quarter_page_params)

param_list = [
Пример #8
0
                 vars['mu_age'].value,
                 'k',
                 linewidth=2,
                 linestyle=params['linestyle'])  #, **params)
    else:
        ax2 = fig.add_subplot(2, 1, i + 1, sharex=ax1)
        ax2.plot(X, Y, 'ks', ms=4, mew=2)
        ax2.plot(ages,
                 vars['mu_age'].value,
                 'k',
                 linewidth=2,
                 linestyle=params['linestyle'])  #, **params)
        pl.xlabel('$a$')
    decorate_figure()
    pl.setp(ax1.get_xticklabels(), visible=False)
    book_graphics.subtitle(params['subt'] + ' ' + params['label'])
pl.subplots_adjust(hspace=.1, top=.99, bottom=.11)
pl.savefig('book/graphics/splines-fig.pdf')

# <codecell>

### @export 'spline_fig'
knots = range(0, 101, 5)
fig1_data = {}

for i, params in enumerate([
        dict(label=r'$\sigma = 0.5$', subt='(a)', smoothing=.5),
        dict(label=r'$\sigma = 0.05$', subt='(b)', smoothing=.05),
        dict(label=r'$\sigma = 0.005$', subt='(c)', smoothing=.005)
]):
Пример #9
0
pl.figure(**book_graphics.half_page_params)

df = best_model.get_data('p')

pl.figure(**book_graphics.half_page_params)

for i in range(2):
    pl.subplot(1,2,1+i)
    dismod3.graphics.plot_data_bars(df[df['x_cv_past_year'] == i])
    pl.xlabel('Age (years)')
    pl.ylabel('Prevalence (%)')
    pl.yticks([0, .07, .14, .21, .28], [0, 7, 14, 21, 28])
    my_axis(.30)
    
    
    if i == 0: book_graphics.subtitle('(a)')
    if i == 1: book_graphics.subtitle('(b)')
    
pl.subplots_adjust(wspace=.35, top=.99, bottom=.14)
pl.savefig('book/graphics/anxiety-data_by_cv.pdf')
pl.savefig('book/graphics/anxiety-data_by_cv.png')

# figure anxiety-FE
data = pandas.read_csv('/home/j/Project/dismod/gbd/data/applications-data_anxiety.csv')
pl.figure(**book_graphics.full_page_params)

my_plot_data_bars(best_model.get_data('p'), color='grey', label='Period prevalence')
my_plot_data_bars(pm_model.get_data('p'), color='black',label='Point prevalence')

pl.plot(pl.arange(101), pl.array(data['best']),  'k-', linewidth=2, label='All data, with fixed effects')
pl.plot(pl.arange(101), pl.array(data['no_FE']), 'k--', linewidth=2, label='All data, without fixed effects')
Пример #10
0
def my_axis(ymax):
    axis([-5, 105, -ymax / 10., ymax])


model = dismod3.data.load('/home/j/Project/dismod/notebooks/models/bipolar')
df = model.get_data('p')

pl.figure(**book_graphics.half_page_params)
for i in range(2):
    pl.subplot(1, 2, 1 + i)
    dismod3.graphics.plot_data_bars(df[df['x_cv_past_year'] == i])
    pl.xlabel('Age (years)')
    pl.ylabel('Prevalence (%)')
    pl.yticks([0, .01, .02, .03, .04], [0, 1, 2, 3, 4])
    pl.axis([-5, 105, -.0045, .045])
    if i == 0: book_graphics.subtitle('(a) Past-year prevalence')
    else: book_graphics.subtitle('(b) Past-month prevalence')
    #title('cv_past_year = %d'%i)

pl.subplots_adjust(wspace=.35, bottom=.14)
pl.savefig('book/graphics/bipolar-data-by-cv.pdf')

# Compare alternative reference values
# -------------------------------------

model = dismod3.data.load('/home/j/Project/dismod/notebooks/models/bipolar')
#model.keep(areas=['super-region_0'], sexes=['male', 'total'], end_year=1997)

# remove expert prior on pyp effect
model.parameters['p']['fixed_effects'].pop('x_cv_past_year')
Пример #11
0
          #dict(type='m_with', title='(d)', ylabel='With-condition mortality \n (per 100 PY)', yticks=([0, .1, .2, .3, .4], [0, 10, 20, 30, 40]), axis=[-5,105,-.045,.45], loc='upper left'),
          ]

for i, params in enumerate(param_list):
    ax = pl.subplot(2,2,i+1)
    dismod3.graphics.plot_data_bars(best_model.get_data(params['type']), color='grey') 

    pl.plot(pl.arange(101), pl.array(output['0k_'+params['type']]), 'k:', linewidth=3, label='{}')
    pl.plot(pl.arange(101), pl.array(output['1k_'+params['type']]), 'k--', linewidth=3, label='{35}')
    pl.plot(pl.arange(101), pl.array(output['2k_'+params['type']]), 'k-', linewidth=3, label='{31, 35}')
    
    pl.xlabel('Age (years)')
    pl.ylabel(params['ylabel']+'\n\n', ha='center')
    pl.yticks(*params.get('yticks', ([0, .025, .05], [0, 2.5, 5])))
    pl.axis(params.get('axis', [-5,105,-.005,.06]))
    book_graphics.subtitle(params['title'])
    
pl.subplots_adjust(top=.99, bottom=.14, wspace=.35, hspace=.25)


pl.legend(bbox_to_anchor=(.42, 0, .3, .53), bbox_transform=pl.gcf().transFigure, fancybox=True, shadow=True, title='Additional knots at:')
pl.savefig('book/graphics/oa_knee-knots.pdf')
pl.savefig('book/graphics/oa_knee-knots.png')

# figure oa_knee-i_prior
pl.figure(**book_graphics.three_quarter_page_params)

param_list = [dict(type='p', title='(a)', ylabel='Prevalence (%)', yticks=([0, .12, .24, .36, .48], [0, 12, 24, 36, 48]), axis=[25,105,-.054,.54], loc='upper left'),
          dict(type='i', title='(b)', ylabel='Incidence \n (per 1000 PY)', yticks=([0, .004, .008, .012, .016], [0, 4, 8, 12, 16]), axis=[-5,105,-.0018,.018], loc='upper left'),
          #dict(type='f', title='(c)', ylabel='Excess mortality (Per 100 PY)', yticks=([0, .002, .004, .006, .008], [0, 2, 4, 6, 8]), axis=[-5,105,-.0018,.009], loc='upper left' ),
          #dict(type='r', title='(c)', ylabel='Excess mortality (Per 100 PY)', yticks=([0, .002, .004, .006, .008], [0, 2, 4, 6, 8]), axis=[-5,105,-.0018,.009], loc='upper left' ),
Пример #12
0
def my_axis(ymax):
    axis([-5,105,-ymax/10.,ymax])

model = dismod3.data.load('/home/j/Project/dismod/notebooks/models/bipolar')
df = model.get_data('p')

pl.figure(**book_graphics.half_page_params)
for i in range(2):
    pl.subplot(1,2,1+i)
    dismod3.graphics.plot_data_bars(df[df['x_cv_past_year'] == i])
    pl.xlabel('Age (years)')
    pl.ylabel('Prevalence (%)')
    pl.yticks([0, .01, .02, .03, .04], [0, 1, 2, 3, 4])
    pl.axis([-5,105,-.0045, .045])
    if i == 0: book_graphics.subtitle('(a) Past-year prevalence')
    else: book_graphics.subtitle('(b) Past-month prevalence')
    #title('cv_past_year = %d'%i)

pl.subplots_adjust(wspace=.35, bottom=.14)    
pl.savefig('book/graphics/bipolar-data-by-cv.pdf')


# Compare alternative reference values
# -------------------------------------

model = dismod3.data.load('/home/j/Project/dismod/notebooks/models/bipolar')
#model.keep(areas=['super-region_0'], sexes=['male', 'total'], end_year=1997)

# remove expert prior on pyp effect
model.parameters['p']['fixed_effects'].pop('x_cv_past_year')
Пример #13
0
    model.parameters["f"]["parameter_age_mesh"] = [0, 100]
    return model


csmr_model = load_new_model()

# figure alcohol-data
pl.figure(**book_graphics.full_plus_page_params)

pl.subplot(2, 2, 1)
dismod3.graphics.plot_data_bars(csmr_model.get_data("p"))
pl.xlabel("Age (years)")
pl.ylabel("Prevalence (%)")
pl.yticks([0, 0.03, 0.06, 0.09, 0.12], [0, 3, 6, 9, 12])
my_axis(0.13)
book_graphics.subtitle("(a)")


pl.subplot(2, 2, 2)
dismod3.graphics.plot_data_bars(csmr_model.get_data("i"))
pl.xlabel("Age (years)")
pl.ylabel("Incidence (per PY)")
pl.yticks([0, 3, 6, 9, 12])
my_axis(13)
book_graphics.subtitle("(b)")


pl.subplot(2, 2, 3)
dismod3.graphics.plot_data_bars(csmr_model.get_data("csmr"))
pl.xlabel("Age (years)")
pl.ylabel("Cause-specific mortality \n (per 100,000 PY)" + "\n\n", ha="center")