예제 #1
0
 def test_one_column_exog(self):
     from statsmodels.formula.api import ols
     res = ols("y~var1-1", data=self.data).fit()
     fig = plot_regress_exog(res, "var1")
     plt.close(fig)
     res = ols("y~var1", data=self.data).fit()
     fig = plot_regress_exog(res, "var1")
     plt.close(fig)
예제 #2
0
 def test_one_column_exog(self):
     from statsmodels.formula.api import ols
     res = ols("y~var1-1", data=self.data).fit()
     plot_regress_exog(res, "var1")
     plt.close('all')
     res = ols("y~var1", data=self.data).fit()
     plot_regress_exog(res, "var1")
     plt.close('all')
  def test_plot_oth(self, close_figures):
      #just test that they run
      res = self.res
      plot_fit(res, 0, y_true=None)
      plot_partregress_grid(res, exog_idx=[0,1])
      plot_regress_exog(res, exog_idx=0)
      plot_ccpr(res, exog_idx=0)
      plot_ccpr_grid(res, exog_idx=[0])
      fig = plot_ccpr_grid(res, exog_idx=[0,1])
      for ax in fig.axes:
          add_lowess(ax)
 
      close_or_save(pdf, fig)
예제 #4
0
    def test_plot_oth(self):
        #just test that they run
        res = self.res
        endog = res.model.endog
        exog = res.model.exog

        plot_fit(res, 0, y_true=None)
        plot_partregress(endog, exog, exog_idx=[0, 1])
        plot_regress_exog(res, exog_idx=0)
        plot_ccpr(res, exog_idx=[0])
        plot_ccpr(res, exog_idx=[0, 1])

        plt.close('all')
    def test_plot_oth(self):
        #just test that they run
        res = self.res
        endog = res.model.endog
        exog = res.model.exog

        plot_fit(res, 0, y_true=None)
        plot_partregress(endog, exog, exog_idx=[0,1])
        plot_regress_exog(res, exog_idx=0)
        plot_ccpr(res, exog_idx=[0])
        plot_ccpr(res, exog_idx=[0,1])

        plt.close('all')
    def test_plot_oth(self, close_figures):
        #just test that they run
        res = self.res
        plot_fit(res, 0, y_true=None)
        plot_partregress_grid(res, exog_idx=[0, 1])
        plot_regress_exog(res, exog_idx=0)
        plot_ccpr(res, exog_idx=0)
        plot_ccpr_grid(res, exog_idx=[0])
        fig = plot_ccpr_grid(res, exog_idx=[0, 1])
        for ax in fig.axes:
            add_lowess(ax)

        close_or_save(pdf, fig)
예제 #7
0
    def test_plot_oth(self):
        #just test that they run
        res = self.res
        endog = res.model.endog
        exog = res.model.exog

        plot_fit(res, 0, y_true=None)
        plot_partregress_grid(res, exog_idx=[0,1])
        plot_regress_exog(res, exog_idx=0)
        plot_ccpr(res, exog_idx=0)
        plot_ccpr_grid(res, exog_idx=[0])
        fig = plot_ccpr_grid(res, exog_idx=[0,1])
        for ax in fig.axes:
            add_lowess(ax)

        plt.close('all')
예제 #8
0
    def test_plot_oth(self):
        #just test that they run
        res = self.res
        endog = res.model.endog
        exog = res.model.exog

        plot_fit(res, 0, y_true=None)
        plot_partregress_grid(res, exog_idx=[0, 1])
        plot_regress_exog(res, exog_idx=0)
        plot_ccpr(res, exog_idx=0)
        plot_ccpr_grid(res, exog_idx=[0])
        fig = plot_ccpr_grid(res, exog_idx=[0, 1])
        for ax in fig.axes:
            add_lowess(ax)

        plt.close('all')
예제 #9
0
    x2beta = x2 * res.params[2]
    plt.plot(x1, x1beta + res.resid, 'o')
    plt.plot(x1, x1beta, '-')
    ax.set_title('X_i beta_i plus residuals versus exog (CCPR)')  # + namestr)
    ax = fig6.add_subplot(2, 1, 2)
    plt.plot(x2, x2beta + res.resid, 'o')
    plt.plot(x2, x2beta, '-')

    #print res.summary()

doplots = 1
if doplots:
    fig1 = smrp.plot_fit(res, 0, y_true=None)
    smrp.plot_fit(res, 1, y_true=None)
    smrp.plot_partregress(y, exog0, exog_idx=[0, 1])
    smrp.plot_regress_exog(res, exog_idx=0)
    smrp.plot_ccpr(res, exog_idx=[0])
    smrp.plot_ccpr(res, exog_idx=[0, 1])

from statsmodels.graphics.tests.test_regressionplots import TestPlot
tp = TestPlot()
tp.test_plot_fit()

fig1 = smrp.plot_partregress(y, exog0, exog_idx=[0, 1])
#add lowess
ax = fig1.axes[0]
y0 = ax.get_lines()[0]._y
x0 = ax.get_lines()[0]._x
lres = sm.nonparametric.lowess(y0, x0, frac=0.2)
ax.plot(lres[:, 0], lres[:, 1], 'r', lw=1.5)
ax = fig1.axes[1]
예제 #10
0
 def test_one_column_exog(self, close_figures):
     from statsmodels.formula.api import ols
     res = ols("y~var1-1", data=self.data).fit()
     fig = plot_regress_exog(res, "var1")
     res = ols("y~var1", data=self.data).fit()
     fig = plot_regress_exog(res, "var1")
예제 #11
0
 def test_graphs(self, res):
     col_num = self.X.shape[1]
     rp.plot_fit(res, exog_idx=col_num - 3)
     rp.plot_regress_exog(res, exog_idx=col_num - 1, fig=None)
     rp.plot_leverage_resid2(res)  # squared
예제 #12
0
파일: OLS.py 프로젝트: kangzheng1990/PyEcon
"""

# /// Graphical Diagnostic Tools /// ---------------------------------
import statsmodels.graphics.regressionplots as regplot
"""
まず、以下のinfluence_plot()は、サンプルの中にはずれ値的な動きをした期間があるかを検出してくれます。
"""
# Checking Outlier effect
regplot.influence_plot(rlt)  # Studentized Residual
regplot.plot_leverage_resid2(rlt)  # Leverage vs. resid^2
"""
また、plot_regress_exog()は、個別の説明変数ごとに、誤差項と説明変数の関係や、他の要因をコントロールした上での当該変数の説明力を見る偏回帰プロットが表示されます。誤差や説明力が説明変数の値に連動して変化するなら、他変数からの影響や非線形性が現れていると考えられます。
"""

# Selected exog vs. other things controlled endog plot
regplot.plot_regress_exog(rlt, 1)

N = DD.shape[0]

x = DD['Pic'].values * 100
y = DD['GAP'].values * 100

radii = np.random.random(size=N) / 10
colors = [
    "#%02x%02x%02x" % (r, g, 150)
    for r, g in zip(np.floor(50 + 2 * x), np.floor(30 + 2 * y))
]

output_file("color_scatter.html", title="color_scatter.py example")

scatter(x,
예제 #13
0
    plt.plot(x1, x1beta + res.resid, 'o')
    plt.plot(x1, x1beta, '-')
    ax.set_title('X_i beta_i plus residuals versus exog (CCPR)')# + namestr)
    ax = fig6.add_subplot(2,1,2)
    plt.plot(x2, x2beta + res.resid, 'o')
    plt.plot(x2, x2beta, '-')


    #print res.summary()

doplots = 1
if doplots:
    fig1 = smrp.plot_fit(res, 0, y_true=None)
    smrp.plot_fit(res, 1, y_true=None)
    smrp.plot_partregress_grid(res, exog_idx=[0,1])
    smrp.plot_regress_exog(res, exog_idx=0)
    smrp.plot_ccpr(res, exog_idx=0)
    smrp.plot_ccpr_grid(res, exog_idx=[0,1])

from statsmodels.graphics.tests.test_regressionplots import TestPlot
tp = TestPlot()
tp.test_plot_fit()

fig1 = smrp.plot_partregress_grid(res, exog_idx=[0,1])
#add lowess
ax = fig1.axes[0]
y0 = ax.get_lines()[0]._y
x0 = ax.get_lines()[0]._x
lres = sm.nonparametric.lowess(y0, x0, frac=0.2)
ax.plot(lres[:,0], lres[:,1], 'r', lw=1.5)
ax = fig1.axes[1]
예제 #14
0
파일: OLS.py 프로젝트: kangzheng1990/PyEcon

"""
まず、以下のinfluence_plot()は、サンプルの中にはずれ値的な動きをした期間があるかを検出してくれます。
"""
# Checking Outlier effect
regplot.influence_plot(rlt) # Studentized Residual
regplot.plot_leverage_resid2(rlt) # Leverage vs. resid^2


"""
また、plot_regress_exog()は、個別の説明変数ごとに、誤差項と説明変数の関係や、他の要因をコントロールした上での当該変数の説明力を見る偏回帰プロットが表示されます。誤差や説明力が説明変数の値に連動して変化するなら、他変数からの影響や非線形性が現れていると考えられます。
"""

# Selected exog vs. other things controlled endog plot
regplot.plot_regress_exog(rlt,1)




N = DD.shape[0]

x = DD['Pic'].values*100
y = DD['GAP'].values*100


radii = np.random.random(size=N)/10
colors = ["#%02x%02x%02x" % (r, g, 150) for r, g in zip(np.floor(50+2*x), np.floor(30+2*y))]

output_file("color_scatter.html", title="color_scatter.py example")