Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
A DataFrame shaped (num_samples x num_of_possible_treatment_categories).
Raises:
ValueError: If given more than to categories. This method supports dichotomous treatment only.
"""
if prob_category.size != 2: # this method suited for dichotomous outcome only
raise ValueError("logistic method supports only binary treatment. Got the distribution vector "
"{p_vec} of length {n_cat}".format(n_cat=prob_category.size, p_vec=prob_category))
index_names = x_continuous.index
columns_names = prob_category.index
propensity = pd.DataFrame(index=index_names, columns=columns_names)
# compute propensities:
t = stats.norm(loc=0, scale=1).ppf(prob_category.iloc[1]) # percentile given a distribution
cur_propensity = stats.norm(loc=x_continuous, scale=(1 - snr)).sf(t) # sf is 1 - CDF
# discretize values:
treatment = CausalSimulator3._discretize_col(x_continuous, prob_category)
propensity.loc[:, columns_names[1]] = cur_propensity
propensity.loc[:, columns_names[0]] = np.ones(cur_propensity.size) - cur_propensity
return propensity, treatment