# load libraries 
library("knitr")  
library("pwr")        
library("modelr")     
library("lsr")
library("knitr")
library("GGally")
## Loading required package: ggplot2
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library("sjPlot")
library("sjmisc")
library("mediation")
## Loading required package: MASS
## Loading required package: Matrix
## Loading required package: mvtnorm
## Loading required package: sandwich
## mediation: Causal Mediation Analysis
## Version: 4.5.0
library("lavaan")
## This is lavaan 0.6-7
## lavaan is BETA software! Please report any bugs.
library("ggplot2")
library("psych")
## 
## Attaching package: 'psych'
## The following object is masked from 'package:lavaan':
## 
##     cor2cov
## The following object is masked from 'package:mediation':
## 
##     mediate
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library("ggthemes")
library("car")
## Loading required package: carData
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
library("summarytools")
## Registered S3 method overwritten by 'pryr':
##   method      from
##   print.bytes Rcpp
## For best results, restart R session and update pander using devtools:: or remotes::install_github('rapporter/pander')
## 
## Attaching package: 'summarytools'
## The following object is masked from 'package:sjmisc':
## 
##     descr
library("desc")
library("boot")
## 
## Attaching package: 'boot'
## The following object is masked from 'package:car':
## 
##     logit
## The following object is masked from 'package:psych':
## 
##     logit
library("extrafont")
## Registering fonts with R
library("plyr")
## 
## Attaching package: 'plyr'
## The following object is masked from 'package:desc':
## 
##     desc
library("reshape2")
library("lme4")
library("sjmisc")
library("plotrix")
## 
## Attaching package: 'plotrix'
## The following object is masked from 'package:psych':
## 
##     rescale
library("lattice")
## 
## Attaching package: 'lattice'
## The following object is masked from 'package:boot':
## 
##     melanoma
library("stringr")
library("mediation")
library("multilevel")
## Loading required package: nlme
## 
## Attaching package: 'nlme'
## The following object is masked from 'package:lme4':
## 
##     lmList
library("QuantPsyc")
## 
## Attaching package: 'QuantPsyc'
## The following object is masked from 'package:Matrix':
## 
##     norm
## The following object is masked from 'package:base':
## 
##     norm
library("Hmisc")
## Loading required package: survival
## 
## Attaching package: 'survival'
## The following object is masked from 'package:boot':
## 
##     aml
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:plyr':
## 
##     is.discrete, summarize
## The following objects are masked from 'package:summarytools':
## 
##     label, label<-
## The following object is masked from 'package:psych':
## 
##     describe
## The following object is masked from 'package:sjmisc':
## 
##     %nin%
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library("ggpubr")
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
## 
##     mutate
library("lme4")
library("lmerTest")
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library("nlme")
library("corrr")
## 
## Attaching package: 'corrr'
## The following object is masked from 'package:lsr':
## 
##     correlate
library("sjstats")
## 
## Attaching package: 'sjstats'
## The following object is masked from 'package:psych':
## 
##     phi
## The following objects are masked from 'package:modelr':
## 
##     bootstrap, mse, rmse
library("psych")
library("ggcorrplot")
library("knitr")
library("GGally")
library("sjPlot")
library("sjmisc")
library("kableExtra") 
library("janitor")     
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:sjmisc':
## 
##     remove_empty_cols, remove_empty_rows
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library("afex")       
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'KR', 'S', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - NEWS: library('emmeans') now needs to be called explicitly!
## - Get and set global package options with: afex_options()
## - Set orthogonal sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
## 
## Attaching package: 'afex'
## The following object is masked from 'package:lme4':
## 
##     lmer
library("emmeans")    
## 
## Attaching package: 'emmeans'
## The following object is masked from 'package:GGally':
## 
##     pigs
library("car")        
library("broom")    
## 
## Attaching package: 'broom'
## The following object is masked from 'package:sjstats':
## 
##     bootstrap
## The following object is masked from 'package:modelr':
## 
##     bootstrap
library("plyr")
library("lubridate")
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library("tidyverse")
## ── Attaching packages ─────────── tidyverse 1.3.0 ──
## ✓ tibble  3.0.3     ✓ purrr   0.3.4
## ✓ tidyr   1.1.1     ✓ dplyr   1.0.1
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ────────────── tidyverse_conflicts() ──
## x psych::%+%()             masks ggplot2::%+%()
## x tibble::add_case()       masks sjmisc::add_case()
## x psych::alpha()           masks ggplot2::alpha()
## x dplyr::arrange()         masks plyr::arrange()
## x lubridate::as.difftime() masks base::as.difftime()
## x broom::bootstrap()       masks sjstats::bootstrap(), modelr::bootstrap()
## x dplyr::collapse()        masks nlme::collapse()
## x purrr::compact()         masks plyr::compact()
## x dplyr::count()           masks plyr::count()
## x lubridate::date()        masks base::date()
## x dplyr::desc()            masks plyr::desc(), desc::desc()
## x tidyr::expand()          masks Matrix::expand()
## x dplyr::failwith()        masks plyr::failwith()
## x dplyr::filter()          masks stats::filter()
## x dplyr::group_rows()      masks kableExtra::group_rows()
## x dplyr::id()              masks plyr::id()
## x lubridate::intersect()   masks base::intersect()
## x purrr::is_empty()        masks sjmisc::is_empty()
## x dplyr::lag()             masks stats::lag()
## x sjstats::mse()           masks modelr::mse()
## x dplyr::mutate()          masks ggpubr::mutate(), plyr::mutate()
## x tidyr::pack()            masks Matrix::pack()
## x dplyr::recode()          masks car::recode()
## x dplyr::rename()          masks plyr::rename()
## x tidyr::replace_na()      masks sjmisc::replace_na()
## x sjstats::rmse()          masks modelr::rmse()
## x dplyr::select()          masks MASS::select()
## x lubridate::setdiff()     masks base::setdiff()
## x purrr::some()            masks car::some()
## x dplyr::src()             masks Hmisc::src()
## x dplyr::summarise()       masks plyr::summarise()
## x dplyr::summarize()       masks Hmisc::summarize(), plyr::summarize()
## x lubridate::union()       masks base::union()
## x tidyr::unpack()          masks Matrix::unpack()
## x tibble::view()           masks summarytools::view()
library("lubridate")
library("dplyr")
# data file
covid = read.csv("/Volumes/group/users/borchersLR/COVID/github/covid.csv")

