class_docstr: Diagnostic plots to identify potential problems in a linear regression fit.
  Mainly,
      a. non-linearity of data
      b. Correlation of error terms
      c. non-constant variance 
      d. outliers
      e. high-leverage points
      f. collinearity
  
  Author:
      Prajwal Kafle (p33ajkafle@gmail.com, where 3 = r)
      Does not come with any sort of warranty. 
      Please test the code one your end before using.
class_docstr_tok: ["Diagnostic","plots","to","identify","potential","problems","in","a","linear","regression","fit",".","Mainly",",","a.","non-linearity","of","data","b",".","Correlation","of","error","terms","c.","non-constant","variance","d.","outliers","e.","high-leverage","points","f.","collinearity","Author",":","Prajwal","Kafle","(","p33ajkafle","@","gmail.com",",","where","3","=","r",")","Does","not","come","with","any","sort","of","warranty",".","Please","test","the","code","one","your","end","before","using","."]
docstr: For a linear regression model, generates following diagnostic plots:
  
  a. residual
  b. qq
  c. scale location and
  d. leverage
  
  and a table
  
  e. vif
  
  Args:
      results (Type[statsmodels.regression.linear_model.RegressionResultsWrapper]): 
          must be instance of statsmodels.regression.linear_model object
  
  Raises:
      TypeError: if instance does not belong to above object
  
  Example:
  >>> import numpy as np
  >>> import pandas as pd
  >>> import statsmodels.formula.api as smf
  >>> x = np.linspace(-np.pi, np.pi, 100)
  >>> y = 3*x + 8 + np.random.normal(0,1, 100)
  >>> df = pd.DataFrame({'x':x, 'y':y})
  >>> res = smf.ols(formula= "y ~ x", data=df).fit()
  >>> cls = Linear_Reg_Diagnostic(res)
  >>> cls(plot_context="seaborn-paper")     
  
  In case you do not need all plots you can also independently make an individual plot/table
  in following ways
  
  >>> cls = Linear_Reg_Diagnostic(res)
  >>> cls.residual_plot()
  >>> cls.qq_plot()
  >>> cls.scale_location_plot()
  >>> cls.leverage_plot()
  >>> cls.vif_table()
docstr_tok: ["For","a","linear","regression","model",",","generates","following","diagnostic","plots",":","a.","residual","b.","qq","c.","scale","location","and","d.","leverage","and","a","table","e.","vif","Args",":","results","(","Type","[","statsmodels.regression.linear_model.RegressionResultsWrapper","]",")",":","must","be","instance","of","statsmodels.regression.linear_model","object","Raises",":","TypeError",":","if","instance","does","not","belong","to","above","object","Example",":",">",">",">","import","numpy","as","np",">",">",">","import","pandas","as","pd",">",">",">","import","statsmodels.formula.api","as","smf",">",">",">","x","=","np.linspace","(","-np.pi",",","np.pi",",","100",")",">",">",">","y","=","3","*","x","+","8","+","np.random.normal","(","0,1",",","100",")",">",">",">","df","=","pd.DataFrame","(","{","'","x","'",":","x",",","'","y","'",":","y","}",")",">",">",">","res","=","smf.ols","(","formula=","``","y","~","x","''",",","data=df",")",".fit","(",")",">",">",">","cls","=","Linear_Reg_Diagnostic","(","res",")",">",">",">","cls","(","plot_context=","''","seaborn-paper","''",")","In","case","you","do","not","need","all","plots","you","can","also","independently","make","an","individual","plot\/table","in","following","ways",">",">",">","cls","=","Linear_Reg_Diagnostic","(","res",")",">",">",">","cls.residual_plot","(",")",">",">",">","cls.qq_plot","(",")",">",">",">","cls.scale_location_plot","(",")",">",">",">","cls.leverage_plot","(",")",">",">",">","cls.vif_table","(",")"]
code: def __init__(
      self,
      results: type[
          statsmodels.regression.linear_model.RegressionResultsWrapper
      ],
  ) -> None:
      """
      For a linear regression model, generates following diagnostic plots:
  
      a. residual
      b. qq
      c. scale location and
      d. leverage
  
      and a table
  
      e. vif
  
      Args:
          results (Type[statsmodels.regression.linear_model.RegressionResultsWrapper]):
              must be instance of statsmodels.regression.linear_model object
  
      Raises:
          TypeError: if instance does not belong to above object
  
      Example:
      >>> import numpy as np
      >>> import pandas as pd
      >>> import statsmodels.formula.api as smf
      >>> x = np.linspace(-np.pi, np.pi, 100)
      >>> y = 3*x + 8 + np.random.normal(0,1, 100)
      >>> df = pd.DataFrame({'x':x, 'y':y})
      >>> res = smf.ols(formula= "y ~ x", data=df).fit()
      >>> cls = Linear_Reg_Diagnostic(res)
      >>> cls(plot_context="seaborn-paper")
  
      In case you do not need all plots you can also independently make an individual plot/table
      in following ways
  
      >>> cls = Linear_Reg_Diagnostic(res)
      >>> cls.residual_plot()
      >>> cls.qq_plot()
      >>> cls.scale_location_plot()
      >>> cls.leverage_plot()
      >>> cls.vif_table()
      """
  
      if (
          isinstance(
              results,
              statsmodels.regression.linear_model.RegressionResultsWrapper,
          )
          is False
      ):
          raise TypeError(
              "result must be instance of statsmodels.regression.linear_model.RegressionResultsWrapper object"
          )
  
      self.results = maybe_unwrap_results(results)
  
      self.y_true = self.results.model.endog
      self.y_predict = self.results.fittedvalues
      self.xvar = self.results.model.exog
      self.xvar_names = self.results.model.exog_names
  
      self.residual = np.array(self.results.resid)
      influence = self.results.get_influence()
      self.residual_norm = influence.resid_studentized_internal
      self.leverage = influence.hat_matrix_diag
      self.cooks_distance = influence.cooks_distance[0]
      self.nparams = len(self.results.params)
  
file_path: statsmodels/examples/python/linear_regression_diagnostics_plots.py
imports: import statsmodels
  import statsmodels.formula.api
  import pandas
  import numpy
  import seaborn
  from statsmodels.tools.tools import maybe_unwrap_results
  from statsmodels.graphics.gofplots import ProbPlot
  from statsmodels.stats.outliers_influence import variance_inflation_factor
  import matplotlib.pyplot
  from typing import Type
label_desc: Use image node_id 1 to create a new Linear_Reg_Diagnostic object  with example: obj = Linear_Reg_Diagnostic(results)