internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: statsmodels/statsmodels

Issue:
proportion_chisquare_*pairs* functions mistaken docstring
https://github.com/statsmodels/statsmodels/blob/f67fc16d581767c030b6f191cf650c3a69d9ed5d/statsmodels/stats/proportion.py#L982
https://github.com/statsmodels/statsmodels/blob/f67fc16d581767c030b6f191cf650c3a69d9ed5d/statsmodels/stats/proportion.py#L1024

I may be mistaken, but I think these docs are wrong.  Idon't think this parameter is actually used in either of these chisquare "all" functions.  It looks like maybe it was intended to be a control, which should only apply to the second function, but _proportions_chisquare_pairscontrol_ specifies that the control is assumed to be the first element of the count and nobs arrays.

Never done a pull request so i'm not actually sure the process to suggest the correction


Discussion:
Thanks for reporting.

I guess it's a copy paste error

For this you could try the `edit` icon when viewing the file in `main`. AFAIK, it will automatically create a pull request.
(I never tried it myself)
https://github.com/statsmodels/statsmodels/edit/main/statsmodels/stats/proportion.py

But it's also useful to learn how to do a full pull request on github, because by now most "action" for opensource, and for personal version control, is on github.


Resolving patch:
diff --git a/statsmodels/stats/proportion.py b/statsmodels/stats/proportion.py
--- a/statsmodels/stats/proportion.py
+++ b/statsmodels/stats/proportion.py
@@ -979,9 +979,6 @@ def proportions_chisquare_allpairs(count, nobs, multitest_method='hs'):
         the number of successes in nobs trials.
     nobs : int
         the number of trials or observations.
-    prop : float, optional
-        The probability of success under the null hypothesis,
-        `0 <= prop <= 1`. The default value is `prop = 0.5`
     multitest_method : str
         This chooses the method for the multiple testing p-value correction,
         that is used as default in the results.
