csv.covariate_both

View page source

Add both Sex to csv Covariate Table

Prototype

# at_cascade.csv.covariate_both
def covariate_both(covariate_table_in) :
    assert type(covariate_table_in) == list
    for row in covariate_table_in :
        for key in row :
            type_check = str if key in [ 'node_name' , 'sex' ] else float
            assert type( row[key] ) == type_check
    #
    assert type(covariate_table_out) == list
    for row in covariate_table_out :
        for key in row :
            type_check = str if key in [ 'node_name' , 'sex' ] else float
            assert type( row[key] ) == type_check
    return covariate_table_out

covariate_table_in

Is a list of dict representation of a covariate.csv file.

covariate_table_out

Is a list of dict representation of covariate.csv file. This has all the rows that are in covariate_table_in plus rows with sex equal to both .

both

For each node_name, age, time, the covariate table value for sex equal both is the average of its value for female and male . To be specific, if female_value, male_value, both_value are a covariate’s values for a specific (node_name, age, time) then:

    if female_value == male_value :
        both_value = female_value
    else :
        both_value = ( float( female_value ) + float( male_value ) ) / 2.0

Example

see csv.cov_both_xam .