absolute_covariates

View page source

Example Using absolute_covariates Option in all_node_database

For this example everything is constant w.r.t. age and time.

Nodes

The following is a diagram of the node tree for this example. The root_node is n0, the fit_goal_set and fit_goal_table are {n3, n4, n2}, and the leaf nodes are {n3, n4, n5, n6}:

                n0
        /-----/\-----\
     n1             (n2)
    /  \            /  \
(n3)  (n4)       n5    n6

fit_goal_set

fit_goal_set = { 'n3', 'n4', 'n2' }
fit_goal_table = [  { 'node_id' : 3 }, {'node_id' : 4 }, { 'node_id' : 2 } ]

Rates

The only non-zero dismod_at rates for this example are iota.and omega.

Splitting Covariate

This cascade is set up to split by sex reference value; see split_reference_table

option_all            = {
    'refit_split':               'true',
    'result_dir':                'build/example',
    'root_node_name':            'n0',
    'root_split_reference_name': 'both',
    'split_covariate_name':      'sex',
    'max_number_cpu':            '1',
}
option_all['root_database'] = option_all['result_dir'] + '/root.db'
split_reference_table = [
    {'split_reference_name': 'female', 'split_reference_value': 1.0},
    {'split_reference_name': 'both',   'split_reference_value': 2.0},
    {'split_reference_name': 'male',   'split_reference_value': 3.0},
]

Covariate

There are three covariates for this example, sex, vaccine, and income. Income is the only Relative Covariate.

avg_income = dict()
leaf_node_set     = { 3, 4, 5, 6 }
for node_id in leaf_node_set :
    node_name = 'n' + str(node_id)
    avg_income[node_name] = [ 1.0 - node_id / 10.0, 1.0, 1.0 + node_id / 10.0 ]
# child_list
# children of node 0, 1, 2 in that order
child_list = [ (1,2), (3,4), (5,6) ]
for node_id in [2, 1, 0] :
    avg_list = list()
    for split_reference_id in range(3) :
        avg = 0.0
        for child_id in child_list[node_id] :
            child_name = 'n' + str(child_id)
            avg += avg_income[child_name][split_reference_id]
        avg = avg / len( child_list[node_id] )
        avg_list.append( avg )
    node_name = 'n' + str(node_id)
    #
    avg_income[node_name] = avg_list
split_reference_list = list()
for row in split_reference_table :
    split_reference_list.append( row['split_reference_value'] )

absolute_covariates

The only absolute covariate in this example is vaccine (0 for no vaccine, 1 for yes vaccine).

option_all['absolute_covariates'] = 'vaccine'

alpha

We use alpha[income] and alpha[vaccine] for the rate_value covariate multipliers that multiply the income and vaccine covariates. The true value for alpha (used which simulating the data) is

alpha_true = {'vaccine': -0.3,  'income': -0.2}

Random Effects

There are no random effect for this example.

Simulated Data

rate_true(rate, a, t, n, c)

For rate equal to iota or omega, this is the true value for rate in node n at age a, time t, and covariate values c=[sex,income]. The covariate values are a list in the same order as the covariate table. The values a, t, n, sex are not used by this function for this example.

def rate_true(rate, a, t, n, c) :
    sex     = c[0]
    vaccine = c[1]
    income  = c[2]
    r_0     = avg_income['n0'][split_index]
    effect  = alpha_true['income']*(income - r_0)
    effect += alpha_true['vaccine'] * vaccine
    if rate == 'iota' :
        return 1e-2 * exp(effect)
    if rate == 'omega' :
        return 2e-2 * exp(effect)
    return 0.0

y_i

The only simulated integrand for this example is Sincidence which is a direct measurement of iota. This data is simulated without any noise; i.e., the i-th measurement is simulated as y_i = rate_true(‘iota’, None, None, None, [None, I_i]) where I_i is the income for the i-th measurement. The data is modeled as having noise even though there is no simulated noise.

n_i

Data is only simulated for the leaf nodes; i.e., each n_i is in the set { n3, n4, n5, n6 }. Since the data does not have any nose, the data residuals are a measure of how good the fit is for the nodes in the fit_goal_set.

Parent Rate Smoothing

This is the iota smoothing used for the fit_node. There are no dage or dtime priors because there is only one age and one time point in the smoothing grid.

Value Prior

The following is the value prior used for the root_node

        {    'name':    'parent_value_prior',
            'density': 'gaussian',
            'lower':   iota_n0 / 10.0,
            'upper':   iota_n0 * 10.0,
            'mean':    iota_n0 ,
            'std':     iota_n0 * 10.0,
            'eta':     iota_n0 * 1e-3
        },

The mean and standard deviation are only used for the root_node. The create_shift_db routine replaces them for other nodes.

Alpha Smoothing

This is the smoothing used for alpha which multiplies the income covariate. There is only one age and one time point in this smoothing so it does not have dage or dtime priors.

Value Prior

The following is the value prior used for this smoothing:

        {
            'name':    'alpha_vaccine_value_prior',
            'density': 'gaussian',
            'lower':   - 10 * abs(alpha_true['vaccine']),
            'upper':   + 10 * abs(alpha_true['vaccine']),
            'std':     + 10 * abs(alpha_true['vaccine']),
            'mean':    0.0,
        },{
            'name':    'alpha_income_value_prior',
            'density': 'gaussian',
            'lower':   - 10 * abs(alpha_true['income']),
            'upper':   + 10 * abs(alpha_true['income']),
            'std':     + 10 * abs(alpha_true['income']),
            'mean':    0.0,
        }

The mean and standard deviation are only used for the root_node. The create_shift_db routine replaces them for other nodes.

Checking The Fit

The results of the fit are checked by check_cascade_node using the avgint_table that was created by the root_node_db routine. The node_id for each row is replaced by the node_id for the fit being checked.

Child

Title

absolute_covariates.py

absolute_covariates: Python Source Code