Skip to content

Commit

Permalink
Merge pull request #9240 from bashtage/fix-linear-reset
Browse files Browse the repository at this point in the history
BUG: Correct cov_kwargs -> cov_kwds
  • Loading branch information
bashtage committed May 8, 2024
2 parents c22837f + dffb340 commit aa3c42e
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 305 deletions.
40 changes: 20 additions & 20 deletions examples/notebooks/gls.ipynb
Expand Up @@ -15,12 +15,12 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import statsmodels.api as sm"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -37,12 +37,12 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"data = sm.datasets.longley.load()\n",
"data.exog = sm.add_constant(data.exog)\n",
"print(data.exog.head())"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -64,10 +64,10 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"ols_resid = sm.OLS(data.endog, data.exog).fit().resid"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -90,14 +90,14 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"resid_fit = sm.OLS(\n",
" np.asarray(ols_resid)[1:], sm.add_constant(np.asarray(ols_resid)[:-1])\n",
").fit()\n",
"print(resid_fit.tvalues[1])\n",
"print(resid_fit.pvalues[1])"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -115,10 +115,10 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"rho = resid_fit.params[1]"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -136,12 +136,12 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"from scipy.linalg import toeplitz\n",
"\n",
"toeplitz(range(5))"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -151,10 +151,10 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"order = toeplitz(range(len(ols_resid)))"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -168,12 +168,12 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sigma = rho ** order\n",
"gls_model = sm.GLS(data.endog, data.exog, sigma=sigma)\n",
"gls_results = gls_model.fit()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -188,12 +188,12 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"glsar_model = sm.GLSAR(data.endog, data.exog, 1)\n",
"glsar_results = glsar_model.iterative_fit(1)\n",
"print(glsar_results.summary())"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -210,13 +210,13 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(gls_results.params)\n",
"print(glsar_results.params)\n",
"print(gls_results.bse)\n",
"print(glsar_results.bse)"
]
],
"outputs": []
}
],
"metadata": {
Expand Down
48 changes: 24 additions & 24 deletions examples/notebooks/influence_glm_logit.ipynb
Expand Up @@ -22,7 +22,6 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"import os.path\n",
"import pandas as pd\n",
Expand All @@ -33,7 +32,8 @@
"\n",
"plt.rc(\"figure\", figsize=(16, 8))\n",
"plt.rc(\"font\", size=14)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -43,7 +43,6 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"import statsmodels.stats.tests.test_influence\n",
"\n",
Expand All @@ -53,7 +52,8 @@
"file_name = \"binary_constrict.csv\"\n",
"file_path = os.path.join(cur_dir, \"results\", file_name)\n",
"df = pd.read_csv(file_path, index_col=0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -63,15 +63,15 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"res = GLM(\n",
" df[\"constrict\"],\n",
" df[[\"const\", \"log_rate\", \"log_volumne\"]],\n",
" family=families.Binomial(),\n",
").fit(attach_wls=True, atol=1e-10)\n",
"print(res.summary())"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -92,10 +92,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"infl = res.get_influence(observed=False)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -105,11 +105,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"summ_df = infl.summary_frame()\n",
"summ_df.sort_values(\"cooks_d\", ascending=False)[:10]"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -119,11 +119,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_influence()\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -133,11 +133,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_index(y_var=\"cooks\", threshold=2 * infl.cooks_distance[0].mean())\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -147,11 +147,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_index(y_var=\"resid\", threshold=1)\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -161,11 +161,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_index(y_var=\"dfbeta\", idx=1, threshold=0.5)\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -175,11 +175,11 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_index(y_var=\"dfbeta\", idx=2, threshold=0.5)\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -189,20 +189,20 @@
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"fig = infl.plot_index(y_var=\"dfbeta\", idx=0, threshold=0.5)\n",
"fig.tight_layout(pad=1.0)"
]
],
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": []
"source": [],
"outputs": []
}
],
"metadata": {
Expand Down

0 comments on commit aa3c42e

Please sign in to comment.