Ejemplo n.º 1
0
Archivo: table.py Proyecto: flaxter/gbd
def write_table_group_value(dm, key, item, ws, x, y, group_sizes):
    """Write estimated values into table for all age_groups

    Parameters
    ----------
    dm : str or DiseaseJson object
      the json string or a thin python wrapper around this data that
      is to be plotted
    key : key
    item : 
    ws : work sheet
    x : horizontal shift
    y : vertical shift
    group_sizes : list of group sizes in order
    """
    c = dismod3.utils.KEY_DELIM_CHAR
    type, region, year, sex = key.split(c)
    start = 0
    end = 0
   
    if type == 'with-condition-death':
        key_prevalence = 'prevalence' + c + region + c + year + c + sex
        key_mortality = 'mortality' + c + region + c + year + c + sex
        if len(dm.get_mcmc(item, key_prevalence)) == dismod3.MAX_AGE and \
           len(dm.get_mcmc(item, key_mortality)) == dismod3.MAX_AGE and \
           len(population_by_region_year_sex(region, year, sex)) == dismod3.MAX_AGE:
            for j, gs in enumerate(group_sizes):
                start = end
                end = start + gs
                raw_rate = dm.get_mcmc(item, key_prevalence)[start:end] * \
                           dm.get_mcmc(item, key_mortality)[start:end] * \
                           population_by_region_year_sex(region, year, sex)[start:end]
                age_indices = []
                for i in range(len(raw_rate)):
                    age_indices.append(i)
                age_weights = dm.get_population(region)[start:end]
                ws.write(x + j, y, rate_for_range(raw_rate, age_indices, age_weights) / gs)
    else:
        if(len(dm.get_mcmc(item, key)) == dismod3.MAX_AGE):
            for j, gs in enumerate(group_sizes):
                start = end
                end = start + gs
                raw_rate = dm.get_mcmc(item, key)[start:end]
                age_indices = []
                for i in range(len(raw_rate)):
                    age_indices.append(i)
                age_weights = dm.get_population(region)[start:end]
                ws.write(x + j, y, rate_for_range(raw_rate, age_indices, age_weights) / gs)
Ejemplo n.º 2
0
 def obs(f=vars['rate_stoch'],
         age_indices=age_indices,
         age_weights=age_weights,
         value=np.log(dm.value_per_1(d)),
         tau=se**-2, data=d):
     f_i = rate_for_range(f, age_indices, age_weights)
     return mc.normal_like(value, np.log(f_i), tau)
Ejemplo n.º 3
0
 def obs(f=rate_stoch,
         age_indices=age_indices,
         age_weights=age_weights,
         value=d_val,
         tau=1./(d_se)**2):
     f_i = rate_for_range(f, age_indices, age_weights)
     return mc.normal_like(value, f_i, tau)
Ejemplo n.º 4
0
        def obs(value=logit_val, logit_se=logit_se,
                X=covariates(d),
                alpha=alpha, beta=beta, gamma=gamma, sigma=sigma,
                age_indices=age_indices,
                age_weights=age_weights):

            # calculate study-specific rate function
            mu = predict_logit_rate(X, alpha, beta, gamma)
            mu_i = rate_for_range(mu, age_indices, age_weights)
            
            tau_i = 1. / (sigma**2 + logit_se**2)
            logp = mc.normal_like(x=value, mu=mu_i, tau=tau_i)
            return logp
Ejemplo n.º 5
0
 def b_i(beta=beta, age_indices=age_indices, age_weights=age_weights):
     return rate_for_range(beta, age_indices, age_weights)
Ejemplo n.º 6
0
 def a_i(alpha=alpha, age_indices=age_indices, age_weights=age_weights):
     return rate_for_range(alpha, age_indices, age_weights)