# excluding participants with no cesdc
covid = covid %>% 
    filter(!is.na(CESDC_total.TC))

# N = 109
covid
### key
# tc = covid-19 assessment time point
## sex
# 1 is male; 2 is female
## race
# 1 is white; 2 is african american; 3 is hispanic; 4 is asian; 5 is biracial; 6 is other
# els = early life stress
# abstract

# number of male and female participants in the sample
# 1 is male; 2 is female
covid %>% 
      group_by(Child_Sex.T1) %>%
      summarise(n=n())
## `summarise()` ungrouping output (override with `.groups` argument)
# age range of participants
min(covid$Child_Age.TC)
## [1] 12.82
max(covid$Child_Age.TC)
## [1] 19.98
# years between baseline and tc assessment
covid$years <- covid$Child_Age.TC-covid$Age_S1.T1
summary(covid$years)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.020   4.510   5.070   5.064   5.810   6.540
mean(covid$years)
## [1] 5.064312
sd(covid$years)
## [1] 0.8592346
# correlation between els and depression 
cor.test(covid$sumsev_type_t1, covid$CESDC_total.TC)
## 
##  Pearson's product-moment correlation
## 
## data:  covid$sumsev_type_t1 and covid$CESDC_total.TC
## t = 2.8112, df = 107, p-value = 0.005871
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.07800399 0.42918713
## sample estimates:
##       cor 
## 0.2622577
# sex differences in depression
t.test(CESDC_total.TC ~ Child_Sex.T1, data = covid, rm.na=TRUE,  var.equal=T)
## 
##  Two Sample t-test
## 
## data:  CESDC_total.TC by Child_Sex.T1
## t = -3.5573, df = 107, p-value = 0.0005598
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.569219  -3.289132
## sample estimates:
## mean in group 1 mean in group 2 
##        16.11628        23.54545
# methods
dates <- read.csv('/Volumes/group/users/borchersLR/COVID/github/tc_dates.csv',sep=",",header=T)
dates_sample <-left_join(covid, dates, by="ELS_ID")

# time between
dates_sample$background_timestamp<-as.Date(dates_sample$background_timestamp, format = "%m/%d/%y")
summary(dates_sample$background_timestamp)
##         Min.      1st Qu.       Median         Mean      3rd Qu.         Max. 
## "2020-04-03" "2020-04-04" "2020-04-07" "2020-04-08" "2020-04-12" "2020-04-23"
# days between shelter in place March 17
shelter<-as.Date(as.character("03/17/2020"), format="%m/%d/%y")
dates_sample$date_diff <- dates_sample$background_timestamp- shelter
summary(as.integer(dates_sample$date_diff))
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   17.00   18.00   21.00   22.57   26.00   37.00
mean(as.integer(dates_sample$date_diff), na.rm=T)
## [1] 22.56881
sd(as.integer(dates_sample$date_diff), na.rm=T)
## [1] 4.941073
# percent of participants who completed the covid-19 (TC) assessment 
109/221
## [1] 0.4932127
# age of participants
min(covid$Child_Age.TC)
## [1] 12.82
max(covid$Child_Age.TC)
## [1] 19.98
mean(covid$Child_Age.TC)
## [1] 16.29789
sd(covid$Child_Age.TC)
## [1] 1.473223
# cdi
# one participant did not complete the cdi at baseline
min(covid$cdi_TOTAL.T1, na.rm = TRUE)
## [1] 0
max(covid$cdi_TOTAL.T1, na.rm = TRUE)
## [1] 10
mean(covid$cdi_TOTAL.T1, na.rm = TRUE)
## [1] 1.768519
sd(covid$cdi_TOTAL.T1, na.rm = TRUE)
## [1] 2.048964
# crobach's alpha for cdi at baseline
cdi_t1 = read.csv("/Volumes/group/users/borchersLR/COVID/github/cdi_t1.csv")

cdi_t1 = cdi_t1 %>% 
   filter(!is.na(cdi_1.T1)) 

cdi_t1 %>% 
  select(
    cdi_1.T1, 
    cdi_2_R.T1, 
    cdi_3.T1, 
    cdi_4_R.T1, 
    cdi_5_R.T1, 
    cdi_6_R.T1,
    cdi_7.T1,
    cdi_8.T1,
    cdi_9.T1,
    cdi_10_R.T1
  ) %>% 
  alpha()
