class_docstr: Cox Proportional Hazards Regression Model
  
  The Cox PH Model is for right censored data.
  
  Parameters
  ----------
  endog : array_like
      The observed times (event or censoring)
  exog : 2D array_like
      The covariates or exogeneous variables
  status : array_like
      The censoring status values; status=1 indicates that an
      event occurred (e.g. failure or death), status=0 indicates
      that the observation was right censored. If None, defaults
      to status=1 for all cases.
  entry : array_like
      The entry times, if left truncation occurs
  strata : array_like
      Stratum labels.  If None, all observations are taken to be
      in a single stratum.
  ties : str
      The method used to handle tied times, must be either 'breslow'
      or 'efron'.
  offset : array_like
      Array of offset values
  missing : str
      The method used to handle missing data
  
  Notes
  -----
  Proportional hazards regression models should not include an
  explicit or implicit intercept.  The effect of an intercept is
  not identified using the partial likelihood approach.
  
  `endog`, `event`, `strata`, `entry`, and the first dimension
  of `exog` all must have the same length
class_docstr_tok: ["Cox","Proportional","Hazards","Regression","Model","The","Cox","PH","Model","is","for","right","censored","data",".","Parameters","--","--","--","--","--","endog",":","array_like","The","observed","times","(","event","or","censoring",")","exog",":","2D","array_like","The","covariates","or","exogeneous","variables","status",":","array_like","The","censoring","status","values",";","status=1","indicates","that","an","event","occurred","(","e.g",".","failure","or","death",")",",","status=0","indicates","that","the","observation","was","right","censored",".","If","None",",","defaults","to","status=1","for","all","cases",".","entry",":","array_like","The","entry","times",",","if","left","truncation","occurs","strata",":","array_like","Stratum","labels",".","If","None",",","all","observations","are","taken","to","be","in","a","single","stratum",".","ties",":","str","The","method","used","to","handle","tied","times",",","must","be","either","'breslow'","or","'efron","'",".","offset",":","array_like","Array","of","offset","values","missing",":","str","The","method","used","to","handle","missing","data","Notes","--","--","-","Proportional","hazards","regression","models","should","not","include","an","explicit","or","implicit","intercept",".","The","effect","of","an","intercept","is","not","identified","using","the","partial","likelihood","approach",".","`","endog","`",",","`","event","`",",","`","strata","`",",","`","entry","`",",","and","the","first","dimension","of","`","exog","`","all","must","have","the","same","length"]
docstr: Returns the score residuals calculated at a given vector of
  parameters.
  
  Parameters
  ----------
  params : ndarray
      The parameter vector at which the score residuals are
      calculated.
  
  Returns
  -------
  The score residuals, returned as a ndarray having the same
  shape as `exog`.
  
  Notes
  -----
  Observations in a stratum with no observed events have undefined
  score residuals, and contain NaN in the returned matrix.
docstr_tok: ["Returns","the","score","residuals","calculated","at","a","given","vector","of","parameters",".","Parameters","--","--","--","--","--","params",":","ndarray","The","parameter","vector","at","which","the","score","residuals","are","calculated",".","Returns","--","--","--","-","The","score","residuals",",","returned","as","a","ndarray","having","the","same","shape","as","`","exog","`",".","Notes","--","--","-","Observations","in","a","stratum","with","no","observed","events","have","undefined","score","residuals",",","and","contain","NaN","in","the","returned","matrix","."]
code: def score_residuals(self, params):
      """
      Returns the score residuals calculated at a given vector of
      parameters.
  
      Parameters
      ----------
      params : ndarray
          The parameter vector at which the score residuals are
          calculated.
  
      Returns
      -------
      The score residuals, returned as a ndarray having the same
      shape as `exog`.
  
      Notes
      -----
      Observations in a stratum with no observed events have undefined
      score residuals, and contain NaN in the returned matrix.
      """
  
      surv = self.surv
  
      score_resid = np.zeros(self.exog.shape, dtype=np.float64)
  
      # Use to set undefined values to NaN.
      mask = np.zeros(self.exog.shape[0], dtype=np.int32)
  
      w_avg = self.weighted_covariate_averages(params)
  
      # Loop over strata
      for stx in range(surv.nstrat):
          uft_ix = surv.ufailt_ix[stx]
          exog_s = surv.exog_s[stx]
          nuft = len(uft_ix)
          strat_ix = surv.stratum_rows[stx]
  
          xp0 = 0.0
  
          linpred = np.dot(exog_s, params)
          if surv.offset_s is not None:
              linpred += surv.offset_s[stx]
          linpred -= linpred.max()
          e_linpred = np.exp(linpred)
  
          at_risk_ix = set()
  
          # Iterate backward through the unique failure times.
          for i in range(nuft)[::-1]:
              # Update for new cases entering the risk set.
              ix = surv.risk_enter[stx][i]
              at_risk_ix |= set(ix)
              xp0 += e_linpred[ix].sum()
  
              atr_ix = list(at_risk_ix)
              leverage = exog_s[atr_ix, :] - w_avg[stx][i, :]
  
              # Event indicators
              d = np.zeros(exog_s.shape[0])
              d[uft_ix[i]] = 1
  
              # The increment in the cumulative hazard
              dchaz = len(uft_ix[i]) / xp0
  
              # Piece of the martingale residual
              mrp = d[atr_ix] - e_linpred[atr_ix] * dchaz
  
              # Update the score residuals
              ii = strat_ix[atr_ix]
              score_resid[ii, :] += leverage * mrp[:, None]
              mask[ii] = 1
  
              # Update for cases leaving the risk set.
              ix = surv.risk_exit[stx][i]
              at_risk_ix -= set(ix)
              xp0 -= e_linpred[ix].sum()
  
      jj = np.flatnonzero(mask == 0)
      if len(jj) > 0:
          score_resid[jj, :] = np.nan
  
      return score_resid
  
imports: import numpy
  from statsmodels.base import model
  import statsmodels.base.model
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.compat.pandas import Appender
label_desc: Use image node_id 15 for calling the PHReg obj's underlying member method code with example usage: obj.score_residuals(params) and returns: score_resid