class_docstr: This class implements fitting Cox's time-varying proportional hazard model:
  
      .. math::  h(t|x(t)) = h_0(t)\exp((x(t)-\overline{x})'\beta)
  
  Parameters
  ----------
  alpha: float, optional (default=0.05)
     the level in the confidence intervals.
  penalizer: float, optional
      the coefficient of an L2 penalizer in the regression
  
  Attributes
  ----------
  params_ : Series
      The estimated coefficients. Changed in version 0.22.0: use to be ``.hazards_``
  hazard_ratios_ : Series
      The exp(coefficients)
  confidence_intervals_ : DataFrame
      The lower and upper confidence intervals for the hazard coefficients
  event_observed: Series
      The event_observed variable provided
  weights: Series
      The event_observed variable provided
  variance_matrix_ : DataFrame
      The variance matrix of the coefficients
  strata: list | str
      the strata provided
  standard_errors_: Series
      the standard errors of the estimates
  baseline_cumulative_hazard_: DataFrame
  baseline_survival_: DataFrame
class_docstr_tok: ["This","class","implements","fitting","Cox","'s","time-varying","proportional","hazard","model",":","..","math",":",":","h","(","t|x","(","t",")",")","=","h_0","(","t",")","\\exp","(","(","x","(","t",")","-\\overline","{","x","}",")","'\\beta",")","Parameters","--","--","--","--","--","alpha",":","float",",","optional","(","default=0.05",")","the","level","in","the","confidence","intervals",".","penalizer",":","float",",","optional","the","coefficient","of","an","L2","penalizer","in","the","regression","Attributes","--","--","--","--","--","params_",":","Series","The","estimated","coefficients",".","Changed","in","version","0.22.0",":","use","to","be","``",".hazards_","``","hazard_ratios_",":","Series","The","exp","(","coefficients",")","confidence_intervals_",":","DataFrame","The","lower","and","upper","confidence","intervals","for","the","hazard","coefficients","event_observed",":","Series","The","event_observed","variable","provided","weights",":","Series","The","event_observed","variable","provided","variance_matrix_",":","DataFrame","The","variance","matrix","of","the","coefficients","strata",":","list","|","str","the","strata","provided","standard_errors_",":","Series","the","standard","errors","of","the","estimates","baseline_cumulative_hazard_",":","DataFrame","baseline_survival_",":","DataFrame"]
docstr: Fit the Cox Proportional Hazard model to a time varying dataset. Tied survival times
  are handled using Efron's tie-method.
  
  Parameters
  -----------
  df: DataFrame
      a Pandas DataFrame with necessary columns `duration_col` and
     `event_col`, plus other covariates. `duration_col` refers to
     the lifetimes of the subjects. `event_col` refers to whether
     the 'death' events was observed: 1 if observed, 0 else (censored).
  event_col: string
     the column in DataFrame that contains the subjects' death
     observation. If left as None, assume all individuals are non-censored.
  start_col: string
      the column that contains the start of a subject's time period.
  stop_col: string
      the column that contains the end of a subject's time period.
  weights_col: string, optional
      the column that contains (possibly time-varying) weight of each subject-period row.
  id_col: string, optional
      A subject could have multiple rows in the DataFrame. This column contains
     the unique identifier per subject. If not provided, it's up to the
     user to make sure that there are no violations.
  show_progress: since the fitter is iterative, show convergence
     diagnostics.
  robust: bool, optional (default: True)
      Compute the robust errors using the Huber sandwich estimator, aka Wei-Lin estimate. This does not handle
    ties, so if there are high number of ties, results may significantly differ. See
    "The Robust Inference for the Cox Proportional Hazards Model", Journal of the American Statistical Association, Vol. 84, No. 408 (Dec., 1989), pp. 1074- 1078
  strata: list | string, optional
      specify a column or list of columns n to use in stratification. This is useful if a
      categorical covariate does not obey the proportional hazard assumption. This
      is used similar to the `strata` expression in R.
      See http://courses.washington.edu/b515/l17.pdf.
  initial_point: (d,) numpy array, optional
      initialize the starting point of the iterative
      algorithm. Default is the zero vector.
  formula: str, optional
      A R-like formula for transforming the covariates
  fit_options: dict, optional
      Override the default values in NR algorithm:
          step_size: 0.95,
          precision: 1e-07,
          r_precision=1e-9,
          max_steps: 500,
  
  Returns
  --------
  self: CoxTimeVaryingFitter
      self, with additional properties like ``hazards_`` and ``print_summary``
docstr_tok: ["Fit","the","Cox","Proportional","Hazard","model","to","a","time","varying","dataset",".","Tied","survival","times","are","handled","using","Efron","'s","tie-method",".","Parameters","--","--","--","--","--","-","df",":","DataFrame","a","Pandas","DataFrame","with","necessary","columns","`","duration_col","`","and","`","event_col","`",",","plus","other","covariates",".","`","duration_col","`","refers","to","the","lifetimes","of","the","subjects",".","`","event_col","`","refers","to","whether","the","'death","'","events","was","observed",":","1","if","observed",",","0","else","(","censored",")",".","event_col",":","string","the","column","in","DataFrame","that","contains","the","subjects","'","death","observation",".","If","left","as","None",",","assume","all","individuals","are","non-censored",".","start_col",":","string","the","column","that","contains","the","start","of","a","subject","'s","time","period",".","stop_col",":","string","the","column","that","contains","the","end","of","a","subject","'s","time","period",".","weights_col",":","string",",","optional","the","column","that","contains","(","possibly","time-varying",")","weight","of","each","subject-period","row",".","id_col",":","string",",","optional","A","subject","could","have","multiple","rows","in","the","DataFrame",".","This","column","contains","the","unique","identifier","per","subject",".","If","not","provided",",","it","'s","up","to","the","user","to","make","sure","that","there","are","no","violations",".","show_progress",":","since","the","fitter","is","iterative",",","show","convergence","diagnostics",".","robust",":","bool",",","optional","(","default",":","True",")","Compute","the","robust","errors","using","the","Huber","sandwich","estimator",",","aka","Wei-Lin","estimate",".","This","does","not","handle","ties",",","so","if","there","are","high","number","of","ties",",","results","may","significantly","differ",".","See","``","The","Robust","Inference","for","the","Cox","Proportional","Hazards","Model","''",",","Journal","of","the","American","Statistical","Association",",","Vol",".","84",",","No",".","408","(","Dec.",",","1989",")",",","pp",".","1074-","1078","strata",":","list","|","string",",","optional","specify","a","column","or","list","of","columns","n","to","use","in","stratification",".","This","is","useful","if","a","categorical","covariate","does","not","obey","the","proportional","hazard","assumption",".","This","is","used","similar","to","the","`","strata","`","expression","in","R.","See","http",":","\/\/courses.washington.edu\/b515\/l17.pdf",".","initial_point",":","(","d",",",")","numpy","array",",","optional","initialize","the","starting","point","of","the","iterative","algorithm",".","Default","is","the","zero","vector",".","formula",":","str",",","optional","A","R-like","formula","for","transforming","the","covariates","fit_options",":","dict",",","optional","Override","the","default","values","in","NR","algorithm",":","step_size",":","0.95",",","precision",":","1e-07",",","r_precision=1e-9",",","max_steps",":","500",",","Returns","--","--","--","--","self",":","CoxTimeVaryingFitter","self",",","with","additional","properties","like","``","hazards_","``","and","``","print_summary","``"]
code: def fit(
      self,
      df,
      event_col,
      start_col="start",
      stop_col="stop",
      weights_col=None,
      id_col=None,
      show_progress=False,
      robust=False,
      strata=None,
      initial_point=None,
      formula: str = None,
      fit_options: Optional[dict] = None,
  ):  # pylint: disable=too-many-arguments
      """
      Fit the Cox Proportional Hazard model to a time varying dataset. Tied survival times
      are handled using Efron's tie-method.
  
      Parameters
      -----------
      df: DataFrame
          a Pandas DataFrame with necessary columns `duration_col` and
         `event_col`, plus other covariates. `duration_col` refers to
         the lifetimes of the subjects. `event_col` refers to whether
         the 'death' events was observed: 1 if observed, 0 else (censored).
      event_col: string
         the column in DataFrame that contains the subjects' death
         observation. If left as None, assume all individuals are non-censored.
      start_col: string
          the column that contains the start of a subject's time period.
      stop_col: string
          the column that contains the end of a subject's time period.
      weights_col: string, optional
          the column that contains (possibly time-varying) weight of each subject-period row.
      id_col: string, optional
          A subject could have multiple rows in the DataFrame. This column contains
         the unique identifier per subject. If not provided, it's up to the
         user to make sure that there are no violations.
      show_progress: since the fitter is iterative, show convergence
         diagnostics.
      robust: bool, optional (default: True)
          Compute the robust errors using the Huber sandwich estimator, aka Wei-Lin estimate. This does not handle
        ties, so if there are high number of ties, results may significantly differ. See
        "The Robust Inference for the Cox Proportional Hazards Model", Journal of the American Statistical Association, Vol. 84, No. 408 (Dec., 1989), pp. 1074- 1078
      strata: list | string, optional
          specify a column or list of columns n to use in stratification. This is useful if a
          categorical covariate does not obey the proportional hazard assumption. This
          is used similar to the `strata` expression in R.
          See http://courses.washington.edu/b515/l17.pdf.
      initial_point: (d,) numpy array, optional
          initialize the starting point of the iterative
          algorithm. Default is the zero vector.
      formula: str, optional
          A R-like formula for transforming the covariates
      fit_options: dict, optional
          Override the default values in NR algorithm:
              step_size: 0.95,
              precision: 1e-07,
              r_precision=1e-9,
              max_steps: 500,
  
      Returns
      --------
      self: CoxTimeVaryingFitter
          self, with additional properties like ``hazards_`` and ``print_summary``
  
      """
      self.strata = utils._to_list_or_singleton(
          coalesce(strata, self.strata)
      )
      self.robust = robust
      if self.robust:
          raise NotImplementedError("Not available yet.")
  
      self.event_col = event_col
      self.id_col = id_col
      self.stop_col = stop_col
      self.start_col = start_col
      self.formula = formula
      self._time_fit_was_called = (
          datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
      )
  
      df = df.copy()
  
      if not (event_col in df and start_col in df and stop_col in df):
          raise KeyError(
              "A column specified in the call to `fit` does not exist in the DataFrame provided."
          )
  
      if weights_col is None:
          self.weights_col = None
          assert (
              "__weights" not in df.columns
          ), "__weights is an internal lifelines column, please rename your column first."
          df["__weights"] = 1.0
      else:
          self.weights_col = weights_col
          if (df[weights_col] <= 0).any():
              raise ValueError(
                  "values in weights_col must be positive."
              )
  
      df = df.rename(
          columns={
              event_col: "event",
              start_col: "start",
              stop_col: "stop",
              weights_col: "__weights",
          }
      )
  
      if self.strata is not None and self.id_col is not None:
          df = df.set_index(_to_list(self.strata) + [id_col])
          df = df.sort_index()
      elif self.strata is not None and self.id_col is None:
          df = df.set_index(_to_list(self.strata))
      elif self.strata is None and self.id_col is not None:
          df = df.set_index([id_col])
  
      events, start, stop = (
          pass_for_numeric_dtypes_or_raise_array(
              df.pop("event")
          ).astype(bool),
          df.pop("start"),
          df.pop("stop"),
      )
      weights = df.pop("__weights").astype(float)
  
      self.regressors = utils.CovariateParameterMappings(
          {"beta_": self.formula}, df, force_no_intercept=True
      )
      X = self.regressors.transform_df(df)["beta_"]
  
      self._check_values(X, events, start, stop)
  
      self._norm_mean = X.mean(0)
      self._norm_std = X.std(0)
  
      (
          beta_,
          self.log_likelihood_,
          self._hessian_,
      ) = self._newton_raphson_for_efron_model(
          normalize(X, self._norm_mean, self._norm_std),
          events,
          start,
          stop,
          weights,
          initial_point=initial_point,
          show_progress=show_progress,
          **utils.coalesce(fit_options, {}),
      )
  
      self.params_ = (
          pd.Series(
              beta_,
              index=pd.Index(X.columns, name="covariate"),
              name="coef",
          )
          / self._norm_std
      )
      if self._hessian_.size > 0:
          # possible if the df is trivial (no covariate columns)
          self.variance_matrix_ = pd.DataFrame(
              -inv(self._hessian_)
              / np.outer(self._norm_std, self._norm_std),
              index=X.columns,
          )
  
      else:
          self.variance_matrix_ = pd.DataFrame(
              index=X.columns, columns=X.columns
          )
  
      self.standard_errors_ = self._compute_standard_errors(
          normalize(X, self._norm_mean, self._norm_std),
          events,
          start,
          stop,
          weights,
      )
      self.confidence_intervals_ = self._compute_confidence_intervals()
      self.baseline_cumulative_hazard_ = (
          self._compute_cumulative_baseline_hazard(
              df, events, start, stop, weights
          )
      )
      self.baseline_survival_ = self._compute_baseline_survival()
      self.event_observed = events
      self.start_stop_and_events = pd.DataFrame(
          {"event": events, "start": start, "stop": stop}
      )
      self.weights = weights
  
      self._n_examples = X.shape[0]
      self._n_unique = X.index.unique().shape[0]
      return self
  
imports: from datetime import datetime
  import warnings
  import time
  from typing import Optional
  import numpy
  import pandas
  from scipy import stats
  from numpy.linalg import norm, inv
  from numpy import sum
  from scipy.linalg import solve, LinAlgError
  from autograd import elementwise_grad
  from autograd import numpy
  from lifelines.fitters import SemiParametricRegressionFitter
  from lifelines.fitters.mixins import ProportionalHazardMixin
  from lifelines.utils.printer import Printer
  from lifelines.statistics import _chisq_test_p_value, StatisticalResult
  from lifelines.exceptions import ConvergenceError, ConvergenceWarning
  from lifelines.utils import _get_index, _to_list, check_for_numeric_dtypes_or_raise, check_low_var, check_complete_separation_low_variance, check_for_immediate_deaths, check_for_instantaneous_events_at_time_zero, check_for_instantaneous_events_at_death_time, check_for_nonnegative_intervals, pass_for_numeric_dtypes_or_raise_array, inv_normal_cdf, normalize, StepSizer, check_nans_or_infs, string_rjustify, coalesce
  from lifelines import utils
label_desc: Use image node_id 2 for calling the CoxTimeVaryingFitter obj's underlying member method code with example usage: obj.fit(df, event_col, start_col, stop_col, weights_col, id_col, show_progress, robust, strata, initial_point, formula, fit_options) and returns: self