src/dlt/power_analysis_utils.py
def gen_annual_income(
    number_control_per_week: Union[int, List[int]],
    effect_size: float,
    inc_base_rate: int = 36_121,
    inc_base_std: int = 5_000,
    inc_treatment_std: int = 5_000,
    number_of_weeks: int = 13,
    number_treat_per_week: int = 150,
    seed: Optional[Union[int, np.random.mtrand.RandomState]] = 189389,
) -> Tuple[pd.DataFrame, pd.DataFrame]:
    """
    Generates annual income before and after RESEA intervention according to a normal
    distribution using `np.random.randn`. The initial_value is used in generating
    outcome_value to ensure some correlation.

    Args:
        number_control_per_week: a single number if control does not vary weekly.
            List of int otherwise
        effect_size: used to define the treatment effect, which modifies the mean of
            generated data
        inc_base_rate: average income per capita in RI in 2019 according to
            https://www.census.gov/quickfacts/fact/table/RI,US/INC110219
        inc_base_std: standard deviation for the normal distribution generation
        inc_treatment_std: given the randomness of assignemnt to treatment, there
            should be no difference between base and treatment a priori
        number_of_weeks: how many cohorts we want to generate. Defaults to 13 because
            we generate data quarterly
        number_treat_per_week: number of individuals selected for treatment.
            Defaults to 150 based on DLT's experiment design
        seed: seed for randomization

    Returns: treated_df, control_df
    """
    random = _convert_seed_to_randomstate(seed)

    # Define the effect
    inc_treatment_effect = inc_base_rate * effect_size

    inc_initial_value_of_treated = (
        random.randn(number_of_weeks * number_treat_per_week) * inc_base_std
        + inc_base_rate
    )
    inc_outcome_value_of_treated = (
        inc_initial_value_of_treated
        + random.randn(number_of_weeks * number_treat_per_week) * inc_treatment_std
        + inc_treatment_effect
    )

    inc_initial_value_of_control = (
        random.randn(number_of_weeks * number_control_per_week) * inc_base_std
        + inc_base_rate
    )

    inc_outcome_value_of_control = (
        random.randn(number_of_weeks * number_control_per_week) * inc_base_std
        + inc_base_rate
    )
    control_df = pd.DataFrame(
        {
            "inc_initial": inc_initial_value_of_control,
            "inc_outcome": inc_outcome_value_of_control,
        }
    )
    treated_df = pd.DataFrame(
        {
            "inc_initial": inc_initial_value_of_treated,
            "inc_outcome": inc_outcome_value_of_treated,
        }
    )
    return treated_df, control_df

    Generates annual income before and after RESEA intervention according to a normal
    distribution using `np.random.randn`. The initial_value is used in generating
    outcome_value to ensure some correlation.

    Args:
        number_control_per_week: a single number if control does not vary weekly.
            List of int otherwise
        effect_size: used to define the treatment effect, which modifies the mean of
            generated data
        inc_base_rate: average income per capita in RI in 2019 according to
            https://www.census.gov/quickfacts/fact/table/RI,US/INC110219
        inc_base_std: standard deviation for the normal distribution generation
        inc_treatment_std: given the randomness of assignemnt to treatment, there
            should be no difference between base and treatment a priori
        number_of_weeks: how many cohorts we want to generate. Defaults to 13 because
            we generate data quarterly
        number_treat_per_week: number of individuals selected for treatment.
            Defaults to 150 based on DLT's experiment design
        seed: seed for randomization

    Returns: treated_df, control_df
    
Generates annual income before and after RESEA intervention according to a normal
distribution using `np.random.randn`. The initial_value is used in generating
outcome_value to ensure some correlation.
Generates annual income before and after RESEA intervention according to a normal distribution using ` np . random . randn ` . The initial_value is used in generating outcome_value to ensure some correlation .
def gen_annual_income(
    number_control_per_week: Union[int, List[int]],
    effect_size: float,
    inc_base_rate: int = 36_121,
    inc_base_std: int = 5_000,
    inc_treatment_std: int = 5_000,
    number_of_weeks: int = 13,
    number_treat_per_week: int = 150,
    seed: Optional[Union[int, np.random.mtrand.RandomState]] = 189389,
) -> Tuple[pd.DataFrame, pd.DataFrame]:
    random = _convert_seed_to_randomstate(seed)
    inc_treatment_effect = inc_base_rate * effect_size
    inc_initial_value_of_treated = (
        random.randn(number_of_weeks * number_treat_per_week) * inc_base_std
        + inc_base_rate
    )
    inc_outcome_value_of_treated = (
        inc_initial_value_of_treated
        + random.randn(number_of_weeks * number_treat_per_week) * inc_treatment_std
        + inc_treatment_effect
    )
    inc_initial_value_of_control = (
        random.randn(number_of_weeks * number_control_per_week) * inc_base_std
        + inc_base_rate
    )
    inc_outcome_value_of_control = (
        random.randn(number_of_weeks * number_control_per_week) * inc_base_std
        + inc_base_rate
    )
    control_df = pd.DataFrame(
        {
            "inc_initial": inc_initial_value_of_control,
            "inc_outcome": inc_outcome_value_of_control,
        }
    )
    treated_df = pd.DataFrame(
        {
            "inc_initial": inc_initial_value_of_treated,
            "inc_outcome": inc_outcome_value_of_treated,
        }
    )
    return treated_df, control_df