## 
## Reliability analysis   
## Call: alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.75      0.77    0.77      0.26 3.4 0.025 0.22 0.24     0.24
## 
##  lower alpha upper     95% confidence boundaries
## 0.7 0.75 0.8 
## 
##  Reliability if an item is dropped:
##             raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## cdi_1.T1         0.72      0.75    0.74      0.25 2.9    0.027 0.0082  0.24
## cdi_2_R.T1       0.74      0.76    0.76      0.26 3.2    0.026 0.0090  0.24
## cdi_3.T1         0.75      0.78    0.78      0.28 3.5    0.025 0.0071  0.28
## cdi_4_R.T1       0.73      0.74    0.74      0.24 2.9    0.027 0.0081  0.24
## cdi_5_R.T1       0.73      0.75    0.75      0.25 3.0    0.027 0.0083  0.24
## cdi_6_R.T1       0.74      0.76    0.76      0.26 3.2    0.026 0.0101  0.25
## cdi_7.T1         0.74      0.76    0.76      0.26 3.2    0.026 0.0102  0.27
## cdi_8.T1         0.71      0.74    0.74      0.24 2.9    0.029 0.0083  0.24
## cdi_9.T1         0.74      0.76    0.76      0.26 3.2    0.026 0.0094  0.26
## cdi_10_R.T1      0.72      0.74    0.73      0.24 2.8    0.028 0.0085  0.23
## 
##  Item statistics 
##               n raw.r std.r r.cor r.drop  mean   sd
## cdi_1.T1    211  0.60  0.63  0.58   0.48 0.185 0.39
## cdi_2_R.T1  211  0.57  0.54  0.46   0.40 0.332 0.50
## cdi_3.T1    211  0.35  0.41  0.29   0.25 0.071 0.26
## cdi_4_R.T1  211  0.60  0.64  0.60   0.51 0.095 0.29
## cdi_5_R.T1  210  0.58  0.60  0.54   0.47 0.114 0.35
## cdi_6_R.T1  211  0.61  0.54  0.46   0.41 0.488 0.63
## cdi_7.T1    211  0.55  0.52  0.43   0.37 0.346 0.52
## cdi_8.T1    211  0.67  0.66  0.62   0.53 0.223 0.48
## cdi_9.T1    211  0.54  0.53  0.45   0.38 0.242 0.44
## cdi_10_R.T1 211  0.63  0.67  0.64   0.55 0.090 0.29
## 
## Non missing response frequency for each item
##                0    1    2 miss
## cdi_1.T1    0.82 0.18 0.00    0
## cdi_2_R.T1  0.68 0.30 0.01    0
## cdi_3.T1    0.93 0.07 0.00    0
## cdi_4_R.T1  0.91 0.09 0.00    0
## cdi_5_R.T1  0.90 0.10 0.01    0
## cdi_6_R.T1  0.58 0.35 0.07    0
## cdi_7.T1    0.68 0.30 0.02    0
## cdi_8.T1    0.81 0.17 0.03    0
## cdi_9.T1    0.76 0.23 0.00    0
## cdi_10_R.T1 0.91 0.09 0.00    0
# cesdc
# internal consistency 

# df with all cesdc and pss items at tc
items = read.csv("/Volumes/group/users/borchersLR/COVID/github/pss_cesd_items.csv")

# pss
# one participant did not complete the pss at tc
# reverse code 4, 5, 7, 8, then sum
items <-
  items %>%
  mutate_at(
    vars(
      covid_pss_c_4, covid_pss_c_5, covid_pss_c_7, covid_pss_c_8
    ),
    funs(
      . %>%
        dplyr::recode(
          "0" = 4,
          "1" = 3,
          "2" = 2,
          "3" = 1,
          "4" = 0
        )
    )
  )
## Warning: `funs()` is deprecated as of dplyr 0.8.0.
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
items %>% 
  select(
    covid_pss_c_1, 
    covid_pss_c_2, 
    covid_pss_c_3, 
    covid_pss_c_4, 
    covid_pss_c_5, 
    covid_pss_c_6,
    covid_pss_c_7,
    covid_pss_c_8,
    covid_pss_c_9,
    covid_pss_c_10
  ) %>% 
  alpha()
## 
## Reliability analysis   
## Call: alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.84      0.84    0.87      0.35 5.3 0.016  1.8 0.66     0.33
## 
##  lower alpha upper     95% confidence boundaries
## 0.81 0.84 0.87 
## 
##  Reliability if an item is dropped:
##                raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## covid_pss_c_1       0.82      0.82    0.85      0.34 4.6    0.019 0.022  0.32
## covid_pss_c_2       0.83      0.83    0.86      0.35 4.9    0.018 0.021  0.32
## covid_pss_c_3       0.82      0.82    0.84      0.34 4.6    0.019 0.019  0.32
## covid_pss_c_4       0.83      0.83    0.86      0.36 5.1    0.017 0.020  0.34
## covid_pss_c_5       0.83      0.83    0.85      0.35 4.8    0.018 0.023  0.32
## covid_pss_c_6       0.83      0.83    0.86      0.35 4.9    0.018 0.023  0.34
## covid_pss_c_7       0.84      0.84    0.86      0.36 5.1    0.017 0.024  0.34
## covid_pss_c_8       0.83      0.82    0.85      0.34 4.7    0.018 0.021  0.32
## covid_pss_c_9       0.83      0.83    0.85      0.35 4.8    0.018 0.021  0.33
## covid_pss_c_10      0.81      0.81    0.83      0.32 4.2    0.020 0.020  0.29
## 
##  Item statistics 
##                  n raw.r std.r r.cor r.drop mean   sd
## covid_pss_c_1  108  0.69  0.69  0.65   0.60  1.8 0.97
## covid_pss_c_2  108  0.61  0.60  0.54   0.49  2.1 1.12
## covid_pss_c_3  108  0.70  0.68  0.65   0.60  2.1 1.08
## covid_pss_c_4  108  0.54  0.57  0.51   0.44  1.5 0.91
## covid_pss_c_5  108  0.60  0.62  0.58   0.50  2.0 0.91
## covid_pss_c_6  108  0.63  0.61  0.56   0.51  1.7 1.20
## covid_pss_c_7  108  0.54  0.56  0.48   0.43  1.8 0.90
## covid_pss_c_8  108  0.65  0.66  0.64   0.54  1.9 1.00
## covid_pss_c_9  108  0.64  0.63  0.58   0.52  1.9 1.11
## covid_pss_c_10 108  0.80  0.79  0.79   0.73  1.7 1.08
## 
## Non missing response frequency for each item
##                   0    1    2    3    4 miss
## covid_pss_c_1  0.09 0.25 0.44 0.19 0.04 0.48
## covid_pss_c_2  0.09 0.19 0.38 0.22 0.12 0.48
## covid_pss_c_3  0.06 0.21 0.35 0.26 0.11 0.48
## covid_pss_c_4  0.10 0.43 0.36 0.07 0.04 0.48
## covid_pss_c_5  0.04 0.28 0.40 0.25 0.04 0.48
## covid_pss_c_6  0.16 0.36 0.22 0.17 0.09 0.48
## covid_pss_c_7  0.06 0.32 0.42 0.17 0.03 0.48
## covid_pss_c_8  0.07 0.26 0.40 0.21 0.06 0.48
## covid_pss_c_9  0.16 0.18 0.35 0.28 0.04 0.48
## covid_pss_c_10 0.14 0.31 0.32 0.17 0.06 0.48
# cesdc
# reverse code 4, 8, 12, 16, then sum
items <-
  items %>%
  mutate_at(
    vars(
      covid_cesd_c_4, covid_cesd_c_8, covid_cesd_c_12, covid_cesd_c_16
    ),
    funs(
      . %>%
        dplyr::recode(
          "0" = 3,
          "1" = 2,
          "2" = 1,
          "3" = 0
        )
    )
  )

