
    M/Ph[j                         d dl Zd dlZd dlmZmZ d dlmZ 	 	 ddZ	ddZ
d Z G d d	          Z G d
 d          Z	 	 ddZddZddZdS )    N)chi2norm)utilsTc                    |t          j        | d          \  }}nFt          j        | |f          }t          j        |d          \  }}|dt          |                    }t          |          }	|t          j        |||	          }
nt          j        |||z  |	          }
|t          j        ||	          }nt          j        |||	          }|{t          j        |          |z
  }t          j        ||d          }|t          j        ||	          }nt          j        |||	          }t          j        |          |z
  }||z
  }n&t          j        |ddd	                   ddd	         }|r0t          j        |
dk              }|
|         }
||         }||         }d
|
|                    t           j	                  z  z
  }|dk     }d||<   t          j
        |          }t          j        |          }t          j        |          }d||<   |s|||||
fS ||||
z
  z  }t          j        |dt           j                  }|
|                    t           j	                  z  }t           j        |||
k    |dk    z  <   t          j        |          }t          j        |          }t          j        |          |dk    z  }||xx         ||         z  cc<   t           j        || <   nM|
||z                      t           j	                  z  }t          j        |          }t          j        |          }||||||
fS )zX
    Calculate the survival function and its standard error for a single
    group.
    NTreturn_inverser   weights	minlengthr   leftside   gؗҜ<g-q=)npuniqueconcatenatelenbincountcumsumsearchsortedflatnonzeroastypefloat64logexpclipinfnansqrtisfinite)timestatusr
   entrycompressretallutimertimetxmldnrentryn0iispdenomselocss                      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/duration/survfunc.py_calc_survfunc_rightr6      s)    }yd;;;uu^T5M**yD999uaD		k" 
UBKv<<<Kvg~DDD K,,,Kw"===IaLL1F;;;?Vr222BBVWCCCBYr]]RFIa"gttt$  ^AE""bEbEb	 
Q"*%%%	%B	eBBrF	B	2B	BBrF &5%A%% QUubf--bj)))"$&AFqAvYr]]WR[[{2"'*
4BtHFD5		 !a%
+++Yr]]WR[[r5%A%%    c                 v   |dk                         t          j                  }t          | ||dd          \  }}}}}t	          |                                          }	g }t          |	          D ]}
||
dz   k                         t          j                  }|%t          j        ||t          |                    }n't          j        |||z  t          |                    }|	                    |           g }t          j
        d|dd         f         |z  }t          |	          D ]4}
t          j        |||
         z            }|	                    |           5||d|fS g }t          |          }t          |	          D ],}
