# load packages
library(readxl)
library(writexl)
library(corrplot)
library(magrittr)
library(tidyverse)
library(readr)
library(reshape2)
library(dplyr)
library(irr)
library(psych)
library(stats)
library(readr)
library(lavaan)
library(ggplot2)
library(car)
library(knitr)
library(corrplot)
library(ggplot2)
library(reshape2)

Difference Scores Creation

The following code creates difference scores in a new column added to the original dataset looking at performance differences in RAVLT_immediate and RAVLT_learning between baseline and month 6, month 6 and month 12, month 12 and month 24, and month 24 and baseline.The file that is loaded has already been cleaned. Timepoint m36 removed to mantain larger sample. Inclusion of m36 resulted in sample of 700 participants while exclusion results in 1229 participants. Participants were further excluded if they did not have data at all timepoints. DIM1-45 and DIM2-45 removed for missing values. Anyone with incomplete values in occupation dimensions removed.This left us with a final sample of 1059.

# Set the working directory
setwd("C:/Users/narde/Documents/Baycrest/ADNI/ADNI Data")

# Read the exported CSV file
df.adni.wide <- read.csv("adni_final_sample.csv")

# Calculate difference scores and save to a new data frame for RAVLT immediate
adni_difference_score <- df.adni.wide %>%
  mutate(difference_RAVLT_imm_blv06 = RAVLT_immediate_bl - RAVLT_immediate_m06,
         difference_RAVLT_imm_06v12 = RAVLT_immediate_m06 - RAVLT_immediate_m12,
         difference_RAVLT_imm_12v24 = RAVLT_immediate_m12 - RAVLT_immediate_m24,
         difference_RAVLT_imm_blv24 = RAVLT_immediate_bl - RAVLT_immediate_m24)

# Calculate difference scores for RAVLT_learning and add to data frame
adni_difference_score <- adni_difference_score %>%
  mutate(difference_RAVLT_learn_blv06 = RAVLT_learning_bl - RAVLT_learning_m06,
         difference_RAVLT_learn_06v12 = RAVLT_learning_m06 - RAVLT_learning_m12,
         difference_RAVLT_learn_12v24 = RAVLT_learning_m12 - RAVLT_learning_m24,
         difference_RAVLT_learn_blv24 = RAVLT_learning_bl - RAVLT_learning_m24)

Correlation of Difference Scores with Occupation Dimensions

The following code produces a correlation matrix for all variables of interets at all timepoints include age, MMSE, occupation dimensions, difference scores, and RAVLT immediate, learning, and forgetting.

# Set the size of the plotting window
options(repr.plot.width = 20, repr.plot.height = 20)  

# Select columns of interest
variables_of_interest <- c("MMSE_bl", "MMSE_m06", "MMSE_m12", "MMSE_m24",
                            "RAVLT_immediate_bl", "RAVLT_immediate_m06", "RAVLT_immediate_m12", "RAVLT_immediate_m24",
                            "RAVLT_learning_bl", "RAVLT_learning_m06", "RAVLT_learning_m12", "RAVLT_learning_m24",
                            "RAVLT_forgetting_bl", "RAVLT_forgetting_m06", "RAVLT_forgetting_m12", "RAVLT_forgetting_m24",
                            "dim1_all_bl", "dim1_all_m06", "dim1_all_m12", "dim1_all_m24",
                            "dim2_all_bl", "dim2_all_m06", "dim2_all_m12", "dim2_all_m24",
                            "dim3_all_bl", "dim3_all_m06", "dim3_all_m12", "dim3_all_m24",
                            "AGE_bl", "AGE_m06", "AGE_m12", "AGE_m24")

adni_difference_score_subset <- adni_difference_score[, variables_of_interest, drop = FALSE]

# Multiply dim variables by -1
adni_difference_score_subset$dim1_all_bl <- adni_difference_score_subset$dim1_all_bl * -1
adni_difference_score_subset$dim1_all_m06 <- adni_difference_score_subset$dim1_all_m06 * -1
adni_difference_score_subset$dim1_all_m12 <- adni_difference_score_subset$dim1_all_m12 * -1
adni_difference_score_subset$dim1_all_m24 <- adni_difference_score_subset$dim1_all_m24 * -1
adni_difference_score_subset$dim2_all_bl <- adni_difference_score_subset$dim2_all_bl * -1
adni_difference_score_subset$dim2_all_m06 <- adni_difference_score_subset$dim2_all_m06 * -1
adni_difference_score_subset$dim2_all_m12 <- adni_difference_score_subset$dim2_all_m12 * -1
adni_difference_score_subset$dim2_all_m24 <- adni_difference_score_subset$dim2_all_m24 * -1
adni_difference_score_subset$dim3_all_bl <- adni_difference_score_subset$dim3_all_bl * -1
adni_difference_score_subset$dim3_all_m06 <- adni_difference_score_subset$dim3_all_m06 * -1
adni_difference_score_subset$dim3_all_m12 <- adni_difference_score_subset$dim3_all_m12 * -1
adni_difference_score_subset$dim3_all_m24 <- adni_difference_score_subset$dim3_all_m24 * -1

