def _survdiff(time, status, group, weight_type, gr, **kwargs):
    # logrank test for one stratum

    ii = (group == gr[0])
    time1 = time[ii]
    status1 = status[ii]
    ii = (group == gr[1])
    time2 = time[ii]
    status2 = status[ii]

    # Get the unique times.
    utimes = np.unique(time)

    status1 = status1.astype(np.bool)
    status2 = status2.astype(np.bool)

    # The positions of the observed event times in each group, in the
    # overall list of unique times.
    ix1 = np.searchsorted(utimes, time1[status1])
    ix2 = np.searchsorted(utimes, time2[status2])

    # Number of events observed at each time point, per group and
    # overall.
    obs1 = np.bincount(ix1, minlength=len(utimes))
    obs2 = np.bincount(ix2, minlength=len(utimes))
    obs = obs1 + obs2

    # Risk set size at each time point, per group and overall.
    nvec = []
    for time0 in time1, time2:
        ix = np.searchsorted(utimes, time0)
        n = np.bincount(ix, minlength=len(utimes))
        n = np.cumsum(n)
        n = np.roll(n, 1)
        n[0] = 0
        n = len(time0) - n
        nvec.append(n)
    n1, n2 = tuple(nvec)
    n = n1 + n2

    # The variance of event counts in the first group.
    r = n1 / n.astype(np.float64)
    var = obs * r * (1 - r) * (n - obs) / (n - 1)

    # The expected number of events in the first group.
    exp1 = obs * r

    weights = None
    if weight_type is not None:
        weight_type = weight_type.lower()
        if weight_type == "gb":
            weights = n
        elif weight_type == "tw":
            weights = np.sqrt(n)
        elif weight_type == "fh":
            if "fh_p" not in kwargs:
                raise ValueError("weight_type type 'fh' requires specification of fh_p")
            fh_p = kwargs["fh_p"]
            # Calculate the survivor function directly to avoid the
            # overhead of creating a SurvfuncRight object
            sp = 1 - obs / n.astype(np.float64)
            sp = np.log(sp)
            sp = np.cumsum(sp)
            sp = np.exp(sp)
            weights = sp**fh_p
            weights = np.roll(weights, 1)
            weights[0] = 1
        else:
            raise ValueError("weight_type not implemented")

    # The Z-scale test statistic (compare to normal reference
    # distribution).
    ix = np.flatnonzero(n > 1)
    if weights is None:
        obs = np.sum(obs1[ix] - exp1[ix])
        var = np.sum(var[ix])
    else:
        obs = np.dot(weights[ix], obs1[ix] - exp1[ix])
        var = np.dot(weights[ix]**2, var[ix])

    return obs, var
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/duration/survfunc.py/_survdiff/original