class_docstr: Results class for generalized additive models, GAM.
  
  This inherits from GLMResults.
  
  Warning: some inherited methods might not correctly take account of the
  penalization
  
  GLMGamResults inherits from GLMResults
  All methods related to the loglikelihood function return the penalized
  values.
  
  Attributes
  ----------
  
  edf
      list of effective degrees of freedom for each column of the design
      matrix.
  hat_matrix_diag
      diagonal of hat matrix
  gcv
      generalized cross-validation criterion computed as
      ``gcv = scale / (1. - hat_matrix_trace / self.nobs)**2``
  cv
      cross-validation criterion computed as
      ``cv = ((resid_pearson / (1 - hat_matrix_diag))**2).sum() / nobs``
  
  Notes
  -----
  status: experimental
class_docstr_tok: ["Results","class","for","generalized","additive","models",",","GAM",".","This","inherits","from","GLMResults",".","Warning",":","some","inherited","methods","might","not","correctly","take","account","of","the","penalization","GLMGamResults","inherits","from","GLMResults","All","methods","related","to","the","loglikelihood","function","return","the","penalized","values",".","Attributes","--","--","--","--","--","edf","list","of","effective","degrees","of","freedom","for","each","column","of","the","design","matrix",".","hat_matrix_diag","diagonal","of","hat","matrix","gcv","generalized","cross-validation","criterion","computed","as","``","gcv","=","scale","\/","(","1",".","-","hat_matrix_trace","\/","self.nobs",")","*","*","2","``","cv","cross-validation","criterion","computed","as","``","cv","=","(","(","resid_pearson","\/","(","1","-","hat_matrix_diag",")",")","*","*","2",")",".sum","(",")","\/","nobs","``","Notes","--","--","-","status",":","experimental"]
docstr: Compute the diagonal of the hat matrix
  
  Parameters
  ----------
  observed : bool
      If true, then observed hessian is used in the hat matrix
      computation. If false, then the expected hessian is used.
      In the case of a canonical link function both are the same.
      This is only relevant for models that implement both observed
      and expected Hessian, which is currently only GLM. Other
      models only use the observed Hessian.
  _axis : int
      This is mainly for internal use. By default it returns the usual
      diagonal of the hat matrix. If _axis is zero, then the result
      corresponds to the effective degrees of freedom, ``edf`` for each
      column of exog.
  
  Returns
  -------
  hat_matrix_diag : ndarray
      The diagonal of the hat matrix computed from the observed
      or expected hessian.
docstr_tok: ["Compute","the","diagonal","of","the","hat","matrix","Parameters","--","--","--","--","--","observed",":","bool","If","true",",","then","observed","hessian","is","used","in","the","hat","matrix","computation",".","If","false",",","then","the","expected","hessian","is","used",".","In","the","case","of","a","canonical","link","function","both","are","the","same",".","This","is","only","relevant","for","models","that","implement","both","observed","and","expected","Hessian",",","which","is","currently","only","GLM",".","Other","models","only","use","the","observed","Hessian",".","_axis",":","int","This","is","mainly","for","internal","use",".","By","default","it","returns","the","usual","diagonal","of","the","hat","matrix",".","If","_axis","is","zero",",","then","the","result","corresponds","to","the","effective","degrees","of","freedom",",","``","edf","``","for","each","column","of","exog",".","Returns","--","--","--","-","hat_matrix_diag",":","ndarray","The","diagonal","of","the","hat","matrix","computed","from","the","observed","or","expected","hessian","."]
code: def get_hat_matrix_diag(self, observed=True, _axis=1):
      """
      Compute the diagonal of the hat matrix
  
      Parameters
      ----------
      observed : bool
          If true, then observed hessian is used in the hat matrix
          computation. If false, then the expected hessian is used.
          In the case of a canonical link function both are the same.
          This is only relevant for models that implement both observed
          and expected Hessian, which is currently only GLM. Other
          models only use the observed Hessian.
      _axis : int
          This is mainly for internal use. By default it returns the usual
          diagonal of the hat matrix. If _axis is zero, then the result
          corresponds to the effective degrees of freedom, ``edf`` for each
          column of exog.
  
      Returns
      -------
      hat_matrix_diag : ndarray
          The diagonal of the hat matrix computed from the observed
          or expected hessian.
      """
      weights = self.model.hessian_factor(
          self.params, scale=self.scale, observed=observed
      )
      wexog = np.sqrt(weights)[:, None] * self.model.exog
  
      # we can use inverse hessian directly instead of computing it from
      # WLS/IRLS as in GLM
  
      # TODO: does `normalized_cov_params * scale` work in all cases?
      # this avoids recomputing hessian, check when used for other models.
      hess_inv = self.normalized_cov_params * self.scale
      # this is in GLM equivalent to the more generic and direct
      # hess_inv = np.linalg.inv(-self.model.hessian(self.params))
      hd = (wexog * hess_inv.dot(wexog.T).T).sum(axis=_axis)
      return hd
  
imports: from collections.abc import Iterable
  import copy
  import numpy
  from scipy import optimize
  import pandas
  import statsmodels.base.wrapper
  from statsmodels.discrete.discrete_model import Logit
  from statsmodels.genmod.generalized_linear_model import GLM, GLMResults, GLMResultsWrapper, _check_convergence
  import statsmodels.regression.linear_model
  from statsmodels.tools.sm_exceptions import PerfectSeparationError, ValueWarning
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.tools.data import _is_using_pandas
  from statsmodels.tools.linalg import matrix_sqrt
  from statsmodels.base._penalized import PenalizedMixin
  from statsmodels.gam.gam_penalties import MultivariateGamPenalty
  from statsmodels.gam.gam_cross_validation.gam_cross_validation import MultivariateGAMCVPath
  from statsmodels.gam.gam_cross_validation.cross_validators import KFold
label_desc: Use image node_id 8 for calling the GLMGamResults obj's underlying member method code with example usage: obj.get_hat_matrix_diag(observed, _axis) and returns: hd