3
3
4
4
import causalpy as cp
5
5
6
+ sample_kwargs = {"tune" : 20 , "draws" : 20 , "chains" : 2 , "cores" : 2 }
7
+
6
8
7
9
@pytest .mark .integration
8
10
def test_did ():
@@ -14,10 +16,18 @@ def test_did():
14
16
group_variable_name = "group" ,
15
17
treated = 1 ,
16
18
untreated = 0 ,
17
- prediction_model = cp .pymc_models .LinearRegression (),
19
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
18
20
)
19
21
assert isinstance (df , pd .DataFrame )
20
22
assert isinstance (result , cp .pymc_experiments .DifferenceInDifferences )
23
+ assert (
24
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
25
+ == sample_kwargs ["chains" ]
26
+ )
27
+ assert (
28
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
29
+ == sample_kwargs ["draws" ]
30
+ )
21
31
22
32
23
33
@pytest .mark .integration
@@ -47,10 +57,18 @@ def test_did_banks():
47
57
group_variable_name = "district" ,
48
58
treated = "Sixth District" ,
49
59
untreated = "Eighth District" ,
50
- prediction_model = cp .pymc_models .LinearRegression (),
60
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
51
61
)
52
62
assert isinstance (df , pd .DataFrame )
53
63
assert isinstance (result , cp .pymc_experiments .DifferenceInDifferences )
64
+ assert (
65
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
66
+ == sample_kwargs ["chains" ]
67
+ )
68
+ assert (
69
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
70
+ == sample_kwargs ["draws" ]
71
+ )
54
72
55
73
56
74
@pytest .mark .integration
@@ -59,11 +77,19 @@ def test_rd():
59
77
result = cp .pymc_experiments .RegressionDiscontinuity (
60
78
df ,
61
79
formula = "y ~ 1 + bs(x, df=6) + treated" ,
62
- prediction_model = cp .pymc_models .LinearRegression (),
80
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
63
81
treatment_threshold = 0.5 ,
64
82
)
65
83
assert isinstance (df , pd .DataFrame )
66
84
assert isinstance (result , cp .pymc_experiments .RegressionDiscontinuity )
85
+ assert (
86
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
87
+ == sample_kwargs ["chains" ]
88
+ )
89
+ assert (
90
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
91
+ == sample_kwargs ["draws" ]
92
+ )
67
93
68
94
69
95
@pytest .mark .integration
@@ -77,11 +103,19 @@ def test_rd_drinking():
77
103
df ,
78
104
formula = "all ~ 1 + age + treated" ,
79
105
running_variable_name = "age" ,
80
- prediction_model = cp .pymc_models .LinearRegression (),
106
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
81
107
treatment_threshold = 21 ,
82
108
)
83
109
assert isinstance (df , pd .DataFrame )
84
110
assert isinstance (result , cp .pymc_experiments .RegressionDiscontinuity )
111
+ assert (
112
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
113
+ == sample_kwargs ["chains" ]
114
+ )
115
+ assert (
116
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
117
+ == sample_kwargs ["draws" ]
118
+ )
85
119
86
120
87
121
@pytest .mark .integration
@@ -94,10 +128,18 @@ def test_its():
94
128
df ,
95
129
treatment_time ,
96
130
formula = "y ~ 1 + t + C(month)" ,
97
- prediction_model = cp .pymc_models .LinearRegression (),
131
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
98
132
)
99
133
assert isinstance (df , pd .DataFrame )
100
134
assert isinstance (result , cp .pymc_experiments .SyntheticControl )
135
+ assert (
136
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
137
+ == sample_kwargs ["chains" ]
138
+ )
139
+ assert (
140
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
141
+ == sample_kwargs ["draws" ]
142
+ )
101
143
102
144
103
145
@pytest .mark .integration
@@ -110,10 +152,18 @@ def test_its_covid():
110
152
df ,
111
153
treatment_time ,
112
154
formula = "standardize(deaths) ~ 0 + standardize(t) + C(month) + standardize(temp)" , # noqa E501
113
- prediction_model = cp .pymc_models .LinearRegression (),
155
+ prediction_model = cp .pymc_models .LinearRegression (sample_kwargs = sample_kwargs ),
114
156
)
115
157
assert isinstance (df , pd .DataFrame )
116
158
assert isinstance (result , cp .pymc_experiments .SyntheticControl )
159
+ assert (
160
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
161
+ == sample_kwargs ["chains" ]
162
+ )
163
+ assert (
164
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
165
+ == sample_kwargs ["draws" ]
166
+ )
117
167
118
168
119
169
@pytest .mark .integration
@@ -124,10 +174,18 @@ def test_sc():
124
174
df ,
125
175
treatment_time ,
126
176
formula = "actual ~ 0 + a + b + c + d + e + f + g" ,
127
- prediction_model = cp .pymc_models .WeightedSumFitter (),
177
+ prediction_model = cp .pymc_models .WeightedSumFitter (sample_kwargs = sample_kwargs ),
128
178
)
129
179
assert isinstance (df , pd .DataFrame )
130
180
assert isinstance (result , cp .pymc_experiments .SyntheticControl )
181
+ assert (
182
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
183
+ == sample_kwargs ["chains" ]
184
+ )
185
+ assert (
186
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
187
+ == sample_kwargs ["draws" ]
188
+ )
131
189
132
190
133
191
@pytest .mark .integration
@@ -148,7 +206,15 @@ def test_sc_brexit():
148
206
df ,
149
207
treatment_time ,
150
208
formula = formula ,
151
- prediction_model = cp .pymc_models .WeightedSumFitter (),
209
+ prediction_model = cp .pymc_models .WeightedSumFitter (sample_kwargs = sample_kwargs ),
152
210
)
153
211
assert isinstance (df , pd .DataFrame )
154
212
assert isinstance (result , cp .pymc_experiments .SyntheticControl )
213
+ assert (
214
+ len (result .prediction_model .idata .posterior .coords ["chain" ])
215
+ == sample_kwargs ["chains" ]
216
+ )
217
+ assert (
218
+ len (result .prediction_model .idata .posterior .coords ["draw" ])
219
+ == sample_kwargs ["draws" ]
220
+ )
0 commit comments