# work our way backwards through the time series, randomly sampling confidence leve

    U = [0] * T_idx  # a place to store this replicate
    U[-1] = U_T
    impossibleFlag = False

    for t in tV:  # work our way backwards

        alpha = uniform.rvs()
        S0 = S[t - 1]
        S1 = S[t]
        U1 = U[t]
        d0 = d[t - 1]
        U[t - 1], impossibleFlag = find_U0_bnd(alpha, S0, S1, U1, d0,
                                               impossibleFlag, omega,
                                               biasedurn)

    # calculate X_t from U_t

    N = S[0] + E[0] + U[0]  # assumes X(0) = 0
    X = [N - EE - SS - UU for EE, SS, UU in zip(E, S, U)]

    # append results

    UM.append(U)
    XM.append(X)

# calculate statistics on sample
# ---
        U = [0] * T_idx  # a place to store this replicate
        U[-1] = U_T
        impossibleFlag = False

        for t in tV:

            S0 = S[t - 1]
            S1 = S[t]
            U1 = U[t]
            d0 = d[t - 1]

            # if type_of_ci == 'midp':
            alpha = stats.uniform.rvs()
            min_poss_U0 = max((min_poss_UV[t - 1], U1 + d0))
            U[t - 1], impossibleFlag = find_U0_bnd(alpha, S0, S1, U1, d0,
                                                   impossibleFlag, None, None)

        # store this example
        UV.append(U)

    # plot them
    # ---

    # plot the simulation as "true" values
    plt.plot(S_orig, 'green', lw=1, label=r'$S_t$')
    plt.plot(E_orig, 'red', lw=1, label=r'$E_t$')
    plt.plot(X_orig, 'blue', lw=1, label=r'$X_t$')

    # plot each of the examples
    for i, U in enumerate(UV):