||||z
  z  z  }||
         dz  t          j        |          z  }|d||
         z  t          j        ||
         |z            z  z  }|t          j        ||
         dz  |z            z  }|||
         z
  ||
         z  |z  }|t          j        |dz  |z            z  }|||
         z  |z  }|d||
         z  t          j        |          z  z  }|dt          j        ||
         |z            z  z  }|	                    t          j        |                     .|||fS )zM
    Calculate the cumulative incidence function and its standard error.
    r   F)r&   r'   Nr	   r      )r   r   r   r6   intmaxranger   r   appendr_r   sumr!   )r#   r$   r
   status0r1   r(   r)   r-   r,   ngrpkd0ipsp0ip0r3   daravs                      r5   _calc_incidence_rightrJ   V   s    {""2:..G1$;@P P PBua vzz||D 	A4[[  QU?**2:66?UGs5zzJJJBBUGGO'*5zz3 3 3B	 
B
%2crc7

a
C4[[  iad
##
		# 4	B	QB4[[  1B< qE1Hry}}$	QAY2a52:....	RYr!uax"}%%%!A$h!A$"	RYsAv{###1Q4Z!^	QAY2&&	Q2a52:&&&&
		"'!**r5=r7   c                    t          |           t          |          k    rt          d          |1t          |          t          |           k    rd}t          |          |)t          j        || k              rd}t          |          |/t          |          t          |           k    rt          d          |-|j        d         t          |           k    rt          d          d S d S )Nz)time and status must have the same lengthz5entry times and event times must have the same lengthz2Entry times must not occur on or after event timesz2weights, time and status must have the same lengthr   z'the rows of exog should align with time)r   
ValueErrorr   anyshape)r#   r$   r%   freq_weightsexogmsgs         r5   
_checkargsrR      s    
4yyCKKDEEEc%jjCII55EooRVETM22BooS%6%6#d))%C%CMNNNTZ]c$ii77BCCC 77r7   c                       e Zd ZdZ	 	 ddZdS )CumIncidenceRighta
  
    Estimation and inference for a cumulative incidence function.

    If J = 1, 2, ... indicates the event type, the cumulative
    incidence function for cause j is:

    I(t, j) = P(T <= t and J=j)

    Only right censoring is supported.  If frequency weights are provided,
    the point estimate is returned without a standard error.

    Parameters
    ----------
    time : array_like
        An array of times (censoring times or event times)
    status : array_like
        If status >= 1 indicates which event occurred at time t.  If
        status = 0, the subject was censored at time t.
    title : str
        Optional title used for plots and summary output.
    freq_weights : array_like
        Optional frequency weights
    exog : array_like
        Optional, if present used to account for violation of
        independent censoring.
    bw_factor : float
        Band-width multiplier for kernel-based estimation.  Only
        used if exog is provided.
    dimred : bool
        If True, proportional hazards regression models are used to
        reduce exog to two columns by predicting overall events and
        censoring in two separate models.  If False, exog is used
        directly for calculating kernel weights without dimension
        reduction.

    Attributes
    ----------
    times : array_like
        The distinct times at which the incidence rates are estimated
    cinc : list of arrays
        cinc[k-1] contains the estimated cumulative incidence rates
        for outcome k=1,2,...
    cinc_se : list of arrays
        The standard errors for the values in `cinc`.  Not available when
        exog and/or frequency weights are provided.

    Notes
    -----
    When exog is provided, a local estimate of the cumulative incidence
    rate around each point is provided, and these are averaged to
    produce an estimate of the marginal cumulative incidence
    functions.  The procedure is analogous to that described in Zeng
    (2004) for estimation of the marginal survival function.  The
    approach removes bias resulting from dependent censoring when the
    censoring becomes independent conditioned on the columns of exog.

    References
    ----------
    The Stata stcompet procedure:
        http://www.stata-journal.com/sjpdf.html?articlenum=st0059

    Dinse, G. E. and M. G. Larson. 1986. A note on semi-Markov models
    for partially censored data. Biometrika 73: 379-386.

    Marubini, E. and M. G. Valsecchi. 1995. Analysing Survival Data
    from Clinical Trials and Observational Studies. Chichester, UK:
    John Wiley & Sons.

    D. Zeng (2004).  Estimating marginal survival function by
    adjusting for dependent censoring using many covariates.  Annals
    of Statistics 32:4.
    https://arxiv.org/pdf/math/0409180.pdf
    N      ?Tc                 ,   t          ||d |d            t          j        |          x}| _        t          j        |          x}| _        |t          j        |          x}| _        |gddlm} t          j        |          x}| _        |j	        d         }	|	dz  |z  fd}
 |||||
||          }|d         | _
        |d         | _        d S t          |||          }|d         | _        |d         | _        |d         | _
        |sdn|| _        d S )Nr   )_kernel_cumincidencer   UUUUUUտc                 f    t          j        | dz   dz  z                                d          S Nr9   r   r   r   r?   xkws    r5   <lambda>z,CumIncidenceRight.__init__.<locals>.<lambda>   -    bfadURU]3377:: r7   r9    )rR   r   asarrayr#   r$   rO   _kernel_estimatesrW   rP   rN   timescincrJ   cinc_setitle)selfr#   r$   rg   rO   rP   	bw_factordimredrW   nobskfuncr]   r^   s               @r5   __init__zCumIncidenceRight.__init__   s9    	4|T::::d+++ty!z&111#/1z,/G/GGL4,??????!z$///D49:a=D)+B::::E$$T64%+- -A1DJ!DIF!$==aD	tqT
$/RR%


