Load Required Libraries

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.7     ✔ stringr 1.4.0
## ✔ tidyr   1.2.0     ✔ forcats 0.5.1
## ✔ readr   2.1.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(readxl)
library(ggplot2)
library(lmerTest)
## Loading required package: lme4
## Loading required package: Matrix
## Warning: package 'Matrix' was built under R version 4.2.1
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library(tidyr)
# Begin data upload
full_cross_sectional_data <- read.csv('Z:/Brackins dissertation r script and dummy data frames/cross-sectional dummy data frame.csv')
head(full_cross_sectional_data)
##   subject_id    sub_study SNQ_Quantity SNQ_Quality snq_total RAVLT Age    sex
## 1          1 Discoverysci           40           3        38    11  84 Female
## 2          2 Discoverysci           39           9        37     4  61   Male
## 3          3 Discoverysci           31          12        35    15  85   Male
## 4          4 Discoverysci           29           9        47    10  58 Female
## 5          5 Discoverysci           36           3        51     3  23   Male
## 6          6 Discoverysci           41           9        37    11  66   Male
##                           ethnicity                      race personality
## 1 Not Hispanic or Latino or Spanish                     white           1
## 2 Not Hispanic or Latino or Spanish Black or African American           2
## 3 Not Hispanic or Latino or Spanish                     white           3
## 4 Not Hispanic or Latino or Spanish                     white           2
## 5 Not Hispanic or Latino or Spanish                     Asian           3
## 6 Not Hispanic or Latino or Spanish                     white           2
##   Left.Thalamus.Proper Right.Thalamus.Proper thalamus_total_volume Left.Caudate
## 1               5773.2                5897.8               11671.0       2954.1
## 2               7300.9                6999.6               14300.5       3105.6
## 3               6751.6                6128.8               12880.4       3276.8
## 4               6907.9                6661.7               13569.6       2787.9
## 5               8358.7                8224.3               16583.0       3645.5
## 6               6321.5                6158.5               12480.0       2612.1
##   Right.Caudate caudate_total_volume Left.Putamen Right.Putamen
## 1        3044.6               5998.7       3373.0        3401.6
## 2        3129.6               6235.2       4493.3        4626.2
## 3        3456.4               6733.2       4336.0        4739.3
## 4        2848.7               5636.6       3585.7        3777.8
## 5        3579.6               7225.1       5324.1        5072.2
## 6        2910.9               5523.0       3837.8        3753.5
##   putamen_total_volume Left.Hippocampus Right.Hippocampus
## 1               6774.6           3679.3            3643.8
## 2               9119.5           3694.1            3768.9
## 3               9075.3           3101.9            3732.1
## 4               7363.5           3790.6            3899.8
## 5              10396.3           4127.0            4731.2
## 6               7591.3           4064.9            4077.8
##   hippocampus_total_volume Left.Amygdala Right.Amygdala amygdala_total_volume
## 1                     7483        1307.3         1391.3                  2383
## 2                     6708        1486.8         1417.6                  2529
## 3                     8318         847.0         1350.2                  2338
## 4                     7763        1303.0         1468.0                  2126
## 5                     7106        2004.6         1920.3                  2576
## 6                     8536        1296.0         1666.3                  3324
##   lhCortexVol rhCortexVol CortexVol SubCortGrayVol TotalGrayVol
## 1    180099.9    180873.9  360973.8          46657     515272.8
## 2    209443.4    215176.8  424620.3          54962     595006.3
## 3    212829.6    223411.2  436240.8          50870     596354.8
## 4    235435.5    236103.3  471538.8          48988     625777.8
## 5    243773.6    246826.7  490600.3          62668     677188.3
## 6    203425.2    203020.1  406445.2          49865     563753.2
##   EstimatedTotalIntraCranialVol lh_rostralmiddlefrontal_thickness
## 1                       1158574                             2.344
## 2                       1374227                             2.580
## 3                       1479439                             2.242
## 4                       1514698                             2.464
## 5                       1553358                             2.579
## 6                       1410264                             2.286
##   rh_rostralmiddlefrontal_thickness rostral_middle_frontal_average_thickness
## 1                             2.394                                   2.3690
## 2                             2.758                                   2.6690
## 3                             2.306                                   2.2740
## 4                             2.385                                   2.4245
## 5                             2.553                                   2.5660
## 6                             2.251                                   2.2685
##   lh_caudalmiddlefrontal_thickness rh_caudalmiddlefrontal_thickness
## 1                            2.560                            2.588
## 2                            2.998                            3.093
## 3                            2.434                            2.499
## 4                            2.619                            2.638
## 5                            2.825                            2.721
## 6                            2.429                            2.477
##   caudal_middle_average_thickness lh_parsopercularis_thickness
## 1                          2.5740                        2.552
## 2                          3.0455                        2.944
## 3                          2.4665                        2.400
## 4                          2.6285                        2.615
## 5                          2.7730                        2.853
## 6                          2.4530                        2.557
##   rh_parsopercularis_thickness lh_parsorbitalis_thickness
## 1                        2.618                      2.612
## 2                        2.853                      3.017
## 3                        2.556                      2.689
## 4                        2.539                      3.144
## 5                        2.846                      2.876
## 6                        2.418                      2.619
##   rh_parsorbitalis_thickness lh_parstriangularis_thickness
## 1                      2.932                         2.621
## 2                      3.102                         2.779
## 3                      2.473                         2.258
## 4                      2.528                         2.507
## 5                      2.738                         2.602
## 6                      2.556                         2.117
##   rh_parstriangularis_thickness left_inferior_pfc_average_thickness
## 1                         2.680                             1.94625
## 2                         2.640                             2.18500
## 3                         2.404                             1.83675
## 4                         2.391                             2.06650
## 5                         2.594                             2.08275
## 6                         2.198                             1.82325
##   right_inferior_pfc_average_thickness inferior_pfc_average_thickness
## 1                             2.743333                       2.344792
## 2                             2.865000                       2.525000
## 3                             2.477667                       2.157208
## 4                             2.486000                       2.276250
## 5                             2.726000                       2.404375
## 6                             2.390667                       2.106958
##   lh_superiorfrontal_thickness rh_superiorfrontal_thickness
## 1                        2.825                        2.693
## 2                        2.825                        3.040
## 3                        2.825                        2.512
## 4                        2.825                        2.687
## 5                        2.825                        2.871
## 6                        2.825                        2.489
##   superior_frontal_average_thickness left_pfc_average_thickness
## 1                             2.7590                    1.93505
## 2                             2.9325                    2.11760
## 3                             2.6685                    1.86755
## 4                             2.7560                    1.99490
## 5                             2.8480                    2.06235
## 6                             2.6570                    1.87265
##   right_pfc_average_thickness pfc_average_thickness
## 1                    2.083667              2.009358
## 2                    2.939000              2.528300
## 3                    2.448667              2.158108
## 4                    2.549000              2.271950
## 5                    2.717750              2.390050
## 6                    2.401917              2.137283
##   lh_inferiorparietal_thickness rh_inferiorparietal_thickness
## 1                         2.699                         2.677
## 2                         2.503                         2.561
## 3                         2.249                         2.423
## 4                         2.467                         2.548
## 5                         2.564                         2.602
## 6                         2.291                         2.378
##   inferior_parietal_average_thickness lh_superiorparietal_thickness
## 1                              2.6880                         2.397
## 2                              2.5320                         2.187
## 3                              2.3360                         2.042
## 4                              2.5075                         2.257
## 5                              2.5830                         2.315
## 6                              2.3345                         2.079
##   rh_superiorparietal_thickness superior_parietal_average_thickness
## 1                         2.291                               2.344
## 2                         2.507                               2.347
## 3                         2.226                               2.134
## 4                         2.329                               2.293
## 5                         2.085                               2.200
## 6                         2.235                               2.157
##   left_ppc_average_thickness right_ppc_average_thickness ppc_average_thickness
## 1                     2.5480                      2.4840               2.51600
## 2                     2.3450                      2.5340               2.43950
## 3                     2.1455                      2.3245               2.23500
## 4                     2.3620                      2.4385               2.40025
## 5                     2.4395                      2.3435               2.39150
## 6                     2.1850                      2.3065               2.24575
##   lh_MeanThickness_thickness rh_MeanThickness_thickness mean_thickness_average
## 1                    2.56971                    2.55457               2.562140
## 2                    2.63834                    2.67018               2.654260
## 3                    2.34325                    2.40386               2.373555
## 4                    2.54392                    2.53097               2.537445
## 5                    2.59484                    2.61362               2.604230
## 6                    2.38080                    2.38929               2.385045
##   lh_rostralmiddlefrontal_volume rh_rostralmiddlefrontal_volume
## 1                           9516                          10586
## 2                          12052                          14879
## 3                          12786                          13033
## 4                          14226                          15372
## 5                          15189                          15461
## 6                          13507                          12734
##   rostral_middle_frontal_total_volume lh_caudalmiddlefrontal_volume
## 1                               20102                          4300
## 2                               26931                          4944
## 3                               25819                          5319
## 4                               29598                          7763
## 5                               30650                          8307
## 6                               26241                          5147
##   rh_caudalmiddlefrontal_volume caudal_middle_total_volume
## 1                          3776                       8076
## 2                          5189                      10133
## 3                          5555                      10874
## 4                          5910                      13673
## 5                          6075                      14382
## 6                          4194                       9341
##   lh_parsopercularis_volume rh_parsopercularis_volume lh_parsorbitalis_volume
## 1                      3419                      3000                    1527
## 2                      4911                      4267                    2110
## 3                      4424                      3968                    2606
## 4                      4094                      3737                    2416
## 5                      8615                      3568                    2630
## 6                      3737                      2949                    2423
##   rh_parsorbitalis_volume lh_parstriangularis_volume rh_parstriangularis_volume
## 1                    2310                       3163                       3935
## 2                    2368                       2813                       3758
## 3                    2074                       2939                       3782
## 4                    2901                       3257                       3998
## 5                    2621                       4049                       3546
## 6                    2433                       2715                       2889
##   left_inferior_pfc_total_volume right_inferior_pfc_total_volume
## 1                           8109                            9245
## 2                           9834                           10393
## 3                           9969                            9824
## 4                           9767                           10636
## 5                          15294                            9735
## 6                           8875                            8271
##   inferior_pfc_total_volume lh_superiorfrontal_volume rh_superiorfrontal_volume
## 1                     17354                     18279                     15867
## 2                     20227                     20659                     19351
## 3                     19793                     21598                     20955
## 4                     20403                     23104                     21690
## 5                     25029                     24464                     18694
## 6                     17146                     19484                     19499
##   superior_frontal_total_volume left_pfc_total_volume right_pfc_total_volume
## 1                         34146                 40204                  39474
## 2                         40010                 47489                  49812
## 3                         42553                 49672                  49367
## 4                         44794                 54860                  53608
## 5                         43158                 63254                  49965
## 6                         38983                 47013                  44698
##   pfc_total_volume lh.rostralanteriorcingulate rh.rostralanteriorcingulate
## 1            79678                        8280                       10421
## 2            97301                       11336                       13624
## 3            99039                       12039                       12930
## 4           108468                       12213                       14344
## 5           113219                       14096                       14063
## 6            91711                        9078                       10673
##   lh.posteriorcingulate rh.posteriorcingulate lh.caudalanteriorcingulate
## 1                 18701                  9684                       9665
## 2                 24960                  9812                      11474
## 3                 24969                  9826                      10409
## 4                 26557                 11910                      12520
## 5                 28159                 10029                      13735
## 6                 19751                 11365                       9813
##   rh.caudalanteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                      19349               17964               20086
## 2                      21286               21148               25098
## 3                      20235               21865               23339
## 4                      24430               24123               26864
## 5                      23764               24125               27798
## 6                      21178               20443               20486
##   ppc_total_volume
## 1            38050
## 2            46246
## 3            45204
## 4            50987
## 5            51923
## 6            40929
# Select specific columns
selected_cross_sectional_data <- full_cross_sectional_data %>%
  select(subject_id, sub_study, SNQ_Quality, SNQ_Quantity, snq_total, RAVLT, Age, sex, personality, ethnicity, race, 
         hippocampus_total_volume, amygdala_total_volume, EstimatedTotalIntraCranialVol, 
         lh.caudalanteriorcingulate, rh.caudalanteriorcingulate, 
         lh.rostralanteriorcingulate, rh.rostralanteriorcingulate, 
         lh.posteriorcingulate, rh.posteriorcingulate, lh.isthmuscingulate, rh.isthmuscingulate)
