causarray 0.0.3__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {causarray-0.0.3 → causarray-0.0.4}/.gitignore +2 -1
- {causarray-0.0.3 → causarray-0.0.4}/PKG-INFO +1 -1
- {causarray-0.0.3 → causarray-0.0.4}/causarray/DR_estimation.py +15 -4
- {causarray-0.0.3 → causarray-0.0.4}/causarray/DR_learner.py +12 -10
- causarray-0.0.4/causarray/__about__.py +1 -0
- {causarray-0.0.3 → causarray-0.0.4}/causarray/gcate.py +4 -1
- {causarray-0.0.3 → causarray-0.0.4}/causarray/gcate_glm.py +21 -7
- {causarray-0.0.3 → causarray-0.0.4}/causarray/utils.py +2 -0
- causarray-0.0.3/causarray/__about__.py +0 -1
- {causarray-0.0.3 → causarray-0.0.4}/LICENSE +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/README.md +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/causarray/DR_inference.py +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/causarray/__init__.py +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/causarray/gcate_likelihood.py +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/causarray/gcate_opt.py +0 -0
- {causarray-0.0.3 → causarray-0.0.4}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: causarray
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: causarray is a Python module for simultaneous causal inference with an array of outcomes.
|
|
5
5
|
Author-email: Jin-Hong Du <jinhongd@andrew.cmu.com>, Maya Shen <myshen@andrew.cmu.edu>, Hansruedi Mathys <mathysh@pitt.edu>, Kathryn Roeder <jinhongd@andrew.cmu.com>
|
|
6
6
|
Maintainer-email: Jin-Hong Du <jinhongd@andrew.cmu.com>
|
|
@@ -33,7 +33,7 @@ def _get_func_ps(ps_model, **kwargs):
|
|
|
33
33
|
def cross_fitting(
|
|
34
34
|
Y, A, X, X_A, family='poisson', K=1, glm_alpha=1e-4,
|
|
35
35
|
ps_model='logistic',
|
|
36
|
-
pi_hat=None,
|
|
36
|
+
Y_hat=None, pi_hat=None, mask=None, verbose=False, **kwargs):
|
|
37
37
|
'''
|
|
38
38
|
Cross-fitting for causal estimands.
|
|
39
39
|
|
|
@@ -55,10 +55,16 @@ def cross_fitting(
|
|
|
55
55
|
The regularization parameter for the generalized linear model. The default is 1e-4.
|
|
56
56
|
ps_model : str, optional
|
|
57
57
|
The propensity score model. The default is 'logistic'.
|
|
58
|
-
|
|
59
|
-
Propensity score of shape (n, a). The default is None.
|
|
58
|
+
|
|
60
59
|
Y_hat : array, optional
|
|
61
60
|
Estimated potential outcome of shape (n, p, a, 2). The default is None.
|
|
61
|
+
pi_hat : array, optional
|
|
62
|
+
Propensity score of shape (n, a). The default is None.
|
|
63
|
+
mask : array, optional
|
|
64
|
+
Boolean mask of shape (n, a) for the treatment, indicating which samples are used for
|
|
65
|
+
the estimation of the estimand. This does not affect the estimation of pseudo-outcomes
|
|
66
|
+
and propensity scores.
|
|
67
|
+
|
|
62
68
|
**kwargs : dict
|
|
63
69
|
Additional arguments to pass to the model.
|
|
64
70
|
|
|
@@ -104,7 +110,12 @@ def cross_fitting(
|
|
|
104
110
|
pi = np.zeros_like(A_test, dtype=float)
|
|
105
111
|
for j in range(A.shape[1]):
|
|
106
112
|
i_case = (A_train[:,j] == 1.)
|
|
107
|
-
|
|
113
|
+
|
|
114
|
+
if mask is not None:
|
|
115
|
+
i_cells = mask[:, j]
|
|
116
|
+
else:
|
|
117
|
+
i_ctrl = (np.sum(A_train, axis=1) == 0.)
|
|
118
|
+
i_cells = i_ctrl | i_case
|
|
108
119
|
|
|
109
120
|
if ps_model=='logistic' and XA_train.shape[1]==1 and np.all(XA_train==1):
|
|
110
121
|
prob = np.sum(i_case)/np.sum(i_cells)
|
|
@@ -65,19 +65,16 @@ def compute_causal_estimand(
|
|
|
65
65
|
'''
|
|
66
66
|
reset_random_seeds(random_state)
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
['kwargs_ls_1', 'kwargs_ls_2', 'kwargs_es_1', 'kwargs_es_2', 'c1', 'num_d']
|
|
70
|
-
}
|
|
71
|
-
|
|
68
|
+
# check the input data
|
|
72
69
|
if isinstance(Y, pd.DataFrame):
|
|
73
70
|
gene_names = Y.columns
|
|
74
71
|
Y = Y.values
|
|
75
72
|
else:
|
|
76
73
|
gene_names = range(Y.shape[1])
|
|
74
|
+
Y = Y.astype('float')
|
|
77
75
|
n, p = Y.shape
|
|
78
76
|
|
|
79
|
-
if
|
|
80
|
-
A = A.reshape(-1,1)
|
|
77
|
+
if A.ndim == 1: A = A[:, None]
|
|
81
78
|
if isinstance(A, pd.DataFrame):
|
|
82
79
|
trt_names = A.columns
|
|
83
80
|
A = A.values
|
|
@@ -97,7 +94,10 @@ def compute_causal_estimand(
|
|
|
97
94
|
if len(mask.shape) == 1: mask = mask.reshape(-1,1)
|
|
98
95
|
if mask.shape != A.shape:
|
|
99
96
|
raise ValueError('Mask must have the same shape as the treatment matrix')
|
|
100
|
-
|
|
97
|
+
|
|
98
|
+
kwargs = {k:v for k,v in kwargs.items() if k not in
|
|
99
|
+
['kwargs_ls_1', 'kwargs_ls_2', 'kwargs_es_1', 'kwargs_es_2', 'c1', 'num_d']
|
|
100
|
+
}
|
|
101
101
|
|
|
102
102
|
if verbose:
|
|
103
103
|
d_A = W_A.shape[1]
|
|
@@ -113,10 +113,9 @@ def compute_causal_estimand(
|
|
|
113
113
|
else:
|
|
114
114
|
offset = None
|
|
115
115
|
size_factors = np.ones(n)
|
|
116
|
-
|
|
117
|
-
Y = Y.astype('float')
|
|
116
|
+
|
|
118
117
|
Y_hat, pi_hat = cross_fitting(Y, A, W, W_A, family=family, offset=offset,
|
|
119
|
-
Y_hat=Y_hat, pi_hat=pi_hat, random_state=random_state, verbose=verbose, **kwargs)
|
|
118
|
+
Y_hat=Y_hat, pi_hat=pi_hat, mask=mask, random_state=random_state, verbose=verbose, **kwargs)
|
|
120
119
|
pi_hat = pi_hat.reshape(*A.shape)
|
|
121
120
|
|
|
122
121
|
if verbose: pprint.pprint('Estimating AIPW mean...')
|
|
@@ -201,6 +200,9 @@ def LFC(
|
|
|
201
200
|
Boolean mask of shape (n, a) for the treatment, indicating which samples are used for
|
|
202
201
|
the estimation of the estimand. This does not affect the estimation of pseudo-outcomes
|
|
203
202
|
and propensity scores.
|
|
203
|
+
usevar : str
|
|
204
|
+
The method to use for estimating the variance of treatment effects.
|
|
205
|
+
Options are 'pooled' (default) or 'unequal'.
|
|
204
206
|
|
|
205
207
|
thres_min : float
|
|
206
208
|
The minimum threshold for the treatment effect.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.4"
|
|
@@ -82,7 +82,8 @@ def fit_gcate(Y, X, A, r, family='nb', disp_glm=None, disp_family=None, offset=T
|
|
|
82
82
|
kwargs : dict
|
|
83
83
|
Additional keyword arguments.
|
|
84
84
|
'''
|
|
85
|
-
|
|
85
|
+
if X.ndim == 1: X = X[:, None]
|
|
86
|
+
if A.ndim == 1: A = A[:, None]
|
|
86
87
|
X = np.hstack((X, A))
|
|
87
88
|
a = A.shape[1]
|
|
88
89
|
Y, kwargs_glm, lam1 = _check_input(Y, X, family, disp_glm, disp_family, offset, c1, **kwargs)
|
|
@@ -195,6 +196,8 @@ def estimate_r(Y, X, A, r_max, c=1.,
|
|
|
195
196
|
df_r : DataFrame
|
|
196
197
|
Results of the number of latent factors.
|
|
197
198
|
'''
|
|
199
|
+
if X.ndim == 1: X = X[:, None]
|
|
200
|
+
if A.ndim == 1: A = A[:, None]
|
|
198
201
|
a, d = A.shape[1], X.shape[1]
|
|
199
202
|
X = np.hstack((X, A))
|
|
200
203
|
n, p = Y.shape
|
|
@@ -41,15 +41,29 @@ def fit_glm(Y, X, A=None, family='gaussian', disp_family='poisson',
|
|
|
41
41
|
A : array
|
|
42
42
|
n x 1 vector of treatments or None
|
|
43
43
|
family : str
|
|
44
|
-
|
|
44
|
+
Family of GLM to fit, can be one of: 'gaussian', 'poisson', 'nb'
|
|
45
45
|
disp_glm : array or None
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
impute : bool
|
|
50
|
-
whether to impute potential outcomes and get predicted values
|
|
46
|
+
Dispersion parameter for negative binomial GLM.
|
|
47
|
+
impute : bool or None
|
|
48
|
+
Whether to impute missing values in Y.
|
|
51
49
|
offset : bool
|
|
52
|
-
|
|
50
|
+
Whether to use log of sum of Y as offset.
|
|
51
|
+
shrinkage : bool
|
|
52
|
+
Whether to use regularized GLM.
|
|
53
|
+
alpha : float
|
|
54
|
+
Regularization parameter for regularized GLM.
|
|
55
|
+
maxiter : int
|
|
56
|
+
Maximum number of iterations for GLM fitting.
|
|
57
|
+
thres_disp : float
|
|
58
|
+
Threshold for dispersion parameter for negative binomial GLM.
|
|
59
|
+
n_jobs : int
|
|
60
|
+
Number of jobs to run in parallel.
|
|
61
|
+
random_state : int
|
|
62
|
+
Random seed for reproducibility.
|
|
63
|
+
verbose : bool
|
|
64
|
+
Whether to print progress messages.
|
|
65
|
+
kwargs : dict
|
|
66
|
+
Additional arguments to pass to GLM fitting.
|
|
53
67
|
|
|
54
68
|
Returns
|
|
55
69
|
-------
|
|
@@ -49,6 +49,8 @@ def prep_causarray_data(Y, A, X=None, X_A=None, intercept=True):
|
|
|
49
49
|
Y = np.minimum(Y, np.round(np.quantile(np.max(Y, 0), 0.999)))
|
|
50
50
|
if not isinstance(A, pd.DataFrame):
|
|
51
51
|
A = np.asarray(A)
|
|
52
|
+
if A.ndim == 1:
|
|
53
|
+
A = A[:, None]
|
|
52
54
|
|
|
53
55
|
X = np.zeros((Y.shape[0], 0)) if X is None else np.asarray(X)
|
|
54
56
|
X_A = X if X_A is None else np.asarray(X_A)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|