Skip to content

Commit

Permalink
Merge pull request #20 from nathanramoscfa/legacy-dev-0.2.6
Browse files Browse the repository at this point in the history
Legacy dev 0.2.6
  • Loading branch information
nathanramoscfa committed Jul 7, 2024
2 parents 7f81a50 + adbbd36 commit 0d3a53f
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 164 deletions.
316 changes: 157 additions & 159 deletions examples/monetary_policy_rules/monetary_policy_rules.ipynb

Large diffs are not rendered by default.

Binary file modified media/taylor_rule_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions pyeconomics/diagnostics/residual_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ def plot_residuals(exog: pd.DataFrame, model: sm.RegressionResults) -> None:
model (sm.RegressionResults): The fitted statsmodels model.
"""
if not isinstance(exog, pd.DataFrame) or exog.empty:
raise ValueError("Input 'df_exog' is not a valid non-empty DataFrame.")
raise ValueError("Input 'exog' is not a valid non-empty DataFrame.")

residuals = model.resid_deviance if (
isinstance(model, GLMResultsWrapper)
) else model.resid
num_plots = exog.shape[1]
num_plots = exog.shape[1] - 1 # Exclude the constant term

if num_plots == 0:
raise ValueError("The DataFrame does not contain any columns.")
raise ValueError("The DataFrame does not contain any predictor columns.")

fig, axs = plt.subplots(
max(1, num_plots), 1, figsize=(5, 3 * max(1, num_plots))
num_plots, 1, figsize=(5, 3 * num_plots)
)
axs = axs.flatten() if num_plots > 1 else [axs]

for ax, column in zip(axs, exog.columns[1:]):
for ax, column in zip(axs, exog.columns[1:]): # Skip the constant term
ax.scatter(exog[column], residuals, alpha=0.5)
ax.set_xlabel(f'Log Predictor: {column}')
ax.set_ylabel('Residuals')
Expand Down

0 comments on commit 0d3a53f

Please sign in to comment.