Skip to content

Commit 98971b4

Browse files
authored
Merge pull request statsmodels#8881 from aglebov/plot_partial
ENH: plot prediction curve over scatter in GLMGamResults.plot_partial
2 parents aa78e9c + f80ffe4 commit 98971b4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

statsmodels/gam/generalized_additive_model.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def plot_partial(self, smooth_index, plot_se=True, cpr=False,
319319
If plot_se is true, then the confidence interval for the linear
320320
prediction will be added to the plot.
321321
cpr : bool
322-
If cpr (component plus residual) is true, the a scatter plot of
322+
If cpr (component plus residual) is true, then a scatter plot of
323323
the partial working residuals will be added to the plot.
324324
include_constant : bool
325325
If true, then the estimated intercept is added to the prediction
@@ -332,7 +332,7 @@ def plot_partial(self, smooth_index, plot_se=True, cpr=False,
332332
Returns
333333
-------
334334
Figure
335-
If `ax` is None, the created figure. Otherwise the Figure to which
335+
If `ax` is None, the created figure. Otherwise, the Figure to which
336336
`ax` is connected.
337337
"""
338338
from statsmodels.graphics.utils import _import_mpl, create_mpl_ax
@@ -349,16 +349,18 @@ def plot_partial(self, smooth_index, plot_se=True, cpr=False,
349349
se = se[sort_index]
350350

351351
fig, ax = create_mpl_ax(ax)
352-
ax.plot(x, y_est, c='blue', lw=2)
353-
if plot_se:
354-
ax.plot(x, y_est + 1.96 * se, '-', c='blue')
355-
ax.plot(x, y_est - 1.96 * se, '-', c='blue')
352+
356353
if cpr:
357354
# TODO: resid_response does not make sense with nonlinear link
358355
# use resid_working ?
359356
residual = self.resid_working[sort_index]
360357
cpr_ = y_est + residual
361-
ax.plot(x, cpr_, '.', lw=2)
358+
ax.scatter(x, cpr_, s=4)
359+
360+
ax.plot(x, y_est, c='blue', lw=2)
361+
if plot_se:
362+
ax.plot(x, y_est + 1.96 * se, '-', c='blue')
363+
ax.plot(x, y_est - 1.96 * se, '-', c='blue')
362364

363365
ax.set_xlabel(smoother.smoothers[variable].variable_name)
364366

0 commit comments

Comments
 (0)