# ============================================================================== # Applied Research Pipeline: Causal Inference on ML2 Empirical Data # Framework: Bayesian Network Evaluation (BiDAG) # Objective: Adjudicate between Direct vs. Mediated Causal Pathways # (Disgust Sensitivity -> Conservatism) # ============================================================================== library(BiDAG) # ------------------------------------------------------------------------------ # 1. Data Ingestion & Preprocessing # ------------------------------------------------------------------------------ # We load the rigorously cleaned Many Labs 2 dataset (ml2_inbar_cleaned.csv) # which contains the real empirical z-scores for Religion, Disgust, and Conservatism # across 4,524 matched participants from the 125 global sites. cat("Loading Cleaned Empirical Many Labs 2 Data...\n") data_df <- read.csv("data/ml2_inbar_cleaned.csv") # Ensure variables match exact DAG node names colnames(data_df) <- c("Religion", "Disgust", "Conservatism") # ------------------------------------------------------------------------------ # 2. DAG Topology Definition # ------------------------------------------------------------------------------ nodes <- c("Disgust", "Religion", "Conservatism") # DAG 1: Direct Path (Disgust -> Conservatism) dag1_adj <- matrix(0, nrow = 3, ncol = 3, dimnames = list(nodes, nodes)) dag1_adj["Disgust", "Conservatism"] <- 1 # DAG 2: Mediated Path (Disgust -> Religion -> Conservatism) dag2_adj <- matrix(0, nrow = 3, ncol = 3, dimnames = list(nodes, nodes)) dag2_adj["Disgust", "Religion"] <- 1 dag2_adj["Religion", "Conservatism"] <- 1 # ------------------------------------------------------------------------------ # 3. Parameter Scoring & Marginal Likelihood Evaluation # ------------------------------------------------------------------------------ # The BGe score calculates the exact marginal likelihood of the DAG structure, # solving the intractability issues of standard approximations like BIC. cat("Scoring DAGs using BiDAG (BGe Marginal Likelihood)...\n") # Score parameters for continuous Gaussian data score_params <- scoreparameters("bge", data_df) # Calculate the Log Marginal Likelihood for both causal structures log_marginal_1 <- DAGscore(score_params, dag1_adj) log_marginal_2 <- DAGscore(score_params, dag2_adj) cat(sprintf("Log Marginal Likelihood (DAG 1 - Direct): %.2f\n", log_marginal_1)) cat(sprintf("Log Marginal Likelihood (DAG 2 - Mediated): %.2f\n", log_marginal_2)) # ------------------------------------------------------------------------------ # 4. Exact Model Selection (Bayes Factor) # ------------------------------------------------------------------------------ # The Bayes Factor adjudicates the evidence: P(Data | DAG 1) / P(Data | DAG 2) # Because the scores are log likelihoods, we subtract them before exponentiating. log_BF <- log_marginal_1 - log_marginal_2 BF_12 <- exp(log_BF) cat(sprintf("\nBayes Factor (DAG 1 vs DAG 2): %.5g\n", BF_12)) if (log_BF > 0) { cat("Result: The empirical evidence supports DAG 1 (Direct Causal Path).\n") } else { cat("Result: The empirical evidence supports DAG 2 (Mediated Causal Path).\n") }