head(selected_cross_sectional_data)
##   subject_id    sub_study SNQ_Quality SNQ_Quantity snq_total RAVLT Age    sex
## 1          1 Discoverysci           3           40        38    11  84 Female
## 2          2 Discoverysci           9           39        37     4  61   Male
## 3          3 Discoverysci          12           31        35    15  85   Male
## 4          4 Discoverysci           9           29        47    10  58 Female
## 5          5 Discoverysci           3           36        51     3  23   Male
## 6          6 Discoverysci           9           41        37    11  66   Male
##   personality                         ethnicity                      race
## 1           1 Not Hispanic or Latino or Spanish                     white
## 2           2 Not Hispanic or Latino or Spanish Black or African American
## 3           3 Not Hispanic or Latino or Spanish                     white
## 4           2 Not Hispanic or Latino or Spanish                     white
## 5           3 Not Hispanic or Latino or Spanish                     Asian
## 6           2 Not Hispanic or Latino or Spanish                     white
##   hippocampus_total_volume amygdala_total_volume EstimatedTotalIntraCranialVol
## 1                     7483                  2383                       1158574
## 2                     6708                  2529                       1374227
## 3                     8318                  2338                       1479439
## 4                     7763                  2126                       1514698
## 5                     7106                  2576                       1553358
## 6                     8536                  3324                       1410264
##   lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                       9665                      19349
## 2                      11474                      21286
## 3                      10409                      20235
## 4                      12520                      24430
## 5                      13735                      23764
## 6                       9813                      21178
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                        8280                       10421                 18701
## 2                       11336                       13624                 24960
## 3                       12039                       12930                 24969
## 4                       12213                       14344                 26557
## 5                       14096                       14063                 28159
## 6                        9078                       10673                 19751
##   rh.posteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                  9684               17964               20086
## 2                  9812               21148               25098
## 3                  9826               21865               23339
## 4                 11910               24123               26864
## 5                 10029               24125               27798
## 6                 11365               20443               20486
# Create new column for 'total_cingulate_volume'
selected_cross_sectional_data$total_cingulate_volume <- 
  selected_cross_sectional_data$lh.caudalanteriorcingulate +
  selected_cross_sectional_data$rh.caudalanteriorcingulate +
  selected_cross_sectional_data$lh.rostralanteriorcingulate +
  selected_cross_sectional_data$rh.rostralanteriorcingulate +
  selected_cross_sectional_data$lh.posteriorcingulate +
  selected_cross_sectional_data$rh.posteriorcingulate +
  selected_cross_sectional_data$lh.isthmuscingulate +
  selected_cross_sectional_data$rh.isthmuscingulate

# Check the new data frame
head(selected_cross_sectional_data)
##   subject_id    sub_study SNQ_Quality SNQ_Quantity snq_total RAVLT Age    sex
## 1          1 Discoverysci           3           40        38    11  84 Female
## 2          2 Discoverysci           9           39        37     4  61   Male
## 3          3 Discoverysci          12           31        35    15  85   Male
## 4          4 Discoverysci           9           29        47    10  58 Female
## 5          5 Discoverysci           3           36        51     3  23   Male
## 6          6 Discoverysci           9           41        37    11  66   Male
##   personality                         ethnicity                      race
## 1           1 Not Hispanic or Latino or Spanish                     white
## 2           2 Not Hispanic or Latino or Spanish Black or African American
## 3           3 Not Hispanic or Latino or Spanish                     white
## 4           2 Not Hispanic or Latino or Spanish                     white
## 5           3 Not Hispanic or Latino or Spanish                     Asian
## 6           2 Not Hispanic or Latino or Spanish                     white
##   hippocampus_total_volume amygdala_total_volume EstimatedTotalIntraCranialVol
## 1                     7483                  2383                       1158574
## 2                     6708                  2529                       1374227
## 3                     8318                  2338                       1479439
## 4                     7763                  2126                       1514698
## 5                     7106                  2576                       1553358
## 6                     8536                  3324                       1410264
##   lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                       9665                      19349
## 2                      11474                      21286
## 3                      10409                      20235
## 4                      12520                      24430
## 5                      13735                      23764
## 6                       9813                      21178
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                        8280                       10421                 18701
## 2                       11336                       13624                 24960
## 3                       12039                       12930                 24969
## 4                       12213                       14344                 26557
## 5                       14096                       14063                 28159
## 6                        9078                       10673                 19751
##   rh.posteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                  9684               17964               20086
## 2                  9812               21148               25098
## 3                  9826               21865               23339
## 4                 11910               24123               26864
## 5                 10029               24125               27798
## 6                 11365               20443               20486
##   total_cingulate_volume
## 1                 114150
## 2                 138738
## 3                 135612
## 4                 152961
## 5                 155769
## 6                 122787
# ---- begin loading longitudinal time one data----
# Read in longitudinal data frame
longitudinal_data <- read.csv("Z:/Brackins dissertation r script and dummy data frames/longitudinal dummy data frame.csv")
head(longitudinal_data)
##   subject_id  visit         sub_study SNQ_Quantity SNQ_Quality snq_total RAVLT
## 1          1 Time 1 adultlongitudinal           21          10        53     4
## 2          2 Time 2 adultlongitudinal           22          12        37     8
## 3          3 Time 1 adultlongitudinal           44          11        55     1
## 4          4 Time 2 adultlongitudinal           30          12        31    15
## 5          5 Time 1 adultlongitudinal           37           7        40     3
## 6          6 Time 2 adultlongitudinal           42          10        40     3
##   Age    sex personality                         ethnicity
## 1  78 Female           1 Not Hispanic or Latino or Spanish
## 2  46   Male           5 Not Hispanic or Latino or Spanish
## 3  64   Male           3 Not Hispanic or Latino or Spanish
## 4  70 Female           2 Not Hispanic or Latino or Spanish
## 5  67   Male           3 Not Hispanic or Latino or Spanish
## 6  62   Male           3 Not Hispanic or Latino or Spanish
##                        race Left.Thalamus.Proper Right.Thalamus.Proper
## 1                     white               5773.2                5897.8
## 2 Black or African American               7300.9                6999.6
## 3                     white               6751.6                6128.8
## 4                     white               6907.9                6661.7
## 5                     Asian               8358.7                8224.3
## 6                     white               6321.5                6158.5
##   thalamus_total_volume Left.Caudate Right.Caudate caudate_total_volume
## 1               11671.0       2954.1        3044.6               5998.7
## 2               14300.5       3105.6        3129.6               6235.2
## 3               12880.4       3276.8        3456.4               6733.2
## 4               13569.6       2787.9        2848.7               5636.6
## 5               16583.0       3645.5        3579.6               7225.1
## 6               12480.0       2612.1        2910.9               5523.0
##   Left.Putamen Right.Putamen putamen_total_volume Left.Hippocampus
## 1       3373.0        3401.6               6774.6           3679.3
## 2       4493.3        4626.2               9119.5           3694.1
## 3       4336.0        4739.3               9075.3           3101.9
## 4       3585.7        3777.8               7363.5           3790.6
## 5       5324.1        5072.2              10396.3           4127.0
## 6       3837.8        3753.5               7591.3           4064.9
##   Right.Hippocampus hippocampus_total_volume Left.Amygdala Right.Amygdala
## 1            3643.8                     7414        1307.3         1391.3
## 2            3768.9                     5356        1486.8         1417.6
## 3            3732.1                     7785         847.0         1350.2
## 4            3899.8                     7081        1303.0         1468.0
## 5            4731.2                     5143        2004.6         1920.3
## 6            4077.8                     5975        1296.0         1666.3
##   amygdala_total_volume lhCortexVol rhCortexVol CortexVol SubCortGrayVol
## 1                  3256    180099.9    180873.9  360973.8          46657
## 2                  2345    209443.4    215176.8  424620.3          54962
## 3                  2772    212829.6    223411.2  436240.8          50870
## 4                  3119    235435.5    236103.3  471538.8          48988
## 5                  3261    243773.6    246826.7  490600.3          62668
## 6                  3006    203425.2    203020.1  406445.2          49865
##   TotalGrayVol EstimatedTotalIntraCranialVol lh_rostralmiddlefrontal_thickness
## 1     515272.8                       1158574                             2.344
## 2     595006.3                       1374227                             2.580
## 3     596354.8                       1479439                             2.242
## 4     625777.8                       1514698                             2.464
## 5     677188.3                       1553358                             2.579
## 6     563753.2                       1410264                             2.286
##   rh_rostralmiddlefrontal_thickness rostral_middle_frontal_average_thickness
## 1                             2.394                                   2.3690
## 2                             2.758                                   2.6690
## 3                             2.306                                   2.2740
## 4                             2.385                                   2.4245
## 5                             2.553                                   2.5660
## 6                             2.251                                   2.2685
##   lh_caudalmiddlefrontal_thickness rh_caudalmiddlefrontal_thickness
## 1                            2.560                            2.588
## 2                            2.998                            3.093
## 3                            2.434                            2.499
## 4                            2.619                            2.638
## 5                            2.825                            2.721
## 6                            2.429                            2.477
##   caudal_middle_average_thickness lh_parsopercularis_thickness
## 1                          2.5740                        2.552
## 2                          3.0455                        2.944
## 3                          2.4665                        2.400
## 4                          2.6285                        2.615
## 5                          2.7730                        2.853
## 6                          2.4530                        2.557
##   rh_parsopercularis_thickness lh_parsorbitalis_thickness
## 1                        2.618                      2.612
## 2                        2.853                      3.017
## 3                        2.556                      2.689
## 4                        2.539                      3.144
## 5                        2.846                      2.876
## 6                        2.418                      2.619
##   rh_parsorbitalis_thickness lh_parstriangularis_thickness
## 1                      2.932                         2.621
## 2                      3.102                         2.779
## 3                      2.473                         2.258
## 4                      2.528                         2.507
## 5                      2.738                         2.602
## 6                      2.556                         2.117
##   rh_parstriangularis_thickness left_inferior_pfc_average_thickness
## 1                         2.680                             1.94625
## 2                         2.640                             2.18500
## 3                         2.404                             1.83675
## 4                         2.391                             2.06650
## 5                         2.594                             2.08275
## 6                         2.198                             1.82325
##   right_inferior_pfc_average_thickness inferior_pfc_average_thickness
## 1                             2.743333                       2.344792
## 2                             2.865000                       2.525000
## 3                             2.477667                       2.157208
## 4                             2.486000                       2.276250
## 5                             2.726000                       2.404375
## 6                             2.390667                       2.106958
##   lh_superiorfrontal_thickness rh_superiorfrontal_thickness
## 1                        2.825                        2.693
## 2                        2.825                        3.040
## 3                        2.825                        2.512
## 4                        2.825                        2.687
## 5                        2.825                        2.871
## 6                        2.825                        2.489
##   superior_frontal_average_thickness left_pfc_average_thickness
## 1                             2.7590                    1.93505
## 2                             2.9325                    2.11760
## 3                             2.6685                    1.86755
## 4                             2.7560                    1.99490
## 5                             2.8480                    2.06235
## 6                             2.6570                    1.87265
##   right_pfc_average_thickness pfc_average_thickness
## 1                    2.083667              2.009358
## 2                    2.939000              2.528300
## 3                    2.448667              2.158108
## 4                    2.549000              2.271950
## 5                    2.717750              2.390050
## 6                    2.401917              2.137283
##   lh_inferiorparietal_thickness rh_inferiorparietal_thickness
## 1                         2.699                         2.677
## 2                         2.503                         2.561
## 3                         2.249                         2.423
## 4                         2.467                         2.548
## 5                         2.564                         2.602
## 6                         2.291                         2.378
##   inferior_parietal_average_thickness lh_superiorparietal_thickness
## 1                              2.6880                         2.397
## 2                              2.5320                         2.187
## 3                              2.3360                         2.042
## 4                              2.5075                         2.257
## 5                              2.5830                         2.315
## 6                              2.3345                         2.079
##   rh_superiorparietal_thickness superior_parietal_average_thickness
## 1                         2.291                               2.344
## 2                         2.507                               2.347
## 3                         2.226                               2.134
## 4                         2.329                               2.293
## 5                         2.085                               2.200
## 6                         2.235                               2.157
##   left_ppc_average_thickness right_ppc_average_thickness ppc_average_thickness
## 1                     2.5480                      2.4840               2.51600
## 2                     2.3450                      2.5340               2.43950
## 3                     2.1455                      2.3245               2.23500
## 4                     2.3620                      2.4385               2.40025
## 5                     2.4395                      2.3435               2.39150
## 6                     2.1850                      2.3065               2.24575
##   lh_MeanThickness_thickness rh_MeanThickness_thickness mean_thickness_average
## 1                    2.56971                    2.55457               2.562140
## 2                    2.63834                    2.67018               2.654260
## 3                    2.34325                    2.40386               2.373555
## 4                    2.54392                    2.53097               2.537445
## 5                    2.59484                    2.61362               2.604230
## 6                    2.38080                    2.38929               2.385045
##   lh_rostralmiddlefrontal_volume rh_rostralmiddlefrontal_volume
## 1                           9516                          10586
## 2                          12052                          14879
## 3                          12786                          13033
## 4                          14226                          15372
## 5                          15189                          15461
## 6                          13507                          12734
##   rostral_middle_frontal_total_volume lh_caudalmiddlefrontal_volume
## 1                               20102                          4300
## 2                               26931                          4944
## 3                               25819                          5319
## 4                               29598                          7763
## 5                               30650                          8307
## 6                               26241                          5147
##   rh_caudalmiddlefrontal_volume caudal_middle_total_volume
## 1                          3776                       8076
## 2                          5189                      10133
## 3                          5555                      10874
## 4                          5910                      13673
## 5                          6075                      14382
## 6                          4194                       9341
##   lh_parsopercularis_volume rh_parsopercularis_volume lh_parsorbitalis_volume
## 1                      3419                      3000                    1527
## 2                      4911                      4267                    2110
## 3                      4424                      3968                    2606
## 4                      4094                      3737                    2416
## 5                      8615                      3568                    2630
## 6                      3737                      2949                    2423
##   rh_parsorbitalis_volume lh_parstriangularis_volume rh_parstriangularis_volume
## 1                    2310                       3163                       3935
## 2                    2368                       2813                       3758
## 3                    2074                       2939                       3782
## 4                    2901                       3257                       3998
## 5                    2621                       4049                       3546
## 6                    2433                       2715                       2889
##   left_inferior_pfc_total_volume right_inferior_pfc_total_volume
## 1                           8109                            9245
## 2                           9834                           10393
## 3                           9969                            9824
## 4                           9767                           10636
## 5                          15294                            9735
## 6                           8875                            8271
##   inferior_pfc_total_volume lh_superiorfrontal_volume rh_superiorfrontal_volume
## 1                     17354                     18279                     15867
## 2                     20227                     20659                     19351
## 3                     19793                     21598                     20955
## 4                     20403                     23104                     21690
## 5                     25029                     24464                     18694
## 6                     17146                     19484                     19499
##   superior_frontal_total_volume left_pfc_total_volume right_pfc_total_volume
## 1                         34146                 40204                  39474
## 2                         40010                 47489                  49812
## 3                         42553                 49672                  49367
## 4                         44794                 54860                  53608
## 5                         43158                 63254                  49965
## 6                         38983                 47013                  44698
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                       79678                        8280                 10421
## 2                       97301                       11336                 13624
## 3                       99039                       12039                 12930
## 4                      108468                       12213                 14344
## 5                      113219                       14096                 14063
## 6                       91711                        9078                 10673
##   rh.posteriorcingulate lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                 18701                       9684                       9665
## 2                 24960                       9812                      11474
## 3                 24969                       9826                      10409
## 4                 26557                      11910                      12520
## 5                 28159                      10029                      13735
## 6                 19751                      11365                       9813
##   lh.isthmuscingulate rh.isthmuscingulate right_ppc_total_volume
## 1               19349               17964                  20086
## 2               21286               21148                  25098
## 3               20235               21865                  23339
## 4               24430               24123                  26864
## 5               23764               24125                  27798
## 6               21178               20443                  20486
##   ppc_total_volume
## 1            38050
## 2            46246
## 3            45204
## 4            50987
## 5            51923
## 6            40929
# Filter for Time 1
longitudinal_data_time1 <- longitudinal_data %>%
  filter(visit == "Time 1")
