<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Example 1
Step1:  Example 2
<ASSISTANT_TASK:>
Python Code:
p_hi = 0.8 # probability of success in the high probability subpopulation
p_lo = 0.2 # probability of success in the low probability subpopulation
delta_p = 0.05 # effect size
# probability of success under treatment
P_T_additive = delta_p + 0.5*p_hi+0.5*p_lo
# probability of success under control
P_C_additive = 0.5*p_hi+0.5*p_lo
def sample_additive_model(n):
    # generate covariate and treatment variables and compute conditional outcome probabilities
    covariate = np.random.binomial(1,0.5,n)
    treatment = np.random.binomial(1,0.5,n)
    prob = delta_p*treatment + (p_hi-p_lo)*covariate + p_lo
    outcome = np.random.binomial(1, prob)
    return covariate,treatment,outcome
pop_log_odds_additive=print_population_log_odds(P_T_additive,P_C_additive)
logistic_vs_plugin(sample_additive_model,pop_log_odds_additive)
Explanation: Example 1: An additive model
True model is
$$
\mathbb{E}[Y|X,Z] = \delta_p X + p_{\mathrm{hi}}Z+(1-Z)p_{\mathrm{lo}}
$$
$X$ is the treatment variable, $Z$ the covariate. Both $X$ and $Z$ are independent Bernoulli variables with probability of $1$ equal to $\tfrac{1}{2}$.
End of explanation
# logistic model parameters
alpha_true = -1.5 
beta_true =  0.4 
gamma_true =  3.0
# probability of success under treatment
p_hi_T = logistic_map(alpha_true+beta_true+gamma_true)
p_lo_T = logistic_map(alpha_true+beta_true)
P_T_logistic = 0.5*p_hi_T+0.5*p_lo_T
# probability of success under control
p_hi_C = logistic_map(alpha_true+gamma_true)
p_lo_C = logistic_map(alpha_true)
P_C_logistic = 0.5*p_hi_C+0.5*p_lo_C
def sample_logistic_model(n):
    # generate covariate and treatment variables and compute conditional outcome probabilities
    covariate = np.random.binomial(1,0.5,n)
    treatment = np.random.binomial(1,0.5,n)
    prob = logistic_map(alpha_true + beta_true*treatment + gamma_true*covariate)
    outcome = np.random.binomial(1, prob)
    return covariate,treatment,outcome
pop_log_odds_logistic=print_population_log_odds(P_T_logistic,P_C_logistic)
logistic_vs_plugin(sample_logistic_model,pop_log_odds_logistic)
Explanation: Example 2: An actual logistic model
True model is
$$
\log \frac {\mathbb{P}[Y=1|X,Z]}{1-\mathbb{P}[Y=1|X,Z]} = \alpha + \beta X + \gamma Z
$$
$X$ is the treatment variable, $Z$ the covariate. Both $X$ and $Z$ are independent Bernoulli variables with probability of $1$ equal to $\tfrac{1}{2}$.
End of explanation
<END_TASK>