@@ -1021,9 +1018,6 @@ def proportions_chisquare_pairscontrol(count, nobs, value=None,
         the number of successes in nobs trials.
     nobs : int
         the number of trials or observations.
-    prop : float, optional
-        The probability of success under the null hypothesis,
-        `0 <= prop <= 1`. The default value is `prop = 0.5`
     multitest_method : str
         This chooses the method for the multiple testing p-value correction,
         that is used as default in the results.


Test patch:
Repository: statsmodels/statsmodels

Issue:
Discrepance `zivot_andrews()` function documentation and source code
#### Describe the bug

The documentation of the zivot_andrews() function (https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.zivot_andrews.html) says that it returns `zastat`, `pvalue`, `cvdict`, `bpidx`, and `baselag`, but the in the source code here (https://github.com/statsmodels/statsmodels/blob/main/statsmodels/tsa/stattools.py) the `run()` method of the `ZivotAndrewsUnitRoot` class ends with:

```
return zastat, pval, cvdict, baselags, bpidx
```
This should be really simple to fix: just change the order in the docs, and I could fork the project and submit a PR if you agree.


Discussion:

Resolving patch:
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -2508,11 +2508,11 @@ def run(self, x, trim=0.15, maxlag=None, regression="c", autolag="AIC"):
         cvdict : dict
             The critical values for the test statistic at the 1%, 5%, and 10%
             levels.
+        baselag : int
+            The number of lags used for period regressions.
         bpidx : int
             The index of x corresponding to endogenously calculated break period
             with values in the range [0..nobs-1].
-        baselag : int
-            The number of lags used for period regressions.
 
         Notes
         -----


Test patch:
Repository: statsmodels/statsmodels

Issue:
`gam.generalized_addtive_model.plot_partial` wrong x, y order
https://github.com/statsmodels/statsmodels/blob/718b4c5d8524d227bc170d162be80a74d07665cf/statsmodels/gam/generalized_additive_model.py#L347-L360

It seems on the line 359-360, `y_est` is the sorted version but `self.resid_working` is still the unsorted version. So the resulting data points on the plot is actually wrong.

I can submit a quick PR fixing this if it's indeed the case.


Discussion:
Yes that looks wrong to me.

Thanks for catching this and PR will be welcome

Resolving patch:
diff --git a/statsmodels/gam/generalized_additive_model.py b/statsmodels/gam/generalized_additive_model.py
--- a/statsmodels/gam/generalized_additive_model.py
+++ b/statsmodels/gam/generalized_additive_model.py
@@ -356,7 +356,8 @@ def plot_partial(self, smooth_index, plot_se=True, cpr=False,
         if cpr:
             # TODO: resid_response does not make sense with nonlinear link
             # use resid_working ?
-            cpr_ = y_est + self.resid_working
+            residual = self.resid_working[sort_index]
+            cpr_ = y_est + residual
             ax.plot(x, cpr_, '.', lw=2)
 
         ax.set_xlabel(smoother.smoothers[variable].variable_name)


Test patch:
Repository: statsmodels/statsmodels

Issue:
DOC: Rename maxlag to maxlags in get_robustcov_results
#### `get_robustcov_results` documentation mislabels the `maxlags` argument as `maxlag`

When specifying a HAC, hac-groupsum, or hac-panel covariance type, the documentation suggests using `maxlag` to specify the number of lags to use when `get_robustcov_results` expects `maxlags`.

See statsmodels/statsmodels/base/covtype.py 

```python
""" 
- 'HAC': heteroskedasticity-autocorrelation robust covariance

``maxlag`` :  integer, required
number of lags to use
"""
```

But `maxlags` is expected.

```python
elif cov_type.lower() == 'hac':
    maxlags = kwds['maxlags']   # required?, default in cov_hac_simple
    res.cov_kwds['maxlags'] = maxlags
```




Discussion:

Resolving patch:
diff --git a/statsmodels/base/covtype.py b/statsmodels/base/covtype.py
--- a/statsmodels/base/covtype.py
+++ b/statsmodels/base/covtype.py
@@ -109,7 +109,7 @@ def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):
 
     - 'HAC': heteroskedasticity-autocorrelation robust covariance
 
-      ``maxlag`` :  integer, required
+      ``maxlags`` :  integer, required
         number of lags to use
 
       ``kernel`` : {callable, str}, optional
@@ -152,7 +152,7 @@ def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):
 
       ``time`` : array_like, required
         index of time periods
-      ``maxlag`` : integer, required
+      ``maxlags`` : integer, required
         number of lags to use
       ``kernel`` : {callable, str}, optional
         The available kernels are ['bartlett', 'uniform']. The default is
@@ -176,7 +176,7 @@ def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):
         indicator for groups
       ``time`` : array_like[int]
         index of time periods
-      ``maxlag`` : int, required
+      ``maxlags`` : int, required
         number of lags to use
       ``kernel`` : {callable, str}, optional
         Available kernels are ['bartlett', 'uniform'], default


Test patch:
Repository: statsmodels/statsmodels

Issue:
Wrong upper limit in Bland-Altman plot
"lower" should be "upper"

https://github.com/statsmodels/statsmodels/blob/6d7d42eae9b261eac8b30dd49336ad9c09a31b45/statsmodels/graphics/agreement.py#L139


Discussion:

