Cortical thickness changes precede high levels of amyloid by at least 7 years.
The 6 matches
- [1] § Methods › Participants ↔ scripts/01-prepSlopesYearsBeforeAB_simulated.r, lines 354–440 · score 0.70 · combined MRI, ageing MRI, MRI scans, PET scan, ADNI, BACS
- [2] § Results › Additional analyses ↔ scripts/10-rankThicknessChange.r, lines 672–712 · score 0.62 · CIs excluded zero, thickness changes, confidence, rank, derivative, interval
- [3] § Methods › Statistical analysis ↔ scripts/10-rankThicknessChange.r, lines 672–712 · score 0.57 · excluded zero, thickness changes, rank, gratia, derivative, CI
- [4] § Methods › Statistical analysis ↔ scripts/08-rankAmyloidOrder.r, lines 363–409 · score 0.53 · linear mixed models, tracer, regional, amyloid, SUVR, ADNI
- [5] § Methods › Statistical analysis ↔ scripts/10-rankThicknessChange.r, lines 400–463 · score 0.51 · GAMM interaction, thickness change, ICV, smooth, strength, trajectories
- [6] § Methods › Statistical analysis ↔ scripts/08-rankAmyloidOrder.r, lines 363–409 · score 0.51 · linear mixed models, tracer, rank, regional, SUVRs, intercept
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
R · 1,114 lines · 39 KB · MIT · 3 matches
- #========================================================================================#
- # Author: James M Roe, Ph.D.
- # Center for Lifespan Changes in Brain and Cognition, University of Oslo
- #
- # Purpose: Compute the rank order of thickness changes across all converter MRIs and correlate with the rank order of regional Aβ deposition.
- # Uses linear time-to-Aβ trajectories or SILA input, and computes time-to-Aβ thickness trajectories in regions of high-v-low Aβ.
- # Script requires individual-level data as input and is not executable
- #========================================================================================#
- #---load packages
- loadPackages = function() {
- packages = c("here", "tidyverse","magrittr","gamm4","itsadug","numDeriv","gratia","mgcv","viridis","wesanderson","asbio","broom","cowplot","data.table","stringi","tictoc","lmerTest","effects","ggpubr")
- new.packages = packages[!(packages %in% installed.packages()[,"Package"])]
- if(length(new.packages)) {
- install.packages(new.packages)
- }
- print(sapply(packages, require, character.only = T))
- print(sapply(packages, function(p) as.character(packageVersion(p))))
- }
- loadPackages()
- here()
- #---set dir
- b = "/cluster/projects/p274/projects/p040-ad_change/Berkeley"
- # b = here()
- setwd(b)
- #---set dir
- #---make dirstruct
- plotdir = "plots"; if (! dir.exists(plotdir)) { dir.create(plotdir)}
- resdir = "results"; if (! dir.exists(resdir)) { dir.create(resdir)}
- #---load data
- savefigs=F
- nTime=2
- agecut=30
- saveres=T
- load(file.path(b, "reproduce/data/DF_LONG_4570.Rda"))
- dim(DF); length(unique(DF$subject_id))
- # load converter/nonconverter data
- load(file.path(b, "reproduce/data/converters_all_negfirst_ADNINC_UPDATE.Rda"))
- load(file.path(b, "reproduce/data/converters_all_negfirst_BACS_UPDATE.Rda"))
- load(file.path(b, "reproduce/data/converters_all_negfirst_LCBC_UPDATE_REPRO_corthresh.Rda"))
- load(file.path(b, "reproduce/data/converters_data_for_plot_BACS_UPDATE_REPRO.Rda"))
- load(file.path(b, "reproduce/data/converters_data_for_plot_ADNINC_UPDATE_REPRO.Rda"))
- load(file.path(b, "reproduce/data/converters_data_for_plot_LCBC_UPDATE_REPRO_corthresh.Rda"))
- converters_allMRI_negfirst_LCBC = left_join(converters_allMRI_negfirst_LCBC,
- converters_allMRI_negfirst_LCBC_plotdat %>% select(imageLink, slope, intercept, age_at_threshold, contains("CL_at_thresh")) %>%
- rename(slope_centiloid = slope,
- intercept_centiloid = intercept)
- )
- converters_allMRI_negfirst_ADNINC = left_join(converters_allMRI_negfirst_ADNINC,
- converters_allMRI_negfirst_ADNINC_plotdat %>% select(imageLink, slope, intercept, age_at_threshold, contains("CL_at_thresh")) %>%
- rename(slope_centiloid = slope,
- intercept_centiloid = intercept)
- )
- converters_allMRI_negfirst_BACS = left_join(converters_allMRI_negfirst_BACS,
- converters_allMRI_negfirst_BACS_plotdat %>% select(imageLink, slope, intercept, age_at_threshold, contains("CL_at_thresh")) %>%
- rename(slope_centiloid = slope,
- intercept_centiloid = intercept)
- )
- allFeat = readLines(file.path(b, "reproduce/data/allFeatures364.txt"))
- adnioutlier = "029_S_0845"
- rois=allFeat[grepl("thickness", allFeat)]
- nrois=length(rois)
- subset.size=nrois; jj = 1
- N = ceiling(nrois/subset.size)
- print(N)
- start = (jj*subset.size)-subset.size+1
- if (jj == N) {
- end = nrois
- loopend = length(rois[start:end])
- } else {
- end = jj*subset.size
- loopend = subset.size
- }
- print(paste("subsetting cols", start, "-", end))
- rois = rois[start:end]
- print(rois)
- ROIs = rois
- pb = txtProgressBar(min=2, max=end, style=3)
- Usubs = length(unique(DF$subject_id))
- # load sila outputs
- osila_bacs = fread("/cluster/projects/p274/projects/p040-ad_change/Berkeley/scripts/SILA-AD-Biomarker/demo/output/testBACS.csv")
- osila_adni = fread("/cluster/projects/p274/projects/p040-ad_change/Berkeley/scripts/SILA-AD-Biomarker/demo/output/testADNINC.csv")
- osila_lcbc = fread("/cluster/projects/p274/projects/p040-ad_change/Berkeley/scripts/SILA-AD-Biomarker/demo/output2/testLCBC.csv")
- # load sila inputs (ids get changed in sila modelling)
- isila_all = fread("/cluster/projects/p274/projects/p040-ad_change/Berkeley/scripts/SILA-AD-Biomarker/demo/df_silo_amyloidtimeCorrect.csv")
- isila_adni = isila_all[isila_all$cohort == "ADNINC",] %>% rename(subject_id = subid) %>% rename(subid = subjid)
- isila_bacs = isila_all[isila_all$cohort == "BACS",] %>% rename(subject_id = subid) %>% rename(subid = subjid)
- isila_lcbc = isila_all[isila_all$cohort == "LCBC",] %>% rename(subject_id = subid) %>% rename(subid = subjid)
- range(osila_adni$subid)
- range(isila_adni$subid)
- range(osila_bacs$subid)
- range(isila_bacs$subid)
- range(isila_lcbc$subid)
- range(osila_lcbc$subid)
- osila_adni = left_join(osila_adni, isila_adni)
- osila_bacs = left_join(osila_bacs, isila_bacs)
- osila_lcbc = left_join(osila_lcbc, isila_lcbc)
- mytheme = theme(
- plot.background = element_rect(fill = "white"),
- panel.background = element_rect(fill = "white"),
- panel.grid.major = element_blank(),
- panel.grid.minor = element_blank(),
- title = element_text(size=17),
- text = element_text(color = "black", size = 18, family="Nimbus Sans Narrow"),
- plot.title = element_text(hjust = 0.5),
- # axis.ticks = element_blank(),
- axis.title.y = element_text(color = "black", size = 22, vjust =-1, margin = margin(0,20,0,0)),
- axis.title.x = element_text(color = "black", size = 22, vjust = -2, margin = margin(0,20,20,0)),
- axis.text = element_text(color = "black", size = 18),
- legend.key.size = unit(1,"cm"))
- pal = wes_palette("FantasticFox1", n = 5)
- plotSila = function(dat, cohort) {
- # dat = osila_adni
- (p_sila1 =
- dat %>%
- ggplot(.) +
- geom_line(data=dat,aes(x=age,val,group=subid, col = factor(conv)),alpha=0.6, size=0.5) +
- geom_point(data=dat,aes(x=age,val,group=subid, col = factor(conv)),stat="identity",alpha=1, size=0.5) +
- scale_color_manual(values = c(pal[2], pal[5])) +
- # geom_smooth(method = "gam", col = "black", se = F) +
- ggtitle(cohort) +
- labs(x = "Age") +
- theme_classic() + mytheme)
- (p_sila2 =
- dat %>%
- ggplot(.) +
- geom_line(data=dat,aes(x=estdtt0,val,group=subid, col = factor(conv)),alpha=0.6, size=0.5) +
- geom_point(data=dat,aes(x=estdtt0,val,group=subid, col = factor(conv)),stat="identity",alpha=1, size=0.5) +
- scale_color_manual(values = c(pal[2], pal[5])) +
- geom_hline(yintercept = dat$valt0, linetype = 2, col = "black") +
- ggtitle(cohort) +
- labs(x = "Years to Aβ+ (SILA)") +
- theme_classic() + mytheme)
- return(list(p_sila1 = p_sila1, p_sila2 = p_sila2, threshold = dat$valt0[1]))
- }
- p_sila_adni = plotSila(osila_adni, "ADNI")
- p_sila_bacs = plotSila(osila_bacs, "BACS")
- p_sila_lcbc = plotSila(osila_lcbc, "LCBC")
- p_sila_adni$p_sila2
- p_sila_bacs$p_sila2
- p_sila_lcbc$p_sila2
- if (savefigs) {
- ggsave(filename = "/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_sila_adni.pdf",
- plot = p_sila_adni$p_sila2 + theme(legend.position = "none"),
- width = 13,
- height = 13,
- dpi = 600,
- units = "cm",
- device = cairo_pdf
- )
- ggsave(filename = "/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_sila_bacs.pdf",
- plot = p_sila_bacs$p_sila2 + theme(legend.position = "none"),
- width = 13,
- height = 13,
- dpi = 600,
- units = "cm",
- device = cairo_pdf
- )
- ggsave(filename = "/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_sila_lcbc_threshcorrect.pdf",
- plot = p_sila_lcbc$p_sila2 + theme(legend.position = "none"),
- width = 13,
- height = 13,
- dpi = 600,
- units = "cm",
- device = cairo_pdf
- )
- }
- DF_SILA = rbind(osila_adni,
- osila_bacs,
- osila_lcbc)
- DF_SILA$visit_age = DF_SILA$age
- DF_SILA$subject_id %in% DF$subject_id
- DF_SILA$subject_id[!DF_SILA$subject_id %in% DF$subject_id]
- DF_SILA$age_at_sila_threshold = DF_SILA$age - DF_SILA$estdtt0
- DF_SILA %>%
- filter(subject_id == "002_S_4213") %>%
- pull(age_at_sila_threshold) %>%
- dput()
- # fix four subjects that have very slightly different age at threshold across their observations
- (checkSubs = DF_SILA %>%
- group_by(subject_id) %>%
- summarise(n_unique = n_distinct(round(age_at_sila_threshold, 4))) %>%
- filter(n_unique != 1)
- )
- DF_SILA[DF_SILA$subject_id == "021_S_4276",]
- DF_SILA[DF_SILA$subject_id == "031_S_4021",]
- DF_SILA[DF_SILA$subject_id == "036_S_4491",]
- DF_SILA[DF_SILA$subject_id == "1100591",]
- # by taking their last estimate
- DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "021_S_4276"] = DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "021_S_4276"][4]
- DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "031_S_4021"] = DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "031_S_4021"][3]
- DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "036_S_4491"] = DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "036_S_4491"][4]
- DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "1100591"] = DF_SILA$age_at_sila_threshold[DF_SILA$subject_id == "1100591"][2]
- DF_SILA$age_at_sila_threshold = round(DF_SILA$age_at_sila_threshold, 3)
- DF_SILA %>%
- group_by(subject_id) %>%
- summarise(n_unique = n_distinct(age_at_sila_threshold)) %>%
- filter(n_unique != 1)
- DF = left_join(DF,
- DF_SILA %>% select(subject_id, age_at_sila_threshold, conv) %>% distinct()
- )
- DF$visit_age
- DF$time_from_sila_threshold = DF$age_at_sila_threshold - DF$visit_age
- DF$time_from_sila_threshold_flip = DF$time_from_sila_threshold*-1
- head(DF %>% select(matches("age|time", ignore.case = TRUE)))
- # NB! this is correctly 76 (not 77) due to the negative centiloid slope BACS person -------
- # and this person had 10 MRI scans
- # hence the difference between 477 scans (in this analysis) and max 487 MRI scans in converters (in paper) is correct
- load("/cluster/projects/p274/projects/p040-ad_change/Berkeley/reproduce/data/DF.convallMRI.rda")
- length(unique(DF.convallMRI$subject_id)); dim(DF.convallMRI)
- DF.convallMRI$diff_mriAge_predABpos
- # choose to estimate via original method (linear estimates)
- # or SILA
- estType = "SILA"
- convonly = 1
- estType = "ORIG"
- if (estType != "SILA") {
- # if not SILA analysis (original with converters only)
- DF = DF.convallMRI
- dim(DF)
- length(unique(DF$subject_id))
- converters_allMRI_negfirst_BACS[converters_allMRI_negfirst_BACS$SID == "B16-220",] %>% dim()
- convonly = 0
- } else if (estType == "SILA") {
- # if SILA analysis (review)
- DF = DF %>% filter(!is.na(time_from_sila_threshold))
- dim(DF)
- length(unique(DF$subject_id))
- length(unique(DF$subject_id[DF$conv == 1]))
- # if testing SILA across only converter group
- if (convonly) {
- dim(DF %>% filter(conv == 1))
- DF %<>% filter(conv == 1)
- }
- }
- # high ab region map
- frontal_regions_lh <- c(
- "lh_superiorfrontal_thickness.aparcnative71",
- "lh_rostralmiddlefrontal_thickness.aparcnative71",
- "lh_caudalmiddlefrontal_thickness.aparcnative71",
- "lh_parsopercularis_thickness.aparcnative71",
- "lh_parstriangularis_thickness.aparcnative71",
- "lh_parsorbitalis_thickness.aparcnative71",
- "lh_lateralorbitofrontal_thickness.aparcnative71",
- "lh_medialorbitofrontal_thickness.aparcnative71",
- "lh_frontalpole_thickness.aparcnative71"
- )
- frontal_regions_rh <- c(
- "rh_superiorfrontal_thickness.aparcnative71",
- "rh_rostralmiddlefrontal_thickness.aparcnative71",
- "rh_caudalmiddlefrontal_thickness.aparcnative71",
- "rh_parsopercularis_thickness.aparcnative71",
- "rh_parstriangularis_thickness.aparcnative71",
- "rh_parsorbitalis_thickness.aparcnative71",
- "rh_lateralorbitofrontal_thickness.aparcnative71",
- "rh_medialorbitofrontal_thickness.aparcnative71",
- "rh_frontalpole_thickness.aparcnative71"
- )
- parietalregions = c(
- "lh_precuneus_thickness.aparcnative71",
- "rh_precuneus_thickness.aparcnative71",
- "lh_inferiorparietal_thickness.aparcnative71",
- "rh_inferiorparietal_thickness.aparcnative71",
- "lh_supramarginal_thickness.aparcnative71",
- "rh_supramarginal_thickness.aparcnative71"
- )
- cingulate_regions = c(
- "lh_posteriorcingulate_thickness.aparcnative71",
- "rh_posteriorcingulate_thickness.aparcnative71",
- "lh_isthmuscingulate_thickness.aparcnative71",
- "rh_isthmuscingulate_thickness.aparcnative71",
- "lh_rostralanteriorcingulate_thickness.aparcnative71",
- "rh_rostralanteriorcingulate_thickness.aparcnative71",
- "lh_caudalanteriorcingulate_thickness.aparcnative71",
- "rh_caudalanteriorcingulate_thickness.aparcnative71"
- )
- temporal_regions = c(
- "lh_middletemporal_thickness.aparcnative71",
- "rh_middletemporal_thickness.aparcnative71"
- )
- ab_regions_high = c(frontal_regions_lh, frontal_regions_rh, parietalregions, temporal_regions, cingulate_regions)
- # low ab regions - everything else
- ROIs[!ROIs %in% ab_regions_high]
- ab_regions_low = ROIs[!ROIs %in% ab_regions_high]
- ab_regions_low = ab_regions_low[!grepl("Mean", ab_regions_low)]
- # FDR regions in thickness analysis + homologues
- FDR_mask = c(frontal_regions_lh, frontal_regions_rh,
- "lh_precentral_thickness.aparcnative71",
- "rh_precentral_thickness.aparcnative71",
- "lh_paracentral_thickness.aparcnative71",
- "rh_paracentral_thickness.aparcnative71",
- "lh_insula_thickness.aparcnative71",
- "rh_insula_thickness.aparcnative71",
- "lh_supramarginal_thickness.aparcnative71",
- "rh_supramarginal_thickness.aparcnative71"
- )
- # minus frontal poles which were not FDR sig
- FDR_mask = FDR_mask[!grepl("pole", FDR_mask)]
- ROIs = FDR_mask
- # reverse years to AB to be correct (-years to AB)
- if (estType != "SILA") {
- DF$diff_mriAge_predABpos_flip = DF$diff_mriAge_predABpos*-1
- } else if (estType == "SILA") {
- DF$diff_mriAge_predABpos_flip = DF$time_from_sila_threshold_flip
- }
- DF$brainvarLow = rowMeans(DF[,ab_regions_low])
- DF$brainvarHigh = rowMeans(DF[,ab_regions_high])
- DF$subject_id = as.factor(DF$subject_id)
- fullDF = DF
- if (estType != "SILA") {
- facSmooth = T
- } else {
- facSmooth = F
- }
- if (facSmooth) {
- # ordered factor approach to get test statistics for GAMM interaction
- dat = DF
- dat$brainvarfac = dat$brainvarHigh
- stackdat = rbind(
- dat %>% mutate(highlow = "high"),
- dat %>% mutate(highlow = "low")
- )
- stackdat$brainvarfac[stackdat$highlow == "low"] = dat$brainvarLow
- stackdat = mutate(stackdat,
- ohighlow = factor(highlow, levels = c("low","high"),ordered = T))
- gamm.trajectories = gamm4(brainvarfac ~ s(diff_mriAge_predABpos_flip, by = as.factor(highlow)) + as.factor(highlow) + visit_age + subject_sex + cohort + scanStrength + ICV,
- data = stackdat, random = ~ (1 |subject_id))
- gamm.sum = summary(gamm.trajectories$gam)
- g = gamm.trajectories$gam
- plot.gam(g)
- # estimate smooth for set reflevel and a smoothed difference between ref and other levels
- ogamm.trajectories = gamm4(brainvarfac ~ as.factor(highlow) + s(diff_mriAge_predABpos_flip) + s(diff_mriAge_predABpos_flip, by = ohighlow) + visit_age + subject_sex + cohort + scanStrength + ICV,
- data = stackdat, random = ~ (1 |subject_id))
- ogamm.sum = summary(ogamm.trajectories$gam)
- plot.gam(ogamm.trajectories$gam)
- # thickness trajectory in high Aβ regions was significantly different than low Aβ regions
- ogamm.sum
- }
- # three analyses to run through - select which here
- regionTest = "high"
- regionTest = "low"
- regionTest = "cortex"
- if (regionTest == "high") {
- loopend = 1
- } else if (regionTest == "low") {
- loopend = 1
- } else if (regionTest == "cortex") {
- loopend = length(ROIs)
- }
- for (i in 1:loopend) {
- # tic()
- print(paste(i,"/",length(ROIs)))
- if (i == 1) {
- derivMat = gratiaderivMat = gratiaderivCIlwrMat = gratiaderivCIuprMat = matrix(NA, nrow = 1000, ncol = length(ROIs))
- fitMat = matrix(NA, nrow = 100, ncol = length(ROIs))
- RR = list()
- p_derivs = p_derivs_se = list()
- yearsBeforepredAB_on_ci_exclusion = c()
- yearsBeforepredAB_on_se_exclusion = c()
- maxaccels = c()
- }
- DF = fullDF
- setTxtProgressBar(pb,i)
- set.seed(123)
- # ab regions low / high
- if (regionTest == "high") {
- ROI = "high AB composite"
- DF$brainvar = rowMeans(DF[,ab_regions_high])
- palcol = pal[5]
- anaTitle = "Aβ high"
- }
- if (regionTest == "low") {
- ROI = "low AB composite"
- DF$brainvar = rowMeans(DF[,ab_regions_low])
- palcol = pal[2]
- anaTitle = "Aβ low"
- }
- if (regionTest == "cortex") {
- ROI = ROIs[i]
- DF$brainvar = DF[[ROI]]
- palcol = "darkgrey"
- anaTitle = ROI
- }
- g_convall = gamm4(brainvar ~ s(diff_mriAge_predABpos_flip) + visit_age + subject_sex + cohort + scanStrength + ICV, data = DF, random = ~ (1 | subject_id))
- g_convall_mgcv = gam(
- brainvar ~
- s(diff_mriAge_predABpos_flip) +
- s(subject_id, bs = "re") +
- visit_age + subject_sex + cohort + scanStrength + ICV,
- data = DF,
- method = "REML"
- )
- summary(g_convall$gam)
- g_sum = summary(g_convall_mgcv)
- RR[[i]] = g_sum
- lmm_convall = lmer(
- brainvar ~ diff_mriAge_predABpos_flip + visit_age + subject_sex + cohort + scanStrength + ICV + (1 | subject_id),
- data = DF
- )
- # plot.gam(g_convall$gam, residuals = T)
- summary(lmm_convall)
- # clearly the covariates are important
- ggplot(DF, aes(y=brainvar, x = diff_mriAge_predABpos_flip)) + geom_point(aes(group = subject_id)) + geom_smooth(method = "gam")
- plot(effect("diff_mriAge_predABpos_flip", lmm_convall, residuals=TRUE)) #warning is due to scaling of Y and X
- predictions <- DF %>%
- mutate(visit_age = mean(DF$visit_age), subject_sex = "Female", cohort = "ADNINC", scanStrength = "1-5T", ICV=0) %>%
- select(diff_mriAge_predABpos_flip, visit_age,subject_sex,ICV,mri_info_site_name,scanStrength, cohort) %>%
- predict(g_convall$gam, newdata = ., se.fit = T)
- residualsg <- residuals(g_convall$mer)
- DF$partial_residuals = predictions$fit + residualsg
- DF$fit = predictions$fit
- DF$sefit = predictions$se.fit
- DF$cifit = predictions$se.fit*1.96
- #colour palette ---
- pal = wesanderson::wes_palettes$FantasticFox1
- pointcol = "#6faca8"
- #colour palette ---
- if (estType != "SILA") {
- tmpDF = DF %>% filter(diff_mriAge_predABpos >= 1)
- } else {
- tmpDF = DF %>% filter(time_from_sila_threshold >= 1)
- }
- (fig1 =
- DF %>% #filter(subject_id != adnioutlier) %>%
- ggplot(.) +
- geom_line(data=tmpDF,aes(x=diff_mriAge_predABpos_flip,partial_residuals,group=subject_id),color=pointcol,alpha=0.6, size=0.5) +
- geom_point(data=tmpDF,aes(x=diff_mriAge_predABpos_flip,partial_residuals,group=subject_id),color=pointcol,stat="identity",alpha=1, size=0.5) +
- # geom_ribbon(data=dug,aes(x=diff_mriAge_predABpos_flip,ymin=fit-CI,ymax=fit+CI),alpha=.7,show.legend=F,fill="dark grey") +
- geom_line(data=tmpDF,aes(x=diff_mriAge_predABpos_flip,y=fit),col="black") +
- ggtitle(ROI) +
- labs(x = "Age") +
- theme_classic() + mytheme)
- # Extract plotting data without rendering the plot
- plot_data = plot.gam(g_convall$gam, select = 1, se = TRUE, rug = FALSE, shade = T, pages = 0)
- # get gam intercept
- g_sum = summary(g_convall$gam)
- g_sum$p.coeff
- # The output is a list, extract x, fit, and se
- df = data.frame(
- x = plot_data[[1]]$x,
- fit = plot_data[[1]]$fit + g_sum$p.coeff[1],
- se = plot_data[[1]]$se
- )
- # Calculate upper and lower confidence intervals
- df$upper = df$fit + 1 * df$se #NB! help(plot.gam) shows it is already using CI
- df$lower = df$fit - 1 * df$se
- ggplot(df, aes(x = x, y = fit)) +
- geom_line() +
- geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.2) +
- labs(
- ) +
- theme_minimal()
- # Approximate first derivative
- df$deriv = c(NA, diff(df$fit) / diff(df$x))
- # Find index of minimum (i.e., where uptick starts)
- min_idx = which.min(df$fit)
- # Optionally, find first point where derivative turns positive
- first_uptick_idx = which(df$deriv > 0 & seq_along(df$deriv) > min_idx)[1]
- # Get corresponding x-value
- uptick_point = df$x[first_uptick_idx]
- uptick_pointy = df$fit[first_uptick_idx]
- fitMat[,i] = df$fit
- (pderiv0 = ggplot(df, aes(x = x, y = fit)) +
- geom_line() +
- labs(
- x = "Years to Aβ+",
- y = "Thickness"
- ) +
- # geom_point(aes(x = uptick_point, y = uptick_pointy), col = "black", size = 5) +
- theme_minimal())
- (pderiv0_ci = ggplot(df, aes(x = x, y = fit)) +
- geom_line(col = palcol) +
- ggtitle(ROI) +
- geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.1, col = palcol, fill = palcol) +
- labs(
- x = "Years to Aβ+",
- y = "Thickness"
- ) +
- # geom_point(aes(x = uptick_point, y = uptick_pointy), col = "black", size = 5) +
- theme_minimal())
- # first derivative
- df$deriv = c(NA, diff(df$fit) / diff(df$x))
- df$deriv_lower = c(NA, diff(df$lower) / diff(df$x))
- df$deriv_upper = c(NA, diff(df$upper) / diff(df$x))
- (pderiv1 = ggplot(df, aes(x = x, y = deriv)) +
- geom_line() +
- geom_hline(yintercept = 0, linetype = "dashed") +
- labs(x = "Years to Aβ+", y = "Rate of change") +
- theme_minimal())
- (pderiv1_se = ggplot(df, aes(x = x, y = deriv)) +
- geom_line() +
- geom_ribbon(aes(ymin = deriv_lower, ymax = deriv_upper), alpha = 0.2) +
- geom_hline(yintercept = 0, linetype = "dashed") +
- labs(x = "Years to Aβ+", y = "Rate of change") +
- theme_minimal())
- derivMat[,i] = df$deriv
- # Compute second derivative (numerical)
- second_derivative = diff(diff(df$fit)) / diff(df$x[-1])
- # Align x-axis (midpoints between x values)
- second_x = df$x[-c(1, 2)] + diff(df$x)[-1] / 2
- #point of maximum accerelated change
- maxaccel_y = second_derivative[which(second_derivative == max(second_derivative))]
- maxaccel_x = second_x[which(second_derivative == max(second_derivative))]
- if (length(maxaccel_x) > 1) {
- maxaccel_y = NA
- maxaccel_x = NA
- }
- if (is.na(maxaccel_x)) {
- maxaccels[i] = NA
- } else {
- maxaccels[i] = maxaccel_x
- pderiv2 = ggplot(data.frame(x = second_x, second_derivative = second_derivative), aes(x = x, y = second_derivative)) +
- geom_line() +
- geom_hline(yintercept = 0, linetype = "dashed") +
- labs(y = "Acceleration", x = "Years to Aβ+") +
- geom_point(aes(x = maxaccel_x[i], y = maxaccel_y[i]), col = "black", size = 2) +
- theme_minimal()
- # check all derivatives
- (pcheckderiv = cowplot::plot_grid(pderiv0, pderiv1, pderiv2, nrow = 3))
- }
- # NB! se of calculated derivative not ideal - using gratia instead
- (psumse1 = cowplot::plot_grid(pderiv0_ci, pderiv1_se, nrow = 3))
- # Compute first derivative of the smooth term
- d1 = gratia::derivatives(g_convall_mgcv, term = "s(diff_mriAge_predABpos_flip)", interval = "confidence", n = 1000)
- d1 = as.data.frame(d1)
- d1$.lower_ci[which(d1$.lower_ci > 0)]
- # point at which the derivative CI excluded zero used to estimate the rank order of thickness changes
- cross_point = which(d1$.lower_ci > 0)[1]
- data.frame(d1$diff_mriAge_predABpos_flip, d1$.lower_ci, logical = d1$.lower_ci > 0)
- if (is.na(cross_point)) {
- print("CIs do not exclude zero")
- yearsBeforepredAB_on_ci_exclusion[i] = "never"
- exclude0 = 0
- } else if (cross_point == 1) {
- print("CIs always exclude zero")
- yearsBeforepredAB_on_ci_exclusion[i] = "always"
- cross_y = 0
- cross_x = d1$diff_mriAge_predABpos_flip[cross_point]
- exclude0 = 1
- } else {
- print("CIs exclude zero")
- cross_y = d1$.lower_ci[cross_point]
- cross_x = d1$diff_mriAge_predABpos_flip[cross_point]
- yearsBeforepredAB_on_ci_exclusion[i] = cross_x
- exclude0 = 1
- }
- #repeat for SE (since not all cross)
- d1$upper_se = d1$.derivative + d1$.se
- d1$lower_se = d1$.derivative - d1$.se
- # point at which the derivative SE excluded zero
- cross_point_se = which(d1$lower_se > 0)[1]
- # two instances where the deriv excluded zero on the downward trajectory - fixed to first point on upward trajectory
- data.frame(d1$diff_mriAge_predABpos_flip, d1$lower_se, logical = d1$lower_se > 0)
- # if (estType == "SILA" & convonly == 0) { if (i == 12) { cross_point_se = 420 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 0) { if (i == 2) { cross_point_se = 320 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 0) { if (i == 9) { cross_point_se = 537 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 0) { if (i == 10) { cross_point_se = 322 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 1) { if (i == 4) { cross_point_se = 262 } } # fix if only converters
- # if (estType == "SILA" & convonly == 1) { if (i == 2) { cross_point_se = 281 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 1) { if (i == 15) { cross_point_se = 296 } } # fix the one across full group
- # if (estType == "SILA" & convonly == 1) { if (i == 21) { cross_point_se = NA } } # fix the one across full group
- if (is.na(cross_point_se)) {
- print("SEs do not exclude zero")
- yearsBeforepredAB_on_se_exclusion[i] = "never"
- } else if (cross_point_se == 1) {
- print("SEs always exclude zero")
- cross_yse = 0
- cross_xse = d1$diff_mriAge_predABpos_flip[cross_point_se]
- yearsBeforepredAB_on_se_exclusion[i] = "always"
- } else {
- print("SEs exclude zero")
- cross_yse = d1$lower_se[cross_point_se]
- cross_xse = d1$diff_mriAge_predABpos_flip[cross_point_se]
- yearsBeforepredAB_on_se_exclusion[i] = cross_xse
- }
- # check crossing points
- if (!is.na(cross_point)) {
- ggplot(d1, aes(x = diff_mriAge_predABpos_flip, y = .derivative)) +
- geom_line() +
- geom_ribbon(aes(ymin = .lower_ci, ymax = .upper_ci), alpha = 0.1) +
- geom_hline(yintercept = 0, linetype = "dashed") +
- geom_point(aes(x = cross_x, y = cross_y), col = "black", size = 5)
- }
- if (!is.na(cross_point_se) & cross_point_se != 1) {
- ggplot(d1, aes(x = diff_mriAge_predABpos_flip, y = .derivative)) +
- geom_line() +
- geom_ribbon(aes(ymin = lower_se, ymax = upper_se), alpha = 0.1) +
- geom_hline(yintercept = 0, linetype = "dashed") +
- geom_point(aes(x = cross_xse, y = cross_yse), col = "black", size = 5)
- }
- (pderiv1_gratia_ci = ggplot(d1, aes(x = diff_mriAge_predABpos_flip, y = .derivative)) +
- geom_line(col = palcol) +
- geom_ribbon(aes(ymin = .lower_ci, ymax = .upper_ci), alpha = 0.1, colour = palcol, fill = palcol) +
- geom_hline(yintercept = 0, linetype = "dashed") +
- labs(
- x = "Years to Aβ+",
- y = "First derivative"
- ) +
- # geom_point(aes(x = cross_x, y = cross_y), col = "black", size = 1) +
- theme_classic() + mytheme
- )
- (pderiv1_gratia_se = ggplot(d1, aes(x = diff_mriAge_predABpos_flip, y = .derivative)) +
- geom_line() +
- geom_ribbon(aes(ymin = lower_se, ymax = upper_se), alpha = 0.2) +
- geom_hline(yintercept = 0, linetype = "dashed") +
- labs(
- x = "Years to Aβ+",
- y = "First derivative"
- ) +
- # geom_point(aes(x = cross_xse, y = cross_yse), col = "black", size = 1) +
- theme_classic() + mytheme
- )
- if (regionTest == "cortex") {
- if (!is.na(cross_point)) {
- # add crossing point to plot
- pderiv1_gratia_ci = pderiv1_gratia_ci + geom_point(aes(x = cross_x, y = cross_y), size = 6, fill = "#cbac09", col = "#cbac09")
- }
- if (!is.na(cross_point_se)) {
- pderiv1_gratia_se = pderiv1_gratia_se + geom_point(aes(x = cross_xse, y = cross_yse), size = 6, fill = "#cbac09", col = "#cbac09")
- }
- }
- # save gratia outputs
- gratiaderivMat[,i] = d1$.derivative
- gratiaderivCIlwrMat[,i] = d1$.lower_ci
- gratiaderivCIuprMat[,i] = d1$.upper_ci
- # main plot
- (
- p_combine_fitderiv_ci = ggpubr::ggarrange(
- pderiv0_ci + theme_classic() + mytheme + ggtitle(anaTitle) +
- pderiv1_gratia_ci,
- nrow = 1,
- align = "hv"
- )
- )
- (
- p_combine_fitderiv_se = ggpubr::ggarrange(
- pderiv0_ci + theme_classic() + mytheme + ggtitle(anaTitle) +
- pderiv1_gratia_se,
- nrow = 1,
- align = "hv"
- )
- )
- if (regionTest == "cortex") {
- (
- p_combine_fitderiv_ci = ggpubr::ggarrange(
- pderiv0_ci + theme_classic() + mytheme + ggtitle(anaTitle) + theme(axis.ticks = element_blank(), axis.line = element_blank()),
- pderiv1_gratia_ci + theme(axis.ticks = element_blank(), axis.line = element_blank()),
- nrow = 1,
- align = "hv"
- )
- )
- }
- p_derivs[[i]] = p_combine_fitderiv_ci
- p_derivs_se[[i]] = p_combine_fitderiv_se
- if (savefigs == 1) {
- if (regionTest == "high") {
- print("saving high plot")
- # ggsave(plot = p_combine_fitderiv_ci,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_thickTraj_ABhigh.pdf"),
- # width=20, height=9, units="cm", dpi=600, device = cairo_pdf
- # )
- } else if (regionTest == "low") {
- print("saving low plot")
- # ggsave(plot = p_combine_fitderiv_ci,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_thickTraj_ABlow.pdf"),
- # width=20, height=9, units="cm", dpi=600, device = cairo_pdf
- # )
- } else {
- # ggsave(plot = p_combine_fitderiv_ci,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_thickTraj_", ROI, ".pdf"),
- # width=20, height=9, units="cm", dpi=600, device = cairo_pdf
- # )
- }
- }
- }
- # check cross point on all 24 roi derivs
- p_derivs[[1]]
- p_derivs[[2]]
- p_derivs[[3]]
- p_derivs[[4]]
- p_derivs[[5]]
- p_derivs[[6]]
- p_derivs[[7]]
- p_derivs[[8]]
- p_derivs[[9]]
- p_derivs[[10]]
- p_derivs[[11]]
- p_derivs[[12]]
- p_derivs[[13]]
- p_derivs[[14]]
- p_derivs[[15]]
- p_derivs[[16]]
- p_derivs[[17]]
- p_derivs[[18]]
- p_derivs[[19]]
- p_derivs[[20]]
- p_derivs[[21]]
- p_derivs[[22]]
- p_derivs[[23]]
- p_derivs[[24]]
- p_derivs_se[[1]]
- p_derivs_se[[2]]
- p_derivs_se[[3]]
- p_derivs_se[[4]]
- p_derivs_se[[5]]
- p_derivs_se[[6]]
- p_derivs_se[[7]]
- p_derivs_se[[8]]
- p_derivs_se[[9]]
- p_derivs_se[[10]]
- p_derivs_se[[11]]
- p_derivs_se[[12]]
- p_derivs_se[[13]]
- p_derivs_se[[14]]
- p_derivs_se[[15]]
- p_derivs_se[[16]]
- p_derivs_se[[17]]
- p_derivs_se[[18]]
- p_derivs_se[[19]]
- p_derivs_se[[20]]
- p_derivs_se[[21]]
- p_derivs_se[[22]]
- p_derivs_se[[23]]
- p_derivs_se[[24]]
- # all confirmed correct
- # rank order on thickness change
- data.frame(yearsBeforepredAB_on_ci_exclusion,
- yearsBeforepredAB_on_se_exclusion
- )
- rankThickTraj = data.frame(rois = ROIs,
- rankedThickTraj = yearsBeforepredAB_on_ci_exclusion,
- rankedThickTrajSE = yearsBeforepredAB_on_se_exclusion,
- rankedThickTrajMaxAccel = maxaccels)
- # set as 0 if CI always excludes 0
- rankThickTraj$rankedThickTraj[rankThickTraj$rankedThickTraj == "always"] = 0
- rankThickTraj$rankedThickTraj[rankThickTraj$rankedThickTraj == "never"] = NA
- rankThickTraj$rankedThickTrajSE[rankThickTraj$rankedThickTrajSE == "always"] = 0
- rankThickTraj$rankedThickTrajSE[rankThickTraj$rankedThickTrajSE == "never"] = NA
- rankThickTraj$rankedThickTraj = as.numeric(rankThickTraj$rankedThickTraj)
- rankThickTraj$rankedThickTrajSE = as.numeric(rankThickTraj$rankedThickTrajSE)
- # rank and reorder ROIs based on the point at which the CI / SE of the derivative crosses 0
- # NB! no need to reverse as yearsBeforepredAB was flipped in model (diff_mriAge_predABpos_flip)
- # CI
- rankThickTraj$rankedThickTrajRev <- ifelse(
- is.na(rankThickTraj$rankedThickTraj),
- NA,
- ifelse(rankThickTraj$rankedThickTraj == 0,
- 0,
- rank(rankThickTraj$rankedThickTraj, ties.method = "first"))
- )
- rankThickTraj %<>% arrange(rankedThickTrajRev)
- # SE
- rankThickTraj$rankedThickTrajSERev <- ifelse(
- is.na(rankThickTraj$rankedThickTrajSE),
- NA,
- ifelse(rankThickTraj$rankedThickTrajSE == 0,
- 0,
- rank(rankThickTraj$rankedThickTrajSE, ties.method = "first"))
- )
- rankThickTraj %<>% arrange(rankedThickTrajSERev)
- # load in amyloid order
- rankAB = fread(file.path(b, "reproduce/data/rankABpredTraj.csv"))
- rankAB %<>% rename(rankedABTraj = rankedTraj,
- rankedABTrajRev = revRankedTraj)
- rankThickTraj$rois = paste0("CTX_", toupper(gsub("_thickness.aparcnative71", "", rankThickTraj$rois)), "_SUVR")
- rankThickTraj$rois %in% rankAB$rois
- rankedBoth = merge(
- rankThickTraj, rankAB
- )
- # filter data where there is no rank order for thickness (i.e. ROI derivative did not exclude 0 and thus could not be ranked)
- rankedBoth_cut = rankedBoth %>% filter(!is.na(rankedThickTrajRev))
- # make ranking plots
- rankedBoth$roi = gsub("CTX_", "", rankedBoth$rois)
- rankedBoth$roi = gsub("_SUVR", "", rankedBoth$roi)
- rankedBoth$roi = tolower(rankedBoth$roi)
- orderplot = arrange(rankedBoth, rankedABTrajRev) %>% select(roi)
- rankedBoth$roi = factor(rankedBoth$roi, levels = rev(orderplot$roi))
- rankRange = range(rankedBoth$rankedABTrajRev, na.rm= T)
- table(rankedBoth$rankedABTrajRev)
- rankedBoth$rankedABTrajRev = rankedBoth$rankedABTrajRev-1 # make 0 indexed (so colours match up with thickness rank plot)
- (p_rankAB_FDRregions = ggplot(rankedBoth %>%
- arrange(rankedABTrajRev),
- aes(x = rankedABTrajRev, y = factor(roi, levels = rev(unique(roi))))) +
- geom_bar(aes(x=rankedABTrajRev, y =roi), stat = "identity", colour = "grey", alpha = 0.5, width = 0.01, size=0.5) +
- geom_point(aes(colour = rankedABTrajRev), fill = "white", shape = 21, stroke = 2, size = 5) +
- scale_colour_viridis(option = "E", direction = -1, name = "Rank", limits = c(0, rankRange[2]), oob = scales::squish) +
- theme_classic() +
- mytheme +
- labs(x = "Rank (Aβ)",y = NULL) + theme(legend.position = "none")
- )
- # ggsave(plot = p_rankAB_FDRregions,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankAB_FDRregions.png"),
- # width=7, height=26, units="cm", dpi=600)
- # ensure rank plot for thickness is ordered the same
- (p_rankThick_frontal = ggplot(rankedBoth,
- aes(x = rankedThickTrajRev, y = factor(roi, levels = rev(unique(roi))))) +
- geom_bar(aes(x=rankedThickTrajRev, y =roi), stat = "identity", colour = "grey", alpha = 0.5, width = 0.01, size=0.5) +
- geom_point(aes(colour = rankedThickTrajRev), fill = "white", shape = 21, stroke = 2, size = 5) +
- scale_colour_viridis(option = "E", direction = -1, name = "Rank", limits = c(0, rankRange[2]), oob = scales::squish) +
- theme_classic() +
- mytheme +
- labs(x = "Rank (Thickness)",y = NULL) + theme(legend.position = "none")
- )
- table(rankedBoth$rankedThickTrajSERev)
- (p_rankThick_frontal_bySE = ggplot(rankedBoth,
- aes(x = rankedThickTrajSERev, y = factor(roi, levels = rev(unique(roi))))) +
- geom_bar(aes(x=rankedThickTrajSERev, y =roi), stat = "identity", colour = "grey", alpha = 0.5, width = 0.01, size=0.5) +
- geom_point(aes(colour = rankedThickTrajSERev), fill = "white", shape = 21, stroke = 2, size = 5) +
- scale_colour_viridis(option = "E", direction = -1, name = "Rank", limits = c(0, rankRange[2]), oob = scales::squish) +
- theme_classic() +
- mytheme +
- labs(x = "Rank (Thickness)",y = NULL) + theme(legend.position = "none")
- )
- cp1 = cowplot::plot_grid(p_rankAB_FDRregions, p_rankThick_frontal + theme(axis.text.y = element_text(color = "transparent"), axis.line.y = element_blank(), axis.ticks.y = element_blank()))
- cp2 = cowplot::plot_grid(p_rankAB_FDRregions, p_rankThick_frontal_bySE + theme(axis.text.y = element_text(color = "transparent"), axis.line.y = element_blank(), axis.ticks.y = element_blank()))
- # ggsave(plot = p_rankAB_FDRregions,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankAB_FDRregions.pdf"),
- # width=12, height=26, units="cm", dpi=600, device = cairo_pdf)
- # ggsave(plot = p_rankThick_frontal,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankRThick_FDRregions.pdf"),
- # width=12, height=26, units="cm", dpi=600, device = cairo_pdf)
- table(rankedBoth_cut$rankedThickTrajRev)
- pear1 = cor.test(rankedBoth_cut$rankedThickTrajRev, rankedBoth_cut$rankedABTrajRev)
- pear2 = cor.test(rankedBoth_cut$rankedThickTrajSERev, rankedBoth_cut$rankedABTrajRev)
- pval1 = format(
- tidy(pear1)$p.value[1],
- scientific = TRUE, digits = 2)
- bval1 = round(
- tidy(pear1)$estimate[1],
- digits = 2)
- pval2 = format(
- tidy(pear2)$p.value[1],
- scientific = TRUE, digits = 2)
- bval2 = round(
- tidy(pear2)$estimate[1],
- digits = 2)
- table(rankedBoth_cut$rankedThickTrajRev)
- # correlation plot based on CI (fig 5g)
- (p_rankCI = ggplot(rankedBoth_cut, aes(x = rankedThickTrajRev, y = rankedABTrajRev)) +
- geom_point(aes(col = rankedThickTrajRev), size = 3) +
- scale_colour_viridis(option = "E", direction = -1, name = "Rank", limits = c(0, rankRange[2]), oob = scales::squish) +
- theme_classic() +
- mytheme +
- # coord_fixed() +
- geom_smooth(method = "lm", se = T, col = "black", alpha = .1) +
- labs(x = "Rank (Thickness)",y = "Rank (Aβ)") + theme(legend.position = "none") +
- ggtitle("order of CIs excluding 0") +
- annotate("text", x = 1, y = max(rankedBoth_cut$rankedABTrajRev)+2, label = paste("p =", pval1), color = "black", hjust = 0) +
- annotate("text", x = 1, y = max(rankedBoth_cut$rankedABTrajRev)+3, label = paste("B =", bval1), color = "black", hjust = 0)
- )
- # ggsave(plot = p_rankCI,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankCI.pdf"),
- # width=9, height=12, units="cm", dpi=600, device = cairo_pdf)
- # ggsave(plot = p_rankCI,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankCI_", estType, "convonly", convonly, ".pdf"),
- # width=9, height=12, units="cm", dpi=600, device = cairo_pdf)
- table(rankedBoth_cut$rankedThickTrajSERev)
- # correlation plot based on SE (fig 5h)
- (p_rankSE = ggplot(rankedBoth_cut, aes(x = rankedThickTrajSERev, y = rankedABTrajRev)) +
- geom_point(aes(col = rankedThickTrajSERev), size = 3) +
- scale_colour_viridis(option = "E", direction = -1, name = "Rank", limits = c(0, rankRange[2]), oob = scales::squish) +
- theme_classic() +
- mytheme +
- # coord_fixed() +
- geom_smooth(method = "lm", se = T, col = "black", alpha = .2) +
- labs(x = "Rank (Thickness)",y = "Rank (Aβ)") + theme(legend.position = "none") +
- ggtitle("order of SEs excluding 0") +
- annotate("text", x = 1, y = max(rankedBoth_cut$rankedABTrajRev)+2, label = paste("p =", pval2), color = "black", hjust = 0) +
- annotate("text", x = 1, y = max(rankedBoth_cut$rankedABTrajRev)+3, label = paste("B =", bval2), color = "black", hjust = 0)
- )
- # ggsave(plot = p_rankSE,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankSE.pdf"),
- # width=9, height=12, units="cm", dpi=600, device = cairo_pdf)
- # ggsave(plot = p_rankSE,
- # filename = paste0("/cluster/projects/p274/projects/p040-ad_change/Berkeley/paper2/figs_yearsBeforeAB/p_rankSE_", estType, "convonly", convonly, ".pdf"),
- # width=9, height=12, units="cm", dpi=600, device = cairo_pdf)
10-rankThicknessChange.r at commit 8606e75, under MIT · at the source
Overview
- Center for Lifespan Changes in Brain and Cognition (LCBC), Department of Psychology, University of Oslo,Oslo, Norway
- Computational Radiology and Artificial Intelligence, Department of Radiology and Nuclear Medicine, Oslo University Hospital,Oslo, Norway
- Department of Neuroscience, University of California, Berkeley,Berkeley, CA USA
- Centre for Precision Psychiatry, Oslo University Hospital & Institute of Clinical Medicine, University of Oslo,Oslo, Norway
- Department of Neurology, Akershus University Hospital,Lørenskog, Norway
- Institute for Clinical Medicine, University of Oslo,Oslo, Norway
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repository
Its files are read in the Code ↔ Paper reader above, with 6 matches between paragraphs and lines of code.
jamesmroe/yearsBeforeAB
8606e753805b25245b52466dbf4d2c26cb94a43a, 7 May 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
17 files
- scripts/
01-prepSlopesYearsBefore , R, 1,201 linesAB.r - scripts/
01-prepSlopesYearsBefore , R, 1,282 lines, 1 matchAB_simulated.r - scripts/
02-prepSlopesCompare.r , R, 1,788 lines - scripts/
02-prepSlopesCompare_sim , R, 1,732 linesulate.r - scripts/
03-cortmaps_resample_nTi , R, 117 linesme.r - scripts/
04-cortmaps_summarize.r , R, 136 lines - scripts/
06-regionalWildBootstrap , R, 96 lines.r - scripts/
07-empiricalPmaps.r , R, 265 lines - scripts/
08-rankAmyloidOrder.r , R, 710 lines, 2 matches - scripts/
09-spinTestAB.r , R, 637 lines - scripts/
10-rankThicknessChange.r , R, 1,114 lines, 3 matches - scripts/
plotCovariates_extendedD , R, 478 linesata4.r - scripts/
plotSummary_extendedData , R, 333 lines5.r - scripts/
reproduce.sh , Shell, 570 lines - sourceData.r, R, 239 lines
- LICENSE, License, 21 lines
- README.md, Text, 143 lines
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: jamesmroe/
yearsBeforeAB
Read it in the paper: doi.org/10.1038/s41593-026-02363-4.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 15 scripts, each with its path and the digest of its content;
- 6 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it says that the data are available on request
Read it in the paper: doi.org/10.1038/s41593-026-02363-4.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Publisher: n/a → Nature Portfolio
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 20 authors, 2 keywords, 12 MeSH terms, 2 funders, 65 references.
Cite
This paper
Roe, J. M., Jagust, W. J., Landau, S. M., Harrison, T. M., Grydeland, H., Slivka, M., Alatorre-Warren, J.-L., Garrido, P. F., Sørensen, Ø., Grødem, E. O. S., Ward, T. J., Leonardsen, E. H., Murphy, A., Lee, J., Fladby, T., Bjørnerud, A., Walhovd, K. B., Fjell, A. M., Vidal-Piñeiro, D., & Wang, Y. (2026). Cortical thickness changes precede high levels of amyloid by at least 7 years. Nature neuroscience, 29(9), 2164-2175. https://
BibTeX
@article{roe2026cortical
author = {Roe, James M. and Jagust, William J. and Landau, Susan M. and Harrison, Theresa M. and Grydeland, Håkon and Slivka, Maksim and Alatorre-Warren, José-Luis and Garrido, Pablo F. and Sørensen, Øystein and Grødem, Edvard O. S. and Ward, Tyler J. and Leonardsen, Esten H. and Murphy, Alice and Lee, JiaQie and Fladby, Tormod and Bjørnerud, Atle and Walhovd, Kristine B. and Fjell, Anders M. and Vidal-Piñeiro, Didac and Wang, Yunpeng},
title = {{Cortical thickness changes precede high levels of amyloid by at least 7 years}},
journal = {Nature neuroscience},
year = {2026},
month = aug,
volume = {29},
number = {9},
pages = {2164--2175},
publisher = {Nature Portfolio},
issn = {1097-6256},
doi = {10.1038/
url = {https://
pmid = {42618753},
pmcid = {PMC13533846}
}
RIS
TY - JOUR
AU - Roe, James M.
AU - Jagust, William J.
AU - Landau, Susan M.
AU - Harrison, Theresa M.
AU - Grydeland, Håkon
AU - Slivka, Maksim
AU - Alatorre-Warren, José-Luis
AU - Garrido, Pablo F.
AU - Sørensen, Øystein
AU - Grødem, Edvard O. S.
AU - Ward, Tyler J.
AU - Leonardsen, Esten H.
AU - Murphy, Alice
AU - Lee, JiaQie
AU - Fladby, Tormod
AU - Bjørnerud, Atle
AU - Walhovd, Kristine B.
AU - Fjell, Anders M.
AU - Vidal-Piñeiro, Didac
AU - Wang, Yunpeng
TI - Cortical thickness changes precede high levels of amyloid by at least 7 years
T2 - Nature neuroscience
J2 - Nat Neurosci
PY - 2026
DA - 2026/
VL - 29
IS - 9
SP - 2164
EP - 2175
SN - 1097-6256
PB - Nature Portfolio
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Cortical thickness changes precede high levels of amyloid by at least 7 years",
"container-title": "Nature neuroscience",
"author": [
{
"family": "Roe",
"given": "James M."
},
{
"family": "Jagust",
"given": "William J."
},
{
"family": "Landau",
"given": "Susan M."
},
{
"family": "Harrison",
"given": "Theresa M."
},
{
"family": "Grydeland",
"given": "Håkon"
},
{
"family": "Slivka",
"given": "Maksim"
},
{
"family": "Alatorre-Warren",
"given": "José-Luis"
},
{
"family": "Garrido",
"given": "Pablo F."
},
{
"family": "Sørensen",
"given": "Øystein"
},
{
"family": "Grødem",
"given": "Edvard O. S."
},
{
"family": "Ward",
"given": "Tyler J."
},
{
"family": "Leonardsen",
"given": "Esten H."
},
{
"family": "Murphy",
"given": "Alice"
},
{
"family": "Lee",
"given": "JiaQie"
},
{
"family": "Fladby",
"given": "Tormod"
},
{
"family": "Bjørnerud",
"given": "Atle"
},
{
"family": "Walhovd",
"given": "Kristine B."
},
{
"family": "Fjell",
"given": "Anders M."
},
{
"family": "Vidal-Piñeiro",
"given": "Didac"
},
{
"family": "Wang",
"given": "Yunpeng"
}
],
"container-title-short":
"volume": "29",
"issue": "9",
"page": "2164-2175",
"DOI": "10.1038/
"PMID": "42618753",
"PMCID": "PMC13533846",
"ISSN": "1097-6256",
"publisher": "Nature Portfolio",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
19
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1162/imag.a.1242 [code]
- Stable individual differences dominate adult brain volume variation until later life.Journal: Imaging neuroscience (Cambridge, Mass.)In common: structural MRI / diffusion, 2 references, 4 authors
- [2] doi:10.1162/imag.a.1196 [code]
- Failure to detect entorhinal grid-like signals in a passive navigation human fMRI study.Journal: Imaging neuroscience (Cambridge, Mass.)In common: lmerTest, tidyverse, 3 authors
- [3] doi:10.1016/j.tjpad.2026.100622 [code]
- The time interval from amyloid to tau PET positivity varies by age, sex and APOE-ε4 status.Journal: The journal of prevention of Alzheimer's diseaseIn common: broom, lmerTest, lme4, 3 other tools, PET / SPECT, Alzheimer's / dementia, 5 references
- [4] doi:10.1002/alz.71609
- Cortical gray-white matter contrast alterations precede amyloid-β positivity and macrostructural changes in older adults without dementia.Journal: Alzheimer's & dementia : the journal of the Alzheimer's AssociationIn common: PET / SPECT, Alzheimer's / dementia, structural MRI / diffusion, 9 references
- [5] doi:10.1002/alz.71567 [code]
- Associations of dementia polyexposure scores to Alzheimer's disease endophenotypes in a diverse population.Journal: Alzheimer's & dementia : the journal of the Alzheimer's AssociationIn common: easystats, broom, cowplot, 4 other tools, PET / SPECT, Alzheimer's / dementia, 4 references
- [6] doi:10.1038/s41398-026-04010-9 [code]
- Bullying victimization and brain development: a longitudinal structural magnetic resonance imaging study from adolescence to early adulthood.Journal: Translational psychiatryIn common: ggseg, easystats, broom, 7 other tools, structural MRI / diffusion
- [7] doi:10.1093/brain/awaf413 [code]
- Estimating the time course of biomarker changes in Alzheimer's disease.Journal: Brain : a journal of neurologyIn common: PET / SPECT, Alzheimer's / dementia, structural MRI / diffusion, 9 references
- [8] doi:10.1093/braincomms/fcag176 [code]
- Tau topography subtypes account for clinical heterogeneity and longitudinal trajectories in early-onset Alzheimer's disease.Journal: Brain communicationsIn common: easystats, lmerTest, lme4, 4 other tools, PET / SPECT, Alzheimer's / dementia, 3 references
- [9] doi:10.1162/imag.a.1235 [code]
- Intracranial volume: To adjust or not to adjust? It is not a matter of if, but how.Journal: Imaging neuroscience (Cambridge, Mass.)In common: ggseg, broom, lmerTest, 6 other tools, structural MRI / diffusion, 1 reference
- [10] doi:10.1002/hbm.70605 [code]
- BrainEnrich: Revealing Biological Insights for Imaging-Derived Phenotypes Through Transcriptomic Enrichment.Journal: Human brain mappingIn common: ggseg, easystats, broom, 6 other tools, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 15 scripts, and 6 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:6ac3c10c57010040…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