items %>% 
  select(
    covid_cesd_c_1, 
    covid_cesd_c_2, 
    covid_cesd_c_3, 
    covid_cesd_c_4, 
    covid_cesd_c_5, 
    covid_cesd_c_6,
    covid_cesd_c_7,
    covid_cesd_c_8,
    covid_cesd_c_9,
    covid_cesd_c_10,
    covid_cesd_c_11,
    covid_cesd_c_12,
    covid_cesd_c_13,
    covid_cesd_c_14,
    covid_cesd_c_15,
    covid_cesd_c_16,
    covid_cesd_c_17,
    covid_cesd_c_18,
    covid_cesd_c_19,
    covid_cesd_c_20
  ) %>% 
  alpha()
## 
## Reliability analysis   
## Call: alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.91      0.91    0.94      0.34  10 0.0091    1 0.56     0.34
## 
##  lower alpha upper     95% confidence boundaries
## 0.89 0.91 0.93 
## 
##  Reliability if an item is dropped:
##                 raw_alpha std.alpha G6(smc) average_r  S/N alpha se var.r med.r
## covid_cesd_c_1       0.91      0.91    0.94      0.34 10.0   0.0094 0.021  0.35
## covid_cesd_c_2       0.91      0.91    0.94      0.35 10.0   0.0093 0.021  0.35
## covid_cesd_c_3       0.90      0.90    0.94      0.33  9.5   0.0097 0.021  0.33
## covid_cesd_c_4       0.91      0.91    0.94      0.35 10.1   0.0092 0.021  0.35
## covid_cesd_c_5       0.91      0.91    0.94      0.34  9.9   0.0094 0.021  0.35
## covid_cesd_c_6       0.90      0.90    0.93      0.33  9.4   0.0098 0.019  0.33
## covid_cesd_c_7       0.90      0.91    0.94      0.34  9.6   0.0097 0.022  0.33
## covid_cesd_c_8       0.91      0.91    0.94      0.35 10.0   0.0094 0.021  0.35
## covid_cesd_c_9       0.91      0.91    0.94      0.35 10.0   0.0093 0.021  0.34
## covid_cesd_c_10      0.91      0.91    0.94      0.35 10.2   0.0093 0.020  0.35
## covid_cesd_c_11      0.91      0.91    0.94      0.35 10.4   0.0090 0.019  0.35
## covid_cesd_c_12      0.90      0.91    0.94      0.33  9.5   0.0097 0.021  0.33
## covid_cesd_c_13      0.91      0.91    0.94      0.34  9.8   0.0095 0.021  0.33
## covid_cesd_c_14      0.90      0.91    0.94      0.34  9.6   0.0097 0.019  0.34
## covid_cesd_c_15      0.91      0.91    0.94      0.34  9.9   0.0094 0.018  0.34
## covid_cesd_c_16      0.90      0.91    0.94      0.33  9.5   0.0097 0.021  0.33
## covid_cesd_c_17      0.90      0.90    0.93      0.33  9.3   0.0100 0.020  0.33
## covid_cesd_c_18      0.90      0.90    0.93      0.33  9.3   0.0099 0.019  0.33
## covid_cesd_c_19      0.90      0.91    0.93      0.33  9.6   0.0097 0.019  0.33
## covid_cesd_c_20      0.90      0.90    0.94      0.33  9.4   0.0100 0.021  0.33
## 
##  Item statistics 
##                   n raw.r std.r r.cor r.drop mean   sd
## covid_cesd_c_1  109  0.55  0.55  0.52   0.49 0.99 0.98
## covid_cesd_c_2  109  0.54  0.52  0.49   0.47 0.91 1.02
## covid_cesd_c_3  109  0.69  0.70  0.68   0.65 0.54 0.76
## covid_cesd_c_4  109  0.51  0.51  0.48   0.43 1.27 1.03
## covid_cesd_c_5  109  0.56  0.55  0.52   0.50 1.61 0.97
## covid_cesd_c_6  109  0.72  0.74  0.74   0.69 1.02 0.83
## covid_cesd_c_7  109  0.66  0.65  0.63   0.60 1.16 0.97
## covid_cesd_c_8  109  0.52  0.52  0.49   0.46 1.85 0.85
## covid_cesd_c_9  109  0.52  0.52  0.48   0.46 0.93 0.90
## covid_cesd_c_10 109  0.45  0.46  0.43   0.40 0.70 0.71
## covid_cesd_c_11 109  0.42  0.41  0.37   0.34 0.74 1.01
## covid_cesd_c_12 109  0.67  0.68  0.66   0.62 0.95 0.79
## covid_cesd_c_13 109  0.60  0.59  0.57   0.54 1.06 1.00
## covid_cesd_c_14 109  0.66  0.67  0.66   0.61 0.88 1.04
## covid_cesd_c_15 109  0.56  0.56  0.55   0.50 0.52 0.87
## covid_cesd_c_16 109  0.67  0.68  0.67   0.63 1.18 0.82
## covid_cesd_c_17 109  0.75  0.75  0.75   0.71 0.97 0.98
## covid_cesd_c_18 109  0.74  0.75  0.75   0.70 1.10 0.83
## covid_cesd_c_19 109  0.67  0.67  0.68   0.62 0.68 0.99
## covid_cesd_c_20 109  0.73  0.73  0.72   0.68 1.56 1.06
## 
## Non missing response frequency for each item
##                    0    1    2    3 miss
## covid_cesd_c_1  0.39 0.33 0.19 0.09 0.48
## covid_cesd_c_2  0.48 0.23 0.20 0.09 0.48
## covid_cesd_c_3  0.60 0.29 0.08 0.03 0.48
## covid_cesd_c_4  0.27 0.37 0.20 0.17 0.48
## covid_cesd_c_5  0.17 0.25 0.40 0.18 0.48
## covid_cesd_c_6  0.29 0.43 0.24 0.04 0.48
## covid_cesd_c_7  0.29 0.37 0.23 0.11 0.48
## covid_cesd_c_8  0.06 0.25 0.46 0.23 0.48
## covid_cesd_c_9  0.39 0.36 0.20 0.06 0.48
## covid_cesd_c_10 0.43 0.46 0.09 0.02 0.48
## covid_cesd_c_11 0.56 0.25 0.08 0.11 0.48
## covid_cesd_c_12 0.31 0.44 0.23 0.02 0.48
## covid_cesd_c_13 0.35 0.37 0.17 0.12 0.48
## covid_cesd_c_14 0.50 0.24 0.16 0.11 0.48
## covid_cesd_c_15 0.67 0.19 0.08 0.06 0.48
## covid_cesd_c_16 0.23 0.39 0.36 0.03 0.48
## covid_cesd_c_17 0.41 0.28 0.24 0.07 0.48
## covid_cesd_c_18 0.23 0.50 0.20 0.06 0.48
## covid_cesd_c_19 0.61 0.20 0.10 0.09 0.48
## covid_cesd_c_20 0.18 0.32 0.25 0.25 0.48
# calculating self-report covid symptoms
covid$covid_physs <-covid$Covid_child_fever.TC + covid$Covid_child_cough.TC + covid$Covid_child_short_breath.TC + covid$Covid_child_sore_throat.TC + covid$Covid_child_fatigue.TC + covid$Covid_child_loss_taste_smell.TC + covid$Covid_child_other_symptom.TC
# table 1
corr_covid_plot <- 
  covid %>%
  dplyr::select(
    'CDI-S Baseline' = cdi_TOTAL.T1,
    'ELS Severity Baseline' = sumsev_type_t1,
    'PSS COVID-19' = PSS_total.TC,
    'CES-DC COVID-19' = CESDC_total.TC,
    'Symptoms COVID-19' = covid_physs,
    'Worry About Food COVID-19' = Worry_no_food.TC,
    'Mental Health Impact COVID-19' = Mental_health_rating.TC,
    'Difficulty Cancel Events COVID-19' = Cancelling_events_difficulty.TC,
    'Stress of Restrictions COVID-19' = Stress_of_restrictions.TC,
    'Stress Change Family Contact COVID-19' = Stress_relations_family_change.TC,
    'Stress Change Social Contact COVID-19' = Stress_relations_friends_change.TC,
     ) %>% 
  cor(use = "complete.obs", method = "pearson") 

ggcorrplot(corr_covid_plot, hc.order = FALSE, type = "upper", lab = TRUE, 
           outline.col = "white", sig.level=0.05, lab_size = 2, p.mat = NULL, 
           insig = c("pch", "blank"), pch = 1, pch.col = "black", pch.cex =1,
           tl.cex = 14) +
  theme(axis.text.x=element_text(size=9, angle=60, vjust=1, hjust=1, 
                                 margin=margin(-3,0,0,0)),
        axis.text.y=element_text(size=9, margin=margin(0,-3,0,0)),
        panel.grid.major=element_blank())

# ggsave("~/Desktop/corr_covid_plot_new.tiff", height = 5, width = 6)
### table 2

## age baseline
t.test(Age_S1.T1 ~ Child_Sex.T1, data = covid, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  Age_S1.T1 by Child_Sex.T1
## t = 3.9542, df = 107, p-value = 0.0001382
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.355392 1.069992
## sample estimates:
## mean in group 1 mean in group 2 
##        11.66512        10.95242
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(Age_S1.T1))
## `summarise()` ungrouping output (override with `.groups` argument)
## els severity baseline
t.test(sumsev_type_t1 ~ Child_Sex.T1, data = covid, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  sumsev_type_t1 by Child_Sex.T1
## t = -0.28764, df = 107, p-value = 0.7742
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.999400  1.492705
## sample estimates:
## mean in group 1 mean in group 2 
##        5.686047        5.939394
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(sumsev_type_t1))
## `summarise()` ungrouping output (override with `.groups` argument)
## cdi baseline
# one male participant missing cdi at baseline
t.test(cdi_TOTAL.T1 ~ Child_Sex.T1, data = covid, rm.na = TRUE, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  cdi_TOTAL.T1 by Child_Sex.T1
## t = -2.1506, df = 106, p-value = 0.03378
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.63721329 -0.06654342
## sample estimates:
## mean in group 1 mean in group 2 
##        1.255814        2.107692
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(cdi_TOTAL.T1, na.rm = TRUE))
## `summarise()` ungrouping output (override with `.groups` argument)
## race
# 1 is white; 2 is african american; 3 is hispanic; 4 is asian; 5 is biracial; 6 is other
race <- data.frame(covid$Child_Sex.T1, covid$KSADS_Child_Race_by_P.T1)
race = table(covid$Child_Sex.T1, covid$KSADS_Child_Race_by_P.T1)
print(race)
##    
##      1  2  3  4  5  6
##   1 20  3  3  7  7  3
##   2 26  1  7 13 15  4
print(chisq.test(race))
## Warning in stats::chisq.test(x, y, ...): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  race
## X-squared = 3.5389, df = 5, p-value = 0.6175
covid %>% 
  count(KSADS_Child_Race_by_P.T1, Child_Sex.T1, sort = TRUE) %>% 
  arrange(KSADS_Child_Race_by_P.T1, Child_Sex.T1)
## parental income
covid_income <-
  covid %>%
  mutate_at(
    vars(Parent_Income.T1
    ),
    funs(
      . %>%
        dplyr::recode(
          "10" = 3,
          "9" = 2,
          "8" = 2,
          "7" = 2,
          "6" = 2,
          "5" = 1,
          "4" = 1,
          "3" = 1,
          "2" = 1,
          "1" = 1,
        )
    )
  )

covid_income <- covid_income %>%
    mutate(Parent_Income.T1 = if_else(is.na(Parent_Income.T1), 0, Parent_Income.T1))

income = table(covid_income$Child_Sex.T1, covid_income$Parent_Income.T1)
print(income)
##    
##      0  1  2  3
##   1  3  1 19 20
##   2  5  3 31 27
print(chisq.test(income))
## Warning in stats::chisq.test(x, y, ...): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  income
## X-squared = 0.59587, df = 3, p-value = 0.8974
 covid_income %>% 
  count(Parent_Income.T1, Child_Sex.T1, sort = TRUE) %>% 
  arrange(Parent_Income.T1, Child_Sex.T1)
## age tc
t.test(Child_Age.TC ~ Child_Sex.T1, data = covid, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  Child_Age.TC by Child_Sex.T1
## t = 3.1595, df = 107, p-value = 0.002055
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.3265441 1.4264228
## sample estimates:
## mean in group 1 mean in group 2 
##        16.82860        15.95212
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(Child_Age.TC))
## `summarise()` ungrouping output (override with `.groups` argument)
## pss tc
# one participant missing pss at tc
t.test(PSS_total.TC ~ Child_Sex.T1, data = covid, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  PSS_total.TC by Child_Sex.T1
## t = -3.7252, df = 106, p-value = 0.0003148
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -7.047525 -2.151610
## sample estimates:
## mean in group 1 mean in group 2 
##        15.64286        20.24242
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(PSS_total.TC, na.rm = TRUE))
## `summarise()` ungrouping output (override with `.groups` argument)
## cesdc tc
# one participant missing pss at tc
t.test(CESDC_total.TC ~ Child_Sex.T1, data = covid, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  CESDC_total.TC by Child_Sex.T1
## t = -3.5573, df = 107, p-value = 0.0005598
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.569219  -3.289132
## sample estimates:
## mean in group 1 mean in group 2 
##        16.11628        23.54545
# 1 is male; 2 is female
covid %>%
   group_by(Child_Sex.T1) %>%
   summarise(sd = sd(CESDC_total.TC))
## `summarise()` ungrouping output (override with `.groups` argument)
### sample characteristics 

## race
# 1 is white; 2 is african american; 3 is hispanic; 4 is asian; 5 is biracial; 6 is other
# binarizing race
# covid <-
#   covid %>%
#   mutate_at(
#     vars(KSADS_Child_Race_by_P.T1
#     ),
#     funs(
#       . %>%
#         dplyr::recode(
#           "1" = 1,
#           "2" = 0,
#           "3" = 0,
#           "4" = 0,
#           "5" = 0,
#           "6" = 0
#         )
#     )
#   )
# 
# covid %>%
#    group_by(KSADS_Child_Race_by_P.T1) %>%
#    summarise(n = n())

# calculation of non-white participants
63/109
## [1] 0.5779817
## income
# 2 is less than 10k; 10 is more than 150k
min(covid$Parent_Income.T1, na.rm = TRUE)
## [1] 2
max(covid$Parent_Income.T1, na.rm = TRUE)
## [1] 10
### sex differences crisis
x <- which(names(covid) == "Child_Sex.T1") # name of grouping variable
y <- which(names(covid) == "Mental_health_rating.TC" # names of variables to test
           | names(covid) == "Worry_self_infected.TC"
           | names(covid) == "Worry_fam_infected.TC"
           | names(covid) == "Self_phys_health_influence.TC"
           | names (covid) == "Self_mental_health_influence.TC"
           | names (covid) == "Read_talk_virus.TC"
           | names (covid) == "Covid_positive_changes.TC"
           | names (covid) == "Stress_of_restrictions.TC"
           | names (covid) == "Contacts_outside_change.TC"
           | names (covid) == "Diff_following_contact_rules.TC"
           | names (covid) == "Quality_relations_family_change.TC"
           | names (covid) == "Stress_relations_family_change.TC"
           | names (covid) == "Quality_relations_friends_change.TC"
           | names (covid) == "Stress_relations_friends_change.TC"
           | names (covid) == "Cancelling_events_difficulty.TC"
           | names (covid) == "Family_financial_problems.TC"
           | names (covid) == "Worry_living_stability.TC"
           | names (covid) == "Hope_crisis_end.TC"
           | names (covid) == "covid_physs")

method <- "t.test" # one of "wilcox.test" or "t.test"

paired <- FALSE 

for (i in y) {
  for (j in x) {
    ifelse(paired == TRUE,
           p <- ggpaired(covid,
                         x = colnames(covid[j]), y = colnames(covid[i]),
                         color = colnames(covid[j]), line.color = "gray", line.size = 0.4,
                         palette = "npg",
                         legend = "none",
                         xlab = colnames(covid[j]),
                         ylab = colnames(covid[i]),
                         add = "jitter"
           ),
           p <- ggboxplot(covid,
                          x = colnames(covid[j]), y = colnames(covid[i]),
                          color = colnames(covid[j]),
                          palette = "npg",
                          legend = "none",
                          add = "jitter"
           )
    )
    #  Add p-value
    print(p + stat_compare_means(aes(label = paste0(..method.., ", p-value = ", ..p.format..)),
                                 method = method,
                                 paired = paired,
                                 # group.by = NULL,
                                 ref.group = NULL
    ))
  }
}

# significant sex differences on the crisis
t.test(covid_physs ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  covid_physs by Child_Sex.T1
## t = -2.4475, df = 107, p-value = 0.01601
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.70536132 -0.07406081
## sample estimates:
## mean in group 1 mean in group 2 
##       0.1860465       0.5757576
t.test(Worried_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Worried_2weeks.TC by Child_Sex.T1
## t = -2.2627, df = 107, p-value = 0.02568
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.74635316 -0.04927757
## sample estimates:
## mean in group 1 mean in group 2 
##        2.162791        2.560606
t.test(Happy_sad_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Happy_sad_2weeks.TC by Child_Sex.T1
## t = 3.4525, df = 107, p-value = 0.0007966
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.2681199 0.9912177
## sample estimates:
## mean in group 1 mean in group 2 
##        3.372093        2.742424
t.test(Relaxed_anxious_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Relaxed_anxious_2weeks.TC by Child_Sex.T1
## t = -2.075, df = 107, p-value = 0.04039
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.75720803 -0.01728105
## sample estimates:
## mean in group 1 mean in group 2 
##        2.627907        3.015152
t.test(Fatigued_tired_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Fatigued_tired_2weeks.TC by Child_Sex.T1
## t = -3.4128, df = 107, p-value = 0.0009088
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.9965369 -0.2642101
## sample estimates:
## mean in group 1 mean in group 2 
##        1.930233        2.560606
t.test(Loneliness_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Loneliness_2weeks.TC by Child_Sex.T1
## t = -2.8297, df = 107, p-value = 0.005566
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.0713971 -0.1886452
## sample estimates:
## mean in group 1 mean in group 2 
##        2.279070        2.909091
t.test(Concentration_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Concentration_2weeks.TC by Child_Sex.T1
## t = -2.5794, df = 107, p-value = 0.01126
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.0039271 -0.1313795
## sample estimates:
## mean in group 1 mean in group 2 
##        3.023256        3.590909
t.test(Neg_thoughts_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Neg_thoughts_2weeks.TC by Child_Sex.T1
## t = -2.0837, df = 107, p-value = 0.03957
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.86704455 -0.02160943
## sample estimates:
## mean in group 1 mean in group 2 
##        2.116279        2.560606
t.test(Self_mental_health_influence.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Self_mental_health_influence.TC by Child_Sex.T1
## t = -2.9393, df = 107, p-value = 0.004031
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.1245578 -0.2186416
## sample estimates:
## mean in group 1 mean in group 2 
##        2.116279        2.787879
t.test(Mental_health_rating.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Mental_health_rating.TC by Child_Sex.T1
## t = -2.5713, df = 107, p-value = 0.01151
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.9547513 -0.1234728
## sample estimates:
## mean in group 1 mean in group 2 
##        2.279070        2.818182
t.test(Cancelling_events_difficulty.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Cancelling_events_difficulty.TC by Child_Sex.T1
## t = -3.6008, df = 107, p-value = 0.0004826
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.3101518 -0.3797707
## sample estimates:
## mean in group 1 mean in group 2 
##        2.488372        3.333333
t.test(Worry_no_food.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Worry_no_food.TC by Child_Sex.T1
## t = -2.2379, df = 107, p-value = 0.0273
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.20001257 -0.01210864
## sample estimates:
## mean in group 1 mean in group 2 
##       0.0000000       0.1060606
t.test(Anhedonia_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Anhedonia_2weeks.TC by Child_Sex.T1
## t = 2.5575, df = 107, p-value = 0.01194
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1119646 0.8838071
## sample estimates:
## mean in group 1 mean in group 2 
##        2.906977        2.409091
# no sex differences 
t.test(Physical_health_rating.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Physical_health_rating.TC by Child_Sex.T1
## t = -1.382, df = 107, p-value = 0.1698
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.54812725  0.09781012
## sample estimates:
## mean in group 1 mean in group 2 
##        2.093023        2.318182
t.test(Fidgety_restless_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Fidgety_restless_2weeks.TC by Child_Sex.T1
## t = -1.6416, df = 107, p-value = 0.1036
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.85566977  0.08047597
## sample estimates:
## mean in group 1 mean in group 2 
##        2.279070        2.666667
t.test(Irritability_2weeks.TC ~ Child_Sex.T1, data = covid, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Irritability_2weeks.TC by Child_Sex.T1
## t = -1.5114, df = 107, p-value = 0.1336
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.7558909  0.1019093
## sample estimates:
## mean in group 1 mean in group 2 
##        2.279070        2.606061
# data file for group comparisons of responders/non-responders
completers_noncompleters = read.csv("/Volumes/group/users/borchersLR/COVID/github/completers_noncompleters.csv")

completers_noncompleters = completers_noncompleters %>% 
    mutate(subsample = !is.na(CESDC_total.TC))

# 109 included in sample; 115 did not complete tc assessment
completers_noncompleters %>% 
      group_by(subsample) %>%
      summarise(n=n())
## `summarise()` ungrouping output (override with `.groups` argument)
## group comparisons covid-19 survey completers vs. non-completers

# age at baseline
t.test(Age_S1.T1 ~ subsample, data = completers_noncompleters, var.equal=T)
## 
##  Two Sample t-test
## 
## data:  Age_S1.T1 by subsample
## t = 1.5736, df = 222, p-value = 0.117
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.05545692  0.49490965
## sample estimates:
## mean in group FALSE  mean in group TRUE 
##            11.45330            11.23358
# race
# 1 is white; 2 is african american; 3 is hispanic; 4 is asian; 5 is biracial; 6 is other
race <- data.frame(completers_noncompleters$subsample, completers_noncompleters$KSADS_Child_Race_by_P.T1)
race = table(completers_noncompleters$subsample, completers_noncompleters$KSADS_Child_Race_by_P.T1)
print(race)
##        
##          1  2  3  4  5  6
##   FALSE 54 15 10  4 25  7
##   TRUE  46  4 10 20 22  7
print(chisq.test(race))
## 
##  Pearson's Chi-squared test
## 
## data:  race
## X-squared = 17.719, df = 5, p-value = 0.003321
# els baseline
t.test(sumsev_type_t1 ~ subsample, data = completers_noncompleters, var.equal=T)
## 
##  Two Sample t-test
## 
## data:  sumsev_type_t1 by subsample
## t = 2.8344, df = 221, p-value = 0.005017
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.6235654 3.4694653
## sample estimates:
## mean in group FALSE  mean in group TRUE 
##            7.885965            5.839450
t.test(cdi_TOTAL.T1 ~ subsample, data = completers_noncompleters, rm.na=TRUE,  var.equal=T)
## 
##  Two Sample t-test
## 
## data:  cdi_TOTAL.T1 by subsample
## t = 2.4216, df = 218, p-value = 0.01627
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1427805 1.3916110
## sample estimates:
## mean in group FALSE  mean in group TRUE 
##            2.535714            1.768519
# parental income
covid_income_all <-
  completers_noncompleters %>%
  mutate_at(
    vars(Parent_Income.T1
    ),
    funs(
      . %>%
        dplyr::recode(
          "10" = 3,
          "9" = 2,
          "8" = 2,
          "7" = 2,
          "6" = 2,
          "5" = 1,
          "4" = 1,
          "3" = 1,
          "2" = 1,
          "1" = 1,
        )
    )
  )
## Warning: Problem with `mutate()` input `Parent_Income.T1`.
## x Unreplaced values treated as NA as .x is not compatible. Please specify replacements exhaustively or supply .default
## ℹ Input `Parent_Income.T1` is ``%>%`(...)`.
## Warning: Unreplaced values treated as NA as .x is not compatible. Please specify
## replacements exhaustively or supply .default
# setting na values for income to 0
covid_income_all <- covid_income_all %>%
    mutate(Parent_Income.T1 = if_else(is.na(Parent_Income.T1), 0, Parent_Income.T1))

income <- data.frame(covid_income_all$subsample, covid_income_all$Parent_Income.T1)
income = table(covid_income_all$subsample, covid_income_all$Parent_Income.T1)
print(income)
##        
##          0  1  2  3
##   FALSE 12 16 56 31
##   TRUE   8  4 50 47
print(chisq.test(income))
## 
##  Pearson's Chi-squared test
## 
## data:  income
## X-squared = 11.469, df = 3, p-value = 0.009441
# setting theme for graphs
base_size=9

theme_set(
theme_minimal(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
))

# figure 1a
cor.test(covid$PSS_total.TC, covid$sumsev_type_t1)
## 
##  Pearson's product-moment correlation
## 
## data:  covid$PSS_total.TC and covid$sumsev_type_t1
## t = 3.8394, df = 106, p-value = 0.0002102
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1717782 0.5050365
## sample estimates:
##       cor 
## 0.3494098
covid = covid %>%
  mutate(Child_Sex.T1 = as.factor(Child_Sex.T1))

covid %>% 
  ggplot(mapping = aes(x = sumsev_type_t1,
                       y = PSS_total.TC,
                       color = Child_Sex.T1)) +
  geom_point(alpha = .6, size = 3)+
  geom_smooth(method = "lm", alpha=.1, size = 2) +
  labs(x = "ELS Severity (Baseline)") +
  labs(y = "Perceived Stress (COVID-19)") + 
  ggtitle(~italic(r)~"(106)=0.35,"~italic(p)~"<.001") +
  theme(plot.title = element_text(hjust = 0.5, size=30)) +
  theme(axis.line = element_line(size = 1)) +
  theme(legend.title = element_blank()) +
  theme(legend.position = c(.92, .85)) +
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=18)) +
  geom_hline(yintercept=14.2, color = "gray",
         linetype="dashed") +
  annotate("text", x = 17, y = 12, label = "Avg PSS in Adolescents", color="dark gray") + 
  scale_color_manual(labels = c("Male", "Female"), values = c("#4d4f53", "#8c1515"))+
  xlim(0,20) + 
  ylim(0, 40)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

# ggsave("~/Desktop/els_pss.tiff", height = 5, width = 6)

cor.test(covid$CESDC_total.TC, covid$sumsev_type_t1)
## 
##  Pearson's product-moment correlation
## 
## data:  covid$CESDC_total.TC and covid$sumsev_type_t1
## t = 2.8112, df = 107, p-value = 0.005871
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.07800399 0.42918713
## sample estimates:
##       cor 
## 0.2622577
covid %>% 
  ggplot(mapping = aes(x = sumsev_type_t1,
                       y = CESDC_total.TC,
                       color = Child_Sex.T1)) +
  geom_point(alpha = .6, size = 3)+
  geom_smooth(method = "lm", alpha=.1, size = 2) +
  labs(x = "ELS Severity (Baseline)") +
  labs(y = "Depression Symptoms (COVID-19)") + 
  ggtitle(~italic(r)~"(107)=0.26,"~italic(p)~"=.006") +
  theme(plot.title = element_text(hjust = 0.5, size=30)) +
  theme(axis.line = element_line(size = 1)) +
  theme(legend.title = element_blank()) +
  theme(legend.position = c(.92, .85)) +
  theme(axis.text=element_text(size=20)) +
  theme(axis.title=element_text(size=18)) +
  geom_hline(yintercept=15, color = "gray",
         linetype="dashed") +
  annotate("text", x = 18, y = 12, label = "CESDC cut-off score", color="dark gray") + 
  scale_color_manual(labels = c("Male", "Female"), values = c("#4d4f53", "#8c1515"))+
  xlim(0,20) + 
  ylim(0, 60)
## `geom_smooth()` using formula 'y ~ x'

# ggsave("~/Desktop/els_cesdc.tiff", height = 5, width = 6)
# comparing scores in our sample to validated sample / clinical cutoff
mean(covid$PSS_total.TC, na.rm = TRUE)
## [1] 18.4537
# mean of pss in validated sample of 645 adolescents between 18-29 years old
14.2
## [1] 14.2
# difference between pss in our sample and the validated sample
18.45-14.2
## [1] 4.25
# number of participants above clinical cutoff of 15 on the cesdc
sum(covid$CESDC_total.TC > 15)
## [1] 69
# percent above cutoff in our sample
69/109
## [1] 0.6330275
## mediation analysis 
# centering variables 
covid$Age_S1.T1_z=scale(covid$Age_S1.T1, center=TRUE, scale =TRUE) 
covid$CDI_total.T1_z=scale(covid$cdi_TOTAL.T1, center=TRUE, scale =TRUE)
covid$sumsev_type_t1_z=scale(covid$sumsev_type_t1, center=TRUE, scale =TRUE) 
covid$Child_Age.TC_z=scale(covid$Child_Age.TC, center=TRUE, scale =TRUE) 
covid$PSS_total.TC_z=scale(covid$PSS_total.TC, center=TRUE, scale =TRUE)
covid$CESDC_total.TC_z=scale(covid$CESDC_total.TC, center=TRUE, scale =TRUE) 

covid = covid %>%
  mutate(Child_Sex.T1 = as.numeric(Child_Sex.T1))

# # mediation
# psych::mediate(CESDC_total.TC_z ~ sumsev_type_t1_z + (PSS_total.TC_z) - CDI_total.T1_z - Child_Sex.T1 - Age_S1.T1_z - Child_Age.TC_z - KSADS_Child_Race_by_P.T1 - income_3levels,
#               data = covid) %>% print(short = FALSE)