r7   )NNNrU   T)__name__
__module____qualname____doc__rm    r7   r5   rT   rT      s>        H HT ?C150 0 0 0 0 0r7   rT   c                   B    e Zd ZdZ	 	 ddZddZd Zdd	Zd
 ZddZ	dS )SurvfuncRighta
  
    Estimation and inference for a survival function.

    The survival function S(t) = P(T > t) is the probability that an
    event time T is greater than t.

    This class currently only supports right censoring.

    Parameters
    ----------
    time : array_like
        An array of times (censoring times or event times)
    status : array_like
        Status at the event time, status==1 is the 'event'
        (e.g. death, failure), meaning that the event
        occurs at the given value in `time`; status==0
        indicates that censoring has occurred, meaning that
        the event occurs after the given value in `time`.
    entry : array_like, optional An array of entry times for handling
        left truncation (the subject is not in the risk set on or
        before the entry time)
    title : str
        Optional title used for plots and summary output.
    freq_weights : array_like
        Optional frequency weights
    exog : array_like
        Optional, if present used to account for violation of
        independent censoring.
    bw_factor : float
        Band-width multiplier for kernel-based estimation.  Only used
        if exog is provided.

    Attributes
    ----------
    surv_prob : array_like
        The estimated value of the survivor function at each time
        point in `surv_times`.
    surv_prob_se : array_like
        The standard errors for the values in `surv_prob`.  Not available
        if exog is provided.
    surv_times : array_like
        The points where the survival function changes.
    n_risk : array_like
        The number of subjects at risk just before each time value in
        `surv_times`.  Not available if exog is provided.
    n_events : array_like
        The number of events (e.g. deaths) that occur at each point
        in `surv_times`.  Not available if exog is provided.

    Notes
    -----
    If exog is None, the standard Kaplan-Meier estimator is used.  If
    exog is not None, a local estimate of the marginal survival
    function around each point is constructed, and these are then
    averaged.  This procedure gives an estimate of the marginal
    survival function that accounts for dependent censoring as long as
    the censoring becomes independent when conditioning on the
    covariates in exog.  See Zeng et al. (2004) for details.

    References
    ----------
    D. Zeng (2004).  Estimating marginal survival function by
    adjusting for dependent censoring using many covariates.  Annals
    of Statistics 32:4.
    https://arxiv.org/pdf/math/0409180.pdf
    NrU   c                    t          |||||           t          j        |          x}| _        t          j        |          x}| _        |t          j        |          x}| _        |t          j        |          x}| _        |w|t          d          ddlm	} t          j        |          x}| _
        |j        d         }	|	dz  |z  fd}
 |||||