Resolving patch:
diff --git a/statsmodels/graphics/agreement.py b/statsmodels/graphics/agreement.py
--- a/statsmodels/graphics/agreement.py
+++ b/statsmodels/graphics/agreement.py
@@ -130,13 +130,13 @@ def mean_diff_plot(m1, m2, sd_limit=1.96, ax=None, scatter_kwds=None,
         upper = mean_diff + limit_of_agreement
         for j, lim in enumerate([lower, upper]):
             ax.axhline(lim, **limit_lines_kwds)
-        ax.annotate(f'-SD{sd_limit}: {lower:0.2g}',
+        ax.annotate(f'-{sd_limit} SD: {lower:0.2g}',
                     xy=(0.99, 0.07),
                     horizontalalignment='right',
                     verticalalignment='bottom',
                     fontsize=14,
                     xycoords='axes fraction')
-        ax.annotate(f'+SD{sd_limit}: {lower:0.2g}',
+        ax.annotate(f'+{sd_limit} SD: {upper:0.2g}',
                     xy=(0.99, 0.92),
                     horizontalalignment='right',
                     fontsize=14,


Test patch:
Repository: statsmodels/statsmodels

Issue:
Log-Likelihood Documentation in ETSModel
Hello,

I think there might be a mistake in the documentation for the Log-Likelihood in the ETSModel.  This is what the docs have, 

![image](https://user-images.githubusercontent.com/42855604/117723040-bd0eb300-b196-11eb-9cd1-4f06bdefce89.png).

Shouldn't S^2 square the residuals before taking the mean? The referenced article seems to define it differently, 

![image](https://user-images.githubusercontent.com/42855604/117723497-4aea9e00-b197-11eb-847b-eaea446f5259.png)





Discussion:
At a minimum there is a square missing.

On Mon, May 10, 2021, 21:56 Hong Xiang Yue ***@***.***> wrote:

> Hello,
>
> I think there might be a mistake in the documentation for the
> Log-Likelihood in the ETSModel. This is what the docs have,
>
> [image: image]
> <https://user-images.githubusercontent.com/42855604/117723040-bd0eb300-b196-11eb-9cd1-4f06bdefce89.png>
> .
>
> Shouldn't S^2 square the residuals before taking the mean? The referenced
> article seems to define it differently,
>
> [image: image]
> <https://user-images.githubusercontent.com/42855604/117723497-4aea9e00-b197-11eb-847b-eaea446f5259.png>
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/statsmodels/statsmodels/issues/7443>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABKTSRMIAYP4LO4Z3UV5Q3LTNBCBHANCNFSM44SK5TZA>
> .
>


Resolving patch:
diff --git a/statsmodels/tsa/exponential_smoothing/ets.py b/statsmodels/tsa/exponential_smoothing/ets.py
--- a/statsmodels/tsa/exponential_smoothing/ets.py
+++ b/statsmodels/tsa/exponential_smoothing/ets.py
@@ -1201,7 +1201,7 @@ def loglike(self, params, **kwargs):
 
         .. math::
 
-           s^2 = \frac{1}{n}\sum\limits_{t=1}^n \frac{\hat{y}_t - y_t}{k_t}
+           s^2 = \frac{1}{n}\sum\limits_{t=1}^n \frac{(\hat{y}_t - y_t)^2}{k_t}
 
         where :math:`k_t = 1` for the additive error model and :math:`k_t =
         y_t` for the multiplicative error model.


Test patch:
Repository: statsmodels/statsmodels

Issue:
FAQ: tsa.stattools.q_stat and acorr_ljungbox



Discussion:
However, they don't provide the same result. Anyone has an idea why is this ?
`acorr_ljungbox  is current and more general. `q_stat` shoule be deprecated and removed eventually. 

Resolving patch:
diff --git a/statsmodels/stats/diagnostic.py b/statsmodels/stats/diagnostic.py
--- a/statsmodels/stats/diagnostic.py
+++ b/statsmodels/stats/diagnostic.py
@@ -373,6 +373,9 @@ def acorr_ljungbox(x, lags=None, boxpierce=False, model_df=0, period=None,
         Regression model fitting.
     statsmodels.regression.linear_model.RegressionResults
         Results from linear regression models.
+    statsmodels.stats.stattools.q_stat
+        Ljung-Box test statistic computed from estimated
+        autocorrelations.
 
     Notes
     -----
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -544,6 +544,13 @@ def q_stat(x, nobs):
     p-value : ndarray
         P-value of the Q statistic.
 
+    See Also
+    --------
+    statsmodels.stats.diagnostic.acorr_ljungbox
+        Ljung-Box Q-test for autocorrelation in time series based
+        on a time series rather than the estimated autocorrelation
+        function.
+
     Notes
     -----
     Designed to be used with acf.
@@ -680,24 +687,23 @@ def acf(
     acf = avf[: nlags + 1] / avf[0]
     if not (qstat or alpha):
         return acf
+    _alpha = alpha if alpha is not None else 0.05
+    if bartlett_confint:
+        varacf = np.ones_like(acf) / nobs
+        varacf[0] = 0
+        varacf[1] = 1.0 / nobs
+        varacf[2:] *= 1 + 2 * np.cumsum(acf[1:-1] ** 2)
+    else:
+        varacf = 1.0 / len(x)
+    interval = stats.norm.ppf(1 - _alpha / 2.0) * np.sqrt(varacf)
+    confint = np.array(lzip(acf - interval, acf + interval))
+    if not qstat:
+        return acf, confint
+    qstat, pvalue = q_stat(acf[1:], nobs=nobs)  # drop lag 0
     if alpha is not None:
-        if bartlett_confint:
-            varacf = np.ones_like(acf) / nobs
-            varacf[0] = 0
-            varacf[1] = 1.0 / nobs
-            varacf[2:] *= 1 + 2 * np.cumsum(acf[1:-1] ** 2)
-        else:
-            varacf = 1.0 / len(x)
-        interval = stats.norm.ppf(1 - alpha / 2.0) * np.sqrt(varacf)
-        confint = np.array(lzip(acf - interval, acf + interval))
-        if not qstat:
-            return acf, confint
-    if qstat:
-        qstat, pvalue = q_stat(acf[1:], nobs=nobs)  # drop lag 0
-        if alpha is not None:
-            return acf, confint, qstat, pvalue
-        else:
-            return acf, qstat, pvalue
+        return acf, confint, qstat, pvalue
+    else:
+        return acf, qstat, pvalue
 
 
 def pacf_yw(x, nlags=None, method="adjusted"):


Test patch:
Repository: statsmodels/statsmodels

Issue:
DOC: inter_rater.aggregate_raters hard to reach from fleiss_kappa docs
#### Describe the bug

`statsmodels.stats.inter_rater.aggregate_raters` is important helper function for `statsmodels.stats.inter_rater.fleiss_kappa` but it's not documented there.

https://www.statsmodels.org/dev/generated/statsmodels.stats.inter_rater.fleiss_kappa.html


Discussion:

Resolving patch:
diff --git a/statsmodels/stats/inter_rater.py b/statsmodels/stats/inter_rater.py
--- a/statsmodels/stats/inter_rater.py
+++ b/statsmodels/stats/inter_rater.py
@@ -197,7 +197,9 @@ def fleiss_kappa(table, method='fleiss'):
     Parameters
     ----------
     table : array_like, 2-D
-        assumes subjects in rows, and categories in columns
+        assumes subjects in rows, and categories in columns. Convert raw data
+        into this format by using
+        :func:`statsmodels.stats.inter_rater.aggregate_raters`
     method : str
         Method 'fleiss' returns Fleiss' kappa which uses the sample margin
         to define the chance outcome.


Test patch:
Repository: statsmodels/statsmodels

Issue:
BUG: Check input class in recursive_olsresiduals
In version 13.2.2, the following code:

from statsmodels.tsa.arima.model import ARIMA
from statsmodels.stats.diagnostic import recursive_olsresiduals
import numpy as np
X = np.random.rand(100)
Y = np.random.rand(100)
model = ARIMA(endog=Y,order(2,0,0),exog=X,trend='c')
recursive_olsresiduals(model,alpha=0.95)

Produces the error:
ValueError: could not broadcast input array from shape (2,1). into shape (2,)

This same error occurs when using trend = 'c', 't', or 'ct'. The function recursive_olsresiduals works as expected with trend = 'n'.



Discussion:
It is supposed to be a `RegressionResults` which you `model` is not.  Basically this should be disallowed with a useful error message. 



Resolving patch:
diff --git a/statsmodels/stats/diagnostic.py b/statsmodels/stats/diagnostic.py
--- a/statsmodels/stats/diagnostic.py
+++ b/statsmodels/stats/diagnostic.py
@@ -1447,6 +1447,8 @@ def recursive_olsresiduals(res, skip=None, lamda=0.0, alpha=0.95,
     Journal of the Royal Statistical Society. Series B (Methodological) 37,
     no. 2 (1975): 149-192.
     """
+    if not isinstance(res, RegressionResultsWrapper):
+        raise TypeError("res a regression results instance")
     y = res.model.endog
     x = res.model.exog
     order_by = array_like(order_by, "order_by", dtype="int", optional=True,


Test patch:
diff --git a/statsmodels/regression/tests/test_recursive_ls.py b/statsmodels/regression/tests/test_recursive_ls.py
--- a/statsmodels/regression/tests/test_recursive_ls.py
+++ b/statsmodels/regression/tests/test_recursive_ls.py
@@ -338,6 +338,17 @@ def test_resid_recursive():
     assert_allclose(res.resid_recursive[2:], desired_resid_recursive)
 
 
+def test_recursive_olsresiduals_bad_input(reset_randomstate):
+    from statsmodels.tsa.arima.model import ARIMA
+    e = np.random.standard_normal(250)
+    y = e.copy()
+    for i in range(1, y.shape[0]):
+        y[i] += 0.1 + 0.8 * y[i - 1] + e[i]
+    res = ARIMA(y[20:], order=(1,0,0), trend="c").fit()
+    with pytest.raises(TypeError, match="res a regression results instance"):
+        recursive_olsresiduals(res)
+
+
 def test_cusum():
     mod = RecursiveLS(endog, exog)
     res = mod.fit()
Repository: statsmodels/statsmodels

Issue:
Missing `f` prefix on f-strings
Some strings looks like they're meant to be f-strings but are missing the `f` prefix meaning variable interpolation won't happen.

https://github.com/statsmodels/statsmodels/blob/9846953beef65a63f5f29178b777d88bd8a86168/statsmodels/stats/descriptivestats.py#L294

I found this issue automatically. I'm a bot. Beep Boop 🦊. See other issues I found in your repo [here](https://codereview.doctor/statsmodels/statsmodels)


Discussion:

Resolving patch:
diff --git a/statsmodels/stats/descriptivestats.py b/statsmodels/stats/descriptivestats.py
--- a/statsmodels/stats/descriptivestats.py
+++ b/statsmodels/stats/descriptivestats.py
@@ -291,7 +291,7 @@ def __init__(
         if self._data.shape[1] == 0:
 
             raise ValueError(
-                "Selecting {col_types} results in an empty DataFrame"
+                f"Selecting {col_types} results in an empty DataFrame"
             )
         self._is_numeric = [is_numeric_dtype(dt) for dt in self._data.dtypes]
         self._is_cat_like = [


Test patch:
Repository: statsmodels/statsmodels

Issue:
BUG/ENH: Remove print within graphics.plot_partregress
#### Describe the bug

Within regressionplots.py the plot_partregress function prints the eval_env variable. The default behavior is to print "eval_env: 1" to console. I believe that this parameter is better left to being explained within documentation and see little reason for why it is necessary to print the variable. It also causes any function that calls upon plot_partregress to print, such as plot_regress_exog. 

#### Code Sample

```regressionplots.py
fig, ax = utils.create_mpl_ax(ax)
    print("eval_env:", eval_env)
```




Discussion:
I'm pretty sure that was left over from a debugging session.

PR to delete the line with the print would be welcome.
Thanks for reporting this
No problem! I'll create the PR shortly.

Resolving patch:
diff --git a/statsmodels/graphics/regressionplots.py b/statsmodels/graphics/regressionplots.py
--- a/statsmodels/graphics/regressionplots.py
+++ b/statsmodels/graphics/regressionplots.py
@@ -387,7 +387,7 @@ def plot_partregress(endog, exog_i, exog_others, data=None,
     #NOTE: there is no interaction between possible missing data and
     #obs_labels yet, so this will need to be tweaked a bit for this case
     fig, ax = utils.create_mpl_ax(ax)
-    print("eval_env:", eval_env)
+
     # strings, use patsy to transform to data
     if isinstance(endog, str):
         endog = dmatrix(endog + "-1", data, eval_env=eval_env)


Test patch:
Repository: statsmodels/statsmodels

Issue:
Wrong critical values for Hansen's test (1992)
Refer to https://github.com/statsmodels/statsmodels/blob/27b797389ca1991ac691e6e6f91451a38f84a24d/statsmodels/stats/diagnostic.py#L1573  

The critical values are incorrect as per Greene's text book (section 7.5.1 page 134). They should be "1.01 for K = 2, 1.90
for K = 6, 3.75 for K = 15, and 4.52 for K = 19". See last sentence:

![image](https://user-images.githubusercontent.com/11311783/166480896-5f7a730c-29a7-4973-a2ce-db514f9e33f5.png)

I've created a PR for this [here](https://github.com/statsmodels/statsmodels/pull/8263). 


Discussion:

Resolving patch:
diff --git a/statsmodels/stats/diagnostic.py b/statsmodels/stats/diagnostic.py
--- a/statsmodels/stats/diagnostic.py
+++ b/statsmodels/stats/diagnostic.py
@@ -1570,7 +1570,7 @@ def breaks_hansen(olsresults):
     f = nobs * (ft[:, :, None] * ft[:, None, :]).sum(0)
     s = (score[:, :, None] * score[:, None, :]).sum(0)
     h = np.trace(np.dot(np.linalg.inv(f), s))
-    crit95 = np.array([(2, 1.9), (6, 3.75), (15, 3.75), (19, 4.52)],
+    crit95 = np.array([(2, 1.01), (6, 1.9), (15, 3.75), (19, 4.52)],
                       dtype=[("nobs", int), ("crit", float)])
     # TODO: get critical values from Bruce Hansen's 1992 paper
     return h, crit95


Test patch:
Repository: statsmodels/statsmodels

Issue:
MAINT: `pre`-tests with dev versions are not running anymore
from latest merge commit test run

https://dev.azure.com/statsmodels/statsmodels-testing/_build/results?buildId=4558&view=logs&j=3618ddf5-2391-5260-f9eb-8f35f95d270b&t=a24edd62-b2b9-54c8-9892-98a88509521b

pytest problems with pandas or pytest config problem ?

```
Starting: Run tests (pip pre)
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.201.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/b92f0bde-a9f5-44a0-a8a5-1ef1be8202fc.sh
Testing pip-pre
pytest -m  --skip-examples --junitxml=junit/test-results.xml -n auto --dist loadscope --durations=25 statsmodels
ERROR: while parsing the following warning configuration:

  error::pandas.core.common.SettingWithCopyWarning

This error occurred:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1642, in parse_warning_filter
    category: Type[Warning] = _resolve_warning_category(category_)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1681, in _resolve_warning_category
    cat = getattr(m, klass)
AttributeError: module 'pandas.core.common' has no attribute 'SettingWithCopyWarning'


##[error]Bash exited with code '4'.
```


Discussion:

Resolving patch:
diff --git a/statsmodels/stats/descriptivestats.py b/statsmodels/stats/descriptivestats.py
--- a/statsmodels/stats/descriptivestats.py
+++ b/statsmodels/stats/descriptivestats.py
@@ -392,6 +392,9 @@ def numeric(self) -> pd.DataFrame:
 
         def _mode(ser):
             mode_res = stats.mode(ser.dropna())
+            # Changes in SciPy 1.10
+            if np.isscalar(mode_res[0]):
+                return float(mode_res[0]), mode_res[1]
             if mode_res[0].shape[0] > 0:
                 return [float(val) for val in mode_res]
             return np.nan, np.nan


Test patch: