Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Master-Thesis-Analyses/Sample_Descriptives.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
742 lines (665 sloc)
35.9 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Sample Descriptives | |
#13.07.2021 | |
##ITU: Thesis sample and cortisol characteristics | |
#22/05/2021 | |
library(dplyr) | |
library(gtsummary) | |
library(lubridate) | |
library(rstatix) | |
library(irr) | |
library(gtable) | |
library(gt) | |
library(apaTables) | |
library(flextable) | |
#setwd("C:/Users/User/Desktop/Internship/RScripts/Cortisol/Master_Thesis") | |
setwd("C:/Users/alici/Desktop/Git_Folder/ITU_cortisol_analyses/Master_Thesis") | |
############ Data Preparation ################################## | |
load("Rdata/ITU_combined_cortisol_dates_times_wide_format.Rdata") | |
load("Rdata/processed_register_data.Rdata") | |
medication <- read.delim("Rdata/ITU_psychotrophicmedication05July21_Maternal_CurrentPregnancy.dat") | |
names(medication)[1] <- "participantID" | |
followUp <- read.delim("Rdata/ITU_1to2YearsFollowup_MaternalandChildQuestionnaires.dat") | |
names(followUp)[1] <- "participantID" | |
relevant_followUp <- c("1", | |
grep("CESD", names(followUp)), | |
grep("BAI", names(followUp))) | |
postpartum_followUp <- followUp[,c(as.numeric(relevant_followUp))] | |
postpartum_followUp$ITU_1.7y_mother_CESD_sum <- as.numeric(gsub(",", ".", postpartum_followUp$ITU_1.7y_mother_CESD_sum)) | |
postpartum_followUp$ITU_1.7y_mother_CESD_sum_nomis <- as.numeric(gsub(",", ".", postpartum_followUp$ITU_1.7y_mother_CESD_sum_nomis)) | |
postpartum_followUp$ITU_1.7y_mother_BAI_sum_half_missing <- as.numeric(gsub(",", ".", postpartum_followUp$ITU_1.7y_mother_BAI_sum_half_missing)) | |
postpartum_followUp$ITU_1.7y_mother_BAI_sum_no_missing <- as.numeric(gsub(",", ".", postpartum_followUp$ITU_1.7y_mother_BAI_sum_no_missing)) | |
maternal_edu <- read.delim("Rdata/ITU maternal education.dat") | |
names(maternal_edu)[1] <- "participantID" | |
names(maternal_edu)[3] <- "Maternal_Education" | |
final_wide_cort_wR <- left_join(wide_cort, | |
register_data, | |
copy=TRUE) | |
final_wide_cort_wEdu <- left_join(final_wide_cort_wR, | |
maternal_edu[,-c(2)], | |
copy=TRUE) | |
final_wide_cort_wpost <- left_join(final_wide_cort_wEdu, | |
postpartum_followUp[,c("participantID", | |
"ITU_1.7y_mother_BAI_sum_no_missing", | |
"ITU_1.7y_mother_CESD_sum_nomis")], | |
copy=TRUE) | |
final_wide_cort <- left_join(final_wide_cort_wpost, | |
medication[,c("participantID", | |
"ITUbroadpsychiatricmedication_18_KELA", | |
"antidepressants_18_KELA")], | |
copy=TRUE) | |
##factoring of predictors | |
final_wide_cort$pregstage <- factor(final_wide_cort$pregstage) | |
final_wide_cort$participantID <- factor(final_wide_cort$participantID) | |
final_wide_cort$ELISA_analysis_plate <- factor(final_wide_cort$ELISA_analysis_plate) | |
final_wide_cort$Maternal_Education <- factor(final_wide_cort$Maternal_Education, | |
levels = c(1,2,3), | |
labels = c("Primary/Secondary Education", | |
"Polytechnic Degree/University of Applied Sciences", | |
"University Degree")) | |
final_wide_cort$Current_Diabetes_Disorder <- factor(final_wide_cort$Maternal_Diabetes_Disorders_anyVSnone, | |
levels = c(-999,0,1), | |
labels = c("No","No", "Yes")) | |
final_wide_cort$Current_Hypertensive_Disorder <- factor(final_wide_cort$Maternal_Hypertensive_Disorders_anyVSnone, | |
levels = c(-999,0,1), | |
labels = c("No","No", "Yes")) | |
final_wide_cort$Child_Sex <- factor(final_wide_cort$Child_Sex, | |
levels = c("boy","girl"), | |
labels = c("Male", "Female")) | |
final_wide_cort$Nulliparous <- factor(final_wide_cort$Parity, | |
levels = c("nulliparous","multiparous"), | |
labels = c("Yes", "No")) | |
final_wide_cort$caseVScontrol <- factor(final_wide_cort$caseVScontrol, | |
levels = c("case","control"), | |
labels = c("Case", "Control")) | |
final_wide_cort$ITUbroadpsychiatricmedication_18_KELA <- factor(final_wide_cort$ITUbroadpsychiatricmedication_18_KELA, | |
levels = c(0,1), | |
labels = c("no", "yes")) | |
final_wide_cort$antidepressants_18_KELA <- factor(final_wide_cort$antidepressants_18_KELA, | |
levels = c(0,1), | |
labels = c("no", "yes")) | |
########### add well_being data to it | |
load("Rdata/processed_wellbeingduringpreg_completevars.Rdata") | |
#for now only sleep, nausea, anxiety and CESD are included | |
cols <- c("1", "2",grep("gestage", names(q_data_complete)), | |
grep("GWdiff_cort_qclosest", names(q_data_complete)), | |
grep("Cesd", names(q_data_complete)), | |
#grep("puqe", names(q_data_complete)), | |
grep("PSQI", names(q_data_complete)), | |
# grep("ESS", names(q_data_complete)), | |
grep("BAI",names(q_data_complete))) | |
q_data_sub <- q_data_complete[,c(as.numeric(cols))] | |
q_data_sub <- subset(q_data_sub, abs(GWdiff_cort_qclosest_to_cortGW) < 2) | |
# length(unique(q_data_sub$participantID[!is.na(q_data_sub$Cesd_qclosest_to_cortGW_pregMean)])) | |
# length(unique(q_data_sub$participantID[!is.na(q_data_sub$Cesd_qclosest_to_cortGW) & q_data_sub$pregstage == "I"])) | |
# length(unique(q_data_sub$participantID[!is.na(q_data_sub$Cesd_qclosest_to_cortGW) & q_data_sub$pregstage == "II"])) | |
# length(unique(q_data_sub$participantID[!is.na(q_data_sub$Cesd_qclosest_to_cortGW) & q_data_sub$pregstage == "III"])) | |
#combine with cortisol | |
final_wide_cort <- left_join(final_wide_cort, | |
q_data_sub, | |
by = c("participantID", "pregstage", "gestage_weeks"), | |
copy=TRUE) | |
final_wide_cort <- final_wide_cort %>% | |
group_by(participantID) %>% | |
mutate(Cesd_qclosest_to_cortGW_pregMean = mean(Cesd_qclosest_to_cortGW_pregMean, na.rm =T)) | |
final_wide_cort <- final_wide_cort %>% | |
group_by(participantID) %>% | |
mutate(PSQI_qclosest_to_cortGW_pregMean = mean(PSQI_qclosest_to_cortGW_pregMean, na.rm =T)) | |
final_wide_cort <- final_wide_cort %>% | |
group_by(participantID) %>% | |
mutate(BAI_qclosest_to_cortGW_pregMean = mean(BAI_qclosest_to_cortGW_pregMean, na.rm =T)) | |
final_wide_cort <- mutate_all(final_wide_cort,funs(replace(., is.nan(.), NA))) | |
#average gestage_weeks of cortisol assessment | |
final_wide_cort <- final_wide_cort %>% | |
group_by(participantID) %>% | |
mutate(gestage_weeks_pregMean = mean(gestage_weeks, na.rm =T)) | |
### Exclusion Criteria #### | |
#exclude violattions against cortisol collection protocol | |
comments_to_be_excluded <- c(88,6,12,3,15,9999,7,16,45,5,34,17,57,67,99) | |
final_wide_cort <- subset(final_wide_cort, !(final_wide_cort$notes %in% comments_to_be_excluded)) | |
final_wide_cort <- subset(final_wide_cort, !(final_wide_cort$Maternal_Corticosteroid_Treatment_during_Pregnancy == "yes")) | |
### Depressive Symptom Severity #### | |
final_wide_cort$Depressive_Symptom_Severity <- NA | |
for(i in 1:nrow(final_wide_cort)){ | |
m <- final_wide_cort$Cesd_qclosest_to_cortGW_pregMean[[i]] | |
if(!is.na(m)){ | |
if(m<16){ | |
final_wide_cort$Depressive_Symptom_Severity[[i]] <- "Below_Clinical (CES-D < 16)" | |
} | |
if(m>=16){ | |
final_wide_cort$Depressive_Symptom_Severity[[i]] <- "Clinical (CES-D >= 16)" | |
} | |
} | |
} | |
final_wide_cort$Depressive_Symptom_Severity <- factor(final_wide_cort$Depressive_Symptom_Severity) | |
rm(list= ls()[!(ls() %in% c("final_wide_cort"))]) | |
# length(unique(final_wide_cort$participantID)) | |
# length(unique(final_wide_cort$participantID[final_wide_cort$pregstage == "I"])) | |
# length(unique(final_wide_cort$participantID[final_wide_cort$pregstage == "II"])) | |
# length(unique(final_wide_cort$participantID[final_wide_cort$pregstage == "III"])) | |
#final_wide_cort <- final_wide_cort[abs(final_wide_cort$GWdiff_cort_qclosest_to_cortGW) < 2,] | |
# length(unique(final_wide_cort$participantID[!is.na(final_wide_cort$Cesd_qclosest_to_cortGW_pregMean)])) | |
# length(unique(final_wide_cort$participantID[!is.na(final_wide_cort$Cesd_qclosest_to_cortGW) & final_wide_cort$pregstage == "I"])) | |
# length(unique(final_wide_cort$participantID[!is.na(final_wide_cort$Cesd_qclosest_to_cortGW) & final_wide_cort$pregstage == "II"])) | |
# length(unique(final_wide_cort$participantID[!is.na(final_wide_cort$Cesd_qclosest_to_cortGW) & final_wide_cort$pregstage == "III"])) | |
### Pregstage in wide format #### | |
Wide_Pregstage <- final_wide_cort[,c("participantID", | |
"pregstage", | |
"gestage_weeks")] %>% | |
tidyr::pivot_wider( | |
id_cols = c(participantID), | |
names_from = c(pregstage), # Can accommodate more variables, if needed. | |
values_from = c(gestage_weeks) | |
) | |
final_wide_cort <- left_join(final_wide_cort, | |
Wide_Pregstage, | |
copy=T) | |
### Tab: Demographics #### | |
characteristics <- final_wide_cort[,c("participantID", | |
"caseVScontrol", | |
"I", | |
"II", | |
"III", | |
"Nulliparous", | |
"Maternal_Age_Years", | |
"Maternal_Education", | |
"Mother_Cohabiting", | |
"gestage_weeks_pregMean", | |
"Child_Sex", | |
"Gestational_Age_Weeks", | |
"Maternal_Body_Mass_Index_in_Early_Pregnancy", | |
"Weight_Gain", | |
"Current_Hypertensive_Disorder", | |
"Current_Diabetes_Disorder", | |
"Maternal_Smoking_During_Pregnancy", | |
"Cesd_qclosest_to_cortGW_pregMean", | |
"Depressive_Symptom_Severity", | |
"BAI_qclosest_to_cortGW_pregMean", | |
"PSQI_qclosest_to_cortGW_pregMean", | |
"ITUbroadpsychiatricmedication_18_KELA", | |
"antidepressants_18_KELA", | |
"ITU_1.7y_mother_CESD_sum_nomis", | |
"ITU_1.7y_mother_BAI_sum_no_missing")] | |
characteristics_no_dub <- as.data.frame(characteristics[!duplicated(characteristics),]) #N=687 | |
any_med <- length(unique(characteristics_no_dub$participantID[characteristics_no_dub$ITUbroadpsychiatricmedication_18_KELA == "yes"])) | |
anti_depress <- length(unique(characteristics_no_dub$participantID[characteristics_no_dub$antidepressants_18_KELA == "yes"])) | |
percent_depress <- format(round(anti_depress/any_med*100,2)) | |
demo <- characteristics_no_dub %>% select( | |
I,II,III, | |
caseVScontrol, | |
Maternal_Age_Years, | |
Maternal_Education, | |
Mother_Cohabiting, | |
Nulliparous, | |
Child_Sex, | |
Gestational_Age_Weeks, | |
Maternal_Body_Mass_Index_in_Early_Pregnancy, | |
Weight_Gain, | |
Current_Hypertensive_Disorder, | |
Current_Diabetes_Disorder, | |
Maternal_Smoking_During_Pregnancy, | |
ITUbroadpsychiatricmedication_18_KELA, | |
Cesd_qclosest_to_cortGW_pregMean, | |
Depressive_Symptom_Severity, | |
BAI_qclosest_to_cortGW_pregMean, | |
PSQI_qclosest_to_cortGW_pregMean, | |
ITU_1.7y_mother_CESD_sum_nomis, | |
ITU_1.7y_mother_BAI_sum_no_missing) | |
# Sample_Descriptives1 <- | |
# tbl_summary(data = demo, | |
# statistic = list( | |
# all_continuous() ~ "{mean} ({sd})", | |
# all_categorical() ~ "{n} ({p}%)"), | |
# missing = "no", | |
# digits = list(all_continuous() ~ c(2, 2, 2)), | |
# label = list(Maternal_Age_Years ~ "Maternal Age (Yrs)", | |
# Maternal_Education ~ "Highest Level of Maternal Education", | |
# Mother_Cohabiting ~ "Maternal Cohabitation", | |
# Maternal_Body_Mass_Index_in_Early_Pregnancy ~ "Maternal BMI in Early Pregnancy", | |
# Child_Sex ~ "Fetal Sex", | |
# Maternal_Smoking_During_Pregnancy ~ "Maternal Smoking throughout Pregnancy", | |
# Weight_Gain ~ "Weight Gain across Pregnancy (kg)", | |
# Current_Hypertensive_Disorder ~ "Any Hypertensive Disorders during Pregnancy", | |
# Current_Diabetes_Disorder ~ "Any Diabetes Disorders during Pregnancy", | |
# Cesd_qclosest_to_cortGW_pregMean ~ "Peripartum Depressive Symptoms", | |
# BAI_qclosest_to_cortGW_pregMean ~ "Peripartum Anxiety", | |
# PSQI_qclosest_to_cortGW_pregMean ~ "Peripartum Sleep Problems", | |
# ITUbroadpsychiatricmedication_18_KELA ~ "Any Prescribed Psychotropic Medication", | |
# ITU_1.7y_mother_CESD_sum_nomis ~ "Postpartum Depressive Symptoms", | |
# ITU_1.7y_mother_BAI_sum_no_missing ~ "Postpartum Anxiety", | |
# I ~ "Gestational Week at T1", | |
# II ~ "Gestational Week at T2", | |
# III ~ "Gestational Week at T3")) | |
Sample_Descriptives2 <- | |
tbl_summary(data = demo, | |
by = Depressive_Symptom_Severity, | |
statistic = list( | |
all_continuous() ~ "{mean} ({sd})", | |
all_categorical() ~ "{n} ({p}%)"), | |
missing = "no", | |
digits = list(all_continuous() ~ c(2, 2, 2)), | |
label = list(Maternal_Age_Years ~ "Maternal Age (Yrs)", | |
Maternal_Education ~ "Highest Level of Maternal Education", | |
Mother_Cohabiting ~ "Maternal Cohabitation", | |
Maternal_Body_Mass_Index_in_Early_Pregnancy ~ "Maternal BMI in Early Pregnancy", | |
Child_Sex ~ "Fetal Sex", | |
Maternal_Smoking_During_Pregnancy ~ "Maternal Smoking throughout Pregnancy", | |
Weight_Gain ~ "Weight Gain across Pregnancy (kg)", | |
Current_Hypertensive_Disorder ~ "Any Hypertensive Disorders during Pregnancy", | |
Current_Diabetes_Disorder ~ "Any Diabetes Disorders during Pregnancy", | |
Cesd_qclosest_to_cortGW_pregMean ~ "Peripartum Depressive Symptoms", | |
BAI_qclosest_to_cortGW_pregMean ~ "Peripartum Anxiety", | |
PSQI_qclosest_to_cortGW_pregMean ~ "Peripartum Sleep Problems", | |
ITUbroadpsychiatricmedication_18_KELA ~ "Any Prescribed Psychotropic Medication", | |
ITU_1.7y_mother_CESD_sum_nomis ~ "Postpartum Depressive Symptoms", | |
ITU_1.7y_mother_BAI_sum_no_missing ~ "Postpartum Anxiety", | |
I ~ "Gestational Week at T1", | |
II ~ "Gestational Week at T2", | |
III ~ "Gestational Week at T3")) %>% add_overall() | |
#add p-value | |
Sample_Descriptives2 <- add_p(Sample_Descriptives2, | |
test = list(all_continuous() ~ "kruskal.test", all_categorical() ~ "chisq.test"), | |
pvalue_fun = purrr::partial(style_pvalue, digits = 3)) | |
# Sample_Descriptives <- tbl_merge( | |
# tbls = list(Sample_Descriptives1, Sample_Descriptives2), | |
# tab_spanner = c("**Total**", "**Depressive Symptom Severity**") | |
# ) | |
Sample_Descriptives.Tab <- as_flex_table(Sample_Descriptives2) %>% | |
font(fontname = "Times New ROman") %>% | |
fontsize(size = 12) %>% | |
align(i=1,j=1,align="left") %>% | |
set_table_properties(layout = "autofit") %>% | |
footnote( | |
i=26, | |
j=1, | |
value = as_paragraph(c(paste("Of which", percent_depress, "% were prescribed antidepressant medication during pregnancy"))), | |
ref_symbols = c("3")) | |
### Tab: Questionnaire summary statistics across Pregnancy ############################### | |
final_wide_cort <- as.data.frame(final_wide_cort) | |
Qs_df <- final_wide_cort %>% | |
select( | |
participantID, | |
pregstage, | |
Cesd_qclosest_to_cortGW, | |
BAI_qclosest_to_cortGW, | |
PSQI_qclosest_to_cortGW | |
) | |
Qs_df <- Qs_df %>% | |
tidyr::pivot_wider( | |
id_cols = c(participantID, | |
pregstage), | |
names_from = c(pregstage), # Can accommodate more variables, if needed. | |
values_from = c(3:5) | |
) | |
Qs_by_pregstage_tab <- setNames(data.frame(matrix(ncol = 5, nrow = 12)), | |
c("Variable", | |
"M", | |
"min", | |
"max", | |
"SD")) | |
Qs_by_pregstage_tab[,1] <- c("Early Pregnancy", | |
"CES-D", | |
"BAI", | |
"PSQI", | |
"Mid Pregnancy", | |
"CES-D", | |
"BAI", | |
"PSQI", | |
"Late Pregnancy", | |
"CES-D", | |
"BAI", | |
"PSQI") | |
#early preg | |
Qs_by_pregstage_tab[2,2] <- c(mean(Qs_df$Cesd_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[2,3] <- c(min(Qs_df$Cesd_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[2,4] <- c(max(Qs_df$Cesd_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[2,5] <- c(sd(Qs_df$Cesd_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[3,2] <- c(mean(Qs_df$BAI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[3,3] <- c(min(Qs_df$BAI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[3,4] <- c(max(Qs_df$BAI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[3,5] <- c(sd(Qs_df$BAI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[4,2] <- c(mean(Qs_df$PSQI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[4,3] <- c(min(Qs_df$PSQI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[4,4] <- c(max(Qs_df$PSQI_qclosest_to_cortGW_I, na.rm = T)) | |
Qs_by_pregstage_tab[4,5] <- c(sd(Qs_df$PSQI_qclosest_to_cortGW_I, na.rm = T)) | |
#mid preg | |
Qs_by_pregstage_tab[6,2] <- c(mean(Qs_df$Cesd_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[6,3] <- c(min(Qs_df$Cesd_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[6,4] <- c(max(Qs_df$Cesd_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[6,5] <- c(sd(Qs_df$Cesd_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[7,2] <- c(mean(Qs_df$BAI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[7,3] <- c(min(Qs_df$BAI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[7,4] <- c(max(Qs_df$BAI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[7,5] <- c(sd(Qs_df$BAI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[8,2] <- c(mean(Qs_df$PSQI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[8,3] <- c(min(Qs_df$PSQI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[8,4] <- c(max(Qs_df$PSQI_qclosest_to_cortGW_II, na.rm = T)) | |
Qs_by_pregstage_tab[8,5] <- c(sd(Qs_df$PSQI_qclosest_to_cortGW_II, na.rm = T)) | |
#late preg | |
Qs_by_pregstage_tab[10,2] <- c(mean(Qs_df$Cesd_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[10,3] <- c(min(Qs_df$Cesd_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[10,4] <- c(max(Qs_df$Cesd_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[10,5] <- c(sd(Qs_df$Cesd_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[11,2] <- c(mean(Qs_df$BAI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[11,3] <- c(min(Qs_df$BAI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[11,4] <- c(max(Qs_df$BAI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[11,5] <- c(sd(Qs_df$BAI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[12,2] <- c(mean(Qs_df$PSQI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[12,3] <- c(min(Qs_df$PSQI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[12,4] <- c(max(Qs_df$PSQI_qclosest_to_cortGW_III, na.rm = T)) | |
Qs_by_pregstage_tab[12,5] <- c(sd(Qs_df$PSQI_qclosest_to_cortGW_III, na.rm = T)) | |
### Intraclass Coefficients and correlations ##### | |
Qs_pregMean <- final_wide_cort[, | |
c("Cesd_qclosest_to_cortGW_pregMean", | |
"BAI_qclosest_to_cortGW_pregMean", | |
"PSQI_qclosest_to_cortGW_pregMean", | |
"ITU_1.7y_mother_BAI_sum_no_missing", | |
"ITU_1.7y_mother_CESD_sum_nomis")] | |
Thesis_Q_tabl.pregMean <- apa.cor.table(Qs_pregMean, filename = "Corr_Qs_means.doc", table.number = 4) | |
#Questionnaire scores at T1 | |
Qs_T1 <- final_wide_cort[final_wide_cort$pregstage == "I", | |
c("Cesd_qclosest_to_cortGW", | |
"BAI_qclosest_to_cortGW", | |
"PSQI_qclosest_to_cortGW")] | |
Thesis_Q_tabl.T1 <- apa.cor.table(Qs_T1, filename = "Corr_Qs_T1.doc",table.number = 4 ) | |
#Questionnaire scores at T2 | |
Qs_T2 <- final_wide_cort[final_wide_cort$pregstage == "II", | |
c("Cesd_qclosest_to_cortGW", | |
"BAI_qclosest_to_cortGW", | |
"PSQI_qclosest_to_cortGW")] | |
Thesis_Q_tabl.T2 <-apa.cor.table(Qs_T2,filename = "Corr_Qs_T2.doc",table.number = 4) | |
#Questionnaire scores at T3 | |
Qs_T3 <- final_wide_cort[final_wide_cort$pregstage == "III", | |
c("Cesd_qclosest_to_cortGW", | |
"BAI_qclosest_to_cortGW", | |
"PSQI_qclosest_to_cortGW")] | |
Thesis_Q_tabl.T3 <-apa.cor.table(Qs_T3,filename = "Corr_Qs_T3.doc",table.number = 4) | |
### Questionnaires correlations with themselves ##### | |
#CESD with itself across preg | |
fully_wide_CESD <- final_wide_cort[,c("participantID", | |
"pregstage", | |
"Cesd_qclosest_to_cortGW")] %>% | |
tidyr::pivot_wider( | |
id_cols = c(participantID), | |
names_from = c(pregstage), # Can accommodate more variables, if needed. | |
values_from = c(3) | |
) | |
# plot(factor(final_wide_cort$pregstage), final_wide_cort$Cesd_qclosest_to_cortGW, | |
# xlab = "Pregstage", | |
# ylab = "Depressive Symptoms") | |
#compute correlations across preg | |
cors_Cesd <- fully_wide_CESD[,c("I", "II", "III")] | |
corr_CESD <- apa.cor.table(cors_Cesd) | |
## ICC | |
ICC_CESD <- icc( | |
fully_wide_CESD[,c("I", "II", "II")], model = "oneway", | |
type = "agreement", unit = "single" | |
) | |
##within subject CES-D flucutations | |
#load("Rdata/nr_cesd.Rdata") | |
# nr_Ids <- unique(ASQ_df_final$participantID[ASQ_df_final$nr_cesds > 1]) | |
# res_mean_CESD_fluctuation <- summary(final_wide_cort$Cesd_qclosest_to_cortGW_pregMeanDeviat[final_wide_cort$participantID %in% nr_Ids]) | |
##### BAI | |
fully_wide_BAI <- final_wide_cort[,c("participantID", | |
"pregstage", | |
"BAI_qclosest_to_cortGW")] %>% | |
tidyr::pivot_wider( | |
id_cols = c(participantID), | |
names_from = c(pregstage), # Can accommodate more variables, if needed. | |
values_from = c(3) | |
) | |
#compute correlations across preg | |
cors_BAI <- fully_wide_BAI[,c("I", "II", "III")] | |
corr_BAI <- apa.cor.table(cors_BAI) | |
## ICC | |
ICC_BAI <- icc( | |
fully_wide_BAI[,c("I", "II", "III")], model = "oneway", | |
type = "agreement", unit = "single" | |
) | |
# plot(factor(final_wide_cort$pregstage), final_wide_cort$BAI_qclosest_to_cortGW, | |
# xlab = "Pregstage", | |
# ylab = "Anxiety") | |
##### PSQI | |
fully_wide_PSQI <- final_wide_cort[,c("participantID", | |
"pregstage", | |
"PSQI_qclosest_to_cortGW")] %>% | |
tidyr::pivot_wider( | |
id_cols = c(participantID), | |
names_from = c(pregstage), # Can accommodate more variables, if needed. | |
values_from = c(3) | |
) | |
#compute correlations across preg | |
cors_PSQI <- fully_wide_PSQI[,c("I", "II", "III")] | |
corr_PSQI <- apa.cor.table(cors_PSQI) | |
## ICC | |
ICC_PSQI <- icc( | |
fully_wide_PSQI[,c("I", "II", "III")], model = "oneway", | |
type = "agreement", unit = "single" | |
) | |
############ Tab: Follow-up comparison of participants assessed once vs multiple times ################ | |
at_least_two_assessments <- c() | |
once <- c() | |
final_wide_cort <- as.data.frame(final_wide_cort) | |
IDs <- unique(final_wide_cort$participantID) | |
for(i in 1:length(IDs)){ | |
ID <- IDs[[i]] | |
#print(ID) | |
trims <- unique(final_wide_cort[final_wide_cort$participantID == ID, c("pregstage")]) | |
#print(nrow(trims)) | |
if(length(trims) >= 2){ | |
at_least_two_assessments <- append(at_least_two_assessments, ID) | |
} | |
if(length(trims) == 1){ | |
once <- append(once, ID) | |
} | |
} | |
## add column identifier | |
final_wide_cort$Nr_assessments <- NA | |
for(i in 1:nrow(final_wide_cort)){ | |
ID <- final_wide_cort$participantID[[i]] | |
if(ID %in% once){ | |
final_wide_cort$Nr_assessments[[i]] <- "Once" | |
} | |
if(ID %in% at_least_two_assessments){ | |
final_wide_cort$Nr_assessments[[i]] <- "Multiple" | |
} | |
} | |
characteristics <- final_wide_cort[,c("participantID", | |
"caseVScontrol", | |
"I", | |
"II", | |
"III", | |
"Nulliparous", | |
"Maternal_Age_Years", | |
"Maternal_Education", | |
"Mother_Cohabiting", | |
"gestage_weeks_pregMean", | |
"Child_Sex", | |
"Gestational_Age_Weeks", | |
"Maternal_Body_Mass_Index_in_Early_Pregnancy", | |
"Weight_Gain", | |
"Current_Hypertensive_Disorder", | |
"Current_Diabetes_Disorder", | |
"Maternal_Smoking_During_Pregnancy", | |
"Cesd_qclosest_to_cortGW_pregMean", | |
"Depressive_Symptom_Severity", | |
"BAI_qclosest_to_cortGW_pregMean", | |
"PSQI_qclosest_to_cortGW_pregMean", | |
"ITUbroadpsychiatricmedication_18_KELA", | |
"antidepressants_18_KELA", | |
"ITU_1.7y_mother_CESD_sum_nomis", | |
"ITU_1.7y_mother_BAI_sum_no_missing", | |
"Nr_assessments")] | |
characteristics_no_dub <- as.data.frame(characteristics[!duplicated(characteristics),]) #N=687 | |
demo <- characteristics_no_dub %>% select( | |
I,II,III, | |
caseVScontrol, | |
Maternal_Age_Years, | |
Maternal_Education, | |
Mother_Cohabiting, | |
Nulliparous, | |
Child_Sex, | |
Gestational_Age_Weeks, | |
Maternal_Body_Mass_Index_in_Early_Pregnancy, | |
Weight_Gain, | |
Current_Hypertensive_Disorder, | |
Current_Diabetes_Disorder, | |
Maternal_Smoking_During_Pregnancy, | |
ITUbroadpsychiatricmedication_18_KELA, | |
Cesd_qclosest_to_cortGW_pregMean, | |
Depressive_Symptom_Severity, | |
BAI_qclosest_to_cortGW_pregMean, | |
PSQI_qclosest_to_cortGW_pregMean, | |
ITU_1.7y_mother_CESD_sum_nomis, | |
ITU_1.7y_mother_BAI_sum_no_missing, | |
Nr_assessments) | |
Sample_Descriptives2 <- | |
tbl_summary(data = demo, | |
by = Nr_assessments, | |
statistic = list( | |
all_continuous() ~ "{mean} ({sd})", | |
all_categorical() ~ "{n} ({p}%)"), | |
missing = "no", | |
digits = list(all_continuous() ~ c(2, 2, 2)), | |
label = list(Maternal_Age_Years ~ "Maternal Age (Yrs)", | |
Maternal_Education ~ "Highest Level of Maternal Education", | |
Mother_Cohabiting ~ "Maternal Cohabitation", | |
Maternal_Body_Mass_Index_in_Early_Pregnancy ~ "Maternal BMI in Early Pregnancy", | |
Child_Sex ~ "Fetal Sex", | |
Maternal_Smoking_During_Pregnancy ~ "Maternal Smoking throughout Pregnancy", | |
Weight_Gain ~ "Weight Gain across Pregnancy (kg)", | |
Current_Hypertensive_Disorder ~ "Any Hypertensive Disorders during Pregnancy", | |
Current_Diabetes_Disorder ~ "Any Diabetes Disorders during Pregnancy", | |
Cesd_qclosest_to_cortGW_pregMean ~ "Peripartum Depressive Symptoms", | |
BAI_qclosest_to_cortGW_pregMean ~ "Peripartum Anxiety", | |
PSQI_qclosest_to_cortGW_pregMean ~ "Peripartum Sleep Problems", | |
ITUbroadpsychiatricmedication_18_KELA ~ "Any Prescribed Psychotropic Medication", | |
ITU_1.7y_mother_CESD_sum_nomis ~ "Postpartum Depressive Symptoms", | |
ITU_1.7y_mother_BAI_sum_no_missing ~ "Postpartum Anxiety", | |
I ~ "Gestational Week at T1", | |
II ~ "Gestational Week at T2", | |
III ~ "Gestational Week at T3")) %>% add_overall() | |
#add p-value | |
Sample_Descriptives2 <- add_p(Sample_Descriptives2, | |
test = list(all_continuous() ~ "kruskal.test", all_categorical() ~ "chisq.test"), | |
pvalue_fun = purrr::partial(style_pvalue, digits = 3)) | |
Sample_Descriptives.Sen1 <- as_flex_table(Sample_Descriptives2) %>% | |
font(fontname = "Times New ROman") %>% | |
fontsize(size = 9) %>% | |
align(i=1,j=1,align="left") %>% | |
set_table_properties(layout = "autofit") | |
############ Tab: Follow-up comparison of participants by medication ######## | |
characteristics <- final_wide_cort[,c("participantID", | |
"caseVScontrol", | |
"I", | |
"II", | |
"III", | |
"Nulliparous", | |
"Maternal_Age_Years", | |
"Maternal_Education", | |
"Mother_Cohabiting", | |
"gestage_weeks_pregMean", | |
"Child_Sex", | |
"Gestational_Age_Weeks", | |
"Maternal_Body_Mass_Index_in_Early_Pregnancy", | |
"Weight_Gain", | |
"Current_Hypertensive_Disorder", | |
"Current_Diabetes_Disorder", | |
"Maternal_Smoking_During_Pregnancy", | |
"Cesd_qclosest_to_cortGW_pregMean", | |
"Depressive_Symptom_Severity", | |
"BAI_qclosest_to_cortGW_pregMean", | |
"PSQI_qclosest_to_cortGW_pregMean", | |
"ITUbroadpsychiatricmedication_18_KELA", | |
"antidepressants_18_KELA", | |
"ITU_1.7y_mother_CESD_sum_nomis", | |
"ITU_1.7y_mother_BAI_sum_no_missing")] | |
characteristics_no_dub <- as.data.frame(characteristics[!duplicated(characteristics),]) #N=687 | |
demo <- characteristics_no_dub %>% select( | |
I,II,III, | |
caseVScontrol, | |
Maternal_Age_Years, | |
Maternal_Education, | |
Mother_Cohabiting, | |
Nulliparous, | |
Child_Sex, | |
Gestational_Age_Weeks, | |
Maternal_Body_Mass_Index_in_Early_Pregnancy, | |
Weight_Gain, | |
Current_Hypertensive_Disorder, | |
Current_Diabetes_Disorder, | |
Maternal_Smoking_During_Pregnancy, | |
ITUbroadpsychiatricmedication_18_KELA, | |
Cesd_qclosest_to_cortGW_pregMean, | |
Depressive_Symptom_Severity, | |
BAI_qclosest_to_cortGW_pregMean, | |
PSQI_qclosest_to_cortGW_pregMean, | |
ITU_1.7y_mother_CESD_sum_nomis, | |
ITU_1.7y_mother_BAI_sum_no_missing) | |
Sample_Descriptives2 <- | |
tbl_summary(data = demo, | |
by = ITUbroadpsychiatricmedication_18_KELA, | |
statistic = list( | |
all_continuous() ~ "{mean} ({sd})", | |
all_categorical() ~ "{n} ({p}%)"), | |
missing = "no", | |
digits = list(all_continuous() ~ c(2, 2, 2)), | |
label = list(Maternal_Age_Years ~ "Maternal Age (Yrs)", | |
Maternal_Education ~ "Highest Level of Maternal Education", | |
Mother_Cohabiting ~ "Maternal Cohabitation", | |
Maternal_Body_Mass_Index_in_Early_Pregnancy ~ "Maternal BMI in Early Pregnancy", | |
Child_Sex ~ "Fetal Sex", | |
Maternal_Smoking_During_Pregnancy ~ "Maternal Smoking throughout Pregnancy", | |
Weight_Gain ~ "Weight Gain across Pregnancy (kg)", | |
Current_Hypertensive_Disorder ~ "Any Hypertensive Disorders during Pregnancy", | |
Current_Diabetes_Disorder ~ "Any Diabetes Disorders during Pregnancy", | |
Cesd_qclosest_to_cortGW_pregMean ~ "Peripartum Depressive Symptoms", | |
BAI_qclosest_to_cortGW_pregMean ~ "Peripartum Anxiety", | |
PSQI_qclosest_to_cortGW_pregMean ~ "Peripartum Sleep Problems", | |
ITU_1.7y_mother_CESD_sum_nomis ~ "Postpartum Depressive Symptoms", | |
ITU_1.7y_mother_BAI_sum_no_missing ~ "Postpartum Anxiety", | |
I ~ "Gestational Week at T1", | |
II ~ "Gestational Week at T2", | |
III ~ "Gestational Week at T3")) %>% add_overall() | |
#add p-value | |
Sample_Descriptives2 <- add_p(Sample_Descriptives2, | |
test = list(all_continuous() ~ "kruskal.test", all_categorical() ~ "chisq.test"), | |
pvalue_fun = purrr::partial(style_pvalue, digits = 3)) | |
Sample_Descriptives.Sen2 <- as_flex_table(Sample_Descriptives2) %>% | |
font(fontname = "Times New ROman") %>% | |
fontsize(size = 9) %>% | |
align(i=1,j=1,align="left") %>% | |
set_table_properties(layout = "autofit") | |
############ Tab: Follow-up Qs by season ######### | |
############ Tab: Follow-up comparison of participants by medication ######## | |
characteristics <- final_wide_cort[,c("gestage_weeks", | |
"Cesd_qclosest_to_cortGW_pregMean", | |
"BAI_qclosest_to_cortGW_pregMean", | |
"PSQI_qclosest_to_cortGW_pregMean", | |
"season")] | |
demo <- characteristics %>% select( | |
gestage_weeks, | |
Cesd_qclosest_to_cortGW_pregMean, | |
BAI_qclosest_to_cortGW_pregMean, | |
PSQI_qclosest_to_cortGW_pregMean, | |
season) | |
Sample_Descriptives2 <- | |
tbl_summary(data = demo, | |
by = season, | |
statistic = list( | |
all_continuous() ~ "{mean} ({sd})", | |
all_categorical() ~ "{n} ({p}%)"), | |
missing = "no", | |
digits = list(all_continuous() ~ c(2, 2, 2)), | |
label = list(gestage_weeks ~ "Average Gestational Week", | |
Cesd_qclosest_to_cortGW_pregMean ~ "Antepartum Depressive Symptoms", | |
BAI_qclosest_to_cortGW_pregMean ~ "Antepartum Anxiety", | |
PSQI_qclosest_to_cortGW_pregMean ~ "Antepartum Sleep Problems")) %>% add_overall() | |
#add p-value | |
Sample_Descriptives2 <- add_p(Sample_Descriptives2, | |
test = list(all_continuous() ~ "kruskal.test", all_categorical() ~ "chisq.test"), | |
pvalue_fun = purrr::partial(style_pvalue, digits = 3)) | |
Sample_Descriptives.Qs_season <- as_flex_table(Sample_Descriptives2) %>% | |
font(fontname = "Times New ROman") %>% | |
fontsize(size = 9) %>% | |
align(i=1,j=1,align="left") %>% | |
set_table_properties(layout = "autofit") | |