Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. from __future__ import print_function
  2. import numpy as np
  3. import pandas as pd
  4. from scipy import stats
  5. import statsmodels.api as sm
  6. import matplotlib.pyplot as plt
  7. from statsmodels.sandbox.regression.predstd import wls_prediction_std
  8. from statsmodels.iolib.table import (SimpleTable, default_txt_fmt)
  9. np.random.seed(1024)
  10.  
  11. nsample = 50
  12. x = np.linspace(0, 20, nsample)
  13. X = np.column_stack((x, (x - 5)**2))
  14. X = sm.add_constant(X)
  15. beta = [5., 0.5, -0.01]
  16. sig = 0.5
  17. w = np.ones(nsample)
  18. w[nsample * 6//10:] = 3
  19. y_true = np.dot(X, beta)
  20. e = np.random.normal(size=nsample)
  21. y = y_true + sig * w * e
  22. X = X[:,[0,1]]
  23.  
  24. mod_wls = sm.WLS(y, X, weights=1./(w ** 2))
  25. res_wls = mod_wls.fit()
  26. res_ols = sm.OLS(y, X).fit()
  27.  
  28. infl = res_ols.get_influence()
  29. print(infl.resid_studentized_internal)
  30.  
  31. infl1 = res_wls.get_influence()
  32. print(infl1.resid_studentized_internal)
  33.  
  34. ----> 8 infl1 = res_wls.get_influence()
  35. 9 print(infl1.resid_studentized_internal)
  36. 10 # print(res_wls.summary())
  37.  
  38. ~AppDataLocalProgramsPythonPython36libsite-packagesstatsmodelsbasewrapper.py in __getattribute__(self, attr)
  39. 33 pass
  40. 34
  41. ---> 35 obj = getattr(results, attr)
  42. 36 data = results.model.data
  43. 37 how = self._wrap_attrs.get(attr)
  44.  
  45. AttributeError: 'RegressionResults' object has no attribute 'get_influence'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement