src/dlt/power_analysis_utils.py
def gen_weeks_on_unemployment(
    number_control_per_week: Union[int, List[int]],
    effect_size: float,
    qt_unemp_lambda: float = 3,
    number_of_quarters: int = 6,
    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 weeks of unemployment after RESEA intervention according to a exponential
    distribution using `np.random.exponential`. Input for exponential distribution is
    determined by `qt_unemp_lambda` and `number_of_quarters` variables.

    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
        qt_unemp_lambda: expected frequency of weeks on unemployment for quarter.
            source: https://www.bls.gov/web/empsit/cpseea12.htm
        number_of_quarters: The number of quarters. Defaults to 6 to adjust the lambda rate for the 1.5 year study period.
        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)

    # attempt to estimate this as exponential distribution,
    # because the event can be modeled as the time between occurrances
    unemp_lambda = qt_unemp_lambda * number_of_quarters
    unemp_treatment_effect = unemp_lambda * (1 - effect_size)
    unemp_outcome_value_of_treat = random.exponential(
        unemp_treatment_effect, size=number_of_weeks * number_treat_per_week
    )
    unemp_outcome_value_of_control = random.exponential(
        unemp_lambda, size=number_of_weeks * number_control_per_week
    )
    treated_df = pd.DataFrame({"wks_unemp": unemp_outcome_value_of_treat})
    control_df = pd.DataFrame({"wks_unemp": unemp_outcome_value_of_control})
    return treated_df, control_df

    Generates weeks of unemployment after RESEA intervention according to a exponential
    distribution using `np.random.exponential`. Input for exponential distribution is
    determined by `qt_unemp_lambda` and `number_of_quarters` variables.

    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
        qt_unemp_lambda: expected frequency of weeks on unemployment for quarter.
            source: https://www.bls.gov/web/empsit/cpseea12.htm
        number_of_quarters: The number of quarters. Defaults to 6 to adjust the lambda rate for the 1.5 year study period.
        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 weeks of unemployment after RESEA intervention according to a exponential
distribution using `np.random.exponential`. Input for exponential distribution is
determined by `qt_unemp_lambda` and `number_of_quarters` variables.
Generates weeks of unemployment after RESEA intervention according to a exponential distribution using ` np . random . exponential ` . Input for exponential distribution is determined by ` qt_unemp_lambda ` and ` number_of_quarters ` variables .
def gen_weeks_on_unemployment(
    number_control_per_week: Union[int, List[int]],
    effect_size: float,
    qt_unemp_lambda: float = 3,
    number_of_quarters: int = 6,
    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)
    unemp_lambda = qt_unemp_lambda * number_of_quarters
    unemp_treatment_effect = unemp_lambda * (1 - effect_size)
    unemp_outcome_value_of_treat = random.exponential(
        unemp_treatment_effect, size=number_of_weeks * number_treat_per_week
    )
    unemp_outcome_value_of_control = random.exponential(
        unemp_lambda, size=number_of_weeks * number_control_per_week
    )
    treated_df = pd.DataFrame({"wks_unemp": unemp_outcome_value_of_treat})
    control_df = pd.DataFrame({"wks_unemp": unemp_outcome_value_of_control})
    return treated_df, control_df
def gen_weeks_on_unemployment ( number_control_per_week : Union [ int , List [ int ] ] , effect_size : float , qt_unemp_lambda : float = 3 , number_of_quarters : int = 6 , 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 ) unemp_lambda = qt_unemp_lambda * number_of_quarters unemp_treatment_effect = unemp_lambda * ( 1 - effect_size ) unemp_outcome_value_of_treat = random . exponential ( unemp_treatment_effect , size = number_of_weeks * number_treat_per_week ) unemp_outcome_value_of_control = random . exponential ( unemp_lambda , size = number_of_weeks * number_control_per_week ) treated_df = pd . DataFrame ( { "wks_unemp" : unemp_outcome_value_of_treat } ) control_df = pd . DataFrame ( { "wks_unemp" : unemp_outcome_value_of_control } ) return treated_df , control_df
Generates weeks of unemployment after RESEA intervention according to a exponential
distribution using `np.random.exponential`.
Generates weeks of unemployment after RESEA intervention according to a exponential distribution using ` np . random . exponential ` .
"""
    Generates weeks of unemployment after RESEA intervention according to a exponential
    distribution using `np.random.exponential`. Input for exponential distribution is
    determined by `qt_unemp_lambda` and `number_of_quarters` variables.

    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
        qt_unemp_lambda: expected frequency of weeks on unemployment for quarter.
            source: https://www.bls.gov/web/empsit/cpseea12.htm
        number_of_quarters: The number of quarters. Defaults to 6 to adjust the lambda rate for the 1.5 year study period.
        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

    """ # attempt to estimate this as exponential distribution, # because the event can be modeled as the time between occurrances
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
qt_unemp_lambda
float
expected frequency of weeks on unemployment for quarter.
expected frequency of weeks on unemployment for quarter .
number_of_quarters
int
The number of quarters. Defaults to 6 to adjust the lambda rate for the 1.5 year study period.
The number of quarters . Defaults to 6 to adjust the lambda rate for the 1 . 5 year study period .
6 to adjust the lambda rate for the 1.5 year study period
number_of_weeks
int
None
13 because we generate data quarterly
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