econmethods 1.4__tar.gz → 1.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -6,6 +6,7 @@ import scipy.stats as sc
6
6
  from math import floor
7
7
  import importlib.resources as resources
8
8
  from statsmodels.regression.mixed_linear_model import MixedLM
9
+ from statsmodels.stats.diagnostic import het_goldfeldquandt
9
10
  from typing import Any
10
11
 
11
12
  def read_critical_values(sheet: str) -> pd.DataFrame:
@@ -185,7 +186,6 @@ class CipsTest:
185
186
  pass
186
187
 
187
188
 
188
-
189
189
  class HausmanOneWay:
190
190
  '''
191
191
  Implementation of the Hausman procedure to test whether it is more feasible to used random effects against fixed effects.
@@ -195,7 +195,6 @@ class HausmanOneWay:
195
195
  - *H1*: Cov(a_i, x_{it}) != 0\n
196
196
  PARAMETERS:
197
197
  --
198
- -----
199
198
  - *data*: A pandas DataFrame. Make sure that all items are introduced in this exact order by column index:\n
200
199
  Make sure no columns contain Nan Values!
201
200
  0 - your spatial unit. The data must be homogenous, e.g. only contries, regions, etc.
@@ -278,7 +277,6 @@ class HausmanOneWay:
278
277
  pass
279
278
 
280
279
 
281
-
282
280
  class FECM:
283
281
  '''
284
282
  The implementation of a first-order ECM (Error Correction Model) estimation for panel data.
@@ -556,10 +554,10 @@ class FECM:
556
554
  class CDTwoWay:
557
555
  '''
558
556
  Implementation of the CD test to validate/reject cross-sectional dependence.
559
- -
557
+ Hypotheses:
558
+ --
560
559
  H0: p_{ij} = 0 (No Significant Cross-Sectional Dependence)\n
561
560
  H1: p_{ij} != 0 (Valid Cross-Sectional Dependence)\n
562
- ---
563
561
  PARAMETERS:
564
562
  ----
565
563
  - *df*: a Pandas DataFrame containing panel data. Make sure your data is structured in this exact order (by column index):\n
@@ -608,4 +606,77 @@ class CDTwoWay:
608
606
  print(f'p-value = {pval} < alpha = {self.__alpha}\n There is Significant Cross-Sectional Dependence in your data according to the CD-test. \n Significance level: {self.__alpha*100}%')
609
607
  else:
610
608
  print(f'p-value = {pval} > alpha = {self.__alpha} There is No Significant Cross-Sectional Dependence in your data according to the CD-test. \n Significance level: {self.__alpha*100}%')
611
-
609
+
610
+
611
+ class SlopeHomogeneityF:
612
+ '''
613
+ <h2>The implementation of the F-test for data slope Homogeneity in panel data.</h2>
614
+ <hr>
615
+ <h2>Hypotheses:</h2>
616
+ <hr>
617
+ <ul>
618
+ <li> <em>H0</em>: b_i = b_j given that i != j</li>
619
+ <li><em>H_1</em>: b_i != b_j for at least one such pair of (i, j) that i != j </li>
620
+ </ul>
621
+ <hr>
622
+ <h2>PARAMETERS:</h2>
623
+ <hr>
624
+ <ul>
625
+ <li> <strong>df</strong>: a Pandas DataFrame containing panel data. Make sure your data is structured in this exact order (by column index):
626
+ <ul>
627
+ <li>0 - Spatial units. The data must be homogenous, e.g. only cities, contries, regions, etc.</li>
628
+ <li>1 - Temporal units. The data must be homogenous, e.g. only years, months, quarters, etc.</li>
629
+ <li>2 - Your target/endogenous variable. The data must not contain NaN values.</li>
630
+ <li>3+ - Your exogenous variables. The data must not contain NaN values.</li>
631
+ </ul>
632
+ <li> <strong>level</strong>: Your significance level to test at. Defaults to 5%.</li>
633
+ </ul>
634
+ <hr>
635
+ <h3><em>Note that this test has got certain assumptions, such as error homoskedasticity, N < T.
636
+ The <FTwoWay> instance will check for these conditions to be met, and will yield an error if they are not.</em></h3>
637
+ <hr>
638
+ <h2>RETURNS:</h2>
639
+ <ol>
640
+ <li>Via the instance.verdict() method - prints the result of the F-test.</li>
641
+ </ol>
642
+ '''
643
+ def __init__(self, df: pd.DataFrame, level: int = 5) -> None:
644
+ self.__df = df
645
+ self.__l = []
646
+ self.__alpha = level
647
+ self.__k = 0
648
+ for i, ex in enumerate(self.__df.columns[3:], 1):
649
+ self.__k +=1
650
+ self.__l.append(f'x{i}')
651
+ self.__df.columns = ['SpUnit', 'time', 'target'] + self.__l
652
+ self.__N = len(self.__df.SpUnit.unique())
653
+ self.__T = len(self.__df.time.unique())
654
+ self.__homo_res = het_goldfeldquandt(self.__df['target'], self.__df.iloc[:, 3:])
655
+ self.__verify()
656
+
657
+ def __verify(self) -> None:
658
+ if self.__N > self.__T:
659
+ raise AssertionError('The F-test for slope Homogeneity assumes that N< T!')
660
+ if self.__homo_res[1] < self.__alpha:
661
+ raise AssertionError('The Data contains Heteroskedastic errors according to the Goldfeld-Quandt test!')
662
+
663
+ def fit(self) -> float | int:
664
+ USSR = 0
665
+ RSSR = sm.OLS(self.__df.iloc[:, 2], sm.add_constant(self.__df[:, 3:])).fit().ssr
666
+ for unit in self.__df.SpUnit.unique():
667
+ subdf = self.__df[self.__df.SpUnit == unit]
668
+ USSR += sm.OLS(subdf.iloc[:, 2], sm.add_constant(subdf[:, 3:])).fit().ssr
669
+ F = round(self.__N * (self.__T - self.__k - 1) / (self.__k * (self.__N - 1)))* (RSSR - USSR)/USSR
670
+ return F
671
+
672
+ def verdict(self) -> None:
673
+ f = sc.f(self.__k*(self.__N - 1), self.__N * (self.__T - self.__k - 1))
674
+ pval = f.sf(self.fit())
675
+ if pval < self.__alpha:
676
+ print(f'P-Value: {pval} < Alpha: {self.__alpha}, hence your data does not fit slope homogeneity.')
677
+ else:
678
+ print(f'P-Value: {pval} < Alpha: {self.__alpha}, hence your data fits slope homogeneity.')
679
+
680
+ def __del__(self) -> None:
681
+ pass
682
+
@@ -0,0 +1,3 @@
1
+ from .Lib import CipsTest, HausmanOneWay, FECM, CDTwoWay, SlopeHomogeneityF
2
+
3
+ __all__ = ['CipsTest', 'HausmanOneWay', 'FECM', 'CDTwoWay', 'SlopeHomogeneityF']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
5
5
 
6
6
  setup(
7
7
  name = 'econmethods',
8
- version = 'v1.4',
8
+ version = 'v1.6',
9
9
  description='A python package implementing various econometrical tests and estimators',
10
10
  packages = find_packages(),
11
11
  long_description=long_desc,
@@ -1,3 +0,0 @@
1
- from .Lib import CipsTest, HausmanOneWay, FECM, CDTwoWay
2
-
3
- __all__ = ['CipsTest', 'HausmanOneWay', 'FECM', 'CDTwoWay']
File without changes
File without changes