library(bruceR)
## Warning: package 'bruceR' was built under R version 4.3.3
## 
## bruceR (v2024.6)
## Broadly Useful Convenient and Efficient R functions
## 
## Packages also loaded:
## ✔ data.table ✔ emmeans
## ✔ dplyr      ✔ lmerTest
## ✔ tidyr      ✔ effectsize
## ✔ stringr    ✔ performance
## ✔ ggplot2    ✔ interactions
## 
## Main functions of `bruceR`:
## cc()             Describe()  TTEST()
## add()            Freq()      MANOVA()
## .mean()          Corr()      EMMEANS()
## set.wd()         Alpha()     PROCESS()
## import()         EFA()       model_summary()
## print_table()    CFA()       lavaan_summary()
## 
## For full functionality, please install all dependencies:
## install.packages("bruceR", dep=TRUE)
## 
## Online documentation:
## https://psychbruce.github.io/bruceR
## 
## To use this package in publications, please cite:
## Bao, H.-W.-S. (2024). bruceR: Broadly useful convenient and efficient R functions (Version 2024.6) [Computer software]. https://CRAN.R-project.org/package=bruceR
set.wd()
## ✔ Set working directory to "C:/Users/psyuser/Desktop/ARWA article"
set.seed(6)
rm(list = ls())
library(tidyverse)
## Warning: package 'readr' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ data.table::between() masks dplyr::between()
## ✖ Matrix::expand()      masks tidyr::expand()
## ✖ dplyr::filter()       masks stats::filter()
## ✖ data.table::first()   masks dplyr::first()
## ✖ lubridate::hour()     masks data.table::hour()
## ✖ lubridate::isoweek()  masks data.table::isoweek()
## ✖ dplyr::lag()          masks stats::lag()
## ✖ data.table::last()    masks dplyr::last()
## ✖ lubridate::mday()     masks data.table::mday()
## ✖ lubridate::minute()   masks data.table::minute()
## ✖ lubridate::month()    masks data.table::month()
## ✖ Matrix::pack()        masks tidyr::pack()
## ✖ lubridate::quarter()  masks data.table::quarter()
## ✖ lubridate::second()   masks data.table::second()
## ✖ purrr::transpose()    masks data.table::transpose()
## ✖ Matrix::unpack()      masks tidyr::unpack()
## ✖ lubridate::wday()     masks data.table::wday()
## ✖ lubridate::week()     masks data.table::week()
## ✖ lubridate::yday()     masks data.table::yday()
## ✖ lubridate::year()     masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(mice)
## Warning: package 'mice' was built under R version 4.3.3
## Registered S3 methods overwritten by 'broom':
##   method            from  
##   tidy.glht         jtools
##   tidy.summary.glht jtools
## 
## Attaching package: 'mice'
## 
## The following object is masked from 'package:bruceR':
## 
##     cc
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
library(naniar)
## Warning: package 'naniar' was built under R version 4.3.3
library(broom)
## Warning: package 'broom' was built under R version 4.3.3
library(readxl)

data <- read.csv("./data/EEG_RS_lanExp.csv")

# Select the relevant columns and drop rows with NA values
data_selected <- data %>% 
  # select(EEGID, FatherEducation, MotherEducation, Income) %>% 
  mutate(Age_EEG_yr = Age_EEG / 12) %>% # convert Age_EEG from months to years
  # keep unique EEGID values
  distinct(EEGID, .keep_all = TRUE) %>% 
  dplyr::select(CWR, CDICT, ARITH, EWR, EDICT, PW, CMOI, EMOI, FatherEducation, MotherEducation, Income, Age_EEG_yr, FID, EEGID)

# Visualize the missing data pattern
vis_miss(data_selected)

# Analyze the pattern of missing data
missing_pattern <- naniar::miss_var_summary(data_selected)
print(missing_pattern)
## # A tibble: 14 × 3
##    variable        n_miss pct_miss
##    <chr>            <int>    <num>
##  1 CMOI                39    19.3 
##  2 EMOI                39    19.3 
##  3 PW                  16     7.92
##  4 FatherEducation     13     6.44
##  5 Income               9     4.46
##  6 MotherEducation      7     3.47
##  7 CWR                  5     2.48
##  8 EDICT                4     1.98
##  9 CDICT                3     1.49
## 10 ARITH                3     1.49
## 11 EWR                  3     1.49
## 12 Age_EEG_yr           3     1.49
## 13 FID                  3     1.49
## 14 EEGID                0     0
# Test if the missing data is random using Little's MCAR test
mcar_test <- naniar::mcar_test(data_selected[, c("CMOI", "EMOI", 
                                               "FatherEducation", 
                                               "MotherEducation", "Income")])
print(mcar_test)
## # A tibble: 1 × 4
##   statistic    df  p.value missing.patterns
##       <dbl> <dbl>    <dbl>            <int>
## 1      45.3    17 0.000221                9
# If the missing data is random, perform imputation using the mice package
if (mcar_test$p.value > 0.05) {
  print("The missing data is at random.")
  imputed_data <- mice(data_selected[, c("CMOI", "EMOI", 
                                         "FatherEducation", "MotherEducation", "Income")], 
                       method = "norm.predict", m = 5, maxit = 50, seed = 500)
  completed_data <- complete(imputed_data, 1)
  
  # Replace the original columns with the imputed data
  data_selected$CMOI <- completed_data$CMOI
  data_selected$EMOI <- completed_data$EMOI
  data_selected$FatherEducation <- completed_data$FatherEducation
  data_selected$MotherEducation <- completed_data$MotherEducation
  data_selected$Income <- completed_data$Income
} else {
  print("The missing data is not completely at random.")
}
## [1] "The missing data is not completely at random."
# Check if CMOI and EMOI are normally distributed
shapiro_test_cmo <- shapiro.test(data_selected$CMOI)
shapiro_test_emo <- shapiro.test(data_selected$EMOI)
print(shapiro_test_cmo)
## 
##  Shapiro-Wilk normality test
## 
## data:  data_selected$CMOI
## W = 0.73803, p-value = 9.87e-16
print(shapiro_test_emo)
## 
##  Shapiro-Wilk normality test
## 
## data:  data_selected$EMOI
## W = 0.70746, p-value < 2.2e-16
# Analyze the pattern of missing data
missing_pattern <- naniar::miss_var_summary(data_selected)
print(missing_pattern)
## # A tibble: 14 × 3
##    variable        n_miss pct_miss
##    <chr>            <int>    <num>
##  1 CMOI                39    19.3 
##  2 EMOI                39    19.3 
##  3 PW                  16     7.92
##  4 FatherEducation     13     6.44
##  5 Income               9     4.46
##  6 MotherEducation      7     3.47
##  7 CWR                  5     2.48
##  8 EDICT                4     1.98
##  9 CDICT                3     1.49
## 10 ARITH                3     1.49
## 11 EWR                  3     1.49
## 12 Age_EEG_yr           3     1.49
## 13 FID                  3     1.49
## 14 EEGID                0     0
# Print the results of the normality tests
if (shapiro_test_cmo$p.value < 0.05) {
  print("CMOI is not normally distributed.")
} else {
  print("CMOI is normally distributed.")
}
## [1] "CMOI is not normally distributed."
if (shapiro_test_emo$p.value < 0.05) {
  print("EMOI is not normally distributed.")
} else {
  print("EMOI is normally distributed.")
}
## [1] "EMOI is not normally distributed."
# Choose imputation method based on normality test results
imputation_method <- ifelse(shapiro_test_cmo$p.value < 0.05 | shapiro_test_emo$p.value < 0.05, "pmm", "norm.predict")

