コード例 #1
0
ファイル: statistics.py プロジェクト: azvoleff/chitwanabm
def calc_probability_LL_migration_zvoleff(person, time):
    """
    Calculates the probability of local-local migration for an agent, using the 
    results of Alex Zvoleff's empirical analysis of the CVFS data, as presented 
    in chapter 3 of his dissertation.
    """
    household = person.get_parent_agent()
    neighborhood = household.get_parent_agent()

    #########################################################################
    # Intercept
    inner = rcParams['migration.ll.zv.coef.(Intercept)']

    #######################################################################
    # Neighborhood level variables
    #
    # Note that the EVI measures are based off 2 year mean EVI for the change, 
    # so calculate the 2 year mean EVI.
    EVI_2yr_mean = np.mean(neighborhood._EVI_ts[-2:])
    # Note that the EVI coefficients are expressed for EVI/1000 (given the need 
    # to get smaller betas for lmer to converge when estimating the model)
    inner += rcParams['migration.ll.zv.coef.mean_Sinteg_500m_24mth_2002_div_1000'] * (neighborhood._EVI_t0/1000)
    inner += rcParams['migration.ll.zv.coef.mean_Sinteg_500m_24mth_chg_2002_div_1000'] * ((EVI_2yr_mean - neighborhood._EVI_t0)/1000)
    inner += rcParams['migration.ll.zv.coef.NEAR_R_EVD_reversed'] * neighborhood._elevation_above_river
    inner += rcParams['migration.ll.zv.coef.SCHLFT_2001'] * neighborhood.NFOs['school_min_ft']
    inner += rcParams['migration.ll.zv.coef.MARFT_2001'] * neighborhood.NFOs['market_min_ft']
    inner += rcParams['migration.ll.zv.coef.EMPFT_2001'] * neighborhood.NFOs['employer_min_ft']
    inner += rcParams['migration.ll.zv.coef.num_groups_2001'] * neighborhood._num_groups

    #######################################################################
    # Household level variables
    inner += rcParams['migration.ll.zv.coef.own_total_2001'] * household._total_possessions
    inner += rcParams['migration.ll.zv.coef.any_farming_2001TRUE'] * household._any_farming
    inner += rcParams['migration.ll.zv.coef.TLU_livestock_2001'] * household._TLU_livestock

    #########################################################################
    # Individual level variables
    if person.get_sex() == "female":
        # Male is the reference class
        inner += rcParams['migration.ll.zv.coef.genderfemale']
    age_decades = person.get_age_years() / 10.
    inner += age_decades * rcParams['migration.ll.zv.coef.agedecades']
    inner += (age_decades**2) * rcParams['migration.ll.zv.coef.I(agedecades^2)']

    #########################################################################
    # Baseline hazard
    month_num = int(np.mod(np.round(time*12, 0), 12) + 1)
    if month_num in [1, 2, 3, 4]:
        # Reference class
        pass
    elif month_num in [5, 6, 7, 8]:
        inner += rcParams['migration.ll.zv.coef.SeasonMonsoon (MJJA)']
    elif month_num in [9, 10, 11, 12]:
        inner += rcParams['migration.ll.zv.coef.SeasonWinter (SOND)']
    else:
        raise StatisticsError("Month number is %s. Should not be outside range of [1, 12]"%month_num)

    ethnicity = person.get_ethnicity()
    assert ethnicity!=None, "Ethnicity must be defined"
    if ethnicity == "HighHindu":
        # This was the reference level
        pass
    elif ethnicity == "HillTibeto":
        inner += rcParams['migration.ll.zv.coef.ethnicHillTibeto']
    elif ethnicity == "LowHindu":
        inner += rcParams['migration.ll.zv.coef.ethnicLowHindu']
    elif ethnicity == "Newar":
        inner += rcParams['migration.ll.zv.coef.ethnicNewar']
    elif ethnicity == "TeraiTibeto":
        inner += rcParams['migration.ll.zv.coef.ethnicTeraiTibeto']

    prob = 1./(1 + np.exp(-inner))
    if rcParams['log_stats_probabilities']:
        logger.debug("Person %s local-local migration probability %.6f (age: %s)"%(person.get_ID(), prob, person.get_age_years()))
    return prob
