Fix errors in examples
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Sat, 2 Mar 2019 14:59:35 +0000 (14:59 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Sat, 2 Mar 2019 14:59:35 +0000 (14:59 +0000)
Be compatible with current pandas
https://github.com/statsmodels/statsmodels/commit/66a4f98d0ac86ea957fa6f8168cc2df178c64630
https://github.com/statsmodels/statsmodels/commit/67415ad8d4c04dc1dd9ea9ebb1e059af92646c7b
https://github.com/statsmodels/statsmodels/commit/572d507dfa28044166cf4f183177a046f90934ae

and with one dataset layout change within statsmodels, based on
https://github.com/statsmodels/statsmodels/commit/31ec838d1eab2ec559ab69d42151085bdf9f18e1

Look in the correct path for star_diagram.png
(using this fix instead of
https://github.com/statsmodels/statsmodels/commit/3363ce1dc41b1717db5b6779a2a9cbf8f72a0294
to be minimally risky during freeze)

Author: Kevin "bashtage" Sheppard, Rebecca N. Palmer <rebecca_palmer@zoho.com>
Origin: upstream (mostly)
Forwarded: not-needed

Gbp-Pq: Name examples_fixes.patch

docs/source/contingency_tables.rst
examples/notebooks/discrete_choice_example.ipynb
examples/notebooks/pca_fertility_factors.ipynb
examples/notebooks/robust_models_1.ipynb

index e66c2156f6a5287dc9119e89a8ac99db5e03c8b1..985bd99fb95b76b5a072ed720d91a84fb0a70ab2 100644 (file)
@@ -265,7 +265,7 @@ methods and attributes.
     data = sm.datasets.china_smoking.load()
 
     mat = np.asarray(data.data)
-    tables = [np.reshape(x, (2, 2)) for x in mat]
+    tables = [np.reshape(list(x)[1:], (2, 2)) for x in mat]
 
     st = sm.stats.StratifiedTable(tables)
     print(st.summary())
index 9f9c483fc7eeeff94e81a89885d04ec6dc6a0adc..3b7fda0b1a14be0d7e182679c641ac83dc2a0467 100644 (file)
    },
    "outputs": [],
    "source": [
-    "affair_mod.predict(respondent1000)"
+    "affair_mod.predict(pd.DataFrame(respondent1000).T) # patsy requires a DataFrame, not a Series"
    ]
   },
   {
    },
    "outputs": [],
    "source": [
-    "resp25 = glm_mod.predict(means25)\n",
-    "resp75 = glm_mod.predict(means75)\n",
+    "resp25 = glm_mod.predict(pd.DataFrame(means25).T) # patsy requires a DataFrame, not a Series\n",
+    "resp75 = glm_mod.predict(pd.DataFrame(means75).T)\n",
     "diff = resp75 - resp25"
    ]
   },
index 58a1a719da5c5272b696cb2b94140ef79d735e32..7be3e37f27640ff9a2ab90a3a8bf1d81fa759c74 100644 (file)
    "outputs": [],
    "source": [
     "fig, ax = plt.subplots()\n",
-    "pd.tools.plotting.scatter_plot(pca_model.loadings, 'comp_00', 'comp_01', ax=ax)\n",
+    "pca_model.loadings.plot.scatter(x='comp_00', y='comp_01', ax=ax)\n",
     "ax.set_xlabel(\"PC 1\", size=17)\n",
     "ax.set_ylabel(\"PC 2\", size=17)\n",
     "dta.index[pca_model.loadings.ix[:, 1] > .2].values"
index 69459733f1bd869fbf3f2e3cf892f7180c08fc4d..8f90ee4ecf7dfc21c9c03c97507c2f03826e1d11 100644 (file)
    "outputs": [],
    "source": [
     "sidak = ols_model.outlier_test('sidak')\n",
-    "sidak.sort('unadj_p', inplace=True)\n",
+    "sidak.sort_values('unadj_p', inplace=True)\n",
     "print(sidak)"
    ]
   },
    "outputs": [],
    "source": [
     "fdr = ols_model.outlier_test('fdr_bh')\n",
-    "fdr.sort('unadj_p', inplace=True)\n",
+    "fdr.sort_values('unadj_p', inplace=True)\n",
     "print(fdr)"
    ]
   },
    "outputs": [],
    "source": [
     "from IPython.display import Image\n",
-    "Image(filename='star_diagram.png')"
+    "import os.path\n",
+    "Image(filename='star_diagram.png' if os.path.exists('star_diagram.png') else '../examples/notebooks/star_diagram.png')"
    ]
   },
   {
    "outputs": [],
    "source": [
     "sidak2 = ols_model.outlier_test('sidak')\n",
-    "sidak2.sort('unadj_p', inplace=True)\n",
+    "sidak2.sort_values('unadj_p', inplace=True)\n",
     "print(sidak2)"
    ]
   },
    "outputs": [],
    "source": [
     "fdr2 = ols_model.outlier_test('fdr_bh')\n",
-    "fdr2.sort('unadj_p', inplace=True)\n",
+    "fdr2.sort_values('unadj_p', inplace=True)\n",
     "print(fdr2)"
    ]
   },