head(longitudinal_data_time1)
##   subject_id  visit         sub_study SNQ_Quantity SNQ_Quality snq_total RAVLT
## 1          1 Time 1 adultlongitudinal           21          10        53     4
## 2          3 Time 1 adultlongitudinal           44          11        55     1
## 3          5 Time 1 adultlongitudinal           37           7        40     3
## 4          7 Time 1 adultlongitudinal           41          10        38     7
## 5          9 Time 1 adultlongitudinal           38          11        49     3
## 6         11 Time 1 adultlongitudinal           28          11        53     2
##   Age    sex personality                         ethnicity
## 1  78 Female           1 Not Hispanic or Latino or Spanish
## 2  64   Male           3 Not Hispanic or Latino or Spanish
## 3  67   Male           3 Not Hispanic or Latino or Spanish
## 4  70   Male           4     Hispanic or Latino or Spanish
## 5  60 Female           4 Not Hispanic or Latino or Spanish
## 6  44   Male           5 Not Hispanic or Latino or Spanish
##                        race Left.Thalamus.Proper Right.Thalamus.Proper
## 1                     white               5773.2                5897.8
## 2                     white               6751.6                6128.8
## 3                     Asian               8358.7                8224.3
## 4                     white               7268.4                7087.7
## 5                     white               7765.0                7022.6
## 6 Black or African American               7485.7                7533.6
##   thalamus_total_volume Left.Caudate Right.Caudate caudate_total_volume
## 1               11671.0       2954.1        3044.6               5998.7
## 2               12880.4       3276.8        3456.4               6733.2
## 3               16583.0       3645.5        3579.6               7225.1
## 4               14356.1       2981.0        3013.1               5994.1
## 5               14787.6       3420.9        3299.2               6720.1
## 6               15019.3       3071.1        3272.4               6343.5
##   Left.Putamen Right.Putamen putamen_total_volume Left.Hippocampus
## 1       3373.0        3401.6               6774.6           3679.3
## 2       4336.0        4739.3               9075.3           3101.9
## 3       5324.1        5072.2              10396.3           4127.0
## 4       5140.4        5231.6              10372.0           3530.7
## 5       4200.5        4220.1               8420.6           3761.4
## 6       4185.5        4366.5               8552.0           3561.2
##   Right.Hippocampus hippocampus_total_volume Left.Amygdala Right.Amygdala
## 1            3643.8                     7414        1307.3         1391.3
## 2            3732.1                     7785         847.0         1350.2
## 3            4731.2                     5143        2004.6         1920.3
## 4            3704.1                     5467        1511.2         1521.0
## 5            3865.7                     5107        1399.7         1706.0
## 6            3655.6                     7906        1608.5         1479.0
##   amygdala_total_volume lhCortexVol rhCortexVol CortexVol SubCortGrayVol
## 1                  3256    180099.9    180873.9  360973.8          46657
## 2                  2772    212829.6    223411.2  436240.8          50870
## 3                  3261    243773.6    246826.7  490600.3          62668
## 4                  3504    234988.0    236805.8  471793.8          54672
## 5                  3576    201729.7    203926.7  405656.4          53984
## 6                  2674    208727.0    210406.0  419133.0          53227
##   TotalGrayVol EstimatedTotalIntraCranialVol lh_rostralmiddlefrontal_thickness
## 1     515272.8                       1158574                             2.344
## 2     596354.8                       1479439                             2.242
## 3     677188.3                       1553358                             2.579
## 4     636791.8                       1455158                             2.384
## 5     582896.4                       1321438                             2.463
## 6     571305.0                       1434374                             2.459
##   rh_rostralmiddlefrontal_thickness rostral_middle_frontal_average_thickness
## 1                             2.394                                   2.3690
## 2                             2.306                                   2.2740
## 3                             2.553                                   2.5660
## 4                             2.511                                   2.4475
## 5                             2.382                                   2.4225
## 6                             2.315                                   2.3870
##   lh_caudalmiddlefrontal_thickness rh_caudalmiddlefrontal_thickness
## 1                            2.560                            2.588
## 2                            2.434                            2.499
## 3                            2.825                            2.721
## 4                            2.815                            2.836
## 5                            2.710                            2.550
## 6                            2.658                            2.767
##   caudal_middle_average_thickness lh_parsopercularis_thickness
## 1                          2.5740                        2.552
## 2                          2.4665                        2.400
## 3                          2.7730                        2.853
## 4                          2.8255                        2.828
## 5                          2.6300                        2.648
## 6                          2.7125                        2.622
##   rh_parsopercularis_thickness lh_parsorbitalis_thickness
## 1                        2.618                      2.612
## 2                        2.556                      2.689
## 3                        2.846                      2.876
## 4                        2.885                      2.765
## 5                        2.557                      2.758
## 6                        2.646                      2.632
##   rh_parsorbitalis_thickness lh_parstriangularis_thickness
## 1                      2.932                         2.621
## 2                      2.473                         2.258
## 3                      2.738                         2.602
## 4                      2.994                         2.752
## 5                      2.885                         2.514
## 6                      2.822                         2.361
##   rh_parstriangularis_thickness left_inferior_pfc_average_thickness
## 1                         2.680                             1.94625
## 2                         2.404                             1.83675
## 3                         2.594                             2.08275
## 4                         2.726                             2.08625
## 5                         2.636                             1.98000
## 6                         2.433                             1.90375
##   right_inferior_pfc_average_thickness inferior_pfc_average_thickness
## 1                             2.743333                       2.344792
## 2                             2.477667                       2.157208
## 3                             2.726000                       2.404375
## 4                             2.868333                       2.477292
## 5                             2.692667                       2.336333
## 6                             2.633667                       2.268708
##   lh_superiorfrontal_thickness rh_superiorfrontal_thickness
## 1                        2.825                        2.693
## 2                        2.825                        2.512
## 3                        2.825                        2.871
## 4                        2.825                        3.108
## 5                        2.825                        2.807
## 6                        2.825                        2.754
##   superior_frontal_average_thickness left_pfc_average_thickness
## 1                             2.7590                    1.93505
## 2                             2.6685                    1.86755
## 3                             2.8480                    2.06235
## 4                             2.9665                    2.02205
## 5                             2.8160                    1.99560
## 6                             2.7895                    1.96915
##   right_pfc_average_thickness pfc_average_thickness
## 1                    2.083667              2.009358
## 2                    2.448667              2.158108
## 3                    2.717750              2.390050
## 4                    2.830833              2.426442
## 5                    2.607917              2.301758
## 6                    2.617417              2.293283
##   lh_inferiorparietal_thickness rh_inferiorparietal_thickness
## 1                         2.699                         2.677
## 2                         2.249                         2.423
## 3                         2.564                         2.602
## 4                         2.584                         2.621
## 5                         2.759                         2.683
## 6                         2.443                         2.498
##   inferior_parietal_average_thickness lh_superiorparietal_thickness
## 1                              2.6880                         2.397
## 2                              2.3360                         2.042
## 3                              2.5830                         2.315
## 4                              2.6025                         2.407
## 5                              2.7210                         2.346
## 6                              2.4705                         2.280
##   rh_superiorparietal_thickness superior_parietal_average_thickness
## 1                         2.291                              2.3440
## 2                         2.226                              2.1340
## 3                         2.085                              2.2000
## 4                         2.293                              2.3500
## 5                         2.509                              2.4275
## 6                         2.315                              2.2975
##   left_ppc_average_thickness right_ppc_average_thickness ppc_average_thickness
## 1                     2.5480                      2.4840               2.51600
## 2                     2.1455                      2.3245               2.23500
## 3                     2.4395                      2.3435               2.39150
## 4                     2.4955                      2.4570               2.47625
## 5                     2.5525                      2.5960               2.57425
## 6                     2.3615                      2.4065               2.38400
##   lh_MeanThickness_thickness rh_MeanThickness_thickness mean_thickness_average
## 1                    2.56971                    2.55457               2.562140
## 2                    2.34325                    2.40386               2.373555
## 3                    2.59484                    2.61362               2.604230
## 4                    2.67279                    2.70045               2.686620
## 5                    2.61234                    2.57711               2.594725
## 6                    2.45544                    2.44891               2.452175
##   lh_rostralmiddlefrontal_volume rh_rostralmiddlefrontal_volume
## 1                           9516                          10586
## 2                          12786                          13033
## 3                          15189                          15461
## 4                          13206                          14113
## 5                          12949                          12628
## 6                          13978                          13324
##   rostral_middle_frontal_total_volume lh_caudalmiddlefrontal_volume
## 1                               20102                          4300
## 2                               25819                          5319
## 3                               30650                          8307
## 4                               27319                          6711
## 5                               25577                          4973
## 6                               27302                          5303
##   rh_caudalmiddlefrontal_volume caudal_middle_total_volume
## 1                          3776                       8076
## 2                          5555                      10874
## 3                          6075                      14382
## 4                          5632                      12343
## 5                          4713                       9686
## 6                          5161                      10464
##   lh_parsopercularis_volume rh_parsopercularis_volume lh_parsorbitalis_volume
## 1                      3419                      3000                    1527
## 2                      4424                      3968                    2606
## 3                      8615                      3568                    2630
## 4                      4279                      3617                    2299
## 5                      3423                      3309                    2075
## 6                      4054                      3204                    2414
##   rh_parsorbitalis_volume lh_parstriangularis_volume rh_parstriangularis_volume
## 1                    2310                       3163                       3935
## 2                    2074                       2939                       3782
## 3                    2621                       4049                       3546
## 4                    2693                       3740                       4111
## 5                    2431                       3482                       4088
## 6                    2979                       3647                       4240
##   left_inferior_pfc_total_volume right_inferior_pfc_total_volume
## 1                           8109                            9245
## 2                           9969                            9824
## 3                          15294                            9735
## 4                          10318                           10421
## 5                           8980                            9828
## 6                          10115                           10423
##   inferior_pfc_total_volume lh_superiorfrontal_volume rh_superiorfrontal_volume
## 1                     17354                     18279                     15867
## 2                     19793                     21598                     20955
## 3                     25029                     24464                     18694
## 4                     20739                     22566                     23294
## 5                     18808                     19376                     19232
## 6                     20538                     20825                     19395
##   superior_frontal_total_volume left_pfc_total_volume right_pfc_total_volume
## 1                         34146                 40204                  39474
## 2                         42553                 49672                  49367
## 3                         43158                 63254                  49965
## 4                         45860                 52801                  53460
## 5                         38608                 46278                  46401
## 6                         40220                 50221                  48303
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                       79678                        8280                 10421
## 2                       99039                       12039                 12930
## 3                      113219                       14096                 14063
## 4                      106261                       10021                 16784
## 5                       92679                       11782                 12599
## 6                       98524                        8149                 12012
##   rh.posteriorcingulate lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                 18701                       9684                       9665
## 2                 24969                       9826                      10409
## 3                 28159                      10029                      13735
## 4                 26805                      13974                      13568
## 5                 24381                      11031                      10449
## 6                 20161                      11918                      10642
##   lh.isthmuscingulate rh.isthmuscingulate right_ppc_total_volume
## 1               19349               17964                  20086
## 2               20235               21865                  23339
## 3               23764               24125                  27798
## 4               27542               23995                  30352
## 5               21480               22813                  23048
## 6               22560               20067                  22654
##   ppc_total_volume
## 1            38050
## 2            45204
## 3            51923
## 4            54347
## 5            45861
## 6            42721
# Select specific columns
longitudinal_data_time1_specific_columns <- longitudinal_data_time1 %>% 
  select(subject_id, sub_study, SNQ_Quantity, SNQ_Quality, snq_total, RAVLT, Age, sex, personality, ethnicity, race, 
         hippocampus_total_volume, amygdala_total_volume, EstimatedTotalIntraCranialVol, 
         lh.caudalanteriorcingulate, rh.caudalanteriorcingulate, 
         lh.rostralanteriorcingulate, rh.rostralanteriorcingulate, 
         lh.posteriorcingulate, rh.posteriorcingulate, lh.isthmuscingulate, rh.isthmuscingulate)
