def linear_data_pandas(): w, t, y = generate_wty_linear_multi_w_data(n=N, wdim=5, binary_treatment=True, delta=ATE, data_format='pandas') return w, t, y
def linear_gen_model(): w, t, y = generate_wty_linear_multi_w_data(n=N, wdim=5, binary_treatment=True, delta=ATE, data_format='numpy') return LinearGenModel(w, t, y, binary_treatment=True)
def test_ipw_numpy_data(): w, t, y = generate_wty_linear_multi_w_data(n=N, wdim=5, binary_treatment=True, delta=ATE, data_format='numpy') ipw = IPWEstimator() ipw.fit(w, t, y) assert ipw.estimate_ate() == approx(ATE, rel=.2)
return t_samples def _sample_y(self, t, w=None): y_samples = self.linear_gaussian_sampler(np.concatenate([w, t], 1), self.beta_y_tw, self.sigma_y_tw) return y_samples def mean_y(self, t, w): X = np.concatenate([w, t], 1) return self._pad_with_ones(X).dot(self.beta_y_tw) if __name__ == '__main__': from data.synthetic import generate_wty_linear_multi_w_data from utils import NUMPY # data = generate_wty_linear_multi_w_data(500, data_format=NUMPY, wdim=5) # # dgm = DataGenModel(data) # data_samples = dgm.sample() w, t, y = generate_wty_linear_multi_w_data(500, data_format=NUMPY, wdim=5) lgm = LinearGenModel(w, t, y) data_samples = lgm.sample() lgm.plot_ty_dists() uni_metrics = lgm.get_univariate_quant_metrics() multi_ty_metrics = lgm.get_multivariate_quant_metrics(include_w=False) multi_wty_metrics = lgm.get_multivariate_quant_metrics(include_w=True)
def linear_data(): w, t, y = generate_wty_linear_multi_w_data(n=N, wdim=5, binary_treatment=True, delta=ATE) return w, t, y
def linear_gen_model(): w, t, y = generate_wty_linear_multi_w_data(N, data_format='numpy', wdim=5, delta=ATE) return LinearGenModel(w, t, y)
def linear_gen_model_train_test(): w, t, y = generate_wty_linear_multi_w_data(N, data_format='numpy', wdim=5, delta=ATE) return LinearGenModel(w, t, y, train_prop=.5, test_prop=.5)
def test_multivariate_w_data(): n = 10 d = 5 w, t, y = generate_wty_linear_multi_w_data(n, wdim=5) assert all(isinstance(x, np.ndarray) for x in (w, t, y)) assert w.shape == (n, d) and t.shape == (n, ) and y.shape == (n, )
match_out=match_out, distance_tolerance=distance_tolerance, tolerance=tolerance, version=version) def gen_match(Tr, X, estimand='ATT'): # Install the Matching and rgenoud R packages, if not already installed to_install = [ x for x in [MATCHING, RGENOUD] if not rpackages.isinstalled(x) ] if len(to_install) > 0: utils = importr('utils') utils.chooseCRANmirror(ind=1) # select the first mirror in the list utils.install_packages(StrVector(to_install)) matching = importr(MATCHING) # import Matching R package importr(RGENOUD) return matching.GenMatch(Tr=Tr, X=X, estimand=estimand) if __name__ == '__main__': w, t, y = generate_wty_linear_multi_w_data(100, wdim=5, binary_treatment=True, delta=5) m = MatchingEstimator(weighting=GENETIC) m.fit(w, t, y) est = m.estimate_ate() conf_int = m.ate_conf_int()