|          }|d         | _        |d         | _        d S t          ||||          }|d         | _        |d         | _        |d         | _        |d	         | _        |d
         | _        |sdn|| _        d S )Nz%exog and entry cannot both be presentr   )_kernel_survfuncr   rX   c                 f    t          j        | dz   dz  z                                d          S rZ   r[   r\   s    r5   r_   z(SurvfuncRight.__init__.<locals>.<lambda>^  r`   r7   )r
   r%   r9         ra   )rR   r   rb   r#   r$   rO   r%   rL   rc   rv   rP   rN   	surv_prob
surv_timesr6   surv_prob_sen_riskn_eventsrg   )rh   r#   r$   r%   rg   rO   rP   ri   rv   rk   rl   r]   r^   s               @r5   rm   zSurvfuncRight.__init__K  s    	4d;;;:d+++ty!z&111#/1z,/G/GGL4,!#E!2!22EDJ  !HIII;;;;;;!z$///D49:a=D)+B::::E  vtULIIAqTDNdDOF v|',. . . 1aDA$d!$/RR%


r7   c                 "    t          | |          S )a  
        Plot the survival function.

        Examples
        --------
        Change the line color:

        >>> import statsmodels.api as sm
        >>> data = sm.datasets.get_rdataset("flchain", "survival").data
        >>> df = data.loc[data.sex == "F", :]
        >>> sf = sm.SurvfuncRight(df["futime"], df["death"])
        >>> fig = sf.plot()
        >>> ax = fig.get_axes()[0]
        >>> li = ax.get_lines()
        >>> li[0].set_color('purple')
        >>> li[1].set_color('purple')

        Do not show the censoring points:

        >>> fig = sf.plot()
        >>> ax = fig.get_axes()[0]
        >>> li = ax.get_lines()
        >>> li[1].set_visible(False)
        )plot_survfunc)rh   axs     r5   plotzSurvfuncRight.plotn  s    4 T2&&&r7   c                     t          j        | j        d|z
  k               }t          |          dk    rt           j        S | j        |d                  S )z
        Estimated quantile of a survival distribution.

        Parameters
        ----------
        p : float
            The probability point at which the quantile
            is determined.

        Returns the estimated quantile.
        r   r   )r   r   rz   r   r    r{   )rh   pr0   s      r5   quantilezSurvfuncRight.quantile  sE     ^DNQU233r77a<<6Mr!u%%r7   皙?cloglogc                    t          j        d|dz  z
            }|                                }|dk    rd }d }nL|dk    rd }d }n?|d	k    rt          j        }d
 }n)|dk    rd }d }n|dk    rd }d }nt          d           || j                   |d|z
            z
  }| || j                  | j        z  z  }t          j        t          j	        |          |k              }t          |          dk    rt          j        t          j        fS | j        |d                  }	|d         t          | j                  dz
  k    rt          j        }
n| j        |d         dz            }
|	|
fS )a  
        Returns a confidence interval for a survival quantile.

        Parameters
        ----------
        p : float
            The probability point for which a confidence interval is
            determined.
        alpha : float
            The confidence interval has nominal coverage probability
            1 - `alpha`.
        method : str
            Function to use for g-transformation, must be ...

        Returns
        -------
        lb : float
            The lower confidence limit.
        ub : float
            The upper confidence limit.

        Notes
        -----
        The confidence interval is obtained by inverting Z-tests.  The
        limits of the confidence interval will always be observed
        event times.

        References
        ----------
        The method is based on the approach used in SAS, documented here:

          http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_lifetest_details03.htm
        r   r9   r   c                 P    t          j        t          j        |                      S Nr   r   r]   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    "&"&)),, r7   c                 6    d| t          j        |           z  z  S )Nr   r   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    rQ]3 r7   linearc                     | S r   rr   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    ! r7   c                     dS Nr   rr   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    q r7   r   c                     d| z  S r   rr   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s
    q1u r7   logitc                 6    t          j        | d| z
  z            S r   r   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    "&a!e-- r7   c                     d| d| z
  z  z  S r   rr   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    qAQK0 r7   asinsqrtc                 N    t          j        t          j        |                     S r   )r   arcsinr!   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s    ")BGAJJ// r7   c                 f    ddt          j        |           z  t          j        d| z
            z  z  S )Nr   r9   )r   r!   r   s    r5   r_   z+SurvfuncRight.quantile_ci.<locals>.<lambda>  s(    qA

NRWQU^^$CD r7   zunknown methodr   r   )r   ppflowerr   r   rL   rz   r|   r   absr   r    r{   r   )rh   r   alphamethodtrggprimerr0   lbubs              r5   quantile_cizSurvfuncRight.quantile_ci  s   F Xa%!)m$$Y,,A33FFxA [FFu__A$_FFw--A00FFz!!//ADDFF-...Adn!a%(	ffT^$$t'889^BF1IIO,,r77a<<626>!_RU#b6S))A---BBB!,B2vr7   c                     t          j        | j                  }d|j        _        | j        |d<   | j        |d<   | j        |d<   | j        |d<   |S )z
        Return a summary of the estimated survival function.

        The summary is a dataframe containing the unique event times,
        estimated survival function values, and related quantities.
        )indexTimez	Surv probzSurv prob SEznum at riskz
num events)	pd	DataFramer{   r   namerz   r|   r}   r~   )rh   dfs     r5   summaryzSurvfuncRight.summary  sV     \000.;!.> K==<	r7   hwr   c                    |                                 }|dk    rd}t          |          |dk    rt          d          |                                 }| j        dz  | j        dz  z  }| j        }|dk    rit          j        |          t          j        | j                  z  }dd||z  z   z  |z  }t          j        |          }| j        d|z  z  }	| j        |z  }
n|d	k    rd}|d||z  z   dt          j        |          z  z  z  }|t          j        | j        d| j        z
  z            z  }t          j	        t          j        | j                            }t          j
        ||z
  d
t
          j                  }t          j        |          dz  }	t          j
        ||z   t
          j         t
          j        dz            }t          j        |          dz  }
nt          d          |	|
fS )a  
        Returns a simultaneous confidence band for the survival function.

        Parameters
        ----------
        alpha : float
            `1 - alpha` is the desired simultaneous coverage
            probability for the confidence region.  Currently alpha
            must be set to 0.05, giving 95% simultaneous intervals.
        method : str
            The method used to produce the simultaneous confidence
            band.  Only the Hall-Wellner (hw) method is currently
            implemented.
        transform : str
            The used to produce the interval (note that the returned
            interval is on the survival probability scale regardless
            of which transform is used).  Only `log` and `arcsin` are
            implemented.

        Returns
        -------
        lcb : array_like
            The lower confidence limits corresponding to the points
            in `surv_times`.
        ucb : array_like
            The upper confidence limits corresponding to the points
            in `surv_times`.
        r   z0only the Hall-Wellner (hw) method is implementedr   zalpha must be set to 0.05r9   r   g_)Ǻ?r   r   r   zUnknown transform)r   rL   r|   rz   r}   r   r!   r   r   r   r   r   sinpi)rh   r   r   	transformrQ   s2nnr2   thetalcbucbrB   frI   s                 r5   simultaneous_cbzSurvfuncRight.simultaneous_cb  s   < T>>DCS//!D==8999OO%%	!DNA$55[GBKK"&"8"88Ea"r'k*U2EF5MME.1U7+C.%'CC(""A!b2g+!bgbkk/22A1t~+=>???A	"'$.1122AAq"&))A&))Q,CAwa00A&))Q,CC0111Cxr7   )NNNNrU   r   )r   r   )r   r   r   )
rn   ro   rp   rq   rm   r   r   r   r   r   rr   r7   r5   rt   rt     s        A AF 8<9;!0 !0 !0 !0F' ' ' '8& & &*F F F FP  "; ; ; ; ; ;r7   rt   c           	      b   t          j        |           } t          j        |          }t          j        |          }t          j        |          }|t          | |||||fi |\  }}	nit          j        |          }t          j        |          }
d\  }}	|
D ]9}||k    }t          | |         ||         ||         |||fi |\  }}||z  }|	|z  }	:|                    t           j                            |	|                    }dt          j        |t          |          dz
            z
  }||fS )a9  
    Test for the equality of two survival distributions.

    Parameters
    ----------
    time : array_like
        The event or censoring times.
    status : array_like
        The censoring status variable, status=1 indicates that the
        event occurred, status=0 indicates that the observation was
        censored.
    group : array_like
        Indicators of the two groups
    weight_type : str
        The following weight types are implemented:
            None (default) : logrank test
            fh : Fleming-Harrington, weights by S^(fh_p),
                 requires exponent fh_p to be provided as keyword
                 argument; the weights are derived from S defined at
                 the previous event time, and the first weight is
                 always 1.
            gb : Gehan-Breslow, weights by the number at risk
            tw : Tarone-Ware, weights by the square root of the number
                 at risk
    strata : array_like
        Optional stratum indicators for a stratified test
    entry : array_like
        Entry times to handle left truncation. The subject is not in
        the risk set on or before the entry time.

    Returns
    -------
    chisq : The chi-square (1 degree of freedom) distributed test
            statistic value
    pvalue : The p-value for the chi^2 test
    N)        r   r   )
r   rb   r   	_survdiffdotlinalgsolver   cdfr   )r#   r$   groupweight_typestratar%   kwargsgrobsvarstustr0   obs1var1chisqpvalues                    r5   survdiffr   6  sR   N :dDZFJuE	5		B~T65+r". .&,. .SS F##iS 	 	BB,B"48VBZr#.EE E=CE EJD$4KC4KCCGGBIOOC--..E%R+++F&=r7   c                    |t          j        | d          \  }}nDt          j        t          j        | |f          d          \  }}|dt          |                    }d |D             }	|6t	          |          D ]&\  }
}|||
         k    }||         }||
         |f|	|
<   'g g }}t          |          }|	D ]\  }}||k    }t          j        |||          }t          j        |||z  |          }|                    |           |at          j        |          |z
  }t          j        ||d          }t          j        ||          }t          j        |          |z
  }||z
  }n&t          j        |d d d	                   d d d	         }|                    |           t          |          }t          |          }t          j
        |d
k              }d }||                                }|dk    r|}n|dk    rt          j        |          }n|dk    rd|vrd}t          |          |d         }d
||                    t           j                  z  z
  }t          j        |          }t          j        |          }t          j        |          }||z  }t          j        |d
          }d
|d<   nt          d          t          |          d
z
  } t          j        |          t          j        |dt           j                  d d d f         z  }!g }"g }#|d
z
  }$t          j        |$dt           j                  }$t-          d
| d
z             D ]}||         |!|         |z  z
  }%|!d
d d d f         j        t          j        d
| |d
z
                                            |!|d d d f         z
  z  }&|||z
  z  |$z  }'|&|'d d d f         z  }(|||%z  }%|dz  d d d f         |(z  }(|"                    |%|         	                                           |#                    |(|         	                    d                     t          j        |"          })t          j        |#          }*|)|*fS )NTr   r   c                     g | ]}|d fS r   rr   ).0gr_is     r5   
<listcomp>z_survdiff.<locals>.<listcomp>  s    
'
'
'DD$<
'
'
'r7   r	   r   r   r   r   r   gbtwfhfh_pz4weight_type type 'fh' requires specification of fh_pzweight_type not implementedg|=r9   )axis)r   r   r   r   	enumerater   r=   r   r   r?   r   r   r!   rL   r   r   r   r   rollvstackr   r   r<   Teyeravelhstack)+r#   r$   r   r   r   r%   r   utimesrtimestserB   _r0   entry1nriskobsvr+   r   entry0mkr-   obr.   r/   nrr   	nrisk_totixr
   rQ   r   r1   dfsr   	groups_oe
groups_var	var_denomoevar_tensor_partvar_scalar_partr   obs_vecvar_mats+                                              r5   r   r   x  s    }4===2>4-#@#@268 8 8#d))$ (
'B
'
'
'CbMM 	% 	%DAq2a5.B2YFeV_CFF b4E	VB  	6qjKb999[bAAAB	!q A_VV&AAAFVr222B2#BaBB1TTrT7##DDbD)BR
d))CE

I		A	&	&BG!''))$GGD  gi((GGD  V##L oo%&>D S9++BJ7777BB2BB$hGggq))GGAJJ:;;;
b''A+C
	%279eRV<<T111WEEA IJAI	5"&11I 1c!e__ / /!WqtCx ABBE(*q#qs(;(;(A(A(C(Ca111d
m(STS1I=4 882BA:qqq$w'#-C 	B&&&#b'++1+--....i	""Gi
##GGr7   c           
         t          j        |          \  }}	 t          | d                   t          u sJ n
#  | g} Y nxY wt	          |           D ]`\  }}t          j        dg|j        f          }t          j        dg|j        f          }t          |j
                  }||d         k    r4t          j        ||gf          }t          j        ||d         gf          }t          |dd|dz   z            }|                    ||d|dd	          \  }	t          j        t          j        |j                            }