head(longitudinal_data_time1_specific_columns)
##   subject_id         sub_study SNQ_Quantity SNQ_Quality snq_total RAVLT Age
## 1          1 adultlongitudinal           21          10        53     4  78
## 2          3 adultlongitudinal           44          11        55     1  64
## 3          5 adultlongitudinal           37           7        40     3  67
## 4          7 adultlongitudinal           41          10        38     7  70
## 5          9 adultlongitudinal           38          11        49     3  60
## 6         11 adultlongitudinal           28          11        53     2  44
##      sex personality                         ethnicity
## 1 Female           1 Not Hispanic or Latino or Spanish
## 2   Male           3 Not Hispanic or Latino or Spanish
## 3   Male           3 Not Hispanic or Latino or Spanish
## 4   Male           4     Hispanic or Latino or Spanish
## 5 Female           4 Not Hispanic or Latino or Spanish
## 6   Male           5 Not Hispanic or Latino or Spanish
##                        race hippocampus_total_volume amygdala_total_volume
## 1                     white                     7414                  3256
## 2                     white                     7785                  2772
## 3                     Asian                     5143                  3261
## 4                     white                     5467                  3504
## 5                     white                     5107                  3576
## 6 Black or African American                     7906                  2674
##   EstimatedTotalIntraCranialVol lh.caudalanteriorcingulate
## 1                       1158574                       9684
## 2                       1479439                       9826
## 3                       1553358                      10029
## 4                       1455158                      13974
## 5                       1321438                      11031
## 6                       1434374                      11918
##   rh.caudalanteriorcingulate lh.rostralanteriorcingulate
## 1                       9665                       79678
## 2                      10409                       99039
## 3                      13735                      113219
## 4                      13568                      106261
## 5                      10449                       92679
## 6                      10642                       98524
##   rh.rostralanteriorcingulate lh.posteriorcingulate rh.posteriorcingulate
## 1                        8280                 10421                 18701
## 2                       12039                 12930                 24969
## 3                       14096                 14063                 28159
## 4                       10021                 16784                 26805
## 5                       11782                 12599                 24381
## 6                        8149                 12012                 20161
##   lh.isthmuscingulate rh.isthmuscingulate
## 1               19349               17964
## 2               20235               21865
## 3               23764               24125
## 4               27542               23995
## 5               21480               22813
## 6               22560               20067
# Create new column for 'total_cingulate_volume'
longitudinal_data_time1_specific_columns$total_cingulate_volume <- 
  longitudinal_data_time1_specific_columns$lh.caudalanteriorcingulate +
  longitudinal_data_time1_specific_columns$rh.caudalanteriorcingulate +
  longitudinal_data_time1_specific_columns$lh.rostralanteriorcingulate +
  longitudinal_data_time1_specific_columns$rh.rostralanteriorcingulate +
  longitudinal_data_time1_specific_columns$lh.posteriorcingulate +
  longitudinal_data_time1_specific_columns$rh.posteriorcingulate +
  longitudinal_data_time1_specific_columns$lh.isthmuscingulate +
  longitudinal_data_time1_specific_columns$rh.isthmuscingulate
# Merge the two data frames
full_data_frame_merged <- rbind(selected_cross_sectional_data, longitudinal_data_time1_specific_columns)
head(full_data_frame_merged)
##   subject_id    sub_study SNQ_Quality SNQ_Quantity snq_total RAVLT Age    sex
## 1          1 Discoverysci           3           40        38    11  84 Female
## 2          2 Discoverysci           9           39        37     4  61   Male
## 3          3 Discoverysci          12           31        35    15  85   Male
## 4          4 Discoverysci           9           29        47    10  58 Female
## 5          5 Discoverysci           3           36        51     3  23   Male
## 6          6 Discoverysci           9           41        37    11  66   Male
##   personality                         ethnicity                      race
## 1           1 Not Hispanic or Latino or Spanish                     white
## 2           2 Not Hispanic or Latino or Spanish Black or African American
## 3           3 Not Hispanic or Latino or Spanish                     white
## 4           2 Not Hispanic or Latino or Spanish                     white
## 5           3 Not Hispanic or Latino or Spanish                     Asian
## 6           2 Not Hispanic or Latino or Spanish                     white
##   hippocampus_total_volume amygdala_total_volume EstimatedTotalIntraCranialVol
## 1                     7483                  2383                       1158574
## 2                     6708                  2529                       1374227
## 3                     8318                  2338                       1479439
## 4                     7763                  2126                       1514698
## 5                     7106                  2576                       1553358
## 6                     8536                  3324                       1410264
##   lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                       9665                      19349
## 2                      11474                      21286
## 3                      10409                      20235
## 4                      12520                      24430
## 5                      13735                      23764
## 6                       9813                      21178
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                        8280                       10421                 18701
## 2                       11336                       13624                 24960
## 3                       12039                       12930                 24969
## 4                       12213                       14344                 26557
## 5                       14096                       14063                 28159
## 6                        9078                       10673                 19751
##   rh.posteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                  9684               17964               20086
## 2                  9812               21148               25098
## 3                  9826               21865               23339
## 4                 11910               24123               26864
## 5                 10029               24125               27798
## 6                 11365               20443               20486
##   total_cingulate_volume
## 1                 114150
## 2                 138738
## 3                 135612
## 4                 152961
## 5                 155769
## 6                 122787
# ---- filter data to keep >54 ----
# Filter for Age > 54
full_data_frame_merged_over_55 <- full_data_frame_merged %>%
  filter(Age > 54)
head(full_data_frame_merged_over_55)
##   subject_id    sub_study SNQ_Quality SNQ_Quantity snq_total RAVLT Age    sex
## 1          1 Discoverysci           3           40        38    11  84 Female
## 2          2 Discoverysci           9           39        37     4  61   Male
## 3          3 Discoverysci          12           31        35    15  85   Male
## 4          4 Discoverysci           9           29        47    10  58 Female
## 5          6 Discoverysci           9           41        37    11  66   Male
## 6          7 Discoverysci          12           28        40    15  84   Male
##   personality                         ethnicity                      race
## 1           1 Not Hispanic or Latino or Spanish                     white
## 2           2 Not Hispanic or Latino or Spanish Black or African American
## 3           3 Not Hispanic or Latino or Spanish                     white
## 4           2 Not Hispanic or Latino or Spanish                     white
## 5           2 Not Hispanic or Latino or Spanish                     white
## 6           3     Hispanic or Latino or Spanish                     white
##   hippocampus_total_volume amygdala_total_volume EstimatedTotalIntraCranialVol
## 1                     7483                  2383                       1158574
## 2                     6708                  2529                       1374227
## 3                     8318                  2338                       1479439
## 4                     7763                  2126                       1514698
## 5                     8536                  3324                       1410264
## 6                     8844                  2505                       1455158
##   lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                       9665                      19349
## 2                      11474                      21286
## 3                      10409                      20235
## 4                      12520                      24430
## 5                       9813                      21178
## 6                      13568                      27542
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                        8280                       10421                 18701
## 2                       11336                       13624                 24960
## 3                       12039                       12930                 24969
## 4                       12213                       14344                 26557
## 5                        9078                       10673                 19751
## 6                       10021                       16784                 26805
##   rh.posteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                  9684               17964               20086
## 2                  9812               21148               25098
## 3                  9826               21865               23339
## 4                 11910               24123               26864
## 5                 11365               20443               20486
## 6                 13974               23995               30352
##   total_cingulate_volume
## 1                 114150
## 2                 138738
## 3                 135612
## 4                 152961
## 5                 122787
## 6                 163041
# Correct for ICV
full_data_frame_merged_over_55_corrected_for_icv <- full_data_frame_merged_over_55 %>%
  mutate(
    hippocampus_total_volume_corrected = hippocampus_total_volume / EstimatedTotalIntraCranialVol,
    amygdala_total_volume_corrected = amygdala_total_volume / EstimatedTotalIntraCranialVol,
    total_cingulate_volume_corrected = total_cingulate_volume / EstimatedTotalIntraCranialVol
  )
head(full_data_frame_merged_over_55_corrected_for_icv)
##   subject_id    sub_study SNQ_Quality SNQ_Quantity snq_total RAVLT Age    sex
## 1          1 Discoverysci           3           40        38    11  84 Female
## 2          2 Discoverysci           9           39        37     4  61   Male
## 3          3 Discoverysci          12           31        35    15  85   Male
## 4          4 Discoverysci           9           29        47    10  58 Female
## 5          6 Discoverysci           9           41        37    11  66   Male
## 6          7 Discoverysci          12           28        40    15  84   Male
##   personality                         ethnicity                      race
## 1           1 Not Hispanic or Latino or Spanish                     white
## 2           2 Not Hispanic or Latino or Spanish Black or African American
## 3           3 Not Hispanic or Latino or Spanish                     white
## 4           2 Not Hispanic or Latino or Spanish                     white
## 5           2 Not Hispanic or Latino or Spanish                     white
## 6           3     Hispanic or Latino or Spanish                     white
##   hippocampus_total_volume amygdala_total_volume EstimatedTotalIntraCranialVol
## 1                     7483                  2383                       1158574
## 2                     6708                  2529                       1374227
## 3                     8318                  2338                       1479439
## 4                     7763                  2126                       1514698
## 5                     8536                  3324                       1410264
## 6                     8844                  2505                       1455158
##   lh.caudalanteriorcingulate rh.caudalanteriorcingulate
## 1                       9665                      19349
## 2                      11474                      21286
## 3                      10409                      20235
## 4                      12520                      24430
## 5                       9813                      21178
## 6                      13568                      27542
##   lh.rostralanteriorcingulate rh.rostralanteriorcingulate lh.posteriorcingulate
## 1                        8280                       10421                 18701
## 2                       11336                       13624                 24960
## 3                       12039                       12930                 24969
## 4                       12213                       14344                 26557
## 5                        9078                       10673                 19751
## 6                       10021                       16784                 26805
##   rh.posteriorcingulate lh.isthmuscingulate rh.isthmuscingulate
## 1                  9684               17964               20086
## 2                  9812               21148               25098
## 3                  9826               21865               23339
## 4                 11910               24123               26864
## 5                 11365               20443               20486
## 6                 13974               23995               30352
##   total_cingulate_volume hippocampus_total_volume_corrected
## 1                 114150                        0.006458799
## 2                 138738                        0.004881289
## 3                 135612                        0.005622402
## 4                 152961                        0.005125116
## 5                 122787                        0.006052769
## 6                 163041                        0.006077691
##   amygdala_total_volume_corrected total_cingulate_volume_corrected
## 1                     0.002056838                       0.09852625
## 2                     0.001840307                       0.10095710
## 3                     0.001580329                       0.09166449
## 4                     0.001403581                       0.10098452
## 5                     0.002357006                       0.08706670
## 6                     0.001721463                       0.11204351
# ---- begin running correlations ----
alpha_corrected <- 0.05 / 14
print(paste("Bonferroni-corrected alpha level:", alpha_corrected))
## [1] "Bonferroni-corrected alpha level: 0.00357142857142857"
# Correlation 1: Age vs RAVLT
cor_test_1 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$RAVLT)
print(cor_test_1)
## 
##  Pearson's product-moment correlation
## 
## data:  full_data_frame_merged_over_55_corrected_for_icv$Age and full_data_frame_merged_over_55_corrected_for_icv$RAVLT
## t = 1.1235, df = 253, p-value = 0.2623
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.05284149  0.19164227
## sample estimates:
##        cor 
## 0.07045843
# Plot for Age and RAVLT
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = RAVLT)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs RAVLT", x = "Age", y = "Episodic Memory Performance (RAVLT)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

