def boot_pliv_partial_z_single_treat(theta, Y, D, Z, r_hat, smpls, score, se,
                                     weights, n_rep, dml_procedure):
    r_hat_array = np.zeros_like(D)
    n_folds = len(smpls)
    J = np.zeros(n_folds)
    for idx, (train_index, test_index) in enumerate(smpls):
        r_hat_array[test_index] = r_hat[idx]
        if dml_procedure == 'dml1':
            if score == 'partialling out':
                J[idx] = np.mean(
                    -np.multiply(r_hat_array[test_index], D[test_index]))

    if dml_procedure == 'dml2':
        if score == 'partialling out':
            J = np.mean(-np.multiply(r_hat_array, D))

    if score == 'partialling out':
        psi = np.multiply(Y - D * theta, r_hat_array)
    else:
        raise ValueError('invalid score')

    boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep,
                                          dml_procedure)

    return boot_theta, boot_t_stat
Exemple #2
0
def boot_pliv_partial_x_single_treat(theta, Y, D, Z, g_hat, r_hat, r_hat_tilde,
                                     smpls, score, se, weights, n_rep,
                                     dml_procedure):
    u_hat = np.zeros_like(Y)
    w_hat = np.zeros_like(D)
    n_folds = len(smpls)
    J = np.zeros(n_folds)
    for idx, (train_index, test_index) in enumerate(smpls):
        u_hat[test_index] = Y[test_index] - g_hat[idx]
        w_hat[test_index] = D[test_index] - r_hat[idx]
        if dml_procedure == 'dml1':
            if score == 'partialling out':
                J[idx] = np.mean(
                    -np.multiply(r_hat_tilde[test_index], w_hat[test_index]))

    if dml_procedure == 'dml2':
        if score == 'partialling out':
            J = np.mean(-np.multiply(r_hat_tilde, w_hat))

    if score == 'partialling out':
        psi = np.multiply(u_hat - w_hat * theta, r_hat_tilde)
    else:
        raise ValueError('invalid score')

    boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep,
                                          dml_procedure)

    return boot_theta, boot_t_stat
def boot_plr_single_treat(theta, Y, D, g_hat, m_hat, smpls, score, se, weights,
                          n_rep, dml_procedure, apply_cross_fitting):
    u_hat = np.zeros_like(Y)
    v_hat = np.zeros_like(D)
    n_folds = len(smpls)
    J = np.zeros(n_folds)
    for idx, (train_index, test_index) in enumerate(smpls):
        v_hat[test_index] = D[test_index] - m_hat[idx]
        u_hat[test_index] = Y[test_index] - g_hat[idx]
        if dml_procedure == 'dml1':
            if score == 'partialling out':
                J[idx] = np.mean(
                    -np.multiply(v_hat[test_index], v_hat[test_index]))
            elif score == 'IV-type':
                J[idx] = np.mean(
                    -np.multiply(v_hat[test_index], D[test_index]))

    if dml_procedure == 'dml2':
        if score == 'partialling out':
            J = np.mean(-np.multiply(v_hat, v_hat))
        elif score == 'IV-type':
            J = np.mean(-np.multiply(v_hat, D))

    if score == 'partialling out':
        psi = np.multiply(u_hat - v_hat * theta, v_hat)
    elif score == 'IV-type':
        psi = np.multiply(u_hat - D * theta, v_hat)
    else:
        raise ValueError('invalid score')

    boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep,
                                          dml_procedure, apply_cross_fitting)

    return boot_theta, boot_t_stat