コード例 #2
0
ファイル: statistics.py プロジェクト: azvoleff/chitwanabm
def calc_probability_marriage_zvoleff(person, time):
    """
    Calculates the probability of marriage for an agent, using the results of 
    Alex Zvoleff's empirical analysis of the CVFS data, following the results 
    of the analysis conducted by Yabiku (2006).
    """
    inner = rcParams['marrtime.zv.coef.(Intercept)']

    ethnicity = person.get_ethnicity()
    assert ethnicity!=None, "Ethnicity must be defined"
    if ethnicity == "HighHindu":
        # This was the reference level
        pass
    elif ethnicity == "HillTibeto":
        inner += rcParams['marrtime.zv.coef.ethnicHillTibeto']
    elif ethnicity == "LowHindu":
        inner += rcParams['marrtime.zv.coef.ethnicLowHindu']
    elif ethnicity == "Newar":
        inner += rcParams['marrtime.zv.coef.ethnicNewar']
    elif ethnicity == "TeraiTibeto":
        inner += rcParams['marrtime.zv.coef.ethnicTeraiTibeto']

    # Gender
    if person.get_sex() == "female":
        inner += rcParams['marrtime.zv.coef.genderfemale']

    age = person.get_age_years()
    inner += rcParams['marrtime.zv.coef.age'] * age
    inner += rcParams['marrtime.zv.coef.I(age^2)'] * (age ** 2)

    # Neighborhood characteristics
    neighborhood = person.get_parent_agent().get_parent_agent()
    log_percent_agveg = np.log((neighborhood._land_agveg / neighborhood._land_total)*100 + 1)
    inner += rcParams['marrtime.zv.coef.interp_logpercagveg'] * log_percent_agveg

    inner += rcParams['marrtime.zv.coef.SCHLFT'] * neighborhood.NFOs['school_min_ft']
    inner += rcParams['marrtime.zv.coef.HLTHFT'] * neighborhood.NFOs['health_min_ft']
    inner += rcParams['marrtime.zv.coef.BUSFT'] * neighborhood.NFOs['bus_min_ft']
    inner += rcParams['marrtime.zv.coef.MARFT'] * neighborhood.NFOs['market_min_ft']
    inner += rcParams['marrtime.zv.coef.EMPFT'] * neighborhood.NFOs['employer_min_ft']

    # Schooling
    inner += rcParams['marrtime.zv.coef.schooling_yrs'] * person.get_years_schooling()
    if person.is_in_school():
        inner += rcParams['marrtime.zv.coef.in_school']

    # Account for monthly differences in marriage rates - some days (and 
    # months) are more auspicious for marriage than others.
    month_num = int(np.mod(np.round(time*12, 0), 12) + 1)
    if month_num == 1:
        # This was the reference level
        pass
    elif month_num == 2:
        inner += rcParams['marrtime.zv.coef.month2']
    elif month_num == 3:
        inner += rcParams['marrtime.zv.coef.month3']
    elif month_num == 4:
        inner += rcParams['marrtime.zv.coef.month4']
    elif month_num == 5:
        inner += rcParams['marrtime.zv.coef.month5']
    elif month_num == 6:
        inner += rcParams['marrtime.zv.coef.month6']
    elif month_num == 7:
        inner += rcParams['marrtime.zv.coef.month7']
    elif month_num == 8:
        inner += rcParams['marrtime.zv.coef.month8']
    elif month_num == 9:
        inner += rcParams['marrtime.zv.coef.month9']
    elif month_num == 10:
        inner += rcParams['marrtime.zv.coef.month10']
    elif month_num == 11:
        inner += rcParams['marrtime.zv.coef.month11']
    elif month_num == 12:
        inner += rcParams['marrtime.zv.coef.month12']
    
    prob = 1./(1 + np.exp(-inner))
    if rcParams['log_stats_probabilities']:
        logger.debug("Person %s marriage probability %.6f (age: %s)"%(person.get_ID(), prob, person.get_age_years()))
    return prob