def gen_annual_income ( number_control_per_week : Union [ int , List [ int ] ] , effect_size : float , inc_base_rate : int = 36_121 , inc_base_std : int = 5_000 , inc_treatment_std : int = 5_000 , number_of_weeks : int = 13 , number_treat_per_week : int = 150 , seed : Optional [ Union [ int , np . random . mtrand . RandomState ] ] = 189389 , ) -> Tuple [ pd . DataFrame , pd . DataFrame ] : random = _convert_seed_to_randomstate ( seed ) inc_treatment_effect = inc_base_rate * effect_size inc_initial_value_of_treated = ( random . randn ( number_of_weeks * number_treat_per_week ) * inc_base_std + inc_base_rate ) inc_outcome_value_of_treated = ( inc_initial_value_of_treated + random . randn ( number_of_weeks * number_treat_per_week ) * inc_treatment_std + inc_treatment_effect ) inc_initial_value_of_control = ( random . randn ( number_of_weeks * number_control_per_week ) * inc_base_std + inc_base_rate ) inc_outcome_value_of_control = ( random . randn ( number_of_weeks * number_control_per_week ) * inc_base_std + inc_base_rate ) control_df = pd . DataFrame ( { "inc_initial" : inc_initial_value_of_control , "inc_outcome" : inc_outcome_value_of_control , } ) treated_df = pd . DataFrame ( { "inc_initial" : inc_initial_value_of_treated , "inc_outcome" : inc_outcome_value_of_treated , } ) return treated_df , control_df
Generates annual income before and after RESEA intervention according to a normal
distribution using `np.random.randn`.
Generates annual income before and after RESEA intervention according to a normal distribution using ` np . random . randn ` .
"""
    Generates annual income before and after RESEA intervention according to a normal
    distribution using `np.random.randn`. The initial_value is used in generating
    outcome_value to ensure some correlation.

    Args:
        number_control_per_week: a single number if control does not vary weekly.
            List of int otherwise
        effect_size: used to define the treatment effect, which modifies the mean of
            generated data
        inc_base_rate: average income per capita in RI in 2019 according to
            https://www.census.gov/quickfacts/fact/table/RI,US/INC110219
        inc_base_std: standard deviation for the normal distribution generation
        inc_treatment_std: given the randomness of assignemnt to treatment, there
            should be no difference between base and treatment a priori
        number_of_weeks: how many cohorts we want to generate. Defaults to 13 because
            we generate data quarterly
        number_treat_per_week: number of individuals selected for treatment.
            Defaults to 150 based on DLT's experiment design
        seed: seed for randomization

    Returns: treated_df, control_df
    """ # Define the effect
number_control_per_week
Union[int, List[int]]
a single number if control does not vary weekly.
List of int otherwise
a single number if control does not vary weekly . List of int otherwise
effect_size
float
used to define the treatment effect, which modifies the mean of
generated data
used to define the treatment effect which modifies the mean of generated data
inc_base_rate
int
None
inc_base_std
int
standard deviation for the normal distribution generation
standard deviation for the normal distribution generation
inc_treatment_std
int
given the randomness of assignemnt to treatment, there
should be no difference between base and treatment a priori
given the randomness of assignemnt to treatment there should be no difference between base and treatment a priori
number_of_weeks
int
None
number_treat_per_week
int
number of individuals selected for treatment.
Defaults to 150 based on DLT's experiment design
number of individuals selected for treatment . Defaults to 150 based on DLT ' s experiment design
seed
Optional[Union[int, np.random.mtrand.RandomState]]
seed for randomization
seed for randomization