title: Python confidence bands for predicted values
body: <p>I am fitting a linear regression and want to have confidence bands projected for points that fall out of the range of the values fit.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/17559408/confidence-and-prediction-intervals-with-statsmodels">another post</a>, there's an example of getting the bands for the values within the fit range:</p>
  
  <pre><code>import numpy as np
  import statsmodels.api as sm
  from statsmodels.sandbox.regression.predstd import wls_prediction_std
  
  #Generate some data
  n = 20
  x = np.sort(np.random.normal(size=n))
  e = np.random.normal(size=n)
  y = 1 + 0.5*x + 1*e
  X = sm.add_constant(x)
  
  #Fit the model
  re = sm.OLS(y, X).fit()
  
  
  from statsmodels.stats.outliers_influence import summary_table
  
  st, data, ss2 = summary_table(re, alpha=0.05)
  
  #Get the confidence intervals
  fittedvalues = data[:,2]
  predict_mean_se  = data[:,3]
  predict_mean_ci_low, predict_mean_ci_upp = data[:,4:6].T
  predict_ci_low, predict_ci_upp = data[:,6:8].T
  
  #Plot confidence intervals and data points
  plt.plot(x, y, 'o')
  plt.plot(x, fittedvalues, '-', lw=2)
  plt.plot(x, predict_ci_low, 'r--', lw=2)
  plt.plot(x, predict_ci_upp, 'r--', lw=2)
  plt.plot(x, predict_mean_ci_low, 'r--', lw=2)
  plt.plot(x, predict_mean_ci_upp, 'r--', lw=2)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xM3vi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xM3vi.png" alt=""></a></p>
  
  <p>However, this doesn't allow me to extend the bands to predicted values. How would I go about extending these bounds to values outside of the range of the fit values, e.g. for <code>x=5</code>?</p>