Correlations Between Age, Memory, and Social Connection Quality/Quantity

### Correlation for Age and Memory


# ---- correlations age and memory ----
# Correlation 1: Age negatively associated with episodic memory performance (RAVLT)
cor_test_1 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$RAVLT)
p_value_1 <- cor_test_1$p.value
sig_1 <- ifelse(p_value_1 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 1: Age vs RAVLT - p-value:", p_value_1, "-", sig_1))
## [1] "Correlation 1: Age vs RAVLT - p-value: 0.262289216389112 - Not Significant"
print(paste("Correlation coefficient:", cor_test_1$estimate))
## [1] "Correlation coefficient: 0.0704584305118598"
# Plot for Age and RAVLT
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = RAVLT)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs RAVLT", x = "Age", y = "Episodic Memory Performance (RAVLT)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# ---- correlation age and snq ----
# Correlation 2: Age positively associated with social connection quality (SNQ_Quality)
cor_test_2 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quality)
p_value_2 <- cor_test_2$p.value
sig_2 <- ifelse(p_value_2 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 2: Age vs SNQ_Quality - p-value:", p_value_2, "-", sig_2))
## [1] "Correlation 2: Age vs SNQ_Quality - p-value: 0.316914826833802 - Not Significant"
print(paste("Correlation coefficient:", cor_test_2$estimate))
## [1] "Correlation coefficient: -0.0629206607749498"
# Plot for Age and Social Connection Quality
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = SNQ_Quality)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs Social Connection Quality", x = "Age", y = "Social Connection Quality (SNQ_Quality)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 3: Age negatively associated with social connection quantity (SNQ_Quantity)
cor_test_3 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quantity)
p_value_3 <- cor_test_3$p.value
sig_3 <- ifelse(p_value_3 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 3: Age vs SNQ_Quantity - p-value:", p_value_3, "-", sig_3))
## [1] "Correlation 3: Age vs SNQ_Quantity - p-value: 0.0577298477258219 - Not Significant"
print(paste("Correlation coefficient:", cor_test_3$estimate))
## [1] "Correlation coefficient: -0.119003351004473"
# Plot for Age and Social Connection Quantity
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = SNQ_Quantity)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs Social Connection Quantity", x = "Age", y = "Social Connection Quantity (SNQ_Quantity)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# ---- correlations ravlt and snq ----
# Correlation 4: RAVLT positively associated with social connection quality (SNQ_Quality)
cor_test_4 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$RAVLT, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quality)
p_value_4 <- cor_test_4$p.value
sig_4 <- ifelse(p_value_4 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 4: RAVLT vs SNQ_Quality - p-value:", p_value_4, "-", sig_4))
## [1] "Correlation 4: RAVLT vs SNQ_Quality - p-value: 0.577351810707077 - Not Significant"
print(paste("Correlation coefficient:", cor_test_4$estimate))
## [1] "Correlation coefficient: -0.0350583039623054"
# Plot for RAVLT and Social Connection Quality
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quality, y = RAVLT)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quality vs RAVLT", x = "Social Connection Quality", y = "Episodic Memory Performance (RAVLT)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 5: RAVLT positively associated with social connection quantity (SNQ_Quantity)
cor_test_5 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$RAVLT, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quantity)
p_value_5 <- cor_test_5$p.value
sig_5 <- ifelse(p_value_5 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 5: RAVLT vs SNQ_Quantity - p-value:", p_value_5, "-", sig_5))
## [1] "Correlation 5: RAVLT vs SNQ_Quantity - p-value: 0.212570927903375 - Not Significant"
print(paste("Correlation coefficient:", cor_test_5$estimate))
## [1] "Correlation coefficient: 0.0783253981252475"
# Plot for RAVLT and Social Connection Quantity
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = RAVLT)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quantity vs RAVLT", x = "Social Connection Quantity", y = "Episodic Memory Performance (RAVLT)") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

Correlations Between Age and ROI Corrected Volumes

### Correlation Between Age and Hippocampus Total Volume Corrected


# ---- correlations age and roi ----
# Correlation 1: Age vs Hippocampus Total Volume Corrected
cor_test_1 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$hippocampus_total_volume_corrected)
p_value_1 <- cor_test_1$p.value
sig_1 <- ifelse(p_value_1 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 1: Age vs Hippocampus Total Volume Corrected - p-value:", p_value_1, "-", sig_1))
## [1] "Correlation 1: Age vs Hippocampus Total Volume Corrected - p-value: 0.766031338640573 - Not Significant"
print(paste("Correlation coefficient:", cor_test_1$estimate))
## [1] "Correlation coefficient: 0.0187249216776731"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = hippocampus_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs Hippocampus Total Volume Corrected", x = "Age", y = "Hippocampus Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 2: Age vs Amygdala Total Volume Corrected
cor_test_2 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$amygdala_total_volume_corrected)
p_value_2 <- cor_test_2$p.value
sig_2 <- ifelse(p_value_2 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 2: Age vs Amygdala Total Volume Corrected - p-value:", p_value_2, "-", sig_2))
## [1] "Correlation 2: Age vs Amygdala Total Volume Corrected - p-value: 0.872157736529027 - Not Significant"
print(paste("Correlation coefficient:", cor_test_2$estimate))
## [1] "Correlation coefficient: 0.0101265899081824"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = amygdala_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs Amygdala Total Volume Corrected", x = "Age", y = "Amygdala Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 3: Age vs Total Cingulate Volume Corrected
cor_test_3 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$Age, 
                       full_data_frame_merged_over_55_corrected_for_icv$total_cingulate_volume_corrected)
p_value_3 <- cor_test_3$p.value
sig_3 <- ifelse(p_value_3 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 3: Age vs Total Cingulate Volume Corrected - p-value:", p_value_3, "-", sig_3))
## [1] "Correlation 3: Age vs Total Cingulate Volume Corrected - p-value: 0.247871336182177 - Not Significant"
print(paste("Correlation coefficient:", cor_test_3$estimate))
## [1] "Correlation coefficient: -0.0726236318387365"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = Age, y = total_cingulate_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Age vs Total Cingulate Volume Corrected", x = "Age", y = "Total Cingulate Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# ---- correlations roi and snq quality ----
# Correlation 4: Hippocampus Total Volume Corrected vs Social Connection Quality
cor_test_4 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$hippocampus_total_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quality)
p_value_4 <- cor_test_4$p.value
sig_4 <- ifelse(p_value_4 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 4: Hippocampus Total Volume Corrected vs SNQ_Quality - p-value:", p_value_4, "-", sig_4))
## [1] "Correlation 4: Hippocampus Total Volume Corrected vs SNQ_Quality - p-value: 0.280902553853503 - Not Significant"
print(paste("Correlation coefficient:", cor_test_4$estimate))
## [1] "Correlation coefficient: 0.0677807165227571"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quality, y = hippocampus_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quality vs Hippocampus Total Volume Corrected", x = "Social Connection Quality", y = "Hippocampus Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 5: Amygdala Total Volume Corrected vs Social Connection Quality
cor_test_5 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$amygdala_total_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quality)
p_value_5 <- cor_test_5$p.value
sig_5 <- ifelse(p_value_5 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 5: Amygdala Total Volume Corrected vs SNQ_Quality - p-value:", p_value_5, "-", sig_5))
## [1] "Correlation 5: Amygdala Total Volume Corrected vs SNQ_Quality - p-value: 0.134765722696597 - Not Significant"
print(paste("Correlation coefficient:", cor_test_5$estimate))
## [1] "Correlation coefficient: 0.0939105248853412"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quality, y = amygdala_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quality vs Amygdala Total Volume Corrected", x = "Social Connection Quality", y = "Amygdala Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 6: Total Cingulate Volume Corrected vs Social Connection Quality
cor_test_6 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$total_cingulate_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quality)
p_value_6 <- cor_test_6$p.value
sig_6 <- ifelse(p_value_6 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 6: Total Cingulate Volume Corrected vs SNQ_Quality - p-value:", p_value_6, "-", sig_6))
## [1] "Correlation 6: Total Cingulate Volume Corrected vs SNQ_Quality - p-value: 7.10618050219819e-08 - Significant"
print(paste("Correlation coefficient:", cor_test_6$estimate))
## [1] "Correlation coefficient: 0.329582862168436"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quality, y = total_cingulate_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quality vs Total Cingulate Volume Corrected", x = "Social Connection Quality", y = "Total Cingulate Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

Correlations Between ROI Corrected Volumes and Social Connection Quantity

### Correlation Between Hippocampus Total Volume Corrected and Social Connection Quantity

# ---- correlations roi and snq quantity ----
# Correlation 7: Hippocampus Total Volume Corrected vs Social Connection Quantity
cor_test_7 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$hippocampus_total_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quantity)
p_value_7 <- cor_test_7$p.value
sig_7 <- ifelse(p_value_7 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 7: Hippocampus Total Volume Corrected vs SNQ_Quantity - p-value:", p_value_7, "-", sig_7))
## [1] "Correlation 7: Hippocampus Total Volume Corrected vs SNQ_Quantity - p-value: 0.631916339872348 - Not Significant"
print(paste("Correlation coefficient:", cor_test_7$estimate))
## [1] "Correlation coefficient: 0.0301393655582844"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = hippocampus_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quantity vs Hippocampus Total Volume Corrected", x = "Social Connection Quantity", y = "Hippocampus Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 8: Amygdala Total Volume Corrected vs Social Connection Quantity
cor_test_8 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$amygdala_total_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quantity)
p_value_8 <- cor_test_8$p.value
sig_8 <- ifelse(p_value_8 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 8: Amygdala Total Volume Corrected vs SNQ_Quantity - p-value:", p_value_8, "-", sig_8))
## [1] "Correlation 8: Amygdala Total Volume Corrected vs SNQ_Quantity - p-value: 0.786258896578505 - Not Significant"
print(paste("Correlation coefficient:", cor_test_8$estimate))
## [1] "Correlation coefficient: 0.0170640371229014"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = amygdala_total_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quantity vs Amygdala Total Volume Corrected", x = "Social Connection Quantity", y = "Amygdala Total Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Correlation 9: Total Cingulate Volume Corrected vs Social Connection Quantity
cor_test_9 <- cor.test(full_data_frame_merged_over_55_corrected_for_icv$total_cingulate_volume_corrected, 
                       full_data_frame_merged_over_55_corrected_for_icv$SNQ_Quantity)
p_value_9 <- cor_test_9$p.value
sig_9 <- ifelse(p_value_9 < alpha_corrected, "Significant", "Not Significant")
print(paste("Correlation 9: Total Cingulate Volume Corrected vs SNQ_Quantity - p-value:", p_value_9, "-", sig_9))
## [1] "Correlation 9: Total Cingulate Volume Corrected vs SNQ_Quantity - p-value: 0.602219854888563 - Not Significant"
print(paste("Correlation coefficient:", cor_test_9$estimate))
## [1] "Correlation coefficient: -0.0327918214248807"
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = total_cingulate_volume_corrected)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(title = "Social Connection Quantity vs Total Cingulate Volume Corrected", x = "Social Connection Quantity", y = "Total Cingulate Volume Corrected") +
  geom_hline(yintercept = alpha_corrected, linetype = "dashed", color = "red")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

Linear Mixed Models for RAVLT and SNQ

### Linear Mixed Models for Age, RAVLT, and SNQ

# ---- linear mixed models ravlt and snq ----
# Model 1: Interaction between Social Connection Quality and Quantity Predicting Episodic Memory Performance
# Add covariates Sex + Personality
model_1 <- lmer(RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                  (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Display the summary of Model 1
summary(model_1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +  
##     (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: 1497
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.00317 -0.81597 -0.00711  0.76243  1.93361 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_id (Intercept)  0.0000  0.000   
##  sub_study  (Intercept)  0.1467  0.383   
##  Residual               19.5702  4.424   
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                0.973013   4.070500 247.926537   0.239    0.811
## SNQ_Quality                0.286852   0.412374 247.995042   0.696    0.487
## SNQ_Quantity               0.120122   0.093989 247.616984   1.278    0.202
## Age                        0.039252   0.031849 247.622401   1.232    0.219
## sexMale                    0.498687   0.585491 247.938817   0.852    0.395
## personality               -0.130724   0.199014 247.102297  -0.657    0.512
## SNQ_Quality:SNQ_Quantity  -0.009348   0.012148 247.412386  -0.770    0.442
## 
## Correlation of Fixed Effects:
##             (Intr) SNQ_Ql SNQ_Qn Age    sexMal prsnlt
## SNQ_Quality -0.735                                   
## SNQ_Quantty -0.805  0.889                            
## Age         -0.598  0.032  0.069                     
## sexMale     -0.020 -0.044 -0.028 -0.022              
## personality -0.156  0.050  0.047 -0.038  0.005       
## SNQ_Q:SNQ_Q  0.714 -0.977 -0.912 -0.022  0.049 -0.057
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model 2: Age Moderating the Relationship between Social Connection Quality and Quantity
# Including three-way interaction: Age * Social Connection Quality * Social Connection Quantity
# Add covariates Sex + Personality
model_2 <- lmer(RAVLT ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality +
                  (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
# Display the summary of Model 2
summary(model_2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: RAVLT ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality +  
##     (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: 1524.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.96508 -0.82432 -0.06898  0.77285  1.92284 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_id (Intercept)  0.000   0.0000  
##  sub_study  (Intercept)  0.142   0.3768  
##  Residual               19.771   4.4464  
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                   1.013e+01  2.505e+01  2.436e+02   0.405    0.686
## Age                          -9.164e-02  3.546e-01  2.435e+02  -0.258    0.796
## SNQ_Quality                  -1.663e+00  3.337e+00  2.436e+02  -0.498    0.619
## SNQ_Quantity                 -1.435e-01  7.353e-01  2.435e+02  -0.195    0.845
## sexMale                       4.922e-01  5.905e-01  2.450e+02   0.834    0.405
## personality                  -1.350e-01  2.004e-01  2.442e+02  -0.674    0.501
## Age:SNQ_Quality               2.809e-02  4.746e-02  2.438e+02   0.592    0.554
## Age:SNQ_Quantity              3.780e-03  1.046e-02  2.435e+02   0.361    0.718
## SNQ_Quality:SNQ_Quantity      4.757e-02  9.811e-02  2.437e+02   0.485    0.628
## Age:SNQ_Quality:SNQ_Quantity -8.213e-04  1.401e-03  2.439e+02  -0.586    0.558
## 
## Correlation of Fixed Effects:
##             (Intr) Age    SNQ_Ql SNQ_Qn sexMal prsnlt Ag:SNQ_Ql Ag:SNQ_Qn
## Age         -0.991                                                       
## SNQ_Quality -0.907  0.901                                                
## SNQ_Quantty -0.978  0.973  0.889                                         
## sexMale      0.034 -0.040 -0.021 -0.052                                  
## personality  0.002 -0.031  0.002 -0.018  0.007                           
## Ag:SNQ_Qlty  0.896 -0.904 -0.992 -0.881  0.016  0.004                    
## Ag:SNQ_Qntt  0.967 -0.978 -0.881 -0.992  0.049  0.024  0.887             
## SNQ_Q:SNQ_Q  0.887 -0.883 -0.980 -0.907  0.033 -0.007  0.974     0.901   
## A:SNQ_Q:SNQ -0.876  0.886  0.971  0.898 -0.027  0.001 -0.980    -0.905   
##             SNQ_Q:
## Age               
## SNQ_Quality       
## SNQ_Quantty       
## sexMale           
## personality       
## Ag:SNQ_Qlty       
## Ag:SNQ_Qntt       
## SNQ_Q:SNQ_Q       
## A:SNQ_Q:SNQ -0.992
## fit warnings:
## Some predictor variables are on very different scales: consider rescaling
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model comparison using ANOVA to test if Model 2 significantly improves fit over Model 1
anova_comparison <- anova(model_1, model_2)
## refitting model(s) with ML (instead of REML)
# Display the ANOVA comparison between Model 1 and Model 2
print(anova_comparison)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_1: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
## model_2: RAVLT ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality + (1 | subject_id) + (1 | sub_study)
##         npar    AIC    BIC  logLik deviance Chisq Df Pr(>Chisq)
## model_1   10 1495.9 1531.3 -737.97   1475.9                    
## model_2   13 1501.4 1547.4 -737.70   1475.4 0.529  3     0.9125
# Extract and display the p-values for fixed effects for both models
# Comment out model that does not win
anova(model_1)  # Get significance of fixed effects for Model 1
## Type III Analysis of Variance Table with Satterthwaite's method
##                          Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)
## SNQ_Quality               9.470   9.470     1 248.00  0.4839 0.4873
## SNQ_Quantity             31.966  31.966     1 247.62  1.6334 0.2024
## Age                      29.726  29.726     1 247.62  1.5190 0.2189
## sex                      14.197  14.197     1 247.94  0.7255 0.3952
## personality               8.444   8.444     1 247.10  0.4315 0.5119
## SNQ_Quality:SNQ_Quantity 11.589  11.589     1 247.41  0.5922 0.4423
anova(model_2)  # Get significance of fixed effects for Model 2
## Type III Analysis of Variance Table with Satterthwaite's method
##                               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)
## Age                           1.3206  1.3206     1 243.48  0.0668 0.7963
## SNQ_Quality                   4.9112  4.9112     1 243.61  0.2484 0.6187
## SNQ_Quantity                  0.7530  0.7530     1 243.48  0.0381 0.8454
## sex                          13.7368 13.7368     1 244.96  0.6948 0.4053
## personality                   8.9776  8.9776     1 244.24  0.4541 0.5010
## Age:SNQ_Quality               6.9267  6.9267     1 243.79  0.3503 0.5545
## Age:SNQ_Quantity              2.5817  2.5817     1 243.48  0.1306 0.7181
## SNQ_Quality:SNQ_Quantity      4.6472  4.6472     1 243.72  0.2351 0.6282
## Age:SNQ_Quality:SNQ_Quantity  6.7965  6.7965     1 243.85  0.3438 0.5582
# Model 1: Interaction plot for Social Connection Quality * Quantity
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = RAVLT, color = SNQ_Quality)) + 
  geom_point() + 
  geom_smooth(method = "lm", formula = y ~ x) + 
  labs(title = "Interaction: Social Connection Quality and Quantity on Episodic Memory", 
       x = "Social Connection Quantity", y = "Episodic Memory Performance (RAVLT)")
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Model 2: Interaction plot for Age * Social Connection Quality * Quantity
ggplot(full_data_frame_merged_over_55_corrected_for_icv, aes(x = SNQ_Quantity, y = RAVLT, color = as.factor(Age))) + 
  facet_wrap(~ SNQ_Quality) + 
  geom_point() + 
  geom_smooth(method = "lm", formula = y ~ x) + 
  labs(title = "Age Moderating the Effect of Social Connection Quality and Quantity on Episodic Memory", 
       x = "Social Connection Quantity", y = "Episodic Memory Performance (RAVLT)")
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced

## Warning in qt((1 - level)/2, df): NaNs produced
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

Linear Mixed Models for ROI and SNQ

Linear Mixed Models for Age, ROI, and SNQ

# ---- linear mixed models roi and snq ----
# Model 4: Interaction between Social Connection Quality and Quantity Predicting HPC
# Add covariates Sex + Personality
model_hpc_1 <- lmer(hippocampus_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                      (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Display the summary of Model 1 (HPC)
summary(model_hpc_1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: hippocampus_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity +  
##     Age + sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -2706.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.61365 -0.63593  0.00581  0.71330  2.45051 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev. 
##  subject_id (Intercept) 2.545e-07 0.0005045
##  sub_study  (Intercept) 0.000e+00 0.0000000
##  Residual               6.155e-07 0.0007845
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)               4.596e-03  8.501e-04  2.471e+02   5.406 1.52e-07 ***
## SNQ_Quality               1.776e-05  8.522e-05  2.404e+02   0.208 0.835110    
## SNQ_Quantity              2.573e-06  1.949e-05  2.439e+02   0.132 0.895086    
## Age                       3.804e-06  6.606e-06  2.432e+02   0.576 0.565254    
## sexMale                  -4.919e-04  1.295e-04  1.904e+02  -3.797 0.000197 ***
## personality              -2.904e-05  4.108e-05  2.361e+02  -0.707 0.480275    
## SNQ_Quality:SNQ_Quantity -4.186e-08  2.513e-06  2.407e+02  -0.017 0.986724    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) SNQ_Ql SNQ_Qn Age    sexMal prsnlt
## SNQ_Quality -0.742                                   
## SNQ_Quantty -0.810  0.896                            
## Age         -0.608  0.049  0.084                     
## sexMale     -0.026 -0.036 -0.031 -0.017              
## personality -0.152  0.045  0.050 -0.045 -0.001       
## SNQ_Q:SNQ_Q  0.720 -0.978 -0.916 -0.035  0.046 -0.052
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model 5: Age Moderating the Relationship between Social Connection Quality and Quantity on HPC
# Including three-way interaction: Age * Social Connection Quality * Social Connection Quantity
# Add covariates Sex + Personality
model_hpc_2 <- lmer(hippocampus_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality +
                      (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
# Display the summary of Model 2 (HPC)
summary(model_hpc_2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## hippocampus_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity +  
##     sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -2634.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.7264 -0.6576  0.0111  0.6535  2.4106 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev. 
##  subject_id (Intercept) 2.335e-07 0.0004833
##  sub_study  (Intercept) 0.000e+00 0.0000000
##  Residual               6.228e-07 0.0007892
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                   1.200e-02  5.169e-03  2.446e+02   2.321 0.021119
## Age                          -1.004e-04  7.310e-05  2.442e+02  -1.374 0.170816
## SNQ_Quality                  -9.850e-04  6.877e-04  2.436e+02  -1.432 0.153371
## SNQ_Quantity                 -1.541e-04  1.515e-04  2.441e+02  -1.018 0.309846
## sexMale                      -4.986e-04  1.285e-04  1.890e+02  -3.880 0.000144
## personality                  -2.547e-05  4.095e-05  2.352e+02  -0.622 0.534633
## Age:SNQ_Quality               1.413e-05  9.782e-06  2.433e+02   1.445 0.149770
## Age:SNQ_Quantity              2.203e-06  2.153e-06  2.435e+02   1.023 0.307346
## SNQ_Quality:SNQ_Quantity      2.081e-05  2.019e-05  2.428e+02   1.031 0.303644
## Age:SNQ_Quality:SNQ_Quantity -2.933e-07  2.883e-07  2.428e+02  -1.017 0.310108
##                                 
## (Intercept)                  *  
## Age                             
## SNQ_Quality                     
## SNQ_Quantity                    
## sexMale                      ***
## personality                     
## Age:SNQ_Quality                 
## Age:SNQ_Quantity                
## SNQ_Quality:SNQ_Quantity        
## Age:SNQ_Quality:SNQ_Quantity    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Age    SNQ_Ql SNQ_Qn sexMal prsnlt Ag:SNQ_Ql Ag:SNQ_Qn
## Age         -0.991                                                       
## SNQ_Quality -0.907  0.902                                                
## SNQ_Quantty -0.978  0.973  0.890                                         
## sexMale      0.032 -0.038 -0.020 -0.049                                  
## personality  0.003 -0.032  0.002 -0.018  0.001                           
## Ag:SNQ_Qlty  0.896 -0.905 -0.992 -0.882  0.016  0.003                    
## Ag:SNQ_Qntt  0.967 -0.979 -0.882 -0.992  0.046  0.024  0.888             
## SNQ_Q:SNQ_Q  0.888 -0.884 -0.980 -0.908  0.030 -0.007  0.975     0.902   
## A:SNQ_Q:SNQ -0.876  0.886  0.971  0.897 -0.025  0.001 -0.981    -0.906   
##             SNQ_Q:
## Age               
## SNQ_Quality       
## SNQ_Quantty       
## sexMale           
## personality       
## Ag:SNQ_Qlty       
## Ag:SNQ_Qntt       
## SNQ_Q:SNQ_Q       
## A:SNQ_Q:SNQ -0.992
## fit warnings:
## Some predictor variables are on very different scales: consider rescaling
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model comparison using ANOVA to test if Model 2 significantly improves fit over Model 1
anova_comparison_hpc <- anova(model_hpc_1, model_hpc_2)
## refitting model(s) with ML (instead of REML)
# Display the ANOVA comparison between Model 1 and Model 2 (HPC)
print(anova_comparison_hpc)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_hpc_1: hippocampus_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
## model_hpc_2: hippocampus_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality + (1 | subject_id) + (1 | sub_study)
##             npar     AIC     BIC logLik deviance  Chisq Df Pr(>Chisq)  
## model_hpc_1   10 -2826.7 -2791.2 1423.3  -2846.7                       
## model_hpc_2   13 -2827.1 -2781.1 1426.6  -2853.1 6.4966  3     0.0898 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Extract and display the p-values for fixed effects for both models
# Comment out the model that does not win
anova(model_hpc_1)  # Get significance of fixed effects for Model 1 (HPC)
## Type III Analysis of Variance Table with Satterthwaite's method
##                              Sum Sq    Mean Sq NumDF  DenDF F value    Pr(>F)
## SNQ_Quality              2.6700e-08 2.6700e-08     1 240.45  0.0434 0.8351105
## SNQ_Quantity             1.0700e-08 1.0700e-08     1 243.85  0.0174 0.8950857
## Age                      2.0410e-07 2.0410e-07     1 243.16  0.3316 0.5652539
## sex                      8.8753e-06 8.8753e-06     1 190.43 14.4197 0.0001966
## personality              3.0760e-07 3.0760e-07     1 236.06  0.4998 0.4802752
## SNQ_Quality:SNQ_Quantity 2.0000e-10 2.0000e-10     1 240.69  0.0003 0.9867239
##                             
## SNQ_Quality                 
## SNQ_Quantity                
## Age                         
## sex                      ***
## personality                 
## SNQ_Quality:SNQ_Quantity    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model_hpc_2)  # Get significance of fixed effects for Model 2 (HPC)
## Type III Analysis of Variance Table with Satterthwaite's method
##                                  Sum Sq    Mean Sq NumDF  DenDF F value
## Age                          1.1751e-06 1.1751e-06     1 244.19  1.8869
## SNQ_Quality                  1.2774e-06 1.2774e-06     1 243.55  2.0512
## SNQ_Quantity                 6.4500e-07 6.4500e-07     1 244.06  1.0356
## sex                          9.3740e-06 9.3740e-06     1 188.99 15.0517
## personality                  2.4080e-07 2.4080e-07     1 235.17  0.3867
## Age:SNQ_Quality              1.3002e-06 1.3002e-06     1 243.32  2.0878
## Age:SNQ_Quantity             6.5170e-07 6.5170e-07     1 243.49  1.0464
## SNQ_Quality:SNQ_Quantity     6.6180e-07 6.6180e-07     1 242.84  1.0626
## Age:SNQ_Quality:SNQ_Quantity 6.4430e-07 6.4430e-07     1 242.75  1.0345
##                                 Pr(>F)    
## Age                          0.1708156    
## SNQ_Quality                  0.1533710    
## SNQ_Quantity                 0.3098461    
## sex                          0.0001444 ***
## personality                  0.5346334    
## Age:SNQ_Quality              0.1497696    
## Age:SNQ_Quantity             0.3073458    
## SNQ_Quality:SNQ_Quantity     0.3036436    
## Age:SNQ_Quality:SNQ_Quantity 0.3101078    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Linear Mixed Models for Amygdala and SNQ

Linear Mixed Models for Age, Amygdala, and SNQ

# Model 6: Interaction between Social Connection Quality and Quantity Predicting Amygdala Total Volume
# Add covariates Sex + Personality
model_amygdala_1 <- lmer(amygdala_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                           (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)

# Display the summary of Model 1 (Amygdala)
summary(model_amygdala_1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: amygdala_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity +  
##     Age + sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -3162.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3119 -0.6635 -0.1147  0.6637  2.7559 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev. 
##  subject_id (Intercept) 1.724e-08 1.313e-04
##  sub_study  (Intercept) 6.831e-09 8.265e-05
##  Residual               1.175e-07 3.428e-04
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)               1.851e-03  3.408e-04  2.392e+02   5.431 1.38e-07 ***
## SNQ_Quality               8.332e-06  3.422e-05  2.465e+02   0.243  0.80786    
## SNQ_Quantity              2.507e-06  7.789e-06  2.464e+02   0.322  0.74784    
## Age                       1.822e-06  2.641e-06  2.465e+02   0.690  0.49091    
## sexMale                  -1.493e-04  4.987e-05  1.765e+02  -2.995  0.00314 ** 
## personality              -2.991e-05  1.646e-05  2.438e+02  -1.817  0.07041 .  
## SNQ_Quality:SNQ_Quantity -1.502e-07  1.006e-06  2.456e+02  -0.149  0.88145    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) SNQ_Ql SNQ_Qn Age    sexMal prsnlt
## SNQ_Quality -0.728                                   
## SNQ_Quantty -0.799  0.889                            
## Age         -0.596  0.035  0.076                     
## sexMale     -0.023 -0.046 -0.030 -0.015              
## personality -0.152  0.044  0.046 -0.041  0.004       
## SNQ_Q:SNQ_Q  0.709 -0.976 -0.914 -0.028  0.049 -0.052
# Model 7: Age Moderating the Relationship between Social Connection Quality and Quantity on Amygdala Total Volume
# Including three-way interaction: Age * Social Connection Quality * Social Connection Quantity
# Add covariates Sex + Personality
model_amygdala_2 <- lmer(amygdala_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality +
                           (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
# Display the summary of Model 2 (Amygdala)
summary(model_amygdala_2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: amygdala_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity +  
##     sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -3081.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.26072 -0.68290 -0.04703  0.66826  2.80519 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev. 
##  subject_id (Intercept) 1.632e-08 1.278e-04
##  sub_study  (Intercept) 6.719e-09 8.197e-05
##  Residual               1.184e-07 3.440e-04
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                   4.316e-03  2.066e-03  2.437e+02   2.089  0.03775
## Age                          -3.358e-05  2.923e-05  2.434e+02  -1.149  0.25178
## SNQ_Quality                  -4.149e-04  2.752e-04  2.435e+02  -1.508  0.13293
## SNQ_Quantity                 -7.489e-05  6.059e-05  2.433e+02  -1.236  0.21766
## sexMale                      -1.480e-04  4.997e-05  1.752e+02  -2.962  0.00348
## personality                  -3.051e-05  1.650e-05  2.413e+02  -1.849  0.06563
## Age:SNQ_Quality               6.109e-06  3.916e-06  2.436e+02   1.560  0.12004
## Age:SNQ_Quantity              1.114e-06  8.618e-07  2.432e+02   1.292  0.19751
## SNQ_Quality:SNQ_Quantity      1.303e-05  8.086e-06  2.433e+02   1.612  0.10831
## Age:SNQ_Quality:SNQ_Quantity -1.904e-07  1.155e-07  2.435e+02  -1.649  0.10052
##                                
## (Intercept)                  * 
## Age                            
## SNQ_Quality                    
## SNQ_Quantity                   
## sexMale                      **
## personality                  . 
## Age:SNQ_Quality                
## Age:SNQ_Quantity               
## SNQ_Quality:SNQ_Quantity       
## Age:SNQ_Quality:SNQ_Quantity   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Age    SNQ_Ql SNQ_Qn sexMal prsnlt Ag:SNQ_Ql Ag:SNQ_Qn
## Age         -0.991                                                       
## SNQ_Quality -0.907  0.901                                                
## SNQ_Quantty -0.978  0.973  0.889                                         
## sexMale      0.033 -0.039 -0.020 -0.051                                  
## personality  0.002 -0.031  0.003 -0.018  0.007                           
## Ag:SNQ_Qlty  0.895 -0.904 -0.992 -0.880  0.014  0.002                    
## Ag:SNQ_Qntt  0.967 -0.978 -0.881 -0.992  0.048  0.024  0.887             
## SNQ_Q:SNQ_Q  0.887 -0.883 -0.980 -0.907  0.030 -0.009  0.975     0.901   
## A:SNQ_Q:SNQ -0.875  0.886  0.971  0.897 -0.024  0.003 -0.981    -0.905   
##             SNQ_Q:
## Age               
## SNQ_Quality       
## SNQ_Quantty       
## sexMale           
## personality       
## Ag:SNQ_Qlty       
## Ag:SNQ_Qntt       
## SNQ_Q:SNQ_Q       
## A:SNQ_Q:SNQ -0.992
## fit warnings:
## Some predictor variables are on very different scales: consider rescaling
# Model comparison using ANOVA to test if Model 2 significantly improves fit over Model 1
anova_comparison_amygdala <- anova(model_amygdala_1, model_amygdala_2)
## refitting model(s) with ML (instead of REML)
# Display the ANOVA comparison between Model 1 and Model 2 (Amygdala)
print(anova_comparison_amygdala)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_amygdala_1: amygdala_total_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
## model_amygdala_2: amygdala_total_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality + (1 | subject_id) + (1 | sub_study)
##                  npar     AIC     BIC logLik deviance Chisq Df Pr(>Chisq)
## model_amygdala_1   10 -3294.0 -3258.6 1657.0  -3314.0                    
## model_amygdala_2   13 -3291.1 -3245.1 1658.5  -3317.1 3.131  3     0.3719
# Extract and display the p-values for fixed effects for both models
# Comment out the model that does not win
anova(model_amygdala_1)  # Get significance of fixed effects for Model 1 (Amygdala)
## Type III Analysis of Variance Table with Satterthwaite's method
##                              Sum Sq    Mean Sq NumDF  DenDF F value   Pr(>F)   
## SNQ_Quality              6.9600e-09 6.9600e-09     1 246.51  0.0593 0.807861   
## SNQ_Quantity             1.2170e-08 1.2170e-08     1 246.36  0.1036 0.747838   
## Age                      5.5920e-08 5.5920e-08     1 246.47  0.4760 0.490911   
## sex                      1.0538e-06 1.0538e-06     1 176.46  8.9683 0.003142 **
## personality              3.8802e-07 3.8802e-07     1 243.76  3.3024 0.070407 . 
## SNQ_Quality:SNQ_Quantity 2.6200e-09 2.6200e-09     1 245.56  0.0223 0.881453   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model_amygdala_2)  # Get significance of fixed effects for Model 2 (Amygdala)
## Type III Analysis of Variance Table with Satterthwaite's method
##                                  Sum Sq    Mean Sq NumDF  DenDF F value
## Age                          1.5621e-07 1.5621e-07     1 243.41  1.3197
## SNQ_Quality                  2.6907e-07 2.6907e-07     1 243.50  2.2732
## SNQ_Quantity                 1.8083e-07 1.8083e-07     1 243.33  1.5277
## sex                          1.0386e-06 1.0386e-06     1 175.24  8.7747
## personality                  4.0484e-07 4.0484e-07     1 241.29  3.4202
## Age:SNQ_Quality              2.8808e-07 2.8808e-07     1 243.63  2.4338
## Age:SNQ_Quantity             1.9765e-07 1.9765e-07     1 243.24  1.6698
## SNQ_Quality:SNQ_Quantity     3.0750e-07 3.0750e-07     1 243.27  2.5978
## Age:SNQ_Quality:SNQ_Quantity 3.2171e-07 3.2171e-07     1 243.49  2.7179
##                                Pr(>F)   
## Age                          0.251777   
## SNQ_Quality                  0.132928   
## SNQ_Quantity                 0.217655   
## sex                          0.003478 **
## personality                  0.065627 . 
## Age:SNQ_Quality              0.120044   
## Age:SNQ_Quantity             0.197510   
## SNQ_Quality:SNQ_Quantity     0.108306   
## Age:SNQ_Quality:SNQ_Quantity 0.100519   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Linear Mixed Models for Cingulate and SNQ

Linear Mixed Models for Age, Cingulate, and SNQ

# Model 8: Interaction between Social Connection Quality and Quantity Predicting Total Cingulate Volume
# Add covariates Sex + Personality
model_cingulate_1 <- lmer(total_cingulate_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                            (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)

# Display the summary of Model 1 (Cingulate)
summary(model_cingulate_1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: total_cingulate_volume_corrected ~ SNQ_Quality * SNQ_Quantity +  
##     Age + sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -1563
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.7159 -0.3415 -0.0086  0.3215  2.5299 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev.
##  subject_id (Intercept) 9.614e-05 0.009805
##  sub_study  (Intercept) 8.741e-04 0.029565
##  Residual               1.334e-05 0.003653
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)   
## (Intercept)               1.036e-01  1.839e-02  2.690e+00   5.633  0.01474 * 
## SNQ_Quality               1.853e-03  6.531e-04  9.162e+01   2.836  0.00561 **
## SNQ_Quantity              3.913e-04  1.521e-04  9.753e+01   2.572  0.01161 * 
## Age                       5.723e-05  5.156e-05  9.857e+01   1.110  0.26967   
## sexMale                  -2.994e-03  1.543e-03  1.939e+02  -1.941  0.05374 . 
## personality              -9.990e-06  2.988e-04  8.118e+01  -0.033  0.97341   
## SNQ_Quality:SNQ_Quantity -5.622e-05  1.915e-05  9.164e+01  -2.936  0.00421 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) SNQ_Ql SNQ_Qn Age    sexMal prsnlt
## SNQ_Quality -0.277                                   
## SNQ_Quantty -0.302  0.905                            
## Age         -0.237  0.087  0.145                     
## sexMale     -0.023 -0.030 -0.024  0.001              
## personality -0.063  0.024  0.060 -0.003 -0.005       
## SNQ_Q:SNQ_Q  0.267 -0.972 -0.933 -0.072  0.032 -0.030
# Model 9: Age Moderating the Relationship between Social Connection Quality and Quantity on Total Cingulate Volume
# Including three-way interaction: Age * Social Connection Quality * Social Connection Quantity
# Add covariates Sex + Personality
model_cingulate_2 <- lmer(total_cingulate_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality +
                            (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
# Display the summary of Model 2 (Cingulate)
summary(model_cingulate_2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: total_cingulate_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity +  
##     sex + personality + (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: -1500.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.70161 -0.32313 -0.00319  0.30781  2.53827 
## 
## Random effects:
##  Groups     Name        Variance  Std.Dev.
##  subject_id (Intercept) 9.441e-05 0.009716
##  sub_study  (Intercept) 8.753e-04 0.029586
##  Residual               1.375e-05 0.003709
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                   9.929e-02  4.761e-02  7.287e+01   2.085   0.0405
## Age                           1.321e-04  6.178e-04  1.300e+02   0.214   0.8310
## SNQ_Quality                   4.505e-03  5.628e-03  1.141e+02   0.800   0.4251
## SNQ_Quantity                  9.010e-04  1.284e-03  1.312e+02   0.702   0.4842
## sexMale                      -3.026e-03  1.536e-03  1.933e+02  -1.970   0.0503
## personality                   3.244e-05  3.035e-04  8.052e+01   0.107   0.9151
## Age:SNQ_Quality              -4.107e-05  7.908e-05  1.085e+02  -0.519   0.6046
## Age:SNQ_Quantity             -7.652e-06  1.794e-05  1.236e+02  -0.427   0.6705
## SNQ_Quality:SNQ_Quantity     -1.879e-04  1.636e-04  1.104e+02  -1.148   0.2533
## Age:SNQ_Quality:SNQ_Quantity  1.967e-06  2.315e-06  1.058e+02   0.850   0.3975
##                               
## (Intercept)                  *
## Age                           
## SNQ_Quality                   
## SNQ_Quantity                  
## sexMale                      .
## personality                   
## Age:SNQ_Quality               
## Age:SNQ_Quantity              
## SNQ_Quality:SNQ_Quantity      
## Age:SNQ_Quality:SNQ_Quantity  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Age    SNQ_Ql SNQ_Qn sexMal prsnlt Ag:SNQ_Ql Ag:SNQ_Qn
## Age         -0.927                                                       
## SNQ_Quality -0.855  0.914                                                
## SNQ_Quantty -0.915  0.977  0.901                                         
## sexMale      0.025 -0.037 -0.021 -0.045                                  
## personality  0.030 -0.058 -0.018 -0.042 -0.001                           
## Ag:SNQ_Qlty  0.840 -0.911 -0.993 -0.888  0.017  0.018                    
## Ag:SNQ_Qntt  0.907 -0.981 -0.898 -0.993  0.042  0.048  0.899             
## SNQ_Q:SNQ_Q  0.834 -0.893 -0.982 -0.913  0.027  0.006  0.978     0.911   
## A:SNQ_Q:SNQ -0.818  0.888  0.973  0.897 -0.022 -0.007 -0.983    -0.909   
##             SNQ_Q:
## Age               
## SNQ_Quality       
## SNQ_Quantty       
## sexMale           
## personality       
## Ag:SNQ_Qlty       
## Ag:SNQ_Qntt       
## SNQ_Q:SNQ_Q       
## A:SNQ_Q:SNQ -0.993
## fit warnings:
## Some predictor variables are on very different scales: consider rescaling
# Model comparison using ANOVA to test if Model 2 significantly improves fit over Model 1
anova_comparison_cingulate <- anova(model_cingulate_1, model_cingulate_2)
## refitting model(s) with ML (instead of REML)
# Display the ANOVA comparison between Model 1 and Model 2 (Cingulate)
print(anova_comparison_cingulate)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_cingulate_1: total_cingulate_volume_corrected ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
## model_cingulate_2: total_cingulate_volume_corrected ~ Age * SNQ_Quality * SNQ_Quantity + sex + personality + (1 | subject_id) + (1 | sub_study)
##                   npar     AIC     BIC logLik deviance  Chisq Df Pr(>Chisq)
## model_cingulate_1   10 -1646.6 -1611.2 833.29  -1666.6                     
## model_cingulate_2   13 -1644.8 -1598.8 835.39  -1670.8 4.2127  3     0.2394
# Extract and display the p-values for fixed effects for both models
# Comment out the model that does not win
anova(model_cingulate_1)  # Get significance of fixed effects for Model 1 (Cingulate)
## Type III Analysis of Variance Table with Satterthwaite's method
##                              Sum Sq    Mean Sq NumDF   DenDF F value   Pr(>F)
## SNQ_Quality              1.0735e-04 1.0735e-04     1  91.617  8.0457 0.005614
## SNQ_Quantity             8.8299e-05 8.8299e-05     1  97.526  6.6176 0.011605
## Age                      1.6442e-05 1.6442e-05     1  98.571  1.2322 0.269672
## sex                      5.0254e-05 5.0254e-05     1 193.941  3.7663 0.053744
## personality              1.5000e-08 1.5000e-08     1  81.177  0.0011 0.973414
## SNQ_Quality:SNQ_Quantity 1.1500e-04 1.1500e-04     1  91.644  8.6188 0.004206
##                            
## SNQ_Quality              **
## SNQ_Quantity             * 
## Age                        
## sex                      . 
## personality                
## SNQ_Quality:SNQ_Quantity **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model_cingulate_2)  # Get significance of fixed effects for Model 2 (Cingulate)
## Type III Analysis of Variance Table with Satterthwaite's method
##                                  Sum Sq    Mean Sq NumDF   DenDF F value
## Age                          6.2900e-07 6.2900e-07     1 129.994  0.0457
## SNQ_Quality                  8.8120e-06 8.8120e-06     1 114.141  0.6406
## SNQ_Quantity                 6.7710e-06 6.7710e-06     1 131.169  0.4922
## sex                          5.3384e-05 5.3384e-05     1 193.338  3.8812
## personality                  1.5700e-07 1.5700e-07     1  80.523  0.0114
## Age:SNQ_Quality              3.7100e-06 3.7100e-06     1 108.538  0.2697
## Age:SNQ_Quantity             2.5020e-06 2.5020e-06     1 123.573  0.1819
## SNQ_Quality:SNQ_Quantity     1.8142e-05 1.8142e-05     1 110.363  1.3190
## Age:SNQ_Quality:SNQ_Quantity 9.9280e-06 9.9280e-06     1 105.757  0.7218
##                               Pr(>F)  
## Age                          0.83100  
## SNQ_Quality                  0.42514  
## SNQ_Quantity                 0.48417  
## sex                          0.05026 .
## personality                  0.91514  
## Age:SNQ_Quality              0.60458  
## Age:SNQ_Quantity             0.67047  
## SNQ_Quality:SNQ_Quantity     0.25326  
## Age:SNQ_Quality:SNQ_Quantity 0.39746  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Testing the Order of Fixed Effects

Testing if the Order of Fixed Effects Alters Results

# Model A: original order with interaction between Social Connection Quality and Quantity Predicting RAVLT
# Add covariates in the order: SNQ_Quality * SNQ_Quantity + age + sex + personality
model_A <- lmer(RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                  (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Display the summary of Model A
summary(model_A)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +  
##     (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: 1497
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.00317 -0.81597 -0.00711  0.76243  1.93361 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_id (Intercept)  0.0000  0.000   
##  sub_study  (Intercept)  0.1467  0.383   
##  Residual               19.5702  4.424   
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                0.973013   4.070500 247.926537   0.239    0.811
## SNQ_Quality                0.286852   0.412374 247.995042   0.696    0.487
## SNQ_Quantity               0.120122   0.093989 247.616984   1.278    0.202
## Age                        0.039252   0.031849 247.622401   1.232    0.219
## sexMale                    0.498687   0.585491 247.938817   0.852    0.395
## personality               -0.130724   0.199014 247.102297  -0.657    0.512
## SNQ_Quality:SNQ_Quantity  -0.009348   0.012148 247.412386  -0.770    0.442
## 
## Correlation of Fixed Effects:
##             (Intr) SNQ_Ql SNQ_Qn Age    sexMal prsnlt
## SNQ_Quality -0.735                                   
## SNQ_Quantty -0.805  0.889                            
## Age         -0.598  0.032  0.069                     
## sexMale     -0.020 -0.044 -0.028 -0.022              
## personality -0.156  0.050  0.047 -0.038  0.005       
## SNQ_Q:SNQ_Q  0.714 -0.977 -0.912 -0.022  0.049 -0.057
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model B: altered order changing the order of fixed effects
# Rearrange the order of fixed effects: personality + sex + age + SNQ_Quality * SNQ_Quantity
model_B <- lmer(RAVLT ~ personality + sex + Age + SNQ_Quality * SNQ_Quantity +
                  (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Display the summary of Model B
summary(model_B)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: RAVLT ~ personality + sex + Age + SNQ_Quality * SNQ_Quantity +  
##     (1 | subject_id) + (1 | sub_study)
##    Data: full_data_frame_merged_over_55_corrected_for_icv
## 
## REML criterion at convergence: 1497
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.00317 -0.81597 -0.00711  0.76243  1.93361 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  subject_id (Intercept)  0.0000  0.000   
##  sub_study  (Intercept)  0.1467  0.383   
##  Residual               19.5702  4.424   
## Number of obs: 255, groups:  subject_id, 202; sub_study, 3
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)                0.973013   4.070500 247.926538   0.239    0.811
## personality               -0.130724   0.199014 247.102297  -0.657    0.512
## sexMale                    0.498687   0.585491 247.938817   0.852    0.395
## Age                        0.039252   0.031849 247.622401   1.232    0.219
## SNQ_Quality                0.286852   0.412374 247.995042   0.696    0.487
## SNQ_Quantity               0.120122   0.093989 247.616982   1.278    0.202
## SNQ_Quality:SNQ_Quantity  -0.009348   0.012148 247.412383  -0.770    0.442
## 
## Correlation of Fixed Effects:
##             (Intr) prsnlt sexMal Age    SNQ_Ql SNQ_Qn
## personality -0.156                                   
## sexMale     -0.020  0.005                            
## Age         -0.598 -0.038 -0.022                     
## SNQ_Quality -0.735  0.050 -0.044  0.032              
## SNQ_Quantty -0.805  0.047 -0.028  0.069  0.889       
## SNQ_Q:SNQ_Q  0.714 -0.057  0.049 -0.022 -0.977 -0.912
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Model comparison using ANOVA to test if changing the order affects model fit
anova_comparison_order <- anova(model_A, model_B)
## refitting model(s) with ML (instead of REML)
# Display the ANOVA comparison between Model A and Model B
print(anova_comparison_order)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_A: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
## model_B: RAVLT ~ personality + sex + Age + SNQ_Quality * SNQ_Quantity + (1 | subject_id) + (1 | sub_study)
##         npar    AIC    BIC  logLik deviance Chisq Df Pr(>Chisq)
## model_A   10 1495.9 1531.3 -737.97   1475.9                    
## model_B   10 1495.9 1531.3 -737.97   1475.9     0  0
# Extract and display the p-values for fixed effects for both models to compare significance
anova(model_A)  # Get significance of fixed effects for Model A
## Type III Analysis of Variance Table with Satterthwaite's method
##                          Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)
## SNQ_Quality               9.470   9.470     1 248.00  0.4839 0.4873
## SNQ_Quantity             31.966  31.966     1 247.62  1.6334 0.2024
## Age                      29.726  29.726     1 247.62  1.5190 0.2189
## sex                      14.197  14.197     1 247.94  0.7255 0.3952
## personality               8.444   8.444     1 247.10  0.4315 0.5119
## SNQ_Quality:SNQ_Quantity 11.589  11.589     1 247.41  0.5922 0.4423
anova(model_B)  # Get significance of fixed effects for Model B
## Type III Analysis of Variance Table with Satterthwaite's method
##                          Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)
## personality               8.444   8.444     1 247.10  0.4315 0.5119
## sex                      14.197  14.197     1 247.94  0.7255 0.3952
## Age                      29.726  29.726     1 247.62  1.5190 0.2189
## SNQ_Quality               9.470   9.470     1 248.00  0.4839 0.4873
## SNQ_Quantity             31.966  31.966     1 247.62  1.6334 0.2024
## SNQ_Quality:SNQ_Quantity 11.589  11.589     1 247.41  0.5922 0.4423
# Model with both random effects
model_1 <- lmer(RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                  (1 | subject_id) + (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Model without subject_id
model_no_subject <- lmer(RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                           (1 | sub_study), data = full_data_frame_merged_over_55_corrected_for_icv)

# Model without sub-study
model_no_substudy <- lmer(RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality +
                            (1 | subject_id), data = full_data_frame_merged_over_55_corrected_for_icv)
## boundary (singular) fit: see help('isSingular')
# Compare models using ANOVA 
anova_full_vs_no_subject <- anova(model_1, model_no_subject)
## refitting model(s) with ML (instead of REML)
anova_full_vs_no_substudy <- anova(model_1, model_no_substudy)
## refitting model(s) with ML (instead of REML)
# Display results
print("Comparison of full model vs. model without subject-level random effect:")
## [1] "Comparison of full model vs. model without subject-level random effect:"
print(anova_full_vs_no_subject)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_no_subject: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | sub_study)
## model_1: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
##                  npar    AIC    BIC  logLik deviance Chisq Df Pr(>Chisq)
## model_no_subject    9 1493.9 1525.8 -737.97   1475.9                    
## model_1            10 1495.9 1531.3 -737.97   1475.9     0  1          1
print("Comparison of full model vs. model without sub-study-level random effect:")
## [1] "Comparison of full model vs. model without sub-study-level random effect:"
print(anova_full_vs_no_substudy)
## Data: full_data_frame_merged_over_55_corrected_for_icv
## Models:
## model_no_substudy: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id)
## model_1: RAVLT ~ SNQ_Quality * SNQ_Quantity + Age + sex + personality + (1 | subject_id) + (1 | sub_study)
##                   npar    AIC    BIC  logLik deviance Chisq Df Pr(>Chisq)
## model_no_substudy    9 1493.9 1525.8 -737.97   1475.9                    
## model_1             10 1495.9 1531.3 -737.97   1475.9     0  1          1