# Filter out non-numeric columns
numeric_cols <- sapply(adni_difference_score_subset, is.numeric)
numeric_data <- adni_difference_score_subset[, numeric_cols]

# Calculate correlation matrix, excluding NA values
cor_matrix <- cor(numeric_data, use = "pairwise.complete.obs")

# Customize label names
label_names <- c("MMSE_bl", "MMSE_m06", "MMSE_m12", "MMSE_m24",
                 "RAVLT_immediate_bl", "RAVLT_immediate_m06", "RAVLT_immediate_m12", "RAVLT_immediate_m24",
                 "RAVLT_learning_bl", "RAVLT_learning_m06", "RAVLT_learning_m12", "RAVLT_learning_m24",
                 "RAVLT_forgetting_bl", "RAVLT_forgetting_m06", "RAVLT_forgetting_m12", "RAVLT_forgetting_m24",
                 "dim1_all_bl", "dim1_all_m06", "dim1_all_m12", "dim1_all_m24",
                 "dim2_all_bl", "dim2_all_m06", "dim2_all_m12", "dim2_all_m24",
                 "dim3_all_bl", "dim3_all_m06", "dim3_all_m12", "dim3_all_m24",
                 "AGE_bl", "AGE_m06", "AGE_m12", "AGE_m24")
colnames(cor_matrix) <- label_names
rownames(cor_matrix) <- label_names

# Convert correlation matrix to long format for ggplot
cor_matrix_long <- melt(cor_matrix)

# Set the size of the plotting window
options(repr.plot.width = 12, repr.plot.height = 12)  # Adjust the values as needed