# Perform imputation using the mice package
imputed_data <- mice(data_selected[, c("CMOI", "EMOI", 
                                     "FatherEducation", "MotherEducation", "Income")], method = imputation_method, m = 5, maxit = 50, seed = 500)
## 
##  iter imp variable
##   1   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   1   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   1   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   1   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   1   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   2   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   2   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   2   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   2   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   2   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   3   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   3   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   3   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   3   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   3   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   4   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   4   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   4   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   4   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   4   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   5   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   5   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   5   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   5   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   5   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   6   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   6   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   6   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   6   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   6   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   7   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   7   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   7   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   7   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   7   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   8   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   8   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   8   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   8   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   8   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   9   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   9   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   9   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   9   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   9   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   10   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   10   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   10   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   10   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   10   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   11   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   11   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   11   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   11   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   11   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   12   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   12   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   12   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   12   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   12   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   13   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   13   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   13   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   13   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   13   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   14   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   14   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   14   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   14   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   14   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   15   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   15   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   15   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   15   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   15   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   16   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   16   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   16   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   16   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   16   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   17   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   17   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   17   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   17   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   17   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   18   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   18   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   18   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   18   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   18   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   19   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   19   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   19   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   19   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   19   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   20   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   20   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   20   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   20   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   20   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   21   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   21   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   21   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   21   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   21   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   22   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   22   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   22   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   22   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   22   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   23   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   23   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   23   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   23   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   23   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   24   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   24   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   24   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   24   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   24   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   25   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   25   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   25   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   25   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   25   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   26   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   26   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   26   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   26   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   26   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   27   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   27   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   27   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   27   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   27   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   28   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   28   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   28   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   28   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   28   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   29   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   29   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   29   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   29   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   29   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   30   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   30   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   30   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   30   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   30   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   31   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   31   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   31   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   31   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   31   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   32   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   32   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   32   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   32   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   32   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   33   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   33   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   33   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   33   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   33   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   34   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   34   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   34   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   34   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   34   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   35   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   35   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   35   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   35   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   35   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   36   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   36   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   36   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   36   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   36   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   37   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   37   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   37   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   37   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   37   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   38   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   38   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   38   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   38   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   38   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   39   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   39   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   39   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   39   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   39   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   40   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   40   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   40   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   40   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   40   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   41   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   41   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   41   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   41   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   41   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   42   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   42   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   42   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   42   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   42   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   43   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   43   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   43   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   43   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   43   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   44   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   44   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   44   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   44   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   44   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   45   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   45   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   45   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   45   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   45   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   46   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   46   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   46   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   46   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   46   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   47   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   47   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   47   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   47   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   47   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   48   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   48   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   48   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   48   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   48   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   49   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   49   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   49   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   49   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   49   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   50   1  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   50   2  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   50   3  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   50   4  CMOI  EMOI  FatherEducation  MotherEducation  Income
##   50   5  CMOI  EMOI  FatherEducation  MotherEducation  Income
completed_data <- complete(imputed_data, 1)

# Replace the original columns with the imputed data
data_selected$CMOI <- completed_data$CMOI
data_selected$EMOI <- completed_data$EMOI
data_selected$FatherEducation <- completed_data$FatherEducation
data_selected$MotherEducation <- completed_data$MotherEducation
data_selected$Income <- completed_data$Income

# Select the relevant columns and drop rows with NA values
education_income_data <- data_selected %>% 
  select(EEGID, FatherEducation, MotherEducation, Income) %>% 
  drop_na()


# Perform PCA
pca_result <- prcomp(education_income_data %>% select(-EEGID), scale. = TRUE)

# Extract the first principal component and add SubjectID
pca_scores <- education_income_data %>%
  select(EEGID) %>%
  mutate(SES = -pca_result$x[, 1]) # add minus so that higher scores indicate higher SES

# Merge the PCA scores back into the original data
data_income <- data_selected %>%
  left_join(pca_scores, by = "EEGID")

# output the data_income to csv
write.csv(data_income, file = "./data/EEG_RS_lanExp_income_imputated_all_v2.csv", row.names = FALSE)
# library(lme4)
library(tidyverse)
library(lmerTest)
library(conflicted)

data_income <- read.csv("./data/EEG_RS_lanExp_income_imputated_all_v2.csv")

# Center the variables
data_income <- data_income %>%
  mutate(
    PW_c = scale(PW, center = TRUE, scale = FALSE),
    CMOI_c = scale(CMOI, center = TRUE, scale = FALSE),
    EMOI_c = scale(EMOI, center = TRUE, scale = FALSE),
    Age_EEG_yr_c = scale(Age_EEG_yr, center = TRUE, scale = FALSE),
    SES_c = scale(SES, center = TRUE, scale = FALSE), 
    ARITH_c = scale(ARITH, center = TRUE, scale = FALSE)
  )

# keep only the columns data for the analysis
data_income <- data_income %>% 
select(CWR, CDICT, ARITH, EWR, EDICT, PW_c, CMOI_c, EMOI_c, Age_EEG_yr_c, SES_c, ARITH_c, FID, EEGID, Age_EEG_yr) %>% 
drop_na() 

write.csv(data_income, file = "./data/model_data_180.csv", row.names = F)
          
demo_info <- read.csv("./data/assessment-resting-state-v8-200-drop-duplicated.csv")

# left join data_income with demo_info by selected column age gender
demo_data_summary <- data_income %>%
  left_join(demo_info %>% select(EEGID, Gender), by = "EEGID",  suffix = c("", "")) %>% 
  summarise(count = n(), 
  mean_age = mean(Age_EEG_yr, na.rm = TRUE),
  gender_count = list(table(Gender))
  )
  
knitr::kable(demo_data_summary)
count mean_age gender_count
180 8.135648 73, 107
# Fit separate models for each response variable
model_CWR <- lmerTest::lmer(CWR ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID), data = data_income)
model_CDICT <- lmerTest::lmer(CDICT ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID), data = data_income)
model_EWR <- lmerTest::lmer(EWR ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID), data = data_income)
model_EDICT <- lmerTest::lmer(EDICT ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID), data = data_income)