Exemple #4
0
def boot_iivm_single_treat(theta, Y, D, Z, g_hat0, g_hat1, m_hat, r_hat0,
                           r_hat1, smpls, score, se, weights, n_rep,
                           dml_procedure):
    u_hat0 = np.zeros_like(Y)
    u_hat1 = np.zeros_like(Y)
    w_hat0 = np.zeros_like(Y)
    w_hat1 = np.zeros_like(Y)
    g_hat0_all = np.zeros_like(Y)
    g_hat1_all = np.zeros_like(Y)
    r_hat0_all = np.zeros_like(Y)
    r_hat1_all = np.zeros_like(Y)
    m_hat_all = np.zeros_like(Y)
    n_folds = len(smpls)
    J = np.zeros(n_folds)
    for idx, (train_index, test_index) in enumerate(smpls):
        u_hat0[test_index] = Y[test_index] - g_hat0[idx]
        u_hat1[test_index] = Y[test_index] - g_hat1[idx]
        w_hat0[test_index] = D[test_index] - r_hat0[idx]
        w_hat1[test_index] = D[test_index] - r_hat1[idx]
        g_hat0_all[test_index] = g_hat0[idx]
        g_hat1_all[test_index] = g_hat1[idx]
        r_hat0_all[test_index] = r_hat0[idx]
        r_hat1_all[test_index] = r_hat1[idx]
        m_hat_all[test_index] = m_hat[idx]
        if dml_procedure == 'dml1':
            if score == 'LATE':
                J[idx] = np.mean(-(r_hat1_all[test_index] - r_hat0_all[test_index] \
                              + np.divide(np.multiply(Z[test_index], w_hat1[test_index]), m_hat_all[test_index]) \
                              - np.divide(np.multiply(1. - Z[test_index], w_hat0[test_index]), 1. - m_hat_all[test_index])))

    if dml_procedure == 'dml2':
        if score == 'LATE':
            J = np.mean(-(r_hat1_all - r_hat0_all \
                          + np.divide(np.multiply(Z, w_hat1), m_hat_all) \
                          - np.divide(np.multiply(1. - Z, w_hat0), 1. - m_hat_all)))

    if score == 'LATE':
        psi = g_hat1_all - g_hat0_all \
                + np.divide(np.multiply(Z, u_hat1), m_hat_all) \
                - np.divide(np.multiply(1.-Z, u_hat0), 1.-m_hat_all) \
                -theta*(r_hat1_all - r_hat0_all \
                    + np.divide(np.multiply(Z, w_hat1), m_hat_all) \
                    - np.divide(np.multiply(1.-Z, w_hat0), 1.-m_hat_all))
    else:
        raise ValueError('invalid score')

    boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep,
                                          dml_procedure)

    return boot_theta, boot_t_stat
def boot_irm_single_treat(theta, Y, D, g_hat0, g_hat1, m_hat, p_hat, smpls,
                          score, se, weights, n_rep, dml_procedure):
    u_hat0 = np.zeros_like(Y)
    u_hat1 = np.zeros_like(Y)
    g_hat0_all = np.zeros_like(Y)
    g_hat1_all = np.zeros_like(Y)
    m_hat_all = np.zeros_like(Y)
    p_hat_all = np.zeros_like(Y)
    n_folds = len(smpls)
    J = np.zeros(n_folds)
    for idx, (train_index, test_index) in enumerate(smpls):
        u_hat0[test_index] = Y[test_index] - g_hat0[idx]
        u_hat1[test_index] = Y[test_index] - g_hat1[idx]
        g_hat0_all[test_index] = g_hat0[idx]
        g_hat1_all[test_index] = g_hat1[idx]
        m_hat_all[test_index] = m_hat[idx]
        p_hat_all[test_index] = p_hat[idx]
        if dml_procedure == 'dml1':
            if score == 'ATE':
                J[idx] = -1.0
            elif score == 'ATTE':
                J[idx] = np.mean(
                    -np.divide(D[test_index], p_hat_all[test_index]))

    if dml_procedure == 'dml2':
        if score == 'ATE':
            J = -1.0
        elif score == 'ATTE':
            J = np.mean(-np.divide(D, p_hat_all))

    if score == 'ATE':
        psi = g_hat1_all - g_hat0_all \
                + np.divide(np.multiply(D, u_hat1), m_hat_all) \
                - np.divide(np.multiply(1.-D, u_hat0), 1.-m_hat_all) - theta
    elif score == 'ATTE':
        psi = np.divide(np.multiply(D, u_hat0), p_hat_all) \
                - np.divide(np.multiply(m_hat_all, np.multiply(1.-D, u_hat0)),
                            np.multiply(p_hat_all, (1.-m_hat_all))) \
                - theta * np.divide(D, p_hat_all)
    else:
        raise ValueError('invalid score')

    boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep,
                                          dml_procedure)

    return boot_theta, boot_t_stat