Acute and longitudinal magnetic resonance imaging abnormalities in antibody-mediated encephalitis.
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 · 885 lines · 41 KB · no license
- # MRI Ab-mediated encephalitis data code
- library(tidyverse)
- library(lubridate)
- library(dplyr)
- MRI1 <- MRI1 |>
- mutate(date_first_immunotherapy = pmin(
- pulsesteroids1,
- ivig1,
- plasma_exchange1,
- na.rm = TRUE
- ))
- MRI1$first_line_received <- ifelse(!is.na(MRI1$date_first_immunotherapy), 1, 0)
- # time to first
- MRI1$time_to_firstline <- difftime(MRI1$date_first_immunotherapy, MRI1$date_symptoms, "days")
- # limit time to first to maximum of 365 days from admission_date
- MRI1 <- MRI1 %>%
- mutate(time_to_firstline = pmin(time_to_firstline, as.numeric(first_admission_date + 365 - date_symptoms)))
- # replace "0" with NA in incomplete MRI's - ask Paul for a way to do this along columns in one go #
- MRI1$T1 <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T1)
- MRI1$T2 <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2)
- MRI1$CEL <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL)
- MRI1$DWI <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI)
- MRI1$T2_left_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_frontal)
- MRI1$T2_left_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_parietal)
- MRI1$T2_left_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_occipital)
- MRI1$T2_left_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_brainstem)
- MRI1$T2_left_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_cerebellum)
- MRI1$T2_left_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_temporal)
- MRI1$T2_left_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_mesial_temporal)
- MRI1$T2_left_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_left_insular)
- MRI1$T2_right_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_frontal)
- MRI1$T2_right_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_parietal)
- MRI1$T2_right_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_occipital)
- MRI1$T2_right_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_brainstem)
- MRI1$T2_right_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_cerebellum)
- MRI1$T2_right_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_temporal)
- MRI1$T2_right_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_mesial_temporal)
- MRI1$T2_right_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$T2_right_insular)
- MRI1$CEL_left_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_frontal)
- MRI1$CEL_left_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_parietal)
- MRI1$CEL_left_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_occipital)
- MRI1$CEL_left_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_brainstem)
- MRI1$CEL_left_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_cerebellum)
- MRI1$CEL_left_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_temporal)
- MRI1$CEL_left_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_mesial_temporal)
- MRI1$CEL_left_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_left_insular)
- MRI1$CEL_right_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_frontal)
- MRI1$CEL_right_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_parietal)
- MRI1$CEL_right_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_occipital)
- MRI1$CEL_right_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_brainstem)
- MRI1$CEL_right_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_cerebellum)
- MRI1$CEL_right_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_temporal)
- MRI1$CEL_right_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_mesial_temporal)
- MRI1$CEL_right_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$CEL_right_insular)
- MRI1$DWI_left_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_frontal)
- MRI1$DWI_left_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_parietal)
- MRI1$DWI_left_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_occipital)
- MRI1$DWI_left_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_brainstem)
- MRI1$DWI_left_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_cerebellum)
- MRI1$DWI_left_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_temporal)
- MRI1$DWI_left_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_mesial_temporal)
- MRI1$DWI_left_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_left_insular)
- MRI1$DWI_right_frontal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_frontal)
- MRI1$DWI_right_parietal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_parietal)
- MRI1$DWI_right_occipital <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_occipital)
- MRI1$DWI_right_brainstem <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_brainstem)
- MRI1$DWI_right_cerebellum <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_cerebellum)
- MRI1$DWI_right_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_temporal)
- MRI1$DWI_right_mesial_temporal <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_mesial_temporal)
- MRI1$DWI_right_insular <- ifelse(is.na(MRI1$mri_abnormal), MRI1$mri_abnormal, MRI1$DWI_right_insular)
- # create regions #
- MRI1$T2_mesial_temporal <- MRI1$T2_left_mesial_temporal + MRI1$T2_right_mesial_temporal
- MRI1$T2_mesial_temporal_bilateral <- car::recode(MRI1$T2_mesial_temporal, "2=1; 0=0; 1=0")
- MRI1$T2_mesial_temporal <- car::recode(MRI1$T2_mesial_temporal, "2=1; 1=1; 0=0")
- MRI1$T2_temporal <- MRI1$T2_left_temporal + MRI1$T2_right_temporal
- MRI1$T2_temporal <- car::recode(MRI1$T2_temporal, "2=1; 1=1; 0=0")
- MRI1$T2_extratemporal <- MRI1$T2_left_basal_ganglia + MRI1$T2_left_brainstem + MRI1$T2_left_cerebellum + MRI1$T2_left_frontal + MRI1$T2_left_insular + MRI1$T2_left_occipital + MRI1$T2_right_occipital + MRI1$T2_right_basal_ganglia + MRI1$T2_right_brainstem + MRI1$T2_right_cerebellum + MRI1$T2_right_frontal+MRI1$T2_right_parietal+MRI1$T2_right_insular+MRI1$T2_right_occipital
- MRI1$T2_extratemporal <- car::recode(MRI1$T2_extratemporal, "1:7=1; 0=0")
- MRI1$DWI_coded <- MRI1$DWI_left_brainstem + MRI1$DWI_left_cerebellum + MRI1$DWI_left_frontal + MRI1$DWI_left_parietal + MRI1$DWI_left_insular + MRI1$DWI_left_temporal + MRI1$DWI_left_basal_ganglia + MRI1$DWI_left_mesial_temporal + MRI1$DWI_right_brainstem + MRI1$DWI_right_cerebellum + MRI1$DWI_right_frontal + MRI1$DWI_right_parietal + MRI1$DWI_right_insular + MRI1$DWI_right_basal_ganglia + MRI1$DWI_right_mesial_temporal + MRI1$DWI_right_occipital + MRI1$DWI_right_parietal + MRI1$DWI_right_temporal
- MRI1$DWI_coded <- car::recode(MRI1$DWI_coded, "1:2=1; 0=0")
- MRI1$CEL_coded <- MRI1$CEL_left_brainstem + MRI1$CEL_left_cerebellum + MRI1$CEL_left_frontal + MRI1$CEL_left_insular + MRI1$CEL_left_basal_ganglia + MRI1$CEL_left_mesial_temporal + MRI1$CEL_left_mesial_temporal + MRI1$CEL_left_occipital + MRI1$CEL_left_parietal + MRI1$CEL_left_temporal + MRI1$CEL_right_brainstem + MRI1$CEL_right_cerebellum + MRI1$CEL_right_frontal + MRI1$CEL_right_insular + MRI1$CEL_right_basal_ganglia + MRI1$CEL_right_mesial_temporal + MRI1$CEL_right_occipital + MRI1$CEL_right_parietal+ MRI1$CEL_right_temporal
- MRI1$CEL_coded <- car::recode(MRI1$CEL_coded, "1:3=1; 0=0")
- MRI1$hippocampi_swelling_any <- ifelse((MRI1$size_hippo_l == 2 | MRI1$size_hippo_r == 2), 1, 0)
- MRI1$hippocampi_swelling_bilat <- ifelse((MRI1$size_hippo_l == 2 & MRI1$size_hippo_r == 2), 1, 0)
- MRI1$T2_extra_mesial_temporal <- MRI1$T2_temporal + MRI1$T2_extratemporal
- MRI1$T2_extra_mesial_temporal <- car::recode(MRI1$T2_extra_mesial_temporal, "1:2=1; 0=0")
- MRI1$focal_atrophy <- ifelse(MRI1$atrophy == 1 | MRI1$atrophy == 3, 1, 0)
- MRI1$time_to_MRI <- difftime(MRI1$date_of_mri, MRI1$date_symptoms, "days")
- dat2 <- MRI1 |>
- filter(final_diag == 5)
- dat2$m_mrs_good <- ifelse(dat2$m_mrs < 3, 1, 0)
- dat2$CASE_12 <- factor(dat2$CASE_12, ordered = TRUE)
- dat2$time_to_firstline <- ifelse(dat2$participant_id == "9057-81", difftime(dat2$date_visit_3, dat2$date_symptoms, units = "days"), dat2$time_to_firstline)
- # adjust time to first line to be a maximum of time to visit_3
- dat2 <- dat2 %>%
- mutate(
- time_to_firstline = as.numeric(time_to_firstline),
- time_to_firstline = if_else(
- !is.na(date_visit_3) & as.numeric(date_visit_3 - date_symptoms) < time_to_firstline,
- as.numeric(date_visit_3 - date_symptoms),
- time_to_firstline
- )
- )
- dat2$time_to_firstline <- ifelse(dat2$participant_id == "9057-81", dat2$date_visit_3 - dat2$date_symptoms, dat2$time_to_firstline)
- dat2$twelve_good <- ifelse(dat2$m_mrs_good == 1 & dat2$seizures_12 < 2 & dat2$memory_12 < 2, 1, 0)
- model1 <- glm(m_mrs_good ~ hippocampi_swelling_any, family = "binomial", data = dat2)
- exp(cbind(OR=coef(model1), confint.default(model1)))
- summary(model1)
- model2 <- glm(m_mrs_good ~ time_to_firstline, family = "binomial", data = dat2)
- exp(cbind(OR=coef(model2), confint.default(model2)))
- summary(model2)
- model3 <- glm(m_mrs_good ~ hippocampi_swelling_any + time_to_firstline + nadir_mrs+age_symptom_onset, family = "binomial", data = dat2)
- exp(cbind(OR=coef(model3), confint.default(model3)))
- summary(model3)
- model4 <- glm(m_mrs_good ~ T2 + time_to_firstline + nadir_mrs+age_symptom_onset, family = "binomial", data = dat2)
- exp(cbind(OR=coef(model4), confint.default(model4)))
- summary(model4)
- model5 <- glm(twelve_good ~ hippocampi_swelling_any + time_to_firstline, family = "binomial", data = dat2)
- exp(cbind(OR=coef(model5), confint.default(model5)))
- summary(model5)
- # NMDAR
- dat4 <- MRI1 |>
- filter(final_diag == 4)
- dat4$m_mrs_good <- ifelse(dat4$m_mrs < 3, 1, 0)
- dat4$CASE_12 <- factor(dat4$CASE_12, ordered = TRUE)
- dat4$time_to_firstline <- as.numeric(dat4$time_to_firstline)
- dat4 <- dat4 %>%
- mutate(
- time_to_firstline = as.numeric(time_to_firstline),
- time_to_firstline = if_else(
- !is.na(date_visit_3) & as.numeric(date_visit_3 - date_symptoms) < time_to_firstline,
- as.numeric(date_visit_3 - date_symptoms),
- time_to_firstline
- )
- )
- model6 <- glm(m_mrs_good ~ T2, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model6), confint.default(model6)))
- summary(model6)
- model7 <- glm(m_mrs_good ~ age_symptom_onset, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model7), confint.default(model7)))
- summary(model7)
- model8 <- glm(m_mrs_good ~ sex, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model8), confint.default(model8)))
- summary(model8)
- model9 <- glm(m_mrs_good ~ nadir_mrs, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model9), confint.default(model9)))
- summary(model9)
- model10 <- glm(m_mrs_good ~ time_to_firstline, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model10), confint.default(model10)))
- summary(model10)
- model11 <- glm(m_mrs_good ~ T2 + time_to_firstline + nadir_mrs+age_symptom_onset+sex, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model11), confint.default(model11)))
- summary(model11)
- # sensitivity analyses
- # Time to MRI, VIF, NMDAR
- library(car)
- model12 <- glm(
- m_mrs_good ~ age_symptom_onset +
- nadir_mrs +
- time_to_firstline +
- time_to_MRI +
- T2,
- family = binomial,
- data = dat2
- )
- vif(model12)
- exp(cbind(OR=coef(model12), confint.default(model12)))
- summary(model12)
- model13 <- glm(
- m_mrs_good ~ age_symptom_onset +
- nadir_mrs +
- time_to_firstline +
- time_to_MRI +
- T2,
- family = binomial,
- data = dat4
- )
- vif(model13)
- model14 <- glm(
- m_mrs_good ~ age_symptom_onset +
- nadir_mrs +
- time_to_firstline +
- time_to_MRI +
- T2,
- family = binomial,
- data = dat4a
- )
- vif(model14)
- # VIF here breached including both times
- model15 <- glm(m_mrs_good ~ T2 + time_to_MRI + nadir_mrs+age_symptom_onset+sex, family = "binomial", data = dat4)
- exp(cbind(OR=coef(model15), confint.default(model15)))
- summary(model15)
- # Time to MRI, VIF, LGI1
- # VIF
- model16 <- glm(
- m_mrs_good ~ hippocampi_swelling_any +
- age_symptom_onset +
- nadir_mrs +
- time_to_firstline +
- time_to_MRI,
- family = binomial,
- data = dat2
- )
- vif(model16)
- exp(cbind(OR=coef(model16), confint.default(model16)))
- summary(model16)
- # Table 1
- library(gtsummary)
- MRI1 <- MRI1 |>
- filter(!is.na(date_of_mri))
- MRI1$MRI_before_first <- ifelse(MRI1$date_of_mri < MRI1$date_first_immunotherapy | MRI1$date_of_mri == MRI1$date_first_immunotherapy, 1, 0)
- MRI1 <- MRI1 |>
- filter(final_diag == 4 | final_diag == 5 | final_diag == 6 | final_diag == 7 | final_diag == 8)
- MRI1 <- MRI1 |>
- ungroup()
- MRI1 <- MRI1 |>
- filter(!is.na(mri_abnormal))
- MRI1$final_diag_new <- factor(MRI1$final_diag,
- levels = c("4","5","6","7","8"),
- labels = c(
- "NMDAR",
- "LGI1",
- "CASPR2",
- "GABAB",
- "AMPAR"))
- tbl3 <- MRI1 |>
- select(final_diag_new, time_to_MRI, MRI_before_first, T2, T2_mesial_temporal, T2_mesial_temporal_bilateral, T2_temporal, T2_extratemporal, DWI_coded, CEL_coded, hippocampi_swelling_any, hippocampi_swelling_bilat, focal_atrophy, hippo_sclerosis) |>
- tbl_summary(
- by = final_diag_new,
- statistic = list(
- all_continuous() ~ "{median} ({p25},{p75})", # Median and IQR for continuous
- all_categorical() ~ "{n} ({p}%)" # Count and percentage for categorical
- ),
- digits = list(
- all_continuous() ~ 0, # No decimal places for continuous variables
- all_categorical() ~ c(0, 0) # No decimal places for categorical percentages
- ),
- missing_text = "(Missing)",
- label = c(
- time_to_MRI ~ "Time to MRI",
- MRI_before_first ~ "MRI before 1st line immunotherapy",
- T2 ~ "T2/FLAIR hyperintensity",
- T2_mesial_temporal ~ "T2/FLAIR mesial temporal",
- T2_mesial_temporal_bilateral ~ "Bilateral T2/FLAIR mesial temporal",
- T2_temporal ~ "T2/FLAIR temporal",
- T2_extratemporal ~ "T2/FLAIR extratemporal",
- DWI_coded ~ "DWI",
- CEL_coded ~ "CEL",
- hippocampi_swelling_any ~ "any hippocampi swelling",
- hippocampi_swelling_bilat ~ "bilateral hippocampi swelling",
- focal_atrophy ~ "focal atrophy",
- hippo_sclerosis ~ "Hippocampal sclerosis"
- )
- ) |>
- add_overall() # Add overall summary column
- # follow up evaluations
- # remove additional dates
- dat1 <- dat |>
- filter(final_diag == 4 | final_diag == 5 | final_diag == 6 | final_diag == 7 | final_diag == 8)
- # populate treatment variables further
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(pulsesteroids1, .direction = "down")
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(ivig1, .direction = "down")
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(plasma_exchange1, .direction = "down")
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(rituximab1, .direction = "down")
- dat1$hippocampi_swelling_any <- ifelse((dat1$size_hippo_l == 2 | dat1$size_hippo_r == 2), 1, 0)
- dat1$hippocampi_swelling_bilat <- ifelse((dat1$size_hippo_l == 2 & dat1$size_hippo_r == 2), 1, 0)
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(nadir_mrs, .direction = "down")
- dat1 <- dat1 |>
- filter(!is.na(date_of_mri))
- dat1$date_visit_12m <- as.Date(ifelse(dat1$row_num == 1, dat1$date_visit_3, NA))
- dat1 <- dat1 |>
- group_by(participant_id) |>
- fill(date_visit_12m, .direction = "down")
- # remove duplicates of first row/date:
- dat1_cleaned <- dat1 %>%
- group_by(participant_id) %>%
- mutate(first_mri_date = first(date_of_mri)) %>%
- filter(!(date_of_mri == first_mri_date & row_number() < max(row_number()[date_of_mri == first_mri_date]))) %>%
- ungroup()
- # Create a new dat1_cleaned with only patients who have more than one MRI date
- dat1_follow_up <- dat1_cleaned %>%
- group_by(participant_id) %>% # Group by patient ID
- filter(n() > 1) %>% # Filter patients with more than one MRI date
- ungroup() # Ungroup the data
- # create variable depicting date of first MRI:
- dat1_follow_up <- dat1_follow_up %>%
- group_by(participant_id) %>%
- mutate(date_of_first_MRI = min(date_of_mri, na.rm = TRUE)) %>%
- ungroup()
- # create atrophy
- # create mesial temporal atrophy
- dat1_follow_up$mesial_temporal_atrophy <- ifelse(dat1_follow_up$atrophy_left_mesial_temporal == 1 | dat1_follow_up$atrophy_right_mesial_temporal == 1, 1, 0)
- # frontal atrophy
- dat1_follow_up$frontal_atrophy <- ifelse(dat1_follow_up$atrophy_left_frontal == 1 | dat1_follow_up$atrophy_right_frontal == 1, 1, 0)
- # parietal atrophy
- dat1_follow_up$parietal_atrophy <- ifelse(dat1_follow_up$atrophy_left_parietal == 1 | dat1_follow_up$atrophy_right_parietal == 1, 1, 0)
- # temporal atrophy
- dat1_follow_up$temporal_atrophy <- ifelse(dat1_follow_up$atrophy_left_temporal == 1 | dat1_follow_up$atrophy_right_temporal == 1, 1, 0)
- # occipital atrophy
- dat1_follow_up$occipital_atrophy <- ifelse(dat1_follow_up$atrophy_left_occipital == 1 | dat1_follow_up$atrophy_right_occipital == 1, 1, 0)
- # cerebellar atrophy
- dat1_follow_up$cerebellar_atrophy <- ifelse(dat1_follow_up$atrophy_left_cerebellum == 1 | dat1_follow_up$atrophy_right_cerebellum == 1, 1, 0)
- # 'dat1_follow_up' will have patients with more than one MRI date
- dat1_follow_up2 <- dat1_follow_up |>
- select(participant_id, final_diag, age_symptom_onset, sex, nadir_mrs, first_admission_date, date_symptoms, date_of_mri, date_of_first_MRI, mri_abnormal, T2, atrophy, atrophy_left_mesial_temporal, atrophy_right_mesial_temporal, hippo_sclerosis, T2_right_mesial_temporal, T2_left_mesial_temporal, pulsesteroids1, ivig1, plasma_exchange1, rituximab1, hippocampi_swelling_any, hippocampi_swelling_bilat, final_visit_date, final_visit_mrs, final_visit_CASE, date_final_CASE, final_visit_memory, final_visit_seizures, dre, mesial_temporal_atrophy, frontal_atrophy, parietal_atrophy, temporal_atrophy, occipital_atrophy, cerebellar_atrophy, date_symptoms, date_visit_3, m_mrs, CASE_12, memory_12, date_visit_3, date_visit_12m)
- dat1_follow_up2$focal_atrophy <- ifelse(dat1_follow_up2$atrophy == 1 | dat1_follow_up2$atrophy == 3, 1, 0)
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- fill(date_symptoms, .direction = "down")
- # (below for T2 persistence)
- dat1_follow_up2$time_symptoms_to_MRI <- difftime(dat1_follow_up2$date_of_mri, dat1_follow_up2$date_symptoms, units = "days")
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |> # sequence row within each person
- mutate(max_num = n()) # total number rows per person
- dat1_follow_up2$time_MRI_to_MRI <- difftime(dat1_follow_up2$date_of_mri, dat1_follow_up2$date_of_first_MRI, units = "days")
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |> # sequence row within each person
- mutate(max_num = n()) # total number rows per person
- dat1_follow_up2 <- dat1_follow_up2 %>%
- group_by(participant_id) %>%
- mutate(hippocampi_swelling_initial = hippocampi_swelling_any[row_num == 1]) %>%
- ungroup()
- # flag last MRI, or if there is focal atrophy, the first MRI with focal atrophy
- dat1_follow_up2$flag_last_MR <- ifelse(dat1_follow_up2$row_num == dat1_follow_up2$max_num & dat1_follow_up2$focal_atrophy == 0, 1, 0)
- dat1_follow_up2$flag_last_MR <- ifelse((!is.na(dat1_follow_up2$focal_atrophy) & dat1_follow_up2$focal_atrophy == 1), 1, dat1_follow_up2$flag_last_MR)
- dat1_follow_up2$T2_initial <- ifelse((dat1_follow_up2$row_num == 1 & dat1_follow_up2$T2 == 1), 1, 0)
- dat1_follow_up2$T2_initial <- ifelse(dat1_follow_up2$T2_initial == 0, NA, dat1_follow_up2$T2_initial)
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- fill(T2_initial, .direction = "down")
- dat1_follow_up2$T2_initial <- ifelse(is.na(dat1_follow_up2$T2_initial), 0, dat1_follow_up2$T2_initial)
- dat1_follow_up2$T2_right_mesial_temporal_initial <- ifelse((dat1_follow_up2$row_num == 1 & dat1_follow_up2$T2_right_mesial_temporal == 1), 1, 0)
- dat1_follow_up2$T2_right_mesial_temporal_initial <- ifelse(dat1_follow_up2$T2_right_mesial_temporal_initial == 0, NA, dat1_follow_up2$T2_right_mesial_temporal_initial)
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- fill(T2_right_mesial_temporal_initial, .direction = "down")
- dat1_follow_up2$T2_right_mesial_temporal_initial <- ifelse(is.na(dat1_follow_up2$T2_right_mesial_temporal_initial), 0, dat1_follow_up2$T2_right_mesial_temporal_initial)
- dat1_follow_up2$T2_left_mesial_temporal_initial <- ifelse((dat1_follow_up2$row_num == 1 & dat1_follow_up2$T2_left_mesial_temporal == 1), 1, 0)
- dat1_follow_up2$T2_left_mesial_temporal_initial <- ifelse(dat1_follow_up2$T2_left_mesial_temporal_initial == 0, NA, dat1_follow_up2$T2_left_mesial_temporal_initial)
- dat1_follow_up2 <- dat1_follow_up2 |>
- group_by(participant_id) |>
- fill(T2_left_mesial_temporal_initial, .direction = "down")
- dat1_follow_up2$T2_left_mesial_temporal_initial <- ifelse(is.na(dat1_follow_up2$T2_left_mesial_temporal_initial), 0, dat1_follow_up2$T2_left_mesial_temporal_initial)
- dat1_follow_up2$T2_mesial_temporal_initial <- ifelse(dat1_follow_up2$T2_left_mesial_temporal_initial == 1 | dat1_follow_up2$T2_right_mesial_temporal_initial == 1, 1, 0)
- dat1_filtered <- dat1_follow_up2 %>%
- group_by(participant_id) %>% # Group by participant
- arrange(participant_id, date_of_mri) %>% # Arrange by participant and MRI date
- filter(row_number() == 1 | date_of_mri >= first(date_of_mri) + months(3)) %>% # Keep the first MRI and those >= 3 months later
- ungroup() # Ungroup the data
- dat1_filtered <- dat1_filtered |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |> # sequence row within each person
- mutate(max_num = n()) # total number rows per person
- dat1_filtered2 <- dat1_filtered |>
- filter(!(max_num ==1))
- # flag last MR if no atrophy, first MR that shows atrophy
- dat1_filtered2$flag_last_MR <- NA
- dat1_filtered2$flag_last_MR <- ifelse(dat1_filtered2$row_num == dat1_filtered2$max_num, 1, 0)
- dat1_filtered2$flag_last_MR <- ifelse(!is.na(dat1_filtered2$focal_atrophy) & dat1_filtered2$focal_atrophy == 1, 1, dat1_filtered2$flag_last_MR)
- dat1_flagged <- dat1_filtered2 %>%
- group_by(participant_id) %>% # Group by participant
- mutate(first_flag_last_MR = ifelse(row_number() == which.max(flag_last_MR == 1), 1, 0)) %>% # Flag the first occurrence of "1"
- ungroup() # Ungroup the data
- # 'dat1_flagged' will contain the flagged data
- dat1_flagged <- dat1_flagged |>
- filter(first_flag_last_MR == 1)
- # create first immunotherapy
- dat1_flagged <- dat1_flagged |>
- mutate(date_first_immunotherapy = pmin(
- pulsesteroids1,
- ivig1,
- plasma_exchange1,
- na.rm = TRUE
- ))
- # create Cox time variable
- dat1_flagged$time <- difftime(dat1_flagged$date_of_mri, dat1_flagged$first_admission_date, "days")
- # time to first
- dat1_flagged$time_to_firstline <- difftime(dat1_flagged$date_first_immunotherapy, dat1_flagged$date_symptoms, "days")
- # limit time to first to maximum date of MRI
- dat1_flagged <- dat1_flagged %>%
- mutate(
- time_to_firstline = as.numeric(time_to_firstline), # Ensure numeric
- time_to_firstline = if_else(
- !is.na(date_of_mri) & (as.numeric(date_of_mri - date_symptoms) < time_to_firstline),
- as.numeric(date_of_mri - date_symptoms), # Replace with the new value if condition is met
- time_to_firstline # Otherwise, retain the old value
- )
- )
- dat1_flagged$time_to_firstline <- ifelse(dat1_flagged$participant_id == "9057-81", (dat1_flagged$date_of_mri - dat1_flagged$date_symptoms), dat1_flagged$time_to_firstline)
- # dat1_flagged <- dat1_flagged %>%
- # mutate(time_to_firstline = pmin(time_to_firstline, as.numeric(first_admission_date + 365 - date_symptoms)))
- dat1_flagged$IT30 <- ifelse(dat1_flagged$time_to_firstline < 30, 1, 0) # only a few LGI1
- dat1_flagged$LGI1 <- ifelse(dat1_flagged$final_diag == 5, 1, 0)
- dat5 <- dat1_flagged |>
- filter(final_diag == 5)
- dat5$memory_12bad <- ifelse(dat5$memory_12 > 1, 1, 0)
- dat5$m_mrs_good <- ifelse(dat5$m_mrs < 3, 1, 0)
- dat5$sex <- ifelse(dat5$participant_id == "9061-16", 1, dat5$sex)
- model17 <- glm(focal_atrophy ~ hippocampi_swelling_initial, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model17), confint.default(model17)))
- summary(model17)
- model18 <- glm(focal_atrophy ~ age_symptom_onset, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model18), confint.default(model18)))
- summary(model18)
- model19 <- glm(focal_atrophy ~ sex, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model19), confint.default(model19)))
- summary(model19)
- model20 <- glm(focal_atrophy ~ time_to_firstline, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model20), confint.default(model20)))
- summary(model20)
- model21 <- glm(focal_atrophy ~ nadir_mrs, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model21), confint.default(model21)))
- summary(model21)
- model22 <- glm(focal_atrophy ~ T2_initial, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model22), confint.default(model22)))
- summary(model22)
- model23 <- glm(focal_atrophy ~ T2_mesial_temporal_initial, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model23), confint.default(model23)))
- summary(model23)
- model24 <- glm(focal_atrophy ~ hippocampi_swelling_initial + time_to_firstline, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model24), confint.default(model24)))
- summary(model24)
- model25 <- glm(focal_atrophy ~ T2_initial + time_to_firstline, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model25), confint.default(model25)))
- summary(model25)
- model26 <- glm(focal_atrophy ~ T2_mesial_temporal_initial + time_to_firstline, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model26), confint.default(model26)))
- summary(model26)
- model27 <- glm(memory_12bad ~ focal_atrophy, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model27), confint.default(model27)))
- summary(model27)
- model28 <- glm(memory_12bad ~ mesial_temporal_atrophy + age_symptom_onset, family = "binomial", data = dat5)
- exp(cbind(OR=coef(model28), confint.default(model28)))
- summary(model28)
- # HS
- dat1_filtered3 <- dat1_filtered |>
- filter(!(max_num ==1))
- # flag last MR if no atrophy, first MR that shows atrophy
- dat1_filtered3$flag_last_MR <- NA
- dat1_filtered3$flag_last_MR <- ifelse(dat1_filtered3$row_num == dat1_filtered3$max_num, 1, 0)
- dat1_filtered3$flag_last_MR <- ifelse(!is.na(dat1_filtered3$hippo_sclerosis) & dat1_filtered3$hippo_sclerosis == 1, 1, dat1_filtered3$flag_last_MR)
- dat1_flagged2 <- dat1_filtered3 %>%
- group_by(participant_id) %>% # Group by participant
- mutate(first_flag_last_MR = ifelse(row_number() == which.max(flag_last_MR == 1), 1, 0)) %>% # Flag the first occurrence of "1"
- ungroup() # Ungroup the data
- # 'dat1_flagged2' will contain the flagged data
- dat1_flagged2 <- dat1_flagged2 |>
- filter(first_flag_last_MR == 1)
- # create first immunotherapy
- dat1_flagged2 <- dat1_flagged2 |>
- mutate(date_first_immunotherapy = pmin(
- pulsesteroids1,
- ivig1,
- plasma_exchange1,
- na.rm = TRUE
- ))
- # create Cox time variable
- dat1_flagged2$time <- difftime(dat1_flagged2$date_of_mri, dat1_flagged2$first_admission_date, "days")
- # time to first
- dat1_flagged2$time_to_firstline <- difftime(dat1_flagged2$date_first_immunotherapy, dat1_flagged2$date_symptoms, "days")
- dat1_flagged2 <- dat1_flagged2 %>%
- mutate(
- time_to_firstline = as.numeric(time_to_firstline), # Ensure numeric
- time_to_firstline = if_else(
- !is.na(date_of_mri) & (as.numeric(date_of_mri - date_symptoms) < time_to_firstline),
- as.numeric(date_of_mri - date_symptoms), # Replace with the new value if condition is met
- time_to_firstline # Otherwise, retain the old value
- )
- )
- dat1_flagged2$time_to_firstline <- ifelse(dat1_flagged2$participant_id == "9057-81", dat1_flagged2$date_visit_3 - dat1_flagged2$date_symptoms, dat1_flagged2$time_to_firstline)
- dat5a <- dat1_flagged2 |>
- filter(final_diag == 5)
- dat5a$memory_12bad <- ifelse(dat5a$memory_12 > 1, 1, 0)
- dat5a$sex <- ifelse(dat5a$participant_id == "9061-16", 1, dat5a$sex)
- model29 <- glm(hippo_sclerosis ~ hippocampi_swelling_initial, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model29), confint.default(model29)))
- summary(model29)
- model30 <- glm(hippo_sclerosis ~ age_symptom_onset, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model30), confint.default(model30)))
- summary(model30)
- model31 <- glm(hippo_sclerosis ~ sex, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model31), confint.default(model31)))
- summary(model31)
- model32 <- glm(hippo_sclerosis ~ nadir_mrs, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model32), confint.default(model32)))
- summary(model32)
- model33 <- glm(hippo_sclerosis ~ time_to_firstline, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model33), confint.default(model33)))
- summary(model33)
- model34 <- glm(hippo_sclerosis ~ T2_initial, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model34), confint.default(model34)))
- summary(model34)
- model35 <- glm(hippo_sclerosis ~ T2_mesial_temporal_initial, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model35), confint.default(model35)))
- summary(model35)
- model36 <- glm(hippo_sclerosis ~ hippocampi_swelling_initial+time_to_firstline, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model36), confint.default(model36)))
- summary(model36)
- model37 <- glm(hippo_sclerosis ~ T2_mesial_temporal_initial+time_to_firstline, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model37), confint.default(model37)))
- summary(model37)
- model38 <- glm(hippo_sclerosis ~ T2_initial+time_to_firstline, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model38), confint.default(model38)))
- summary(model38)
- model39 <- glm(memory_12bad ~ hippo_sclerosis+age_symptom_onset, family = "binomial", data = dat5a)
- exp(cbind(OR=coef(model39), confint.default(model39)))
- summary(model39)
- # sensitivity analyses 1 & 2 for atrophy/HS analyses
- # 1 time symptoms to initial MRI (in relation to hippo swelling)
- dat5$time_to_MRI <- difftime(dat5$date_of_first_MRI, dat5$date_symptoms, "days")
- dat5$time_to_MRI <- as.numeric(dat5$time_to_MRI)
- model40 <- glm(focal_atrophy ~ hippocampi_swelling_initial + time_to_firstline + time_to_MRI, family = "binomial", data = dat5)
- library(car)
- vif(model40)
- exp(cbind(OR=coef(model40), confint.default(model40)))
- summary(model40)
- model41 <- glm(focal_atrophy ~ T2_initial + time_to_firstline + time_to_MRI, family = "binomial", data = dat5)
- vif(model41)
- exp(cbind(OR=coef(model41), confint.default(model41)))
- summary(model41)
- model42 <- glm(focal_atrophy ~ T2_mesial_temporal_initial + time_to_firstline + time_to_MRI, family = "binomial", data = dat5)
- vif(model42)
- exp(cbind(OR=coef(model42), confint.default(model42)))
- summary(model42)
- # 2 time MRI to MRI
- # given for this analysis time from one MR to the other was extremely skewed - e.g. over 2000 days for some - log used
- dat5$time_MRI_to_MRI <- as.numeric(dat5$time_MRI_to_MRI)
- model43 <- glm(focal_atrophy ~ hippocampi_swelling_initial + time_to_firstline + log(time_MRI_to_MRI), family = "binomial", data = dat5)
- vif(model43)
- exp(cbind(OR=coef(model43), confint.default(model43)))
- summary(model43)
- model44 <- glm(focal_atrophy ~ T2_initial + time_to_firstline + log(time_MRI_to_MRI), family = "binomial", data = dat5)
- vif(model44)
- exp(cbind(OR=coef(model44), confint.default(model44)))
- summary(model44)
- model45 <- glm(focal_atrophy ~ T2_mesial_temporal_initial + time_to_firstline + log(time_MRI_to_MRI), family = "binomial", data = dat5)
- vif(model45)
- exp(cbind(OR=coef(model45), confint.default(model45)))
- summary(model45)
- # HS sensitivity analysis
- dat5a$time_to_MRI <- difftime(dat5a$date_of_first_MRI, dat5a$date_symptoms, "days")
- dat5a$time_to_MRI <- as.numeric(dat5a$time_to_MRI)
- dat5a$time_MRI_to_MRI <- as.numeric(dat5a$time_MRI_to_MRI)
- # 1
- model46 <- glm(hippo_sclerosis ~ hippocampi_swelling_initial+time_to_firstline + time_to_MRI, family = "binomial", data = dat5a)
- vif(model46)
- exp(cbind(OR=coef(model46), confint.default(model46)))
- summary(model46)
- model47 <- glm(hippo_sclerosis ~ T2_mesial_temporal_initial+time_to_firstline + time_to_MRI, family = "binomial", data = dat5a)
- vif(model47)
- exp(cbind(OR=coef(model47), confint.default(model47)))
- summary(model47)
- model48 <- glm(hippo_sclerosis ~ T2_initial+time_to_firstline+ time_to_MRI, family = "binomial", data = dat5a)
- vif(model48)
- exp(cbind(OR=coef(model48), confint.default(model48)))
- summary(model48)
- # 2
- model49 <- glm(hippo_sclerosis ~ hippocampi_swelling_initial+time_to_firstline + log(time_MRI_to_MRI), family = "binomial", data = dat5a)
- vif(model49)
- exp(cbind(OR=coef(model49), confint.default(model49)))
- summary(model49)
- model50 <- glm(hippo_sclerosis ~ T2_mesial_temporal_initial+time_to_firstline + log(time_MRI_to_MRI), family = "binomial", data = dat5a)
- vif(model50)
- exp(cbind(OR=coef(model50), confint.default(model50)))
- summary(model50)
- model51 <- glm(hippo_sclerosis ~ T2_initial+time_to_firstline+ log(time_MRI_to_MRI), family = "binomial", data = dat5a)
- vif(model51)
- exp(cbind(OR=coef(model51), confint.default(model51)))
- summary(model51)
- # Atrophy table
- dat1_flagged <- dat1_flagged |>
- filter(final_diag == 4 | final_diag == 5 | final_diag == 6 | final_diag == 7 | final_diag == 8)
- # If dat1_flagged was not grouped before, you can remove the ungroup() line
- dat1_flagged <- dat1_flagged |>
- ungroup()
- dat1_flagged$final_diag_new <- factor(dat1_flagged$final_diag,
- levels = c(4, 5, 6, 7, 8),
- labels = c(
- "NMDAR",
- "LGI1",
- "CASPR2",
- "GABAB",
- "AMPAR"))
- tbl4 <- dat1_flagged |>
- select(final_diag_new, time_symptoms_to_MRI, time_MRI_to_MRI, focal_atrophy, mesial_temporal_atrophy, temporal_atrophy, frontal_atrophy, parietal_atrophy, occipital_atrophy, cerebellar_atrophy) |>
- tbl_summary(
- by = final_diag_new,
- statistic = list(
- all_continuous() ~ "{median} ({p25},{p75})", # Display median and IQR
- all_categorical() ~ "{n} ({p}%)" # Display counts and percentages
- ),
- digits = all_continuous() ~ 0, # No decimal points for continuous variables
- missing_text = "(Missing)",
- label = c(
- time_symptoms_to_MRI ~ "Time symptoms to MRI",
- time_MRI_to_MRI ~ "Time MRI from initial MRI",
- focal_atrophy ~ "Focal atrophy",
- mesial_temporal_atrophy ~ "Mesial temporal atrophy",
- temporal_atrophy ~ "Temporal atrophy",
- frontal_atrophy ~ "Frontal atrophy",
- parietal_atrophy ~ "Parietal atrophy",
- occipital_atrophy ~ "Occipital atrophy",
- cerebellar_atrophy ~ "Cerebellar atrophy"
- )
- ) |>
- add_overall() # Add overall summary column
- # HS table
- # Atrophy table
- dat1_flagged2 <- dat1_flagged2 |>
- filter(final_diag == 4 | final_diag == 5 | final_diag == 6 | final_diag == 7 | final_diag == 8)
- # If dat1_flagged was not grouped before, you can remove the ungroup() line
- dat1_flagged2 <- dat1_flagged2 |>
- ungroup()
- dat1_flagged2$final_diag_new <- factor(dat1_flagged2$final_diag,
- levels = c(4, 5, 6, 7, 8),
- labels = c(
- "NMDAR",
- "LGI1",
- "CASPR2",
- "GABAB",
- "AMPAR"))
- tbl5 <- dat1_flagged2 |>
- select(final_diag_new, time_symptoms_to_MRI, time_MRI_to_MRI, hippo_sclerosis) |>
- tbl_summary(
- by = final_diag_new,
- statistic = list(all_continuous() ~ "{median} ({p25},{p75})",
- all_categorical() ~ "{n} ({p}%)"),
- digits = all_continuous() ~ 0,
- missing_text = "(Missing)",
- label = c(time_symptoms_to_MRI ~ "Time symptoms to MRI",
- time_MRI_to_MRI ~ "Time MRI from initial MRI",
- hippo_sclerosis ~ "Hippocampal sclerosis")) |>
- add_overall()
- # T2 persistence
- dat1_filtered3 <- dat1_follow_up2 %>%
- group_by(participant_id) %>% # Group by participant
- arrange(participant_id, date_of_mri) %>% # Arrange by participant and MRI date
- filter(row_number() == 1 | date_of_mri >= first(date_of_mri) + months(1)) %>% # Keep the first MRI and those >= 1 months later
- ungroup() # Ungroup the data
- dat1_filtered3 <- dat1_filtered3 |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |> # sequence row within each person
- mutate(max_num = n()) # total number rows per person
- dat1_filtered3 <- dat1_filtered3 |>
- filter(!(max_num ==1))
- dat1 <- dat1_filtered3 |>
- select(participant_id, final_diag, date_of_mri, time_symptoms_to_MRI, T2, hippo_sclerosis, focal_atrophy, T2_mesial_temporal_initial, T2_left_mesial_temporal, T2_right_mesial_temporal, atrophy_left_mesial_temporal, atrophy_right_mesial_temporal)
- ## dat3 <- dat1 |>
- ## filter(final_diag == 5)
- dat3 <- dat1
- dat3 <- dat3 |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |>
- mutate(max_num = n())
- # create T2 initial MRI variable
- dat3$T2_initial <- ifelse(dat3$row_num == 1, dat3$T2, NA)
- dat3 <- dat3 |>
- group_by(participant_id) |>
- fill(T2_initial, .direction = "down")
- # Ensure that dat3 is sorted by participant_id and date_of_MRI
- dat3 <- dat3 |>
- arrange(participant_id, date_of_mri)
- # Calculate the time between MRIs relative to the first MRI for each participant
- dat3 <- dat3 |>
- group_by(participant_id) |>
- mutate(time_between_MRIs = time_symptoms_to_MRI - first(time_symptoms_to_MRI)) |>
- ungroup()
- dat3b <- dat3 |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |>
- mutate(max_num = n())
- dat3b <- dat3b |>
- filter(max_num > 1)
- # remove initial MRI row
- dat3bb <- dat3b |>
- filter(!(time_between_MRIs == 0))
- dat3bb <- dat3bb |>
- group_by(participant_id) |>
- mutate(row_num = row_number()) |>
- mutate(max_num = n())
- # filter first f/u MRI
- dat3bc <- dat3bb |>
- filter(row_num == 1)
- dat3bc$T2_no_left_mesial_atrophy <- ifelse(dat3bc$T2_left_mesial_temporal == 1 & dat3bc$atrophy_left_mesial_temporal == 0, 1, 0)
- dat3bc$T2_no_right_mesial_atrophy <- ifelse(dat3bc$T2_right_mesial_temporal == 1 & dat3bc$atrophy_right_mesial_temporal == 0, 1, 0)
- dat3bc$T2_no_mesial_atrophy <- ifelse(dat3bc$T2_no_left_mesial_atrophy == 1 | dat3bc$T2_no_right_mesial_atrophy == 1, 1, 0)
- dat3bc$T2_mesial_temporal <- ifelse(dat3bc$T2_left_mesial_temporal == 1 | dat3bc$T2_right_mesial_temporal == 1, 1, 0)
- dat3bc$time_symptoms_to_MRI <- as.numeric(dat3bc$time_symptoms_to_MRI)
- dat3bc$time_between_MRIs <- as.numeric(dat3bc$time_between_MRIs)
- dat3bc <- dat3bc |>
- ungroup()
- dat3bc$final_diag_new <- factor(dat3bc$final_diag,
- levels = c(4, 5, 6, 7, 8),
- labels = c(
- "NMDAR",
- "LGI1",
- "CASPR2",
- "GABAB",
- "AMPAR"))
- tbl5 <- dat3bc |>
- select(final_diag_new, time_symptoms_to_MRI, time_between_MRIs, T2_initial, T2, T2_mesial_temporal, T2_no_mesial_atrophy) |>
- tbl_summary(
- by = final_diag_new,
- statistic = list(
- all_continuous() ~ "{median} ({p25},{p75})", # Display median and IQR
- all_categorical() ~ "{n} ({p}%)" # Display counts and percentages
- ),
- digits = all_continuous() ~ 0, # No decimal points for continuous variables
- missing_text = "(Missing)",
- label = c(
- time_symptoms_to_MRI ~ "Time symptoms to MRI",
- time_between_MRIs ~ "Time MRI from initial MRI",
- T2_initial ~ "T2/FLAIR hyperintensity initial MRI",
- T2 ~ "T2/FLAIR hyperintensity follow-up MRI",
- T2_mesial_temporal ~ "Mesial temporal T2/FLAIR hyperintensity follow-up MRI",
- T2_no_mesial_atrophy ~ "Mesial temporal T2/FLAIR hyperintensity follow-up MRI, no HS"
- )
- ) |>
- add_overall() # Add overall summary column
Data_code_R.R at commit 7baaa12, no license · at the source
Overview
and 17 other authors
Andrew Swayne5,6, Amy Brodtmann1,9,13, David Gillis14, Ernest G Butler15, Tomas Kalincik13,16,17, Udaya Seneviratne1,11,18, Richard A Macdonell11, Sudarshini Ramanathan19,20, Stefan Blum5,6, Charles B Malpas1,21,22, Stephen W Reddel19,23, Todd A Hardy19,23, Terence J O’Brien1,2, Paul Sanfilippo1, Helmut Butzkueven1,2, Mastura Monif1,2, Australian Autoimmune Encephalitis Consortium23 affiliations
- Department of Neuroscience, School of Translational Medicine, Monash University, Melbourne, Victoria 3004, Australia
- Department of Neurology, Alfred Health, Melbourne, Victoria 3004, Australia
- Department of Radiology, Alfred Health, Melbourne, Victoria 3004, Australia
- Department of Radiology, Monash Health, Clayton, Victoria 3168, Australia
- Department of Neurology, Princess Alexandra Hospital, Woolloongabba, Queensland 4102, Australia
- School of Medicine, The University of Queensland, UQ, Herston, Queensland 4006, Australia
- Department of Medicine, St Vincent’s Hospital, University of Melbourne, Fitzroy, Victoria 3065, Australia
- Department of Neuroscience, Barwon Health, Geelong, Victoria 3220, Australia
- Department of Neurosciences, Eastern Health, Box Hill, Victoria 3128, Australia
- Department of Pathology, St Vincent’s Hospital, Fitzroy, Victoria 3065, Australia
- Department of Neurology, Austin Health, Heidelberg, Victoria 3084, Australia
- Department of Neurology, Royal Hobart Hospital, Hobart, Tasmania 7000, Australia
- Department of Neurology, Royal Melbourne Hospital, Parkville, Victoria 3052, Australia
- Division of Immunology, Pathology Queensland Central Laboratory, Herston, Queensland 4006, Australia
- Department of Neurology, Peninsula Health, Frankston, Victoria 3199, Australia
- Department of Medicine, CORE, The University of Melbourne, Parkville, Victoria 3010, Australia
- Department of Neurology, Neuroimmunology Centre, Royal Melbourne Hospital, Melbourne, Victoria 3000, Australia
- Department of Neuroscience, Monash Health, Clayton, Victoria 3168, Australia
- Department of Neurology and Concord Clinical School, Concord Hospital, Concord, New South Wales 2139, Australia
- Translational Neuroimmunology Group, Kids Neuroscience Centre and Brain and Mind Centre, Faculty of Medicine and Health, University of Sydney, Westmead, New South Wales 2145, Australia
- Department of Medicine (Royal Melbourne Hospital), University of Melbourne, Parkville, Victoria 3052, Australia
- Melbourne School of Psychological Sciences, University of Melbourne, Parkville, Victoria 3052, Australia
- Brain and Mind Centre, University of Sydney, Camperdown, New South Wales 2050, Australia
Abstract
Brain magnetic resonance imaging (MRI) abnormalities are an important finding in the evaluation of patients with suspected autoimmune encephalitis (AE). There have been few studies evaluating the frequency and prognostic significance of MRI abnormalities, especially hippocampal swelling, in anti-N-methyl-D-aspartat
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above.
nabilseery/Antibody-mediated-encephalitis-MRI-analysis-code
7baaa126afb2a5ca3c0d2c5cbed3b0624eb77ae9, 31 January 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
2 files
- Data_code_R.R, R, 885 lines
- README.md, Text, 12 lines
The paper's code and data availability statement is in the Data section.
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;
- 1 script, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- 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
Anonymized data is available to any qualified investigator by the corresponding author upon reasonable request and after approval from the relevant HREC. The R code used for statistical analysis and table generation is available at: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
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
- Funding: added National Health and Medical Research Council: APP1201062; Western Australian Future Health and Innovation Fund, Government of Western Australia
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 37 authors, 4 keywords, 40 references.
Cite
This paper
Seery, N., Beech, P., Wesselingh, R., Schoenwaelder, M., Broadley, J., McLaughlin, L., Rushen, T., ter Horst, L., Duncan, A., Tan, T., Kazzi, C., Skinner, G., Nesbitt, C., Buzzard, K., D’Souza, W. J., Tran, Y., van der Walt, A., Halliday, A., Forcadela, M., . . . Australian Autoimmune Encephalitis Consortium. (2026). Acute and longitudinal magnetic resonance imaging abnormalities in antibody-mediated encephalitis. Brain communications, 8(3), fcag193. https://
BibTeX
@article{seery2026acute,
author = {Seery, Nabil and Beech, Paul and Wesselingh, Robb and Schoenwaelder, Mark and Broadley, James and McLaughlin, Laurie and Rushen, Tiffany and ter Horst, Liora and Duncan, Andrew and Tan, Tracie and Kazzi, Christina and Skinner, Genevieve and Nesbitt, Cassie and Buzzard, Katherine and D’Souza, Wendyl J and Tran, Yang and van der Walt, Anneke and Halliday, Amy and Forcadela, Mirasol and Taylor, Bruce and Swayne, Andrew and Brodtmann, Amy and Gillis, David and Butler, Ernest G and Kalincik, Tomas and Seneviratne, Udaya and Macdonell, Richard A and Ramanathan, Sudarshini and Blum, Stefan and Malpas, Charles B and Reddel, Stephen W and Hardy, Todd A and O’Brien, Terence J and Sanfilippo, Paul and Butzkueven, Helmut and Monif, Mastura and {Australian Autoimmune Encephalitis Consortium}},
title = {{Acute and longitudinal magnetic resonance imaging abnormalities in antibody-mediated encephalitis}},
journal = {Brain communications},
year = {2026},
month = jun,
volume = {8},
number = {3},
pages = {fcag193},
publisher = {Oxford University Press},
issn = {2632-1297},
doi = {10.1093/
url = {https://
pmid = {42318510},
pmcid = {PMC13273915}
}
RIS
TY - JOUR
AU - Seery, Nabil
AU - Beech, Paul
AU - Wesselingh, Robb
AU - Schoenwaelder, Mark
AU - Broadley, James
AU - McLaughlin, Laurie
AU - Rushen, Tiffany
AU - ter Horst, Liora
AU - Duncan, Andrew
AU - Tan, Tracie
AU - Kazzi, Christina
AU - Skinner, Genevieve
AU - Nesbitt, Cassie
AU - Buzzard, Katherine
AU - D’Souza, Wendyl J
AU - Tran, Yang
AU - van der Walt, Anneke
AU - Halliday, Amy
AU - Forcadela, Mirasol
AU - Taylor, Bruce
AU - Swayne, Andrew
AU - Brodtmann, Amy
AU - Gillis, David
AU - Butler, Ernest G
AU - Kalincik, Tomas
AU - Seneviratne, Udaya
AU - Macdonell, Richard A
AU - Ramanathan, Sudarshini
AU - Blum, Stefan
AU - Malpas, Charles B
AU - Reddel, Stephen W
AU - Hardy, Todd A
AU - O’Brien, Terence J
AU - Sanfilippo, Paul
AU - Butzkueven, Helmut
AU - Monif, Mastura
AU - Australian Autoimmune Encephalitis Consortium
TI - Acute and longitudinal magnetic resonance imaging abnormalities in antibody-mediated encephalitis
T2 - Brain communications
J2 - Brain Commun
PY - 2026
DA - 2026/
VL - 8
IS - 3
SP - fcag193
SN - 2632-1297
PB - Oxford University Press
DO - 10.1093/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1093/
"type": "article-journal",
"title": "Acute and longitudinal magnetic resonance imaging abnormalities in antibody-mediated encephalitis",
"container-title": "Brain communications",
"author": [
{
"family": "Seery",
"given": "Nabil"
},
{
"family": "Beech",
"given": "Paul"
},
{
"family": "Wesselingh",
"given": "Robb"
},
{
"family": "Schoenwaelder",
"given": "Mark"
},
{
"family": "Broadley",
"given": "James"
},
{
"family": "McLaughlin",
"given": "Laurie"
},
{
"family": "Rushen",
"given": "Tiffany"
},
{
"family": "ter Horst",
"given": "Liora"
},
{
"family": "Duncan",
"given": "Andrew"
},
{
"family": "Tan",
"given": "Tracie"
},
{
"family": "Kazzi",
"given": "Christina"
},
{
"family": "Skinner",
"given": "Genevieve"
},
{
"family": "Nesbitt",
"given": "Cassie"
},
{
"family": "Buzzard",
"given": "Katherine"
},
{
"family": "D’Souza",
"given": "Wendyl J"
},
{
"family": "Tran",
"given": "Yang"
},
{
"family": "van der Walt",
"given": "Anneke"
},
{
"family": "Halliday",
"given": "Amy"
},
{
"family": "Forcadela",
"given": "Mirasol"
},
{
"family": "Taylor",
"given": "Bruce"
},
{
"family": "Swayne",
"given": "Andrew"
},
{
"family": "Brodtmann",
"given": "Amy"
},
{
"family": "Gillis",
"given": "David"
},
{
"family": "Butler",
"given": "Ernest G"
},
{
"family": "Kalincik",
"given": "Tomas"
},
{
"family": "Seneviratne",
"given": "Udaya"
},
{
"family": "Macdonell",
"given": "Richard A"
},
{
"family": "Ramanathan",
"given": "Sudarshini"
},
{
"family": "Blum",
"given": "Stefan"
},
{
"family": "Malpas",
"given": "Charles B"
},
{
"family": "Reddel",
"given": "Stephen W"
},
{
"family": "Hardy",
"given": "Todd A"
},
{
"family": "O’Brien",
"given": "Terence J"
},
{
"family": "Sanfilippo",
"given": "Paul"
},
{
"family": "Butzkueven",
"given": "Helmut"
},
{
"family": "Monif",
"given": "Mastura"
},
{
"literal": "Australian Autoimmune Encephalitis Consortium"
}
],
"container-title-short":
"volume": "8",
"issue": "3",
"page": "fcag193",
"DOI": "10.1093/
"PMID": "42318510",
"PMCID": "PMC13273915",
"ISSN": "2632-1297",
"publisher": "Oxford University Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
17
]
]
}
}
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.1093/braincomms/fcag255 [code]
- Impaired consolidation of spatial memory during sleep in patients with leucine-rich glioma-inactivated 1-associated limbic encephalitis.Journal: Brain communicationsIn common: tidyverse, other condition, 5 references
- [2] doi:10.1093/cercor/bhag069
- Diencephalic integrity explains aspects of hippocampal amnesia.Journal: Cerebral cortex (New York, N.Y. : 1991)In common: structural MRI / diffusion, other condition, 5 references
- [3] doi:10.1186/s12883-026-05085-z
- The use of routinely collected structural neuroimaging to identify cognitive impairment in multiple sclerosis.Journal: BMC neurologyIn common: structural MRI / diffusion, clinical / translational, author Tomas Kalinicik
- [4] doi:
- AMPAR immunization induces progressive autoimmune encephalitis with autoreactive B cells in the brainJournal: bioRxiv : the preprint server for biologyIn common: other condition, 3 references
- [5] doi:10.1126/sciadv.aec9291 [code]
- Computational mechanisms of perception in autism revealed using games inspired by rodent operant tasks.Journal: Science advancesIn common: car, tidyverse, 1 reference
- [6] doi:10.1038/s41398-026-04131-1 [code]
- Multimodal phenotypic classification of generalized anxiety and panic using structural MRI data and psychosocial factors: machine learning results from the German National Cohort (NAKO) study.Journal: Translational psychiatryIn common: car, tidyverse, structural MRI / diffusion, clinical / translational, other condition
- [7] doi:10.1016/j.dcn.2026.101769 [code]
- Differential adolescent neurodevelopment of emotion processing across internalizing psychopathology and childhood adversity.Journal: Developmental cognitive neuroscienceIn common: tidyverse, 2 references
- [8] doi:10.1016/j.xcrm.2026.102822
- Synaptophysin autoantibodies mediate synaptic dysfunction in cerebellar ataxia.Journal: Cell reports. MedicineIn common: other condition, 2 references
- [9] doi:10.1016/j.xcrm.2026.102700
- Checkpoint blockade-related CNS adverse events are characterized by neurotoxic T helper cells with sustained neuroantigen reactivity.Journal: Cell reports. MedicineIn common: clinical / translational, 2 references
- [10] doi:10.1186/s12974-026-03951-8
- Forkhead box versus NF-κB hippocampal snRNA-seq profiles distinguish anti-Drebrin- and anti-GAD65-positive encephalitis.Journal: Journal of neuroinflammationIn common: other condition, 2 references
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, 1 script, and 0 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:e5dec9524273704a…
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.
