ó
áp7]c           @   sÂ   d  d l  Z d  d l Z d  d l m Z m Z d  d l m Z e	 e	 e
 e
 d „ Z e	 d „ Z d „  Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ e	 e	 e	 d „ Z e	 d „ Z e	 d „ Z d S(   iÿÿÿÿN(   t   chi2t   norm(   t   utilsc         C   s‹  | d k r* t j |  d t ƒ\ } } nC t j |  | f ƒ } t j | d t ƒ\ } } | d t |  ƒ !} t | ƒ }	 | d k r£ t j | d | d |	 ƒ}
 n t j | d | | d |	 ƒ}
 | d k ræ t j | d |	 ƒ} n t j | d | d |	 ƒ} | d k	 r—t j | ƒ | } t j | | d d ƒ} | d k r\t j | d |	 ƒ} n t j | d | d |	 ƒ} t j | ƒ | } | | } n) t j | d d d … ƒ d d d … } | rüt j	 |
 d k ƒ } |
 | }
 | | } | | } n  d	 |
 | j
 t j ƒ } | d
 k  } d
 | | <t j | ƒ } t j | ƒ } t j | ƒ } d | | <| s|| | | | |
 f S| d k r=| | |
 } t j | d t j ƒ } |
 | j
 t j ƒ } t j | | |
 k | d k B<t j | ƒ } t j | ƒ } t j | ƒ | d k B} | | c | | 9<t j | | <n8 |
 | | j
 t j ƒ } t j | ƒ } t j | ƒ } | | | | | |
 f S(   sX   
    Calculate the survival function and its standard error for a single
    group.
    t   return_inversei    t   weightst	   minlengtht   sidet   leftNiÿÿÿÿi   g¼‰Ø—²Òœ<gê-™—q=(   t   Nonet   npt   uniquet   Truet   concatenatet   lent   bincountt   cumsumt   searchsortedt   flatnonzerot   astypet   float64t   logt   expt   clipt   inft   nant   sqrtt   isfinite(   t   timet   statusR   t   entryt   compresst   retallt   utimet   rtimet   txt   mlt   dt   nt   rentryt   n0t   iit   spt   denomt   set   locs(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   _calc_survfunc_right   sb    )



c         C   s«  | d k j  t j ƒ } t |  | | d t d t ƒ\ } } } } } t | j ƒ  ƒ }	 g  } x’ t |	 ƒ D]„ }
 | |
 d k j  t j ƒ } | d k r¼ t j	 | d | d t
 | ƒ ƒ} n% t j	 | d | | d t
 | ƒ ƒ} | j | ƒ qj Wg  } t j d | d  f | } x8 t |	 ƒ D]* }
 t j | | |
 ƒ } | j | ƒ q W| d k	 rg| d | f Sg  } t | ƒ } x"t |	 ƒ D]}
 | | | | } | |
 d t j | ƒ } | d | |
 t j | |
 | ƒ 8} | t j | |
 d | ƒ 7} | | |
 | |
 | } | t j | d | ƒ 7} | | |
 | } | d | |
 t j | ƒ 8} | d t j | |
 | ƒ 7} | j t j | ƒ ƒ q†W| | | f S(	   sM   
    Calculate the cumulative incidence function and its standard error.
    i   R   R   R   R   iÿÿÿÿi   N(   R   R	   R   R-   t   Falset   intt   maxt   rangeR   R   R   t   appendt   r_R   t   sumR   (   R   R   R   t   status0R)   R    R!   R%   R$   t   ngrpt   kt   d0t   ipt   sp0t   ip0R+   t   dat   rat   v(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   _calc_incidence_rightV   sB    $'c         C   s  t  |  ƒ t  | ƒ k r' t d ƒ ‚ n  | d  k	 r` t  | ƒ t  |  ƒ k r` d } t | ƒ ‚ n  | d  k	 r– t j | |  k ƒ r– d } t | ƒ ‚ n  | d  k	 rÉ t  | ƒ t  |  ƒ k rÉ t d ƒ ‚ n  | d  k	 rý | j d t  |  ƒ k rý t d ƒ ‚ n  d  S(   Ns)   time and status must have the same lengths5   entry times and event times must have the same lengths2   Entry times must not occur on or after event timess2   weights, time and status must have the same lengthi    s'   the rows of exog should align with time(   R   t
   ValueErrorR   R	   t   anyt   shape(   R   R   R   t   freq_weightst   exogt   msg(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt
   _checkargsŒ   s    $!$%t   CumIncidenceRightc           B   s&   e  Z d  Z d d d d e d „ Z RS(   sô
  
    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 occured at time t.  If
        status = 0, the subject was censored at time t.
    title : string
        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 : boolean
        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.
    http://arxiv.org/pdf/math/0409180.pdf
    g      ð?c            sR  t  | | d  | d  ƒ t j | ƒ } |  _ t j | ƒ } |  _ | d  k	 rg t j | ƒ } |  _ n  | d  k	 r d d l m } t j | ƒ } |  _	 | j
 d }	 |	 d d | ‰  ‡  f d †  }
 | | | | |
 | | ƒ } | d |  _ | d |  _ d  St | | | ƒ } | d |  _ | d |  _ | d |  _ | sEd n | |  _ d  S(	   Ni   (   t   _kernel_cumincidencei    iÿÿÿÿg      @c            s#   t  j |  d ˆ  d ƒ j d ƒ S(   Ni   i   (   R	   R   R4   (   t   x(   t   kw(    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   <lambda>ù   t    i   RL   (   RF   R   R	   t   asarrayR   R   RC   t   _kernel_estimatesRH   RD   RB   t   timest   cincR?   t   cinc_set   title(   t   selfR   R   RR   RC   RD   t	   bw_factort   dimredRH   t   nobst   kfuncRI   (    (   RJ   s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   __init__ë   s*    	N(   t   __name__t
   __module__t   __doc__R   R   RX   (    (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRG       s   It   SurvfuncRightc           B   se   e  Z d  Z d d d d d d „ Z d d „ Z d „  Z d d d „ Z d „  Z d d	 d
 d „ Z	 RS(   s
  
    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 occured, 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 : string
        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.
    http://arxiv.org/pdf/math/0409180.pdf
    g      ð?c            s²  t  | | | | | ƒ t j | ƒ } |  _ t j | ƒ } |  _ | d  k	 rg t j | ƒ } |  _ n  | d  k	 rŒ t j | ƒ } |  _ n  | d  k	 r=| d  k	 r³ t d ƒ ‚ n  d d l	 m
 } t j | ƒ } |  _ | j d }	 |	 d d | ‰  ‡  f d †  }
 | | | | |
 | ƒ } | d |  _ | d |  _ d  St | | d | d	 | ƒ} | d |  _ | d |  _ | d
 |  _ | d |  _ | d |  _ | s¥d n | |  _ d  S(   Ns%   exog and entry cannot both be presenti   (   t   _kernel_survfunci    iÿÿÿÿg      @c            s#   t  j |  d ˆ  d ƒ j d ƒ S(   Ni   i   (   R	   R   R4   (   RI   (   RJ   (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   ^  RL   R   R   i   i   i   RL   (   RF   R	   RM   R   R   R   RC   R   R@   RN   R]   RD   RB   t	   surv_probt
   surv_timesR-   t   surv_prob_set   n_riskt   n_eventsRR   (   RS   R   R   R   RR   RC   RD   RT   R]   RV   RW   RI   (    (   RJ   s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRX   K  s6    	c         C   s   t  |  | ƒ S(   s¦  
        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')

        Don't show the censoring points:

        >>> fig = sf.plot()
        >>> ax = fig.get_axes()[0]
        >>> li = ax.get_lines()
        >>> li[1].set_visible(False)
        (   t   plot_survfunc(   RS   t   ax(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   plotn  s    c         C   sD   t  j |  j d | k  ƒ } t | ƒ d k r5 t  j S|  j | d S(   sõ   
        Estimated quantile of a survival distribution.

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

        Returns the estimated quantile.
        i   i    (   R	   R   R^   R   R   R_   (   RS   t   pR(   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   quantileŠ  s    gš™™™™™©?t   cloglogc         C   s¤  t  j d | d ƒ } | j ƒ  } | d k rD d „  } d „  } n | d k re d „  } d „  } no | d	 k r† d
 „  } d „  } nN | d k r§ d „  } d „  } n- | d k rÈ d „  } d „  } n t d ƒ ‚ | |  j ƒ | d | ƒ } | | |  j ƒ |  j :} t j t j | ƒ | k ƒ } t	 | ƒ d k rKt j
 t j
 f S|  j | d }	 | d t	 |  j ƒ d k r…t j }
 n |  j | d d }
 |	 |
 f S(   så  
        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 : string
            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
        i   i   Rh   c         S   s   t  j t  j |  ƒ ƒ S(   N(   R	   R   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Æ  RL   c         S   s   d |  t  j |  ƒ S(   Niÿÿÿÿ(   R	   R   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ç  RL   t   linearc         S   s   |  S(   N(    (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   É  RL   c         S   s   d S(   Ni   (    (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ê  RL   R   c         S   s   t  j |  ƒ S(   N(   R	   R   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ì  RL   c         S   s   d |  S(   Ni   (    (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Í  RL   t   logitc         S   s   t  j |  d |  ƒ S(   Ni   (   R	   R   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ï  RL   c         S   s   d |  d |  S(   Ni   (    (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ð  RL   t   asinsqrtc         S   s   t  j t  j |  ƒ ƒ S(   N(   R	   t   arcsinR   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ò  RL   c         S   s&   d d t  j |  ƒ t  j d |  ƒ S(   Ni   i   (   R	   R   (   RI   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRK   Ó  RL   s   unknown methodi    iÿÿÿÿ(   R   t   ppft   lowerR@   R^   R`   R	   R   t   absR   R   R_   R   (   RS   Rf   t   alphat   methodt   trt   gt   gprimet   rR(   t   lbt   ub(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   quantile_ciŸ  s8    #					c         C   sY   t  j d |  j ƒ } d | j _ |  j | d <|  j | d <|  j | d <|  j | d <| S(   sÐ   
        Return a summary of the estimated survival function.

        The summary is a datafram containing the unique event times,
        estimated survival function values, and related quantities.
        t   indext   Times	   Surv probs   Surv prob SEs   num at risks
   num events(	   t   pdt	   DataFrameR_   Ry   t   nameR^   R`   Ra   Rb   (   RS   t   df(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   summaryç  s    t   hwR   c         C   sÖ  | j  ƒ  } | d k r- d } t | ƒ ‚ n  | d k rH t d ƒ ‚ n  | j  ƒ  } |  j d |  j d } |  j } | d k ræ t j | ƒ t j |  j ƒ } d d | | | } t j | ƒ } |  j d | }	 |  j | }
 næ | d	 k rÀd } | d | | d t j | ƒ 9} | t j |  j d |  j ƒ 9} t j	 t j |  j ƒ ƒ } t j
 | | d
 t j ƒ } t j | ƒ d }	 t j
 | | t j t j d ƒ } t j | ƒ d }
 n t d ƒ ‚ |	 |
 f S(   s$  
        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 : string
            The method used to produce the simultaneous confidence
            band.  Only the Hall-Wellner (hw) method is currently
            implemented.
        transform : string
            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€   s0   only the Hall-Wellner (hw) method is implementedgš™™™™™©?s   alpha must be set to 0.05i   R   g_)ËÇºõ?i   Rl   i    s   Unknown transform(   Rn   R@   R`   R^   Ra   R	   R   R   R   Rl   R   R   t   sint   pi(   RS   Rp   Rq   t	   transformRE   t   s2t   nnR*   t   thetat   lcbt   ucbR7   t   fR>   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   simultaneous_cbø  s4    	#!$N(
   RY   RZ   R[   R   RX   Re   Rg   Rx   R   RŠ   (    (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyR\     s   B"	H	c      	   K   sX  t  j |  ƒ }  t  j | ƒ } t  j | ƒ } t  j | ƒ } t | ƒ d k r] t d ƒ ‚ n  | d k r t |  | | | | | |  \ } }	 n‹ t  j | ƒ } t  j | ƒ }
 d \ } }	 x^ |
 D]V } | | k } t |  | | | | | | | | |  \ } } | | 7} |	 | 7}	 qÁ W| t  j |	 ƒ } | d } d t j	 | d ƒ } | | f S(   s;  
    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 occured, status=0 indicates that the observation was
        censored.
    group : array-like
        Indicators of the two groups
    weight_type : string
        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
    i   s    logrank only supports two groupsg        i   N(   g        g        (
   R	   RM   R
   R   R@   R   t	   _survdiffR   R    t   cdf(   R   R   t   groupt   weight_typet   strataR   t   kwargst   grt   obst   vart   stut   stR(   t   obs1t   var1t   zstatt   chisqt   pvalue(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   survdiff6  s,    )

c   #      K   s'  | d  k r* t j |  d t ƒ\ } } n= t j t j |  | f ƒ d t ƒ\ } } | d t |  ƒ !} | d d  f | d d  f g }	 | d  k	 rÕ x? d D]4 }
 | | |
 k } | | } | |
 | f |	 |
 <qš Wn  g  g  } } t | ƒ } x	|	 D]\ } } | | k } t j | d | d | ƒ} t j | d | | d | ƒ} | j | ƒ | d  k	 rÀt j | ƒ | } t j	 | | d d ƒ} t j | d | ƒ} t j | ƒ | } | | } n) t j | d  d  d … ƒ d  d  d … } | j | ƒ qõ Wt
 | ƒ } t
 | ƒ } | d t j | d	 t j ƒ } | d } t j | d	 t j ƒ } | | d | | | | } | | } d  } | d  k	 rƒ| j ƒ  } | d
 k r¯| } qƒ| d k rÍt j | ƒ } qƒ| d k rtd | k rúd } t | ƒ ‚ n  | d }  d | | j t j ƒ }! t j |! ƒ }! t j |! ƒ }! t j |! ƒ }! |! |  } t j | d ƒ } d | d <qƒt d ƒ ‚ n  t j | d k ƒ }" | d  k rÙt j
 | d |" | |" ƒ } t j
 | |" ƒ } nD t j | |" | d |" | |" ƒ } t j | |" d | |" ƒ } | | f S(   NR   i    i   R   R   R   R   iÿÿÿÿg»½×Ùß|Û=t   gbt   twt   fht   fh_ps4   weight_type type 'fh' requires specification of fh_ps   weight_type not implementedi   (   i    i   (   R   R	   R
   R   R   R   R   R2   R   R   R4   R   R   Rn   R   R@   R   R   R   R   t   rollR   t   dot(#   R   R   R   RŽ   R‘   R   R   t   utimest   rtimest   tseR7   R(   t   entry1t   nriskt   obsvR#   Rs   t   entry0t   mkR%   t   obR&   R'   t   nrR’   t	   nrisk_totRu   R*   R“   t   exp1R   RE   RŸ   R)   t   ix(    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyR‹     sx     
) 

	

&c         C   sÀ  t  j | ƒ \ } } y  t |  d ƒ t k s4 t ‚ Wn |  g }  n Xxat |  ƒ D]S\ } } t j d g | j f ƒ } t j d g | j	 f ƒ } t
 | j ƒ } | | d k rí t j | | g f ƒ } t j | | d g f ƒ } n  t | d d | d ƒ } | j | | d d | d d	 d
 d ƒ\ }	 t j t j | j ƒ ƒ }
 | j |
 } t j | | ƒ d } | | } | j | | d d d d |	 j ƒ  d | d ƒqU W| j d d ƒ | S(   s  
    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]), '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')
    i    i   iÿÿÿÿRR   s   Group %dt   -t   labelt   lwi   t   wheret   postt   +t   msi   t   colors    pointsg)\Âõ(ð?(   R   t   create_mpl_axt   typeR\   t   AssertionErrort	   enumerateR	   R   R_   R^   R0   R   t   getattrt   stepR   t   logical_notR   R   Re   t	   get_colort   set_ylim(   t	   survfuncsRd   t   figt   gxt   sfR_   R^   t   mxtR°   t   liR(   t   tit   jjR)   (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyRc   Û  s.    ( 
$(   t   numpyR	   t   pandasR{   t   scipy.stats.distributionsR    R   t   statsmodels.graphicsR   R   R   R-   R?   RF   t   objectRG   R\   R›   R‹   Rc   (    (    (    s<   lib/python2.7/site-packages/statsmodels/duration/survfunc.pyt   <module>   s   	N6	gÿ 0H\