Skip to content

Commit dab5824

Browse files
committed
experiment submodule
1 parent d6e058c commit dab5824

File tree

11 files changed

+39
-24
lines changed

11 files changed

+39
-24
lines changed

causalpy/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@
1818
from causalpy.version import __version__
1919

2020
from .data import load_data
21-
from .exp_inverse_propensity_weighting import InversePropensityWeighting
22-
from .expt_diff_in_diff import DifferenceInDifferences
23-
from .expt_instrumental_variable import InstrumentalVariable
24-
from .expt_prepostfit import InterruptedTimeSeries, SyntheticControl
25-
from .expt_prepostnegd import PrePostNEGD
26-
from .expt_regression_discontinuity import RegressionDiscontinuity
27-
from .expt_regression_kink import RegressionKink
21+
from .experiments.diff_in_diff import DifferenceInDifferences
22+
from .experiments.instrumental_variable import InstrumentalVariable
23+
from .experiments.inverse_propensity_weighting import InversePropensityWeighting
24+
from .experiments.prepostfit import InterruptedTimeSeries, SyntheticControl
25+
from .experiments.prepostnegd import PrePostNEGD
26+
from .experiments.regression_discontinuity import RegressionDiscontinuity
27+
from .experiments.regression_kink import RegressionKink
2828

2929
az.style.use("arviz-darkgrid")
3030

3131
__all__ = [
32-
"InterruptedTimeSeries",
33-
"SyntheticControl",
32+
"__version__",
3433
"DifferenceInDifferences",
35-
"PrePostNEGD",
36-
"RegressionDiscontinuity",
37-
"RegressionKink",
3834
"InstrumentalVariable",
35+
"InterruptedTimeSeries",
3936
"InversePropensityWeighting",
37+
"load_data",
38+
"PrePostNEGD",
4039
"pymc_models",
40+
"RegressionDiscontinuity",
41+
"RegressionKink",
4142
"skl_models",
42-
"load_data",
43-
"__version__",
43+
"SyntheticControl",
4444
]

causalpy/experiments/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2024 The PyMC Labs Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

causalpy/expt_diff_in_diff.py renamed to causalpy/experiments/diff_in_diff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
DataException,
2424
FormulaException,
2525
)
26-
from causalpy.experiments import ExperimentalDesign
2726
from causalpy.pymc_models import PyMCModel
2827
from causalpy.skl_models import ScikitLearnModel
2928
from causalpy.utils import _is_variable_dummy_coded, convert_to_string
3029

30+
from .experiments import ExperimentalDesign
31+
3132

3233
class DifferenceInDifferences(ExperimentalDesign):
3334
"""A class to analyse data from Difference in Difference settings.
File renamed without changes.

causalpy/expt_instrumental_variable.py renamed to causalpy/experiments/instrumental_variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from sklearn.linear_model import LinearRegression as sk_lin_reg
2424

2525
from causalpy.custom_exceptions import DataException
26-
from causalpy.experiments import ExperimentalDesign
26+
from .experiments import ExperimentalDesign
2727

2828

2929
class InstrumentalVariable(ExperimentalDesign):

causalpy/exp_inverse_propensity_weighting.py renamed to causalpy/experiments/inverse_propensity_weighting.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
from sklearn.linear_model import LinearRegression as sk_lin_reg
2525

2626
from causalpy.custom_exceptions import DataException
27-
from causalpy.experiments import ExperimentalDesign
2827

29-
# from causalpy.pymc_models import PyMCModel
30-
# from causalpy.utils import round_num
28+
from .experiments import ExperimentalDesign
3129

3230

3331
class InversePropensityWeighting(ExperimentalDesign):
@@ -372,7 +370,8 @@ def weighted_percentile(self, data, weights, perc):
372370
"""
373371
perc : percentile in [0-1]!
374372
"""
375-
assert 0 <= perc <= 1
373+
if not (0 <= perc <= 1):
374+
raise ValueError("Percentile must be between 0 and 1.")
376375
ix = np.argsort(data)
377376
data = data[ix] # sort data
378377
weights = weights[ix] # sort weights

causalpy/expt_prepostfit.py renamed to causalpy/experiments/prepostfit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
from patsy import build_design_matrices, dmatrices
2323

2424
from causalpy.custom_exceptions import BadIndexException
25-
from causalpy.experiments import ExperimentalDesign
2625
from causalpy.pymc_models import PyMCModel
2726
from causalpy.skl_models import ScikitLearnModel
2827

28+
from .experiments import ExperimentalDesign
29+
2930

3031
class PrePostFit(ExperimentalDesign):
3132
"""

causalpy/expt_prepostnegd.py renamed to causalpy/experiments/prepostnegd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
from causalpy.custom_exceptions import (
2323
DataException,
2424
)
25-
from causalpy.experiments import ExperimentalDesign
2625
from causalpy.pymc_models import PyMCModel
2726
from causalpy.skl_models import ScikitLearnModel
2827
from causalpy.utils import _is_variable_dummy_coded, round_num
2928

29+
from .experiments import ExperimentalDesign
30+
3031

3132
class PrePostNEGD(ExperimentalDesign):
3233
"""

causalpy/expt_regression_discontinuity.py renamed to causalpy/experiments/regression_discontinuity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pandas as pd
2222
from patsy import build_design_matrices, dmatrices
2323

24-
from causalpy.experiments import ExperimentalDesign
24+
from .experiments import ExperimentalDesign
2525
from causalpy.pymc_models import PyMCModel
2626
from causalpy.skl_models import ScikitLearnModel
2727
from causalpy.utils import convert_to_string

causalpy/expt_regression_kink.py renamed to causalpy/experiments/regression_kink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pandas as pd
2323
from patsy import build_design_matrices, dmatrices
2424

25-
from causalpy.experiments import ExperimentalDesign
25+
from .experiments import ExperimentalDesign
2626
from causalpy.utils import round_num
2727
from causalpy.custom_exceptions import (
2828
DataException,

0 commit comments

Comments
 (0)