# Create a larger heatmap using ggplot2
ggplot(cor_matrix_long, aes(x = Var1, y = Var2, fill = value)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Correlation Matrix", x = NULL, y = NULL)

Multiple Linear Regression of Occupation Dimensions and RAVLT

The following code conducts numerous multiple linear regressions with the independent variables being the occupation dimensions and that dependent variables being the difference scores for the 4 timepoints for RAVLT_immediate and RAVLT_learning

# Perform multiple linear regressions using RAVLT_immediate and RAVLT_learning difference scores as dependent variables
independent_vars <- c("dim1_all_bl", "dim2_all_bl", "dim3_all_bl")

# Iterate over dependent variables (RAVLT_immediate and RAVLT_learning)
for (dep_var in c("difference_RAVLT_imm_blv06", "difference_RAVLT_imm_06v12", "difference_RAVLT_imm_12v24", "difference_RAVLT_imm_blv24",
                  "difference_RAVLT_learn_blv06", "difference_RAVLT_learn_06v12", "difference_RAVLT_learn_12v24", "difference_RAVLT_learn_blv24")) {
  
  # Create formula for linear regression
  formula <- as.formula(paste(dep_var, "~", paste(independent_vars, collapse = "+")))
  
  # Perform linear regression
  regression_result <- lm(formula, data = adni_difference_score)
  
  # Print regression summary
  cat("Regression for:", dep_var, "\n")
  print(summary(regression_result))
  cat("\n")
}
## Regression for: difference_RAVLT_imm_blv06 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -23.9412  -4.1292  -0.0366   3.9700  30.3531 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.464944   0.283207   8.704   <2e-16 ***
## dim1_all_bl -0.001706   0.043378  -0.039    0.969    
## dim2_all_bl -0.068465   0.045867  -1.493    0.136    
## dim3_all_bl -0.055743   0.057178  -0.975    0.330    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.857 on 1049 degrees of freedom
##   (6 observations deleted due to missingness)
## Multiple R-squared:  0.002967,   Adjusted R-squared:  0.0001157 
## F-statistic: 1.041 on 3 and 1049 DF,  p-value: 0.3737
## 
## 
## Regression for: difference_RAVLT_imm_06v12 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.2906  -4.2081   0.0573   4.2547  27.1571 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.73590    0.29085  -5.968 3.28e-09 ***
## dim1_all_bl  0.01564    0.04462   0.351    0.726    
## dim2_all_bl -0.07361    0.04692  -1.569    0.117    
## dim3_all_bl -0.02758    0.05863  -0.471    0.638    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.009 on 1043 degrees of freedom
##   (12 observations deleted due to missingness)
## Multiple R-squared:  0.002634,   Adjusted R-squared:  -0.0002351 
## F-statistic: 0.9181 on 3 and 1043 DF,  p-value: 0.4315
## 
## 
## Regression for: difference_RAVLT_imm_12v24 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.737  -3.869   0.175   4.130  33.811 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.98979    0.29810   3.320 0.000931 ***
## dim1_all_bl  0.02110    0.04576   0.461 0.644787    
## dim2_all_bl  0.01866    0.04799   0.389 0.697488    
## dim3_all_bl  0.02943    0.05990   0.491 0.623271    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.073 on 1015 degrees of freedom
##   (40 observations deleted due to missingness)
## Multiple R-squared:  0.0006052,  Adjusted R-squared:  -0.002349 
## F-statistic: 0.2049 on 3 and 1015 DF,  p-value: 0.8931
## 
## 
## Regression for: difference_RAVLT_imm_blv24 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -30.243  -5.106  -0.258   4.810  33.228 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.54186    0.33778   4.565 5.62e-06 ***
## dim1_all_bl  0.03218    0.05187   0.620   0.5352    
## dim2_all_bl -0.11538    0.05441  -2.121   0.0342 *  
## dim3_all_bl -0.03995    0.06774  -0.590   0.5555    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.019 on 1016 degrees of freedom
##   (39 observations deleted due to missingness)
## Multiple R-squared:  0.005032,   Adjusted R-squared:  0.002094 
## F-statistic: 1.713 on 3 and 1016 DF,  p-value: 0.1627
## 
## 
## Regression for: difference_RAVLT_learn_blv06 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.2933 -1.3931 -0.3086  1.6485 10.7513 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  0.286974   0.103182   2.781  0.00551 **
## dim1_all_bl -0.010473   0.015804  -0.663  0.50771   
## dim2_all_bl -0.005026   0.016711  -0.301  0.76363   
## dim3_all_bl -0.009000   0.020832  -0.432  0.66582   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.498 on 1049 degrees of freedom
##   (6 observations deleted due to missingness)
## Multiple R-squared:  0.000692,   Adjusted R-squared:  -0.002166 
## F-statistic: 0.2421 on 3 and 1049 DF,  p-value: 0.867
## 
## 
## Regression for: difference_RAVLT_learn_06v12 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.1074  -1.8345   0.1123   1.9971   8.0746 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.08029    0.10719  -0.749    0.454
## dim1_all_bl  0.01212    0.01644   0.737    0.461
## dim2_all_bl -0.01487    0.01729  -0.860    0.390
## dim3_all_bl  0.01397    0.02161   0.646    0.518
## 
## Residual standard error: 2.583 on 1043 degrees of freedom
##   (12 observations deleted due to missingness)
## Multiple R-squared:  0.001656,   Adjusted R-squared:  -0.001215 
## F-statistic: 0.5768 on 3 and 1043 DF,  p-value: 0.6303
## 
## 
## Regression for: difference_RAVLT_learn_12v24 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3969 -1.4497 -0.1349  1.7430 12.8883 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  0.173286   0.106036   1.634   0.1025  
## dim1_all_bl  0.005494   0.016277   0.338   0.7358  
## dim2_all_bl -0.032431   0.017071  -1.900   0.0577 .
## dim3_all_bl -0.005550   0.021305  -0.261   0.7945  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.516 on 1015 degrees of freedom
##   (40 observations deleted due to missingness)
## Multiple R-squared:  0.003684,   Adjusted R-squared:  0.0007393 
## F-statistic: 1.251 on 3 and 1015 DF,  p-value: 0.29
## 
## 
## Regression for: difference_RAVLT_learn_blv24 
## 
## Call:
## lm(formula = formula, data = adni_difference_score)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -9.455 -1.639 -0.058  1.603 12.667 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.399314   0.107896   3.701 0.000226 ***
## dim1_all_bl  0.012730   0.016570   0.768 0.442497    
## dim2_all_bl -0.049737   0.017379  -2.862 0.004297 ** 
## dim3_all_bl  0.001677   0.021638   0.078 0.938223    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.561 on 1016 degrees of freedom
##   (39 observations deleted due to missingness)
## Multiple R-squared:  0.008526,   Adjusted R-squared:  0.005598 
## F-statistic: 2.912 on 3 and 1016 DF,  p-value: 0.0335