t          j        |j
        |
                   }t          j        ||          dz
  }||         }|                    ||d
d|	                                |dz              b|                    dd           |S )a  
    Plot one or more survivor functions.

    Parameters
    ----------
    survfuncs : object or array_like
        A single SurvfuncRight object, or a list or SurvfuncRight
        objects that are plotted together.

    Returns
    -------
    A figure instance on which the plot was drawn.

    Examples
    --------
    Add a legend:

    >>> import statsmodels.api as sm
    >>> from statsmodels.duration.survfunc import plot_survfunc
    >>> data = sm.datasets.get_rdataset("flchain", "survival").data
    >>> df = data.loc[data.sex == "F", :]
    >>> sf0 = sm.SurvfuncRight(df["futime"], df["death"])
    >>> sf1 = sm.SurvfuncRight(3.0 * df["futime"], df["death"])
    >>> fig = plot_survfunc([sf0, sf1])
    >>> ax = fig.get_axes()[0]
    >>> ax.set_position([0.1, 0.1, 0.64, 0.8])
    >>> ha, lb = ax.get_legend_handles_labels()
    >>> leg = fig.legend((ha[0], ha[1]), (lb[0], lb[1]), loc='center right')

    Change the line colors:

    >>> fig = plot_survfunc([sf0, sf1])
    >>> ax = fig.get_axes()[0]
    >>> ax.set_position([0.1, 0.1, 0.64, 0.8])
    >>> ha, lb = ax.get_legend_handles_labels()
    >>> ha[0].set_color('purple')
    >>> ha[1].set_color('orange')
    r   r   r   rg   zGroup %d-r9   post)labellwwhere+   z points)mscolorr   g)\(?)r   create_mpl_axtypert   r   r   r   r{   rz   r;   r#   getattrstepr   logical_notr$   r   r   r   	get_colorset_ylim)	survfuncsr   figgxsfr{   rz   mxtr   lir0   tijjr1   s                 r5   r   r     s   P !"%%GC IaL!!]22222 K			I&& ) )B ^aS"-$899
NQC#677	 "'llBcU(;<<J	IbM?'CDDIGZ26%:;;ggj)S!"  $ $ ^BN295566Yrwr{##_Z,,q0r]
B",,..i' 	 	) 	) 	) 	) KK4Js   8 ?)NNTTr   )NNN)numpyr   pandasr   scipy.stats.distributionsr   r   statsmodels.graphicsr   r6   rJ   rR   rT   rt   r   r   r   rr   r7   r5   <module>r     sN           0 0 0 0 0 0 0 0 & & & & & & KO $L& L& L& L&^3 3 3 3lD D D(d0 d0 d0 d0 d0 d0 d0 d0Nl l l l l l l l^	 <@? ? ? ?Dh h h hVN N N N N Nr7   