# Print the model summaries
summary(model_CWR)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1589.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.37465 -0.49008 -0.04215  0.44863  2.12748 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 424.8    20.61   
##  Residual             199.6    14.13   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   75.3246     2.3252  92.5248  32.394  < 2e-16 ***
## PW_c         145.8202    64.3788 157.5965   2.265  0.02487 *  
## Age_EEG_yr_c  12.2365     3.0922 140.5076   3.957  0.00012 ***
## SES_c          1.0522     1.5998  96.7442   0.658  0.51230    
## CMOI_c         5.1292     3.0743 156.9521   1.668  0.09723 .  
## ARITH_c        2.4775     0.4994 173.5785   4.961 1.66e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  CMOI_c
## PW_c         0.015                            
## Ag_EEG_yr_c -0.014  0.127                     
## SES_c       -0.021 -0.093 -0.190              
## CMOI_c      -0.040 -0.041  0.138 -0.049       
## ARITH_c      0.000 -0.169 -0.638  0.221  0.030
summary(model_CDICT)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1155.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.01949 -0.59068  0.06333  0.59453  2.20665 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 27.46    5.240   
##  Residual             19.60    4.427   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   25.39702    0.62336  93.64021  40.742  < 2e-16 ***
## PW_c          32.70999   18.86733 168.57786   1.734   0.0848 .  
## Age_EEG_yr_c   1.08602    0.85605 136.50649   1.269   0.2067    
## SES_c         -0.05553    0.43024  97.30063  -0.129   0.8976    
## CMOI_c         0.43704    0.85857 145.17260   0.509   0.6115    
## ARITH_c        0.70107    0.14323 171.66027   4.895 2.26e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  CMOI_c
## PW_c         0.012                            
## Ag_EEG_yr_c -0.017  0.137                     
## SES_c       -0.020 -0.102 -0.206              
## CMOI_c      -0.043 -0.020  0.151 -0.051       
## ARITH_c     -0.003 -0.175 -0.660  0.240  0.020
summary(model_EWR)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1286.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.04257 -0.43286 -0.08804  0.43022  3.06768 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 68.09    8.252   
##  Residual             37.26    6.104   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   19.0472     0.9472  91.1184  20.108  < 2e-16 ***
## PW_c          59.4364    27.1520 161.9289   2.189 0.030026 *  
## Age_EEG_yr_c   3.8218     1.2779 138.1279   2.991 0.003297 ** 
## SES_c         -4.1051     0.6579  96.1083  -6.240 1.18e-08 ***
## EMOI_c         4.0537     1.2033 143.0241   3.369 0.000970 ***
## ARITH_c        0.7341     0.2091 173.9392   3.511 0.000569 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  EMOI_c
## PW_c         0.014                            
## Ag_EEG_yr_c -0.015  0.131                     
## SES_c       -0.017 -0.093 -0.208              
## EMOI_c       0.039  0.030 -0.155  0.136       
## ARITH_c     -0.002 -0.172 -0.642  0.221 -0.044
summary(model_EDICT)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1037.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1929 -0.4497 -0.1271  0.3985  2.2033 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 14.273   3.778   
##  Residual              9.738   3.121   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)    7.5914     0.4464  94.9915  17.005  < 2e-16 ***
## PW_c          26.8802    13.3956 167.9086   2.007  0.04639 *  
## Age_EEG_yr_c   1.8857     0.6124 138.1532   3.079  0.00250 ** 
## SES_c         -1.6874     0.3107  99.5468  -5.432 3.96e-07 ***
## EMOI_c         1.8976     0.5772 138.8588   3.288  0.00128 ** 
## ARITH_c        0.3308     0.1020 172.2103   3.243  0.00142 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  EMOI_c
## PW_c         0.012                            
## Ag_EEG_yr_c -0.016  0.136                     
## SES_c       -0.016 -0.099 -0.217              
## EMOI_c       0.039  0.018 -0.162  0.139       
## ARITH_c     -0.003 -0.174 -0.654  0.232 -0.038
# Fit the models with centered variables
moderate_CWR_MOI <- lmerTest::lmer(CWR ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_CDICT_MOI <- lmerTest::lmer(CDICT ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_EWR_MOI <- lmerTest::lmer(EWR ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_EDICT_MOI <- lmerTest::lmer(EDICT ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)

# Print the model summaries
summary(moderate_CWR_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1577.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.41796 -0.48799 -0.01672  0.46316  2.16707 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 421.0    20.52   
##  Residual             199.7    14.13   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   75.4081     2.3180  92.7194  32.532  < 2e-16 ***
## PW_c         149.0621    64.3486 156.6435   2.316   0.0218 *  
## CMOI_c         5.2039     3.0672 155.4031   1.697   0.0918 .  
## SES_c          0.9084     1.5984  96.9826   0.568   0.5711    
## ARITH_c        2.3471     0.5094 172.5239   4.608 7.88e-06 ***
## Age_EEG_yr_c  12.7796     3.1143 140.7418   4.104 6.86e-05 ***
## PW_c:CMOI_c  112.1024    87.5803 130.2120   1.280   0.2028    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c SES_c  ARITH_ A_EEG_
## PW_c         0.016                                   
## CMOI_c      -0.040 -0.040                            
## SES_c       -0.023 -0.096 -0.050                     
## ARITH_c     -0.006 -0.174  0.026  0.230              
## Ag_EEG_yr_c -0.010  0.131  0.139 -0.198 -0.647       
## PW_c:CMOI_c  0.028  0.040  0.014 -0.071 -0.206  0.139
summary(moderate_CDICT_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1145.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.99093 -0.51839  0.06323  0.56310  2.24396 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 28.47    5.335   
##  Residual             19.06    4.366   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   25.37098    0.62917  92.89698  40.324  < 2e-16 ***
## PW_c          31.34968   18.81683 166.06885   1.666   0.0976 .  
## CMOI_c         0.46624    0.86173 147.44708   0.541   0.5893    
## SES_c         -0.02012    0.43501  96.66255  -0.046   0.9632    
## ARITH_c        0.73321    0.14637 171.74968   5.009 1.35e-06 ***
## Age_EEG_yr_c   0.95176    0.86854 137.00244   1.096   0.2751    
## PW_c:CMOI_c  -32.34363   26.04269 139.57623  -1.242   0.2163    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c SES_c  ARITH_ A_EEG_
## PW_c         0.014                                   
## CMOI_c      -0.043 -0.024                            
## SES_c       -0.022 -0.103 -0.049                     
## ARITH_c     -0.009 -0.179  0.025  0.246              
## Ag_EEG_yr_c -0.012  0.140  0.145 -0.211 -0.666       
## PW_c:CMOI_c  0.030  0.041 -0.023 -0.072 -0.207  0.142
summary(moderate_EWR_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1277.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.04347 -0.42291 -0.09249  0.44761  3.06411 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 68.34    8.267   
##  Residual             37.50    6.124   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   19.0563     0.9498  91.0243  20.064  < 2e-16 ***
## PW_c          59.5830    27.2316 160.8970   2.188 0.030111 *  
## EMOI_c         4.0549     1.2062 142.8776   3.362 0.000994 ***
## SES_c         -4.1195     0.6612  95.8856  -6.231 1.24e-08 ***
## ARITH_c        0.7238     0.2129 172.9974   3.400 0.000838 ***
## Age_EEG_yr_c   3.8689     1.2915 138.6082   2.996 0.003246 ** 
## PW_c:EMOI_c  -10.3001    34.7692 127.4813  -0.296 0.767526    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c SES_c  ARITH_ A_EEG_
## PW_c         0.014                                   
## EMOI_c       0.039  0.030                            
## SES_c       -0.019 -0.094  0.135                     
## ARITH_c     -0.008 -0.172 -0.045  0.230              
## Ag_EEG_yr_c -0.011  0.132 -0.153 -0.215 -0.649       
## PW_c:EMOI_c -0.033 -0.018 -0.008  0.075  0.174 -0.128
summary(moderate_EDICT_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1029.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1827 -0.4509 -0.1276  0.4052  2.1953 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 14.283   3.779   
##  Residual              9.825   3.134   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)    7.5898     0.4474  94.9860  16.965  < 2e-16 ***
## PW_c          26.8965    13.4392 167.0170   2.001  0.04697 *  
## EMOI_c         1.8948     0.5786 139.4389   3.275  0.00133 ** 
## SES_c         -1.6850     0.3120  99.3648  -5.400 4.55e-07 ***
## ARITH_c        0.3332     0.1039 171.6256   3.207  0.00160 ** 
## Age_EEG_yr_c   1.8757     0.6189 138.6194   3.030  0.00291 ** 
## PW_c:EMOI_c    1.6212    17.3837 137.1756   0.093  0.92583    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c SES_c  ARITH_ A_EEG_
## PW_c         0.012                                   
## EMOI_c       0.040  0.018                            
## SES_c       -0.019 -0.100  0.136                     
## ARITH_c     -0.009 -0.174 -0.041  0.241              
## Ag_EEG_yr_c -0.012  0.137 -0.157 -0.224 -0.661       
## PW_c:EMOI_c -0.034 -0.015 -0.025  0.075  0.177 -0.130

For the CMOI and EMOI moderation effect, the results are as follows: For CWR, the moderation effect of CMOI is significant (p = .049) and PW significantly correlates with CWR (p = .01). For CDICT, the moderation effect of CMOI is insignificant (p = .45) but PW significantly correlates with CDICT (p = .01). For EWR, the moderation effect of EMOI is insignificant (p = .39) but PW significantly correlates with EWR (p = .038). For EDICT, the moderation effect of EMOI is also insignificant (p = .85) and PW insignificantly correlates with EDICT (p = .09).

# Fit the model with PW as predictor, SES as moderator, and Age_EEG_yr as covariate
moderate_CWR_EIF <- lmerTest::lmer(CWR ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_CDICT_EIF <- lmerTest::lmer(CDICT ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
# moderate_ARITH_EIF <- lmerTest::lmer(ARITH ~ PW_c * SES_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_EWR_EIF <- lmerTest::lmer(EWR ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
moderate_EDICT_EIF <- lmerTest::lmer(EDICT ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)

# Print the model summary
summary(moderate_CWR_EIF)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1579.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.35358 -0.48973 -0.03684  0.45417  2.12615 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 431.1    20.76   
##  Residual             199.2    14.11   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   75.2745     2.3421  90.3429  32.139  < 2e-16 ***
## PW_c         142.5211    65.2020 160.5455   2.186 0.030276 *  
## SES_c          0.9730     1.6240  96.9061   0.599 0.550477    
## CMOI_c         5.0972     3.0854 156.0051   1.652 0.100538    
## ARITH_c        2.4765     0.5008 172.3200   4.945  1.8e-06 ***
## Age_EEG_yr_c  12.2707     3.1051 138.7439   3.952 0.000123 ***
## PW_c:SES_c    15.3266    44.5201 146.4451   0.344 0.731144    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  CMOI_c ARITH_ A_EEG_
## PW_c         0.023                                   
## SES_c       -0.012 -0.070                            
## CMOI_c      -0.040 -0.043 -0.050                     
## ARITH_c     -0.002 -0.172  0.213  0.030              
## Ag_EEG_yr_c -0.014  0.124 -0.189  0.138 -0.636       
## PW_c:SES_c  -0.058 -0.149 -0.138  0.005  0.032  0.011
summary(moderate_CDICT_EIF)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1148
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.97368 -0.58949  0.04713  0.58529  2.13975 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 27.54    5.248   
##  Residual             19.60    4.427   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   25.3618     0.6252  93.1220  40.565  < 2e-16 ***
## PW_c          30.6808    19.0079 169.9476   1.614    0.108    
## SES_c         -0.1158     0.4358  99.5354  -0.266    0.791    
## CMOI_c         0.4392     0.8592 144.3530   0.511    0.610    
## ARITH_c        0.7057     0.1434 170.8559   4.921 2.02e-06 ***
## Age_EEG_yr_c   1.0938     0.8568 135.6227   1.277    0.204    
## PW_c:SES_c    11.8036    13.1207 161.3320   0.900    0.370    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  CMOI_c ARITH_ A_EEG_
## PW_c         0.019                                   
## SES_c       -0.010 -0.082                            
## CMOI_c      -0.043 -0.021 -0.051                     
## ARITH_c     -0.005 -0.178  0.231  0.020              
## Ag_EEG_yr_c -0.017  0.135 -0.204  0.151 -0.659       
## PW_c:SES_c  -0.062 -0.118 -0.153  0.002  0.038  0.009
# summary(moderate_ARITH_EIF)
summary(moderate_EWR_EIF)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1278.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.02838 -0.42962 -0.08467  0.43147  3.05137 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 68.90    8.300   
##  Residual             37.29    6.107   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   19.0334     0.9533  89.2165  19.966  < 2e-16 ***
## PW_c          58.4663    27.4715 164.5728   2.128  0.03481 *  
## SES_c         -4.1307     0.6678  96.6422  -6.185 1.49e-08 ***
## EMOI_c         4.0560     1.2077 141.6001   3.358  0.00101 ** 
## ARITH_c        0.7335     0.2098 172.9834   3.496  0.00060 ***
## Age_EEG_yr_c   3.8328     1.2827 136.4223   2.988  0.00333 ** 
## PW_c:SES_c     4.8386    18.8389 151.8050   0.257  0.79765    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  EMOI_c ARITH_ A_EEG_
## PW_c         0.022                                   
## SES_c       -0.008 -0.071                            
## EMOI_c       0.039  0.033  0.136                     
## ARITH_c     -0.004 -0.175  0.213 -0.045              
## Ag_EEG_yr_c -0.016  0.128 -0.207 -0.155 -0.640       
## PW_c:SES_c  -0.060 -0.138 -0.144 -0.014  0.035  0.012
summary(moderate_EDICT_EIF)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 |  
##     FID)
##    Data: data_income
## 
## REML criterion at convergence: 1030.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1753 -0.4382 -0.1199  0.4112  2.2306 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 14.150   3.762   
##  Residual              9.871   3.142   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)    7.6023     0.4468  94.2080  17.015  < 2e-16 ***
## PW_c          27.6209    13.5346 169.7847   2.041  0.04282 *  
## SES_c         -1.6676     0.3141 101.3757  -5.310  6.5e-07 ***
## EMOI_c         1.8966     0.5775 137.1496   3.284  0.00130 ** 
## ARITH_c        0.3312     0.1023 171.0476   3.239  0.00144 ** 
## Age_EEG_yr_c   1.8763     0.6127 136.7996   3.062  0.00264 ** 
## PW_c:SES_c    -3.7340     9.3396 161.1939  -0.400  0.68983    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  EMOI_c ARITH_ A_EEG_
## PW_c         0.019                                   
## SES_c       -0.006 -0.079                            
## EMOI_c       0.040  0.018  0.139                     
## ARITH_c     -0.006 -0.178  0.224 -0.037              
## Ag_EEG_yr_c -0.017  0.135 -0.217 -0.163 -0.654       
## PW_c:SES_c  -0.063 -0.119 -0.153 -0.012  0.038  0.011

For the CMOI and EMOI moderation effect, the results are as follows: For CWR, the moderation effect of CMOI is significant (p = .049) and PW significantly correlates with CWR (p = .01). For CDICT, the moderation effect of CMOI is insignificant (p = .45) but PW significantly correlates with CDICT (p = .01). For EWR, the moderation effect of EMOI is insignificant (p = .39) but PW significantly correlates with EWR (p = .038). For EDICT, the moderation effect of EMOI is also insignificant (p = .85) and PW insignificantly correlates with EDICT (p = .09).

And for CWR and CDICT, alpha power significantly correlate with then (p = .01 and p = .02, respectively). However, the moderation effect of Education Income Factor (EIF) is not significant for CWR and CDICT (both p > .05). Alpha power did not significantly correlate with ARITH (p = .06) and the moderation effect of EIF is also insignificant (p = .65). Alpha power significantly correlate with then (p = .04 and p = .029, respectively). The moderation effect of EIF is insignificant for EWR and EDICT (both p > .05).

# Fit the models with centered variables
model_CWR_MOI <- lmerTest::lmer(CWR ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
model_CDICT_MOI <- lmerTest::lmer(CDICT ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
# moderate_ARITH_MOI <- lmerTest::lmer(ARITH ~ PW_c + CMOI_c + Age_EEG_yr_c + (1 | FID), data = data_income)
model_EWR_MOI <- lmerTest::lmer(EWR ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)
model_EDICT_MOI <- lmerTest::lmer(EDICT ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID), data = data_income)

#summary
summary(model_CWR_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1592.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4062 -0.4918 -0.0408  0.4519  2.1368 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 422.6    20.56   
##  Residual             199.3    14.12   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   75.3570     2.3195  93.6263  32.489  < 2e-16 ***
## PW_c         149.7652    64.0086 159.2098   2.340   0.0205 *  
## CMOI_c         5.2373     3.0649 158.1111   1.709   0.0894 .  
## ARITH_c        2.4063     0.4863 174.9892   4.949 1.75e-06 ***
## Age_EEG_yr_c  12.6178     3.0301 137.0659   4.164 5.50e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c ARITH_
## PW_c         0.013                     
## CMOI_c      -0.041 -0.046              
## ARITH_c      0.004 -0.153  0.042       
## Ag_EEG_yr_c -0.018  0.112  0.132 -0.622
summary(model_CDICT_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1155.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.01658 -0.59043  0.05636  0.60295  2.20857 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 27.04    5.200   
##  Residual             19.61    4.429   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   25.3961     0.6199  94.6403  40.969  < 2e-16 ***
## PW_c          32.5640    18.7253 170.1683   1.739   0.0838 .  
## CMOI_c         0.4304     0.8540 146.0560   0.504   0.6151    
## ARITH_c        0.7068     0.1386 169.4170   5.100 9.02e-07 ***
## Age_EEG_yr_c   1.0590     0.8341 132.6667   1.270   0.2064    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c ARITH_
## PW_c         0.010                     
## CMOI_c      -0.044 -0.025              
## ARITH_c      0.002 -0.156  0.032       
## Ag_EEG_yr_c -0.021  0.120  0.145 -0.644
summary(model_EWR_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1320.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8439 -0.3833 -0.1098  0.3792  3.1284 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 102.8    10.140  
##  Residual              37.6     6.132  
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   18.9695     1.1158  90.0722  17.000  < 2e-16 ***
## PW_c          46.6254    28.9245 149.0982   1.612 0.109084    
## EMOI_c         5.2681     1.3486 156.0441   3.906 0.000139 ***
## ARITH_c        0.8817     0.2235 173.0758   3.944 0.000116 ***
## Age_EEG_yr_c   2.6127     1.4278 136.7909   1.830 0.069444 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c ARITH_
## PW_c         0.014                     
## EMOI_c       0.040  0.068              
## ARITH_c      0.004 -0.154 -0.085       
## Ag_EEG_yr_c -0.016  0.106 -0.120 -0.601
summary(model_EDICT_MOI)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##    Data: data_income
## 
## REML criterion at convergence: 1063.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1006 -0.4502 -0.1160  0.3749  2.2228 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 19.817   4.452   
##  Residual              9.899   3.146   
## Number of obs: 180, groups:  FID, 101
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)    7.5532     0.5055  93.5471  14.942  < 2e-16 ***
## PW_c          19.2719    14.1400 161.3052   1.363 0.174803    
## EMOI_c         2.3700     0.6311 147.0155   3.755 0.000249 ***
## ARITH_c        0.4160     0.1073 174.7598   3.878 0.000149 ***
## Age_EEG_yr_c   1.3217     0.6628 135.7659   1.994 0.048162 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c ARITH_
## PW_c         0.013                     
## EMOI_c       0.041  0.049              
## ARITH_c      0.002 -0.155 -0.079       
## Ag_EEG_yr_c -0.018  0.113 -0.129 -0.620
# Perform the likelihood ratio test
comparison_CWR <- anova(model_CWR_MOI, moderate_CWR_MOI)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_CWR)
## Data: data_income
## Models:
## model_CWR_MOI: CWR ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
## moderate_CWR_MOI: CWR ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                  npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)
## model_CWR_MOI       7 1628.2 1650.6 -807.12   1614.2                     
## moderate_CWR_MOI    9 1630.1 1658.8 -806.05   1612.1 2.1533  2     0.3407
# Perform the likelihood ratio test
comparison_CWR_EIF <- anova(model_CWR, moderate_CWR_EIF)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_CWR_EIF)
## Data: data_income
## Models:
## model_CWR: CWR ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID)
## moderate_CWR_EIF: CWR ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                  npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)
## model_CWR           8 1629.8 1655.3 -806.89   1613.8                     
## moderate_CWR_EIF    9 1631.7 1660.4 -806.85   1613.7 0.0968  1     0.7557
# Perform the likelihood ratio test
comparison_CDICT <- anova(model_CDICT_MOI, moderate_CDICT_MOI)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_CDICT)
## Data: data_income
## Models:
## model_CDICT_MOI: CDICT ~ PW_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
## moderate_CDICT_MOI: CDICT ~ PW_c * CMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                    npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)
## model_CDICT_MOI       7 1178.7 1201.1 -582.35   1164.7                     
## moderate_CDICT_MOI    9 1181.2 1210.0 -581.61   1163.2 1.4909  2     0.4745
# Perform the likelihood ratio test
comparison_CDICT_EIF <- anova(model_CDICT, moderate_CDICT_EIF)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_CDICT_EIF)
## Data: data_income
## Models:
## model_CDICT: CDICT ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID)
## moderate_CDICT_EIF: CDICT ~ PW_c * SES_c + CMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                    npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)
## model_CDICT           8 1180.7 1206.2 -582.35   1164.7                     
## moderate_CDICT_EIF    9 1181.9 1210.6 -581.93   1163.9 0.8324  1     0.3616
# Perform the likelihood ratio test
comparison_EWR <- anova(model_EWR_MOI, moderate_EWR_MOI)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_EWR)
## Data: data_income
## Models:
## model_EWR_MOI: EWR ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
## moderate_EWR_MOI: EWR ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                  npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)    
## model_EWR_MOI       7 1348.6 1371.0 -667.30   1334.6                         
## moderate_EWR_MOI    9 1317.8 1346.5 -649.89   1299.8 34.832  2  2.731e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Perform the likelihood ratio test
comparison_EWR_EIF <- anova(model_EWR, moderate_EWR_EIF)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_EWR_EIF)
## Data: data_income
## Models:
## model_EWR: EWR ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID)
## moderate_EWR_EIF: EWR ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                  npar    AIC    BIC  logLik deviance Chisq Df Pr(>Chisq)
## model_EWR           8 1315.9 1341.4 -649.93   1299.9                    
## moderate_EWR_EIF    9 1317.8 1346.5 -649.91   1299.8  0.05  1      0.823
# Perform the likelihood ratio test
comparison_EDICT <- anova(model_EDICT_MOI, moderate_EDICT_MOI)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_EDICT)
## Data: data_income
## Models:
## model_EDICT_MOI: EDICT ~ PW_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
## moderate_EDICT_MOI: EDICT ~ PW_c * EMOI_c + SES_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                    npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)    
## model_EDICT_MOI       7 1083.3 1105.7 -534.67   1069.3                         
## moderate_EDICT_MOI    9 1060.0 1088.7 -520.99   1042.0 27.342  2  1.156e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Perform the likelihood ratio test
comparison_EDICT_EIF <- anova(model_EDICT, moderate_EDICT_EIF)
## refitting model(s) with ML (instead of REML)
# Print the comparison results
print(comparison_EDICT_EIF)
## Data: data_income
## Models:
## model_EDICT: EDICT ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID)
## moderate_EDICT_EIF: EDICT ~ PW_c * SES_c + EMOI_c + ARITH_c + Age_EEG_yr_c + (1 | FID)
##                    npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)
## model_EDICT           8 1058.0 1083.5 -521.00   1042.0                     
## moderate_EDICT_EIF    9 1059.8 1088.5 -520.91   1041.8 0.1816  1       0.67
data_child <- read.csv("./data/model_data_180.csv")
  
data_parent_raw <- read_excel("./data/CRF_ADATA_20230620.xlsx")
## Warning: Expecting logical in BQM1490 / R1490C1807: got '曾有懶眼需遮蓋眼睛'
## Warning: Expecting logical in BQM1491 / R1491C1807: got '曾有懶眼需遮蓋眼睛'
## Warning: Expecting logical in BQM1492 / R1492C1807: got '曾有懶眼需遮蓋眼睛'
## Warning: Expecting logical in BQM1493 / R1493C1807: got '曾有懶眼需遮蓋眼睛'
## Warning: Expecting logical in BQM1498 / R1498C1807: got
## '兩眼有白內障已動手術換晶片'
## Warning: Expecting logical in BQM1499 / R1499C1807: got
## '兩眼有白內障已動手術換晶片'
## Warning: Expecting logical in BQM1500 / R1500C1807: got
## '兩眼有白內障已動手術換晶片'
## Warning: Expecting logical in BQM1501 / R1501C1807: got
## '兩眼有白內障已動手術換晶片'
## Warning: Expecting logical in BQM1733 / R1733C1807: got
## '右眼有外斜視問題但幸運地未影響他的立體感建立閱讀距離視力正常'
## Warning: Expecting logical in BQM1734 / R1734C1807: got
## '右眼有外斜視問題但幸運地未影響他的立體感建立閱讀距離視力正常'
## Warning: Expecting logical in BQM1735 / R1735C1807: got
## '右眼有外斜視問題但幸運地未影響他的立體感建立閱讀距離視力正常'
# Filter rows where LP1-LP5 contain at least one '10'
data_parent <- data_parent_raw %>%
  semi_join(data_child, by = c("EEGID", "FID"))
  # dplyr::filter(if_any(LP1:LP5, ~ .x == 10))

  

# # View the filtered data
# View(data_dys)

data_parent_s <- data_parent %>% 
  dplyr::select(SubjectID, FID, EEGID,
                MSWR, MCDICT, MARITH, 
                FSWR, FCDICT, FARITH, LearningProblem, LP1, LP2, LP3, LP4, LP5) %>%
  dplyr::filter(!(rowSums(is.na(select(., MSWR, MCDICT, MARITH, FSWR, FCDICT, FARITH))) == 6)) %>%
  dplyr::mutate(
    PSWR = case_when(
      is.na(MSWR) & is.na(FSWR) ~ NA_real_,  # If both are NA, PSWR is NA
      is.na(MSWR) ~ FSWR,                   # If MSWR is NA, PSWR is FSWR
      is.na(FSWR) ~ MSWR,                   # If FSWR is NA, PSWR is MSWR
      TRUE ~ (MSWR + FSWR) / 2              # If both have values, PSWR is the average
    ),
    PCDICT = case_when(
      is.na(MCDICT) & is.na(FCDICT) ~ NA_real_, 
      is.na(MCDICT) ~ FCDICT,                 
      is.na(FCDICT) ~ MCDICT,                  
      TRUE ~ (MCDICT + FCDICT) / 2              
    ), 
    PARITH = case_when(
      is.na(MARITH) & is.na(FARITH) ~ NA_real_, 
      is.na(MARITH) ~ FARITH,                 
      is.na(FARITH) ~ MARITH,                  
      TRUE ~ (MARITH + FARITH) / 2
    )
  ) %>%
  dplyr::mutate(
    PSWR_z = scale(PSWR),  # Calculate z-score for PSWR
    PCDICT_z = scale(PCDICT),  # Calculate z-score for PCDICT
    PARITH_z = scale(PARITH)  # Calculate z-score for PARITH
  )

# Create a subset where at least one of the z-scores is lower than -1
risk_data <- data_parent_s %>%
  dplyr::filter(
    PSWR_z < -1 | PCDICT_z < -1 | PARITH_z < -1
  ) %>%
  dplyr::select(SubjectID, FID, EEGID, PSWR_z, PCDICT_z, PARITH_z)
## Warning: Using one column matrices in `filter()` was deprecated in dplyr 1.1.0.
## ℹ Please use one dimensional logical vectors instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Select risk child from child_data where EEGID and FID match with risk_data
risk_child <- data_child %>%
  dplyr::inner_join(risk_data, by = c("EEGID", "FID"))

# Fit separate models for each response variable
model_CWR_risk <- lmerTest::lmer(CWR ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID), data = risk_child)
model_CDICT_risk <- lmerTest::lmer(CDICT ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
model_EWR_risk <- lmerTest::lmer(EWR ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
model_EDICT_risk <- lmerTest::lmer(EDICT ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID), data = risk_child)

# Print the model summaries
summary(model_CWR_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 34.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -0.9745 -0.1842 -0.0086  0.2552  0.9655 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 460.31   21.455  
##  Residual              38.85    6.233  
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)    47.267     20.077    3.292   2.354   0.0922 .
## PW_c         -391.825    233.868    2.662  -1.675   0.2039  
## Age_EEG_yr_c   46.590     19.036    3.727   2.447   0.0753 .
## SES_c           8.996     13.424    2.120   0.670   0.5683  
## CMOI_c         -2.572     10.223    1.909  -0.252   0.8258  
## ARITH_c        -2.583      2.473    2.820  -1.044   0.3774  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  CMOI_c
## PW_c         0.487                            
## Ag_EEG_yr_c -0.650 -0.388                     
## SES_c       -0.758 -0.266  0.318              
## CMOI_c       0.035  0.242  0.275 -0.005       
## ARITH_c      0.601  0.614 -0.688 -0.336  0.167
summary(model_CDICT_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c + Age_EEG_yr_c + SES_c + CMOI_c + ARITH_c + (1 |  
##     FID)
##    Data: risk_child
## 
## REML criterion at convergence: 29.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.0927 -0.4329 -0.1442  0.6071  0.9402 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.00    0.000   
##  Residual             27.37    5.231   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)  
## (Intercept)    12.807      5.970   4.000   2.145   0.0985 .
## PW_c          -36.294    127.625   4.000  -0.284   0.7902  
## Age_EEG_yr_c    9.078      6.730   4.000   1.349   0.2486  
## SES_c           5.337      2.819   4.000   1.894   0.1312  
## CMOI_c         -3.071      2.067   4.000  -1.486   0.2116  
## ARITH_c        -1.342      1.075   4.000  -1.249   0.2799  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  CMOI_c
## PW_c         0.499                            
## Ag_EEG_yr_c -0.819 -0.128                     
## SES_c       -0.769 -0.335  0.513              
## CMOI_c       0.261  0.565  0.058 -0.201       
## ARITH_c      0.811  0.198 -0.912 -0.584  0.166
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(model_EWR_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 31.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.92879 -0.47819 -0.05944  0.31982  1.27497 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.00    0.000   
##  Residual             41.56    6.447   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)     1.344      7.304    4.000   0.184   0.8630  
## PW_c         -152.901    156.459    4.000  -0.977   0.3838  
## Age_EEG_yr_c   13.787      8.297    4.000   1.662   0.1719  
## SES_c           7.639      3.475    4.000   2.198   0.0928 .
## EMOI_c         10.053      2.271    4.000   4.426   0.0115 *
## ARITH_c        -1.736      1.322    4.000  -1.313   0.2593  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  EMOI_c
## PW_c         0.487                            
## Ag_EEG_yr_c -0.825 -0.125                     
## SES_c       -0.769 -0.336  0.511              
## EMOI_c      -0.233 -0.559 -0.065  0.202       
## ARITH_c      0.810  0.191 -0.913 -0.582 -0.154
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(model_EDICT_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c + Age_EEG_yr_c + SES_c + EMOI_c + ARITH_c + (1 |  
##     FID)
##    Data: risk_child
## 
## REML criterion at convergence: 21
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.87347 -0.26579  0.01841  0.23442  0.79370 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 10.129   3.183   
##  Residual              1.491   1.221   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)
## (Intercept)    2.8167     3.3176  3.1694   0.849    0.455
## PW_c          56.5792    44.1714  2.8560   1.281    0.294
## Age_EEG_yr_c   4.6889     3.2316  3.7608   1.451    0.225
## SES_c          1.3402     2.0865  1.7679   0.642    0.594
## EMOI_c         4.1022     1.4018  1.5074   2.926    0.137
## ARITH_c       -0.4921     0.4625  3.1653  -1.064    0.362
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   A_EEG_ SES_c  EMOI_c
## PW_c         0.534                            
## Ag_EEG_yr_c -0.713 -0.411                     
## SES_c       -0.768 -0.316  0.374              
## EMOI_c      -0.062 -0.291 -0.194  0.050       
## ARITH_c      0.673  0.589 -0.764 -0.404 -0.192
# Fit the models with centered variables
moderate_CWR_MOI_risk <- lmerTest::lmer(CWR ~ PW_c * CMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
moderate_CDICT_MOI_risk <- lmerTest::lmer(CDICT ~ PW_c * CMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
moderate_EWR_MOI_risk <- lmerTest::lmer(EWR ~ PW_c * EMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
moderate_EDICT_MOI_risk <- lmerTest::lmer(EDICT ~ PW_c * EMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID), data = risk_child)

# Print the model summaries
summary(moderate_CWR_MOI_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c * CMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 21
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.18631 -0.21094 -0.00348  0.36388  0.91812 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.00    0.000   
##  Residual             94.13    9.702   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)     39.7855    11.0875     3.0000   3.588   0.0371 *
## PW_c         -1275.4716   323.5912     3.0000  -3.942   0.0291 *
## CMOI_c          -9.8221     4.0440     3.0000  -2.429   0.0934 .
## Age_EEG_yr_c    26.9640    14.4136     3.0000   1.871   0.1581  
## ARITH_c          0.2571     2.3185     3.0000   0.111   0.9187  
## SES_c           11.2730     5.2293     3.0000   2.156   0.1201  
## PW_c:CMOI_c   -415.5473   180.7504     3.0000  -2.299   0.1051  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c A_EEG_ ARITH_ SES_c 
## PW_c         0.400                                   
## CMOI_c       0.263  0.609                            
## Ag_EEG_yr_c -0.683  0.260  0.207                     
## ARITH_c      0.670 -0.224 -0.027 -0.934              
## SES_c       -0.769 -0.261 -0.198  0.432 -0.490       
## PW_c:CMOI_c  0.051  0.682  0.318  0.500 -0.510 -0.023
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(moderate_CDICT_MOI_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c * CMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 |  
##     FID)
##    Data: risk_child
## 
## REML criterion at convergence: 17.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.15261 -0.19123  0.01820  0.05252  1.09631 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.00    0.000   
##  Residual             25.44    5.044   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)    12.4718     5.7642    3.0000   2.164    0.119
## PW_c         -167.1960   168.2304    3.0000  -0.994    0.394
## CMOI_c         -3.8342     2.1024    3.0000  -1.824    0.166
## Age_EEG_yr_c    4.8014     7.4934    3.0000   0.641    0.567
## ARITH_c        -0.6398     1.2054    3.0000  -0.531    0.632
## SES_c           5.4089     2.7186    3.0000   1.990    0.141
## PW_c:CMOI_c  -107.2364    93.9695    3.0000  -1.141    0.337
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   CMOI_c A_EEG_ ARITH_ SES_c 
## PW_c         0.400                                   
## CMOI_c       0.263  0.609                            
## Ag_EEG_yr_c -0.683  0.260  0.207                     
## ARITH_c      0.670 -0.224 -0.027 -0.934              
## SES_c       -0.769 -0.261 -0.198  0.432 -0.490       
## PW_c:CMOI_c  0.051  0.682  0.318  0.500 -0.510 -0.023
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(moderate_EWR_MOI_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c * EMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 19.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -0.9290 -0.2733  0.0251  0.1667  1.2733 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.00    0.000   
##  Residual             48.29    6.949   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)     1.121      7.881    3.000   0.142   0.8959  
## PW_c         -252.169    225.215    3.000  -1.120   0.3444  
## EMOI_c         10.596      2.581    3.000   4.105   0.0262 *
## Age_EEG_yr_c   10.372     10.313    3.000   1.006   0.3886  
## ARITH_c        -1.176      1.656    3.000  -0.710   0.5288  
## SES_c           7.695      3.747    3.000   2.054   0.1323  
## PW_c:EMOI_c    77.398    116.372    3.000   0.665   0.5536  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c A_EEG_ ARITH_ SES_c 
## PW_c         0.392                                   
## EMOI_c      -0.235 -0.607                            
## Ag_EEG_yr_c -0.693  0.249 -0.211                     
## ARITH_c      0.675 -0.214  0.036 -0.935              
## SES_c       -0.769 -0.267  0.199  0.432 -0.490       
## PW_c:EMOI_c -0.043 -0.663  0.317 -0.498  0.509  0.022
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(moderate_EDICT_MOI_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c * EMOI_c + Age_EEG_yr_c + ARITH_c + SES_c + (1 |  
##     FID)
##    Data: risk_child
## 
## REML criterion at convergence: 9.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.54230 -0.14263  0.00175  0.13111  0.53433 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 47.03380 6.8581  
##  Residual              0.05735 0.2395  
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)  
## (Intercept)    6.51837    4.98280   2.01825   1.308   0.3199  
## PW_c         245.01130   25.19749   1.00355   9.724   0.0648 .
## EMOI_c         2.59440    2.79204   1.97657   0.929   0.4519  
## Age_EEG_yr_c   5.66073    4.30728   2.04123   1.314   0.3170  
## ARITH_c       -0.51161    0.10823   0.98657  -4.727   0.1352  
## SES_c         -0.03226    3.94460   1.96991  -0.008   0.9942  
## PW_c:EMOI_c  -67.28330    9.67150   1.00129  -6.957   0.0907 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   EMOI_c A_EEG_ ARITH_ SES_c 
## PW_c         0.095                                   
## EMOI_c       0.141 -0.071                            
## Ag_EEG_yr_c -0.439  0.036 -0.533                     
## ARITH_c      0.072 -0.072 -0.001 -0.142              
## SES_c       -0.744 -0.044 -0.057  0.137 -0.035       
## PW_c:EMOI_c -0.069 -0.926  0.064 -0.070  0.328  0.032
# Fit the model with PW as predictor, SES as moderator, and Age_EEG_yr as covariate
moderate_CWR_EIF_risk <- lmerTest::lmer(CWR ~ PW_c * SES_c + CMOI_c + SES_c + Age_EEG_yr_c + (1 | FID), data = risk_child)
moderate_CDICT_EIF_risk <- lmerTest::lmer(CDICT ~ PW_c * SES_c + CMOI_c + SES_c + Age_EEG_yr_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
moderate_EWR_EIF_risk <- lmerTest::lmer(EWR ~ PW_c * SES_c + EMOI_c + SES_c + Age_EEG_yr_c + (1 | FID), data = risk_child)
## boundary (singular) fit: see help('isSingular')
moderate_EDICT_EIF_risk <- lmerTest::lmer(EDICT ~ PW_c * SES_c + EMOI_c + SES_c + Age_EEG_yr_c + (1 | FID), data = risk_child)

# Print the model summary
summary(moderate_CWR_EIF_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CWR ~ PW_c * SES_c + CMOI_c + SES_c + Age_EEG_yr_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 23.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.81420 -0.09451 -0.01441  0.11805  0.85910 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 1186.83  34.45   
##  Residual               21.71   4.66   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)    46.7894    26.7469    2.1201   1.749    0.215
## PW_c         -750.2901   408.9639    2.0273  -1.835    0.206
## SES_c          17.3845    21.9782    2.3240   0.791    0.502
## CMOI_c         -0.0619    15.7194    1.5964  -0.004    0.997
## Age_EEG_yr_c   35.9734    21.7300    1.6105   1.655    0.268
## PW_c:SES_c    795.0427   554.7877    2.1593   1.433    0.280
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  CMOI_c A_EEG_
## PW_c         0.367                            
## SES_c       -0.782 -0.411                     
## CMOI_c      -0.107  0.019  0.067              
## Ag_EEG_yr_c -0.422 -0.073  0.162  0.543       
## PW_c:SES_c  -0.360 -0.939  0.424  0.011  0.089
summary(moderate_CDICT_EIF_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CDICT ~ PW_c * SES_c + CMOI_c + SES_c + Age_EEG_yr_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 12.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -0.7944 -0.5729  0.0236  0.2196  1.3729 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 0.000    0.000   
##  Residual             6.196    2.489   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)    32.4064     3.4221    4.0000   9.470 0.000694 ***
## PW_c          604.1896   146.9194    4.0000   4.112 0.014703 *  
## SES_c          -8.3099     2.7795    4.0000  -2.990 0.040349 *  
## CMOI_c         -0.8215     1.0498    4.0000  -0.783 0.477642    
## Age_EEG_yr_c    0.6910     1.3240    4.0000   0.522 0.629300    
## PW_c:SES_c   -619.4038   136.6301    4.0000  -4.533 0.010550 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  CMOI_c A_EEG_
## PW_c         0.915                            
## SES_c       -0.923 -0.885                     
## CMOI_c       0.433  0.556 -0.399              
## Ag_EEG_yr_c -0.266 -0.058  0.088  0.429       
## PW_c:SES_c  -0.874 -0.914  0.920 -0.383  0.121
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(moderate_EWR_EIF_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EWR ~ PW_c * SES_c + EMOI_c + SES_c + Age_EEG_yr_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 19.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.78742 -0.32892 -0.14194  0.06274  1.69441 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept)  0.0     0.000   
##  Residual             34.4     5.865   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)    21.122      8.036    4.000   2.628   0.0583 .
## PW_c          429.543    347.434    4.000   1.236   0.2840  
## SES_c          -5.377      6.587    4.000  -0.816   0.4602  
## EMOI_c          8.111      2.219    4.000   3.656   0.0217 *
## Age_EEG_yr_c    3.192      3.102    4.000   1.029   0.3616  
## PW_c:SES_c   -552.010    323.232    4.000  -1.708   0.1629  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  EMOI_c A_EEG_
## PW_c         0.913                            
## SES_c       -0.923 -0.887                     
## EMOI_c      -0.426 -0.560  0.411              
## Ag_EEG_yr_c -0.278 -0.063  0.088 -0.418       
## PW_c:SES_c  -0.875 -0.916  0.921  0.391  0.122
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(moderate_EDICT_EIF_risk)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EDICT ~ PW_c * SES_c + EMOI_c + SES_c + Age_EEG_yr_c + (1 | FID)
##    Data: risk_child
## 
## REML criterion at convergence: 8.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.96146 -0.38801 -0.06736  0.31322  1.11140 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  FID      (Intercept) 2.467    1.571   
##  Residual             1.847    1.359   
## Number of obs: 10, groups:  FID, 6
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)  
## (Intercept)     9.2222     2.4197    2.8484   3.811   0.0348 *
## PW_c          244.9616    89.7875    3.7791   2.728   0.0559 .
## SES_c          -3.4107     2.0525    2.5187  -1.662   0.2122  
## EMOI_c          3.8421     0.8218    1.0827   4.675   0.1199  
## Age_EEG_yr_c    1.2703     1.2398    0.9165   1.025   0.5043  
## PW_c:SES_c   -229.4077    98.2913    3.1630  -2.334   0.0973 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) PW_c   SES_c  EMOI_c A_EEG_
## PW_c         0.823                            
## SES_c       -0.899 -0.814                     
## EMOI_c      -0.123 -0.286  0.136              
## Ag_EEG_yr_c -0.377 -0.126  0.190 -0.494       
## PW_c:SES_c  -0.793 -0.911  0.848  0.142  0.190