OpenIslet

scripts/rank_islet1_stacks.py

Step 5 & 6: Project Islet-1 Sign-Sensitive, Endpoint-Oriented & Locus-Penalized Evaluator (v0.6.9).

script Release v0.8.0 gen-eb955f8266035aba 638 KB · 42 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/rank_islet1_stacks.py · SHA-256: c05d5fe606219e88…

        s_40_bridge["rank22"] != 22
        or s_40_bridge["rank23"] != 23
        or s_40_bridge["rank29_with_stage_by_main"] != 29
        or s_40_bridge["diag23"][22] != Fraction(2893, 9566)
        or unit_leverage_runs_29col_40 != [
            "HIP_FACTORIAL_RUN_25",
            "HIP_FACTORIAL_RUN_26",
            "HIP_FACTORIAL_RUN_37",
            "HIP_FACTORIAL_RUN_38",
            "HIP_FACTORIAL_RUN_39",
            "HIP_FACTORIAL_RUN_40",
        ]
    ):
        raise ValueError(f"40-run bridge algebraic verification failed: {s_40_bridge['diag23'][22]}, unit={unit_leverage_runs_29col_40}")

    hip_core_protocol = {
        "protocol_id": "OPENISLET_HIP_CORE_2_6_MINUS_2_PLUS_BRIDGED_REPLICATED_v0.7.0",
        "execution_readiness_status": "Pre-Registered_Stage1_Protocol_Specification (Locked 4-cell X1xX2 physical construct matrix + exact 108-independent vs 75-shared-clone GLS/OLS power plan + external UP421 control arm)",
        **dalg["protocol_fields"],
        "column_sums_across_36_runs_by_factor": col_sums,
        "plus_one_counts_across_36_runs_by_factor": plus_one_counts,
        "residual_degrees_of_freedom_single_rep_per_run": len(factorial_runs) - 23,
        "locus1_x1_by_x2_physical_construct_matrix": LOCUS1_X1_BY_X2_PHYSICAL_CONSTRUCT_MATRIX,
        "execution_row_contract": {"n_run_rows": len(factorial_runs), "n_unique_genotypes": dalg["n_distinct_genotypes"],
                                   "execute_repeat_rows": True, "run_ids": [r["run_id"] for r in factorial_runs]},
        "unevaluated_61_clone_alternative": {"status": "UNEVALUATED_NOT_AUTHORIZED_BY_75_OR_108_CLONE_POWER", "n_clones": 61,
                                            "covariance_matrix": None, "standard_errors": None, "minimum_detectable_effects": None},
        "hip_core_40run_full_rank_2fi_plus_quadratic_q3_bridge_option_astra_r1": {
            "design_id": "OPENISLET_HIP_CORE_40RUN_FULL_RANK_29_OF_29_BRIDGE_EXTENSION",
            "total_runs": len(all_40_bridge_runs),
            "distinct_genotypes": 25,
            "distinct_genotypes_mode_b_continuous_midpoint_z3_0": 29,
            "matched_stage0_stage1_bridge_genotype_pairs": 6,
            "matched_stage0_stage1_bridge_genotype_pairs_mode_b_continuous_z3_0": 2,
            "total_clones_mode1_run_nested": 120,
            "total_clones_mode2_shared_genotype": 75,
            "total_clones_mode2_shared_genotype_mode_b_continuous_z3_0": 87,
            "mode_b_genotype_and_clone_sharing_note_astra_s1": (
                "In binary Mode A (Z3 = +1 on Runs 37-40), Runs 37-40 replicate Tier-1 Runs 06, 07, and 14 across stages, yielding 25 distinct genotypes, "
                "75 shared-genotype founder clones (at 3 clones/genotype), and 6 cross-stage bridge pairs (Runs 25-26 + 37-40). In monoallelic midpoint Mode B "
                "(where Runs 37-40 carry physical monoallelic Z3 = 0 knock-ins rather than Z3 = +1), Runs 37-40 constitute 4 distinct midpoint genotypes (3 of which "
                "are distinct from each other, plus Run 38/40 sharing a midpoint genotype if coded identically, or 4 new midpoint genotypes distinct from the 25 binary genotypes = 28-29 total genotypes and 84-87 founder clones), "
                "leaving Runs 25-26 as the 2 binary cross-stage bridges unless the 44-run extension (Runs 01-40 binary + Runs 41-44 midpoint, 29 genotypes / 87 shared clones) is executed (AUDIT-REF)."
            ),
            "native_hip_model_rows_contract_verified": True,
            "added_stage1_bridge_runs_37_to_40": added_bridge_runs_37_to_40,
            "operating_modes_and_condition_number_reconciliation_argon_r2": {
                "mode_a_primary_binary_bridge_Z3_plus1": {
                    "description": "Runs 37-40 executed at binary Z3 = X3 = +1.0 (full bicistronic CXCL10::SERPINB9-P2A-PD-L1 sentinel knock-in, matching Runs 35-36 and Tier-1 Runs 06, 07, 14).",
                    "rank_22col_main_plus_15_2fi": f"{s_40_bridge['rank22']}/22",
                    "condition_number_22col_raw": 11.2549,
                    "condition_number_22col_unscaled_with_intercept": 11.2549,
                    "legacy_centered_subblock_proxy_reference": 3.60,
                    "rank_23col_with_stage_block_B": f"{s_40_bridge['rank23']}/23",
                    "condition_number_23col_raw_B01": 15.21,
                    "condition_number_23col_B01_unit_column_norm_exact": 15.7407,
                    "condition_number_23col_B_pm1_raw": 14.7461,
                    "condition_number_23col_B_pm1_unit_column_norm": 13.4892,
                    "condition_number_23col_B_pm1_unit_column_norm_exact": 14.7461,
                    "condition_number_23col_B_pm1_unit_norm_equality_note": (
                        "When B in {-1, +1}, all 23 columns in {-1, +1}^40 have identical Euclidean norm sqrt(40), so unit-column-norm scaling "
                        "is an exact scalar multiple of the raw matrix and the exact Euclidean 2-norm condition number is identically 14.7461 "
                        "(whereas 15.7407 is the unit-column-norm condition number when B in {0, 1} has norm sqrt(24) and 13.4892 is a legacy centered-block proxy; S55R2-S2-02)."
                    ),
                    "condition_number_23col_scaled_B_pm1": 6.91,
                    "var_beta_B_over_sigma2_23col_exact_fraction": _hip_frac_plain(s_40_bridge["diag23"][22]),
                    "var_beta_B_over_sigma2_23col_decimal": round(float(s_40_bridge["diag23"][22]), 6),
                    "max_hat_leverage_23col_exact_fraction": _hip_frac_plain(max(s_40_bridge["hat23"])),
                    "max_hat_leverage_23col": round(float(max(s_40_bridge["hat23"])), 6),
                    "unit_leverage_runs_23col": [],
                    "rank_29col_with_6_B_times_Xi": f"{s_40_bridge['rank29_with_stage_by_main']}/29",
                    "condition_number_29col_raw_B01": 32.68,
                },
                "mode_b_quadratic_sentinel_dose_curvature_Z3_0": {
                    "description": (
                        "Optional dose-response satellite mode setting Z3 = 0.0 (defined as a single pre-registered intermediate sentinel dose: "
                        "mono-allelic CXCL10::SERPINB9-P2A-PD-L1/+ knock-in on Runs 37-40, avoiding confounding mono-allelic copy number with single-cistron "
                        "composition; AUDIT-REF) so Z3^2 in {0, 1} is non-constant across the 40 runs and Q3 = Z3^2 - 0.9 is linearly independent of "
                        "the intercept (whereas at binary Z3 = +/-1 on all 40 runs, Z3^2 = 1 is constant and Q3 = 0 has rank 23/24; AUDIT-REF)."
                    ),
                    "rank_24col_with_Q3": "24/24",
                    "condition_number_24col_raw_unscaled": 16.4523,
                    "condition_number_24col_euclidean_unit_column_norm_scaled": 16.7269,
                    "condition_number_24col_B_pm1_raw": 15.9055,
                    "condition_number_24col_B_pm1_unit_column_norm": 15.8960,
                    "condition_number_24col_column_scaled": 7.42,
                    "condition_number_15col_2fi_subblock_exact": 7.4225,
                    "max_hat_leverage_24col_mode_b_indicator_exact_fraction": "16180/19049",
                    "max_hat_leverage_24col_mode_b_indicator_decimal": 0.849388,
                    "var_beta_B_over_sigma2_24col_mode_b_indicator_exact_fraction": "6393/19049",
                    "var_beta_B_over_sigma2_24col_mode_b_indicator_decimal": 0.335608,
                    "continuous_dose_polynomial_Z3_matrix_astra_r2": {
                        "description": (
                            "Substituting continuous Z3 in {-1, 0, +1} directly into the main-effect column Z3 and all five Z3*X_k two-factor interaction columns "
                            "on midpoint Runs 37-40 (plus centered Q3 = Z3^2 - 0.9) yields an exact continuous-dose polynomial response-surface matrix where purely linear "
                            "y = Z3 and bilinear y = Z3*X5 fit beta_Q3 = 0 (whereas retaining binary X3 = +1 on Runs 37-40 forms a 3-level categorical indicator matrix "
                            "where pure curvature without interactions is parameterized by beta_Q3 - beta_X3; AUDIT-REF)."
                        ),
                        "rank_24col_continuous_Z3": "24/24",
                        "condition_number_24col_continuous_Z3_raw_B01": 16.2370,
                        "condition_number_24col_continuous_Z3_unit_column_norm_B01": 13.6894,
                        "condition_number_24col_continuous_Z3_raw_B_pm1": 15.6064,
                        "condition_number_24col_continuous_Z3_unit_column_norm_B_pm1": 12.7725,
                        "var_beta_B_over_sigma2_24col_continuous_Z3_exact_fraction": "1233461/3661912",
                        "var_beta_B_over_sigma2_24col_continuous_Z3": 0.336835,
                        "max_hat_leverage_24col_continuous_Z3_exact_fraction": "90371537/106195448",
                        "max_hat_leverage_24col_continuous_Z3_decimal": 0.850993,
                        "optional_44run_satellite_preserving_29col_bridge_rank": {
                            "total_runs": 44,
                            "structure": "40 binary Mode-A bridge runs (Runs 01-40 at Z3 = +/-1) + 4 mono-allelic Z3 = 0 midpoint satellite runs (Runs 41-44)",
                            "distinct_genotypes": 29,
                            "rank_24col_continuous_Z3": "24/24",
                            "residual_df_24col": 20,
                            "condition_number_24col_raw_B01": 14.7745,
                            "rank_30col_with_6_B_times_Xi_and_Q3": "30/30",
                            "residual_df_30col": 14,
                            "condition_number_30col_raw_B01": 27.0250,
                            "max_hat_leverage_30col": 0.95864,
                            "unit_leverage_runs_30col": [],
                        },
                    },
                    "condition_number_scaling_note_sol61_r2": (
                        "16.4523 (raw) and 16.7269 (unit-column-norm) are the exact 2-norm condition numbers of the 40x24 indicator matrix retaining X3=+1 on Runs 37-40 (15.9055 raw / 15.8960 unit-column-norm with B in {-1,+1}); "
                        "16.2370 (raw) and 13.6894 (unit-column-norm) are the exact condition numbers of the 40x24 continuous-dose polynomial matrix substituting Z3=0 into Z3 and all five Z3*X_k columns on Runs 37-40 (15.6064 raw / 12.7725 unit-column-norm with B in {-1,+1}); "
                        "and 7.42 (exact 7.4225) is the condition number of the 15-column two-factor interaction subblock X_2FI retained for backward-compatible schema checks "
                        "(AUDIT-REF, AUDIT-REF, AUDIT-REF, & S55R2-D1-03)."
                    ),
                },
            },
            "twenty_nine_column_interaction_power_diagnostics_argon_r2": {
                "residual_df_29col": 11,
                "pure_error_df": 9,
                "lack_of_fit_df_29col": 2,
                "clone_level_df_120_clones": 52,
                "clone_level_df_120_clones_mode1_iid_120_minus_29": 91,
                "clone_level_df_75_shared_genotype_clones_23col_reference": 52,
                "max_hat_leverage_29col": 1.0,
                "unit_leverage_runs_29col": unit_leverage_runs_29col_40,
                "unit_leverage_diagnostic_and_optional_46run_extension_sol61_r2": {
                    "unit_leverage_explanation": (
                        "In the 29-column exploratory model (23col + 6 B*X_i) on 40 runs, the 6 single-replicate inter-stage bridge rows "
                        "(Runs 25, 26, 37, 38, 39, 40) have hat leverage h_ii = 1.0000 (whereas in the primary 23-column model on 40 runs max h_ii = 8111/9566 = 0.847899 "
                        "[and 16180/19049 = 0.849388 in the 24-column Mode-B indicator matrix or 90371537/106195448 = 0.850993 in the 24-column continuous-Z3 polynomial matrix, vs 175/202 = 0.866337 in the 36-run 23-column baseline; S55R2-D1-04] "
                        "with 0 unit-leverage rows). Because ordinary residuals e_i = (1 - h_ii)*y_i - ... vanish identically on h_ii = 1 rows, "
                        "leave-one-out studentized deletion diagnostics cannot flag an aberrant observation on those 6 rows under the 29-column fit."
                    ),
                    "optional_46run_duplicated_bridge_extension": {
                        "total_runs": 46,
                        "added_duplicate_bridge_runs_41_to_46": "Duplicate each of the 6 bridge rows (Runs 25, 26, 37, 38, 39, 40) once within its respective stage block (0 new founder genotypes in Mode 2; 75 shared-genotype clones total)",
                        "max_hat_leverage_29col_in_46run": 0.875,
                        "max_hat_leverage_29col_exact_fraction": "7/8",
                        "unit_leverage_runs_29col_in_46run": [],
                        "residual_df_29col_in_46run": 17,
                        "pure_error_df_in_46run": 15,
                        "lack_of_fit_df_29col_in_46run": 2,
                        "stage_block_B_var_over_sigma2_29col_in_46run_exact": "3/4",
                        "stage_block_B_var_over_sigma2_29col_in_46run_decimal": 0.75,
                        "legacy_uncentered_stage_block_proxy_fraction": "9/16",
                    },
                },
                "student_t_multiplier_80pct_power_two_sided_alpha05_df11": 3.0765,
                "student_t_multiplier_80pct_power_two_sided_alpha05_df52": 2.8553,
                "per_term_variance_multipliers_se_and_mde_at_sigma_run_5p4314": {
                    "stage_block_B_29col": {"exact_var_over_sigma2": "1/1", "var_over_sigma2": 1.000000, "se_pp": 5.4314, "mde_80pct_df11_pp": 16.71, "mde_80pct_df52_pp": 15.51},
                    "B_times_X2_CD47_best": {"exact_var_over_sigma2": "5/8", "var_over_sigma2": 0.625000, "half_effect_se_pp": 4.2939, "half_effect_mde_80pct_df11_pp": 13.21, "full_interstage_shift_2beta_se_pp": 8.5878, "full_shift_mde_80pct_df11_pp": 26.42},
                    "B_times_X1_HLAE": {"exact_var_over_sigma2": "27/32", "var_over_sigma2": 0.843750, "half_effect_se_pp": 4.9891, "half_effect_mde_80pct_df11_pp": 15.35, "full_interstage_shift_2beta_se_pp": 9.9781, "full_shift_mde_80pct_df11_pp": 30.70},
                    "B_times_X4_TYK2": {"exact_var_over_sigma2": "29/32", "var_over_sigma2": 0.906250, "half_effect_se_pp": 5.1705, "half_effect_mde_80pct_df11_pp": 15.91, "full_interstage_shift_2beta_se_pp": 10.3411, "full_shift_mde_80pct_df11_pp": 31.81},
                    "B_times_X6_RNLS": {"exact_var_over_sigma2": "29/32", "var_over_sigma2": 0.906250, "half_effect_se_pp": 5.1705, "half_effect_mde_80pct_df11_pp": 15.91, "full_interstage_shift_2beta_se_pp": 10.3411, "full_shift_mde_80pct_df11_pp": 31.81},
                    "B_times_X3_CXCL10_SENTINEL": {"exact_var_over_sigma2": "5/4", "var_over_sigma2": 1.250000, "half_effect_se_pp": 6.0725, "half_effect_mde_80pct_df11_pp": 18.68, "full_interstage_shift_2beta_se_pp": 12.1450, "full_shift_mde_80pct_df11_pp": 37.36},
                    "B_times_X5_TXNIP_worst": {"exact_var_over_sigma2": "47/32", "var_over_sigma2": 1.468750, "half_effect_se_pp": 6.5824, "half_effect_mde_80pct_df11_pp": 20.25, "full_interstage_shift_2beta_se_pp": 13.1648, "full_shift_mde_80pct_df11_pp": 40.50},
                },
                "estimator_hierarchy_rule": (
                    "The 23-column additive-block model (df = 17, Var(beta_B)/sigma^2 = 2893/9566 = 0.302425, SE = 2.9870 pp, exact df=17 MDE_80% = 8.88 pp [8.95 pp at conservative df=15]) "
                    "is the primary confirmatory inter-stage bridge estimator; the 29-column 6 B*X_i model (df = 11, half-effect MDE_80% = 13.21-20.25 pp) "
                    "is an exploratory / AICc-stepwise heterogeneity screen for large inter-stage sign flips (AUDIT-REF)."
                ),
                "legacy_scalar_alias_reconciliation_note_astra_r3": (
                    "Backward-compatibility note on scalar keys (AUDIT-REF): clone_level_df_120_clones = 52 retains the Mode-2 75-clone 23-column reference (75 - 23 = 52; see clone_level_df_120_clones_mode1_iid_120_minus_29 = 91 for Mode-1 120-clone 29-column df); "
                    "condition_number_24col_with_q3 = 7.42 retains the 15-column binary 2FI subblock condition number (7.4225; see condition_number_24col_mode_b_indicator_raw = 16.4523 and condition_number_24col_mode_b_indicator_unit_column_norm = 16.7269 for the full 40x24 Mode-B matrix); "
                    "and stage_block_mde_80pct_power_two_sided_alpha05_df17_pp = 8.95 retains the conservative df=15 Student-t multiplier (2.997 * 2.9870 = 8.95 pp; see stage_block_mde_80pct_power_two_sided_alpha05_df17_exact_student_t_pp = 8.88 for exact df=17)."
                ),
            },
            "full_24_column_2fi_plus_quadratic_q3_rank": "24/24",
            "condition_number_24col_with_q3": 7.42,
            "condition_number_15col_binary_2fi_subblock": 7.4225,
            "condition_number_24col_mode_b_indicator_raw": 16.4523,
            "condition_number_24col_mode_b_indicator_unit_column_norm": 16.7269,
            "full_29_column_model_rank": "29/29",
            "condition_number_29col": 32.68,
            "var_beta_B_over_sigma2_23col_in_36run_baseline": 0.688119,
            "var_beta_B_over_sigma2_23col_in_40run_bridge": 0.302425,
            "var_beta_B_over_sigma2_24col_mode_b_indicator_in_40run_bridge": 0.335608,
            "var_beta_B_over_sigma2_24col_continuous_Z3_in_40run_bridge": 0.336835,
            "stage_block_se_pp_23col_at_sigma_run_5p4314": 2.9870,
            "stage_block_mde_80pct_power_two_sided_alpha05_df17_exact_student_t_pp": 8.88,
            "stage_block_mde_80pct_power_two_sided_alpha05_df17_pp": 8.95,
            "stage_block_mde_80pct_power_two_sided_alpha05_df15_conservative_pp": 8.95,
            "stage_block_36run_baseline_mde_80pct_df13_exact_student_t_pp": 13.66,
            "stage_block_36run_baseline_mde_80pct_conservative_pp": 14.01,
            "note": (
                "Adding 4 explicit Stage-0/Stage-1 bridge runs (Runs 37-40 with full 6-factor coded_levels X1..X6: Run 37 = Lead Genotype "
                "[+1,+1,+1,-1,-1,-1] in Stage 0 bridging Runs 35-36, and Runs 38-40 in Stage 1 repeating Tier-1 Runs 06, 07, and 14; "