Brain volumes, Flanker performance, and limits of interpretation#
This lab uses the bundled HCP teaching extract and accompanying data dictionary. It illustrates an observational association, not a population-wide neuroscience discovery. The Flanker score measures performance on that task; it must not be silently renamed working-memory capacity.
Question: how is Flanker_Unadj associated with total gray-matter volume in the available complete records, and how does adjustment for total white-matter volume change that description? The extract has no family/site columns identifiable by those names, so this lab does not claim an independence-respecting external validation or a definitive population confidence interval.
course_path <- if(file.exists("../R/course.R")) "../R/course.R" else "book/R/course.R"
source(course_path)
set.seed(432)
data_dir <- if(dir.exists("../exercises/hcp_data")) "../exercises/hcp_data" else "book/exercises/hcp_data"
raw <- read.csv(file.path(data_dir,"unrestricted_trimmed_1_7_2020_10_50_44.csv"),stringsAsFactors=FALSE)
dictionary <- read.csv(file.path(data_dir,"HCP_S1200_DataDictionary_April_20_2018.csv"),stringsAsFactors=FALSE)
variables <- c("Flanker_Unadj","FS_Total_GM_Vol","FS_Tot_WM_Vol")
stopifnot(all(variables %in% names(raw)),!anyDuplicated(raw$Subject))
dictionary[dictionary$columnHeader %in% variables,c("columnHeader","description")]
missing <- colSums(is.na(raw[variables]))
missing
keep <- complete.cases(raw[variables])
d <- raw[keep,variables]
# Scale volume by 1000 original volume units; verify the dictionary before naming physical units.
d$gray_volume_thousands <- d$FS_Total_GM_Vol/1000
d$white_volume_thousands <- d$FS_Tot_WM_Vol/1000
c(available_records=nrow(raw),complete_records=nrow(d),excluded=sum(!keep))
| columnHeader | description | |
|---|---|---|
| <chr> | <chr> | |
| 195 | Flanker_Unadj | The Flanker is a measure of executive function, specifically tapping inhibitory control and attention for ages 3-85. It is considered a fluid ability measure (i.e. measures the capacity for new learning and information processing in novel situations) in which performance reaches a peak in early adulthood, then tends to decline across the life span. The test requires the participant to focus on a given stimulus while inhibiting attention to stimuli (arrows for ages 8-85) flanking it. Sometimes the middle stimulus is pointing in the same direction as the flankers (congruent) and sometimes in the opposite direction (incongruent). Scoring is based on a combination of accuracy and reaction time. Unadjusted Scale Score: Participant score is normed to those in the entire NIH Toolbox Normative Sample (18 and older), regardless of age or any other variable, where a score of 100 indicates performance that was at the national average and a score of 115 or 85, indicates performance 1 SD above or below the national average. |
| 275 | FS_Total_GM_Vol | |
| 281 | FS_Tot_WM_Vol |
- Flanker_Unadj
- 0
- FS_Total_GM_Vol
- 93
- FS_Tot_WM_Vol
- 93
- available_records
- 1206
- complete_records
- 1113
- excluded
- 93
unadjusted <- lm(Flanker_Unadj~gray_volume_thousands,d)
adjusted <- lm(Flanker_Unadj~gray_volume_thousands+white_volume_thousands,d)
data.frame(model=c("unadjusted","adjusted for white volume"),gray_volume_slope=c(coef(unadjusted)[2],coef(adjusted)[2]))
library(ggplot2)
ggplot(d,aes(gray_volume_thousands,Flanker_Unadj))+geom_point(alpha=.2)+geom_smooth(method="lm",se=FALSE)+labs(x="Gray-matter volume (thousands of original units)",y="Flanker_Unadj score",caption="Complete records from the bundled observational extract; line is unadjusted.")+theme_minimal()
Challenge the description#
Adjustment is a scientific choice, not a way to make a coefficient significant. A causal graph and measurement rationale are needed before interpreting an adjusted coefficient causally. Complete records may differ systematically from excluded records; a missingness count alone does not resolve that problem.
# Influence sensitivity is a diagnostic, not an automatic exclusion rule.
influence <- cooks.distance(adjusted)
flag <- influence>4/nrow(d)
sensitivity <- lm(Flanker_Unadj~gray_volume_thousands+white_volume_thousands,d[!flag,])
data.frame(analysis=c("all complete records","influence sensitivity only"),n=c(nrow(d),sum(!flag)),gray_volume_slope=c(coef(adjusted)[2],coef(sensitivity)[2]))
plot(fitted(adjusted),residuals(adjusted),pch=16,col=adjustcolor("steelblue",.25),xlab="Fitted Flanker score",ylab="Residual")
abline(h=0,lty=2)
Reporting boundary#
Keep the full complete-record model as the main descriptive analysis unless exclusions are independently justified. A change after removing influential records is a sensitivity finding, not a reason to prefer whichever estimate fits a narrative.
For predictive evaluation or population uncertainty, obtain permitted sampling/group metadata and prespecify family/site-aware splits or an appropriate dependence model. Do not substitute an arbitrary row split and label it external validation. The lesson’s conclusion may be that the extract supports a limited association while stronger claims require additional information. Do not upload participant data to an AI service; use schemas or synthetic examples to request coding help.
sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 15.7.7
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.6
loaded via a namespace (and not attached):
[1] pillar_1.8.0 compiler_4.2.1 base64enc_0.1-3
[4] tools_4.2.1 digest_0.6.29 uuid_1.1-0
[7] lattice_0.20-45 nlme_3.1-157 jsonlite_1.8.0
[10] evaluate_0.15 lifecycle_1.0.1 tibble_3.1.8
[13] gtable_0.3.0 mgcv_1.8-40 pkgconfig_2.0.3
[16] rlang_1.0.6 Matrix_1.4-1 IRdisplay_1.1
[19] cli_3.3.0 DBI_1.1.3 IRkernel_1.3.0.9000
[22] fastmap_1.1.0 withr_2.5.0 repr_1.1.4
[25] dplyr_1.0.9 generics_0.1.3 vctrs_0.4.1
[28] grid_4.2.1 tidyselect_1.1.2 glue_1.6.2
[31] R6_2.5.1 fansi_1.0.3 pbdZMQ_0.3-7
[34] farver_2.1.1 purrr_0.3.4 magrittr_2.0.3
[37] splines_4.2.1 scales_1.2.0 htmltools_0.5.3
[40] assertthat_0.2.1 colorspace_2.0-3 labeling_0.4.2
[43] utf8_1.2.2 munsell_0.5.0 crayon_1.5.1