## Warning: package 'labelled' was built under R version 4.3.3
## Warning: package 'gtsummary' was built under R version 4.3.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Import Dataset and isolate selected columns

library(agricolae)
temp1 <- read.csv('C:/Users/User/Desktop/Academics/Practicum and Thesis/Completed Forms/Practicum_dataset.csv')
temp2 = temp1[,c('subjectid', 'wk2_epds_score','wk6_epds_score','mat.age','gest_age_num','nasal_count','text_count','wk2_hh_ttl18to64','race','mat_educ_cat','income_cat','married_cat','ins_type_cat','wk6_blood','wks_active')]
dim(temp2)
## [1] 245  15

Remove rows with incomplete/missing data

all_data <- na.omit(temp2)
dim(all_data)
## [1] 224  15

Create categories for EPDS scores

EPDS Categories: None: 0-6, Mild: 7-13, Moderate: 14-19, Severe: 20-30

all_data$wk2_epds_cat = cut(all_data$wk2_epds_score, breaks=c(-1,6,30), labels= c("Depressed", "Not Depressed"))
hist(all_data$wk2_epds_score)

table(all_data$wk2_epds_cat)
## 
##     Depressed Not Depressed 
##           179            45

Setting compliance (PREVAIL definition)

0=No, 1=Yes

## Set Weeks Active level
all_data$weekly_comp <- ifelse(all_data$wks_active >= 73, 1, 0)

## Set text compliance level
tcomp_scrap <- 100*(all_data$text_count/102)
all_data$tcomp_cat <- ifelse(tcomp_scrap >= 70, 1, 0)

## Create is.comp.2 column
all_data$is.comp.2 <- ifelse(all_data$weekly_comp == 1, ifelse(all_data$tcomp_cat == 1, 1, ifelse(all_data$wk6_blood == 1, 1, 0)), 0)
table(all_data$is.comp.2)
## 
##   0   1 
##  30 194

Setting categories for factors

## Race
## Binomial
all_data$race_cat = ifelse(all_data$race=="White", 0, 1)
## Category
all_data$race_cat2 = ifelse(all_data$race=="White", "White", "POC")

## Income (Category)
all_data$income_cat_bin <- ifelse(all_data$income_cat == "<25k", "Less than 25k", "25k or more")

GLM with all factors

model <- glm(is.comp.2 ~ wk2_epds_cat + race_cat2 + mat.age + gest_age_num + mat_educ_cat + income_cat_bin + married_cat + wk2_hh_ttl18to64 + ins_type_cat, data = all_data, family = "binomial")
summary(model)
## 
## Call:
## glm(formula = is.comp.2 ~ wk2_epds_cat + race_cat2 + mat.age + 
##     gest_age_num + mat_educ_cat + income_cat_bin + married_cat + 
##     wk2_hh_ttl18to64 + ins_type_cat, family = "binomial", data = all_data)
## 
## Coefficients:
##                             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)                  7.60294    7.61630   0.998   0.3182  
## wk2_epds_catNot Depressed    1.35042    0.79238   1.704   0.0883 .
## race_cat2White               0.08472    0.61345   0.138   0.8902  
## mat.age                      0.08059    0.05193   1.552   0.1207  
## gest_age_num                -0.20234    0.18966  -1.067   0.2860  
## mat_educ_cat>HS              0.61223    0.63528   0.964   0.3352  
## income_cat_binLess than 25k  0.29262    0.51728   0.566   0.5716  
## married_catSingle            0.07922    0.48196   0.164   0.8694  
## wk2_hh_ttl18to64            -0.20777    0.22005  -0.944   0.3451  
## ins_type_catPublic          -0.56882    0.76088  -0.748   0.4547  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 176.42  on 223  degrees of freedom
## Residual deviance: 155.90  on 214  degrees of freedom
## AIC: 175.9
## 
## Number of Fisher Scoring iterations: 6

The following are the Fisher’s Exact for categorical factors:

Fisher’s Exact Test - Definition 2 (PREVAIL)

## EPDS categories
Fdata2 <- data.frame("comp_yes" = c(151, 43),
                    "comp_no" = c(28, 2),
                    row.names = c("Depressed", "Not Depressed"),
                    stringsAsFactors = FALSE
                    )
colnames(Fdata2) <- c("Compliant", "Noncompliant")
print(Fdata2)
##               Compliant Noncompliant
## Depressed           151           28
## Not Depressed        43            2
fisher.test(Fdata2)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  Fdata2
## p-value = 0.05154
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.02798151 1.06836348
## sample estimates:
## odds ratio 
##  0.2519048
## Race
X2 <- all_data[,c("race_cat", "is.comp.2")]
table(X2)
##         is.comp.2
## race_cat   0   1
##        0  11 105
##        1  19  89
fisher.test(X2)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  X2
## p-value = 1
## alternative hypothesis: two.sided
## Maternal Education
all_data$edu_temp <- ifelse(all_data$mat_educ_cat == "<=HS", 0, 1)
X3 <- all_data[,c("edu_temp", "is.comp.2")]
table(X3)
##         is.comp.2
## edu_temp   0   1
##        0  21  80
##        1   9 114
fisher.test(X3)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  X3
## p-value = 1
## alternative hypothesis: two.sided
## Income
all_data$inc_temp <- ifelse(all_data$income_cat == "<25k", 0, 1)
all_data$income_cat_bin <- ifelse(all_data$income_cat == "<25k", "Less than 25k", "25k or more")
X4 <- all_data[,c("inc_temp", "is.comp.2")]
table(X4)
##         is.comp.2
## inc_temp   0   1
##        0  12  59
##        1  18 135
fisher.test(X4)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  X4
## p-value = 1
## alternative hypothesis: two.sided
## Marriage Status
all_data$mar_temp <- ifelse(all_data$married_cat == "Single", 0, 1)
X5 <- all_data[,c("mar_temp", "is.comp.2")]
table(X5)
##         is.comp.2
## mar_temp   0   1
##        0  13  58
##        1  17 136
fisher.test(X5)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  X5
## p-value = 1
## alternative hypothesis: two.sided
## Insurance Type
all_data$ins_temp <- ifelse(all_data$ins_type_cat == "Private", 0, 1)
X6 <- all_data[,c("ins_temp", "is.comp.2")]
table(X6)
##         is.comp.2
## ins_temp   0   1
##        0   7  91
##        1  23 103
fisher.test(X6)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  X6
## p-value = 1
## alternative hypothesis: two.sided

Tables and Graphs