#' @title Cybernetic Laterality & Unmodeled Variance Pipeable Verbs (`|>`) #' @description Extends Sweetbrier's `dplyr` topological grammar (`hypervolume_dplyr.R`) #' to audit intracranial "Hemisphere Theory" against Bateson's cybernetic loop closure #' and Tarski/Lob self-instantiation limits. source("C:/Users/Vivian/Desktop/DreamLLM/gestalt_r_package/R/hypervolume_dplyr.R") #' @title Audit Batesonian Loop-Severing & Murphy (2009) GSR Artifacts #' @export audit_cybernetic_loop_closure <- function(.data) { .data |> dplyr::mutate( Age_z = as.numeric(base::scale(mean_age)), study_id = as.factor(study_id), paradigm_class = as.factor(paradigm_class), cognitive_domain = as.factor(cognitive_domain), cybernetic_regime = dplyr::case_when( open_loop_clamped == 1L ~ "OpenLoop_HeadClamped_LabArtifact", gsr_applied == 1L ~ "GSR_AutonomicErased_Artifact", TRUE ~ "ClosedLoop_Ecological_WholeBrain" ), precision_weight = 1.0 / (sei^2) ) } #' @title Decompose Unmodeled Hierarchical Variance vs. Hemispheric Signal #' @description Computes posterior draws of the Unmodeled Variance Ratio (UVR) #' comparing external study/paradigm SD against the global dual-mode intercept/contrasts. #' @export decompose_unmodeled_variance <- function(post_draws, rope_bounds = c(-0.1, 0.1)) { sd_study <- post_draws$`sd_study_id__yi_Intercept` sd_paradigm <- post_draws$`sd_paradigm_class__yi_Intercept` sd_domain <- post_draws$`sd_cognitive_domain__yi_Intercept` # Total unmodeled contextual/experimental SD (study + paradigm quadrature) sd_unmodeled_total <- sqrt(sd_study^2 + sd_paradigm^2) # Primary dual-attention / left-right typology posterior draws b_typology <- post_draws$`b_yi_Intercept` b_coupling <- if ("b_yi_cognitive_domainCross_Domain_Coupling" %in% names(post_draws)) { b_typology + post_draws$`b_yi_cognitive_domainCross_Domain_Coupling` } else { b_typology } b_global_rh <- if ("b_yi_cognitive_domainGlobal_Contextual_RH" %in% names(post_draws)) { b_typology + post_draws$`b_yi_cognitive_domainGlobal_Contextual_RH` } else { b_typology } tibble::tibble( draw_id = seq_along(sd_study), b_typology = b_typology, b_cross_coupling = b_coupling, b_global_rh = b_global_rh, sd_study = sd_study, sd_paradigm = sd_paradigm, sd_domain = sd_domain, sd_unmodeled_total = sd_unmodeled_total, uvr_ratio = sd_unmodeled_total / pmax(abs(b_typology), 0.01), in_rope_typology = (b_typology >= rope_bounds[1]) & (b_typology <= rope_bounds[2]), in_rope_coupling = (b_coupling >= rope_bounds[1]) & (b_coupling <= rope_bounds[2]) ) } #' @title Project Posterior Regime Draws into N-Dimensional Hypervolume Manifolds #' @description Uses `summarise_hypervolume()` + `cross_hypervolume_overlap()` to measure #' geometric Jaccard separation between Open-Loop Clamped lab artifacts and #' Closed-Loop Whole-Brain ecological observations in (Effect, SE, Precision) space. #' @export compute_regime_hypervolume_overlap <- function(.data) { hv_tbl <- .data |> dplyr::mutate( regime_binary = ifelse(open_loop_clamped == 1L | gsr_applied == 1L, "Artifactual_Clamped_or_GSR", "Naturalistic_Unclamped") ) |> dplyr::group_by(regime_binary) |> summarise_hypervolume(yi, sei, scale_axes = TRUE) overlap_tbl <- cross_hypervolume_overlap(hv_tbl, regime_binary) list(hypervolumes = hv_tbl, overlap = overlap_tbl) }