file_path <- "~/Desktop/CII/CHILDREN_FIRST/QuestionnaireToAccom_DATA_LABELS_2024-04-02_1341.csv"
quest <- read.csv(file_path)
file_path <- "~/Desktop/CII/CHILDREN_FIRST/Samples - Abnormal values.xlsx"
samples1 <- openxlsx::read.xlsx(file_path)
file_path <- "~/Desktop/CII/CHILDREN_FIRST/Samples - Abnormal values (2).xlsx"
samples2 <- openxlsx::read.xlsx(file_path)
rm(file_path)
# quest
quest <- quest %>%
dplyr::select(4, 6:13)
quest$Sample.ID. <- as.character(quest$Sample.ID.)
quest$Sample.ID. <- substr(quest$Sample.ID., start = 4, stop = nchar(quest$Sample.ID.))
quest[quest == ""] <- NA
quest <- quest %>%
mutate(filter = case_when(filter == "Όχι" | filter_type == "Αποσκληρυντικό νερού" ~ "Όχι",
filter == "Δεν γνωρίζω" ~ "Δεν γνωρίζω",
filter == "Ναι" ~ "Ναι"))
# samples1
samples1 <- samples1[-1, -4]
samples1$X1 <- substr(samples1$X1, start = 4, stop = nchar(samples1$X1))
samples1$OMX22 <- samples1$ΟΜΧ.22οC # ensure same names across df
samples1$OMX37 <- samples1$ΟΜΧ.37oC
# samples2
samples2 <- samples2[-1, -4]
samples2$X1 <- substr(samples2$X1, start = 4, stop = nchar(samples2$X1))
samples2$OMX22 <- samples2$OMX.22o.C # ensure same names across df
samples2$OMX37 <- samples2$OMX.37oC
# merge samples
samples <- merge(samples1, samples2, all.x=TRUE, all.y=TRUE)
vars <- c("X1", "OMX22", "OMX37")
samples <- samples[vars]
# abnormal variables
samples <- samples %>%
mutate(OMX22 = case_when(OMX22 == "N.D" | OMX22 == "TNTC" ~ NA,
TRUE ~ OMX22)) %>%
mutate(OMX37 = case_when(OMX22 == "N.D" | OMX22 == "TNTC" ~ NA,
TRUE ~ OMX37)) %>%
mutate(OMX22 = as.numeric(OMX22)) %>%
mutate(OMX37 = as.numeric(OMX37)) %>%
mutate(abnormal_22 = case_when(is.na(OMX22) | OMX22 >= 1.3 ~ "Abnormal",
TRUE ~ "Normal")) %>%
mutate(abnormal_37 = case_when(is.na(OMX37) | OMX37 >= 2.0 ~ "Abnormal",
TRUE ~ "Normal"))
# df of only abnormal samples
abnormal <- left_join(samples, quest, by = c("X1" = "Sample.ID."), keep = TRUE)
abnormal = subset(abnormal, select = -Sample.ID.)
# all samples
# rename columns
colnames(quest)[which(colnames(quest) == "Sample.ID.")] <- "ID"
colnames(samples)[which(colnames(samples) == "X1")] <- "ID"
all <- merge(quest, samples[, c("ID", "abnormal_22", "abnormal_37")], by = "ID", all.x = TRUE)
all <- all %>%
mutate(abnormal_22 = case_when(abnormal_22 == "Abnormal" ~ "Abnormal",
abnormal_22 == "Normal" | is.na(abnormal_22) ~ "Normal")) %>%
mutate(abnormal_37 = case_when(abnormal_37 == "Abnormal" ~ "Abnormal",
abnormal_37 == "Normal" | is.na(abnormal_37) ~ "Normal")) %>%
mutate(abnormal_sample = case_when(abnormal_22 == "Abnormal" | abnormal_37 == "Abnormal" ~ "Abnormal",
abnormal_22 == "Normal" | abnormal_37 == "Normal" ~ "Normal"))
# Set reference levels
all$abnormal_22 <- factor(all$abnormal_22)
all$abnormal_22 <- relevel(all$abnormal_22, ref = "Normal")
all$abnormal_37 <- factor(all$abnormal_37)
all$abnormal_37 <- relevel(all$abnormal_37, ref = "Normal")
all$abnormal_sample <- factor(all$abnormal_sample)
all$abnormal_sample <- relevel(all$abnormal_sample, ref = "Normal")
all <- all %>%
mutate(filter = case_when(filter == "Ναι" ~ "Filter",
filter == "Όχι" ~ "No Filter",
TRUE ~ NA))
all$filter <- factor(all$filter)
all$filter <- relevel(all$filter, ref = "Filter")
# Recode variables
all <- all %>%
mutate(clean_tap = case_when(clean_tap == "Ναι" ~ "Yes",
clean_tap == "Όχι" ~ "No",
TRUE ~ NA)) %>%
mutate(tap_running = case_when(tap_running == "Ναι" ~ "Yes",
tap_running == "Όχι" ~ "No",
TRUE ~ NA)) %>%
mutate(reduce_flow = case_when(reduce_flow == "Ναι" ~ "Yes",
reduce_flow == "Όχι" ~ "No",
TRUE ~ NA))
all$clean_tap <- factor(all$clean_tap)
all$clean_tap <- relevel(all$clean_tap, ref = "Yes")
all$tap_running <- factor(all$tap_running)
all$tap_running <- relevel(all$tap_running, ref = "Yes")
all$reduce_flow <- factor(all$reduce_flow)
all$reduce_flow <- relevel(all$reduce_flow, ref = "Yes")
rm(vars)
table(all$abnormal_22, all$abnormal_37)
##
## Normal Abnormal
## Normal 157 3
## Abnormal 15 40
table(all$abnormal_sample)
##
## Normal Abnormal
## 157 58
157 participants have both Normal OMX_22 and OMX_37 samples. 58 participants have at least one abnormal sample: 40 participants have both abnormal sample, 18 participants have 1 abnormal sample.
# Chi-square loop of all questionnaire variables on abnormal vs normal samples
# List of variables in quest to analyze
variables_to_analyze <- c("filter", "filter_type", "clean_tap",
"tap_running", "reduce_flow")
# Create an empty list to store significant variables
significant_variables <- c()
# Loop over each variable
for (variable in variables_to_analyze) {
# Create a contingency table
contingency_table <- table(all[[variable]], all$abnormal_22)
# Perform chi-square test
chi_sq_result <- chisq.test(contingency_table)
# Print the variable name
cat("Variable:", variable, "\n")
# Check if p-value is less than 0.05
if (chi_sq_result$p.value < 0.05) {
significant_variables <- c(significant_variables, variable)
cat("Significant\n")
} else {
cat("Not Significant\n")
}
cat("\n")
}
## Variable: filter
## Significant
##
## Variable: filter_type
## Not Significant
##
## Variable: clean_tap
## Not Significant
##
## Variable: tap_running
## Not Significant
##
## Variable: reduce_flow
## Not Significant
# Print significant variables
cat("Significant Variables:", paste(significant_variables, collapse = ", "), "\n")
## Significant Variables: filter
Given a p-value of <0.05, there is sufficient evidence to reject the null hypothesis and conclude that there is an association between the variables “abnormal_22” and “filter”.
# Filter is signficant
# Fit logistic regression model for abnormal_22 and filter
model <- glm(abnormal_22 ~ filter, data = all, family = binomial)
summary(model)
##
## Call:
## glm(formula = abnormal_22 ~ filter, family = binomial, data = all)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.4906 0.2318 -2.116 0.03431 *
## filterNo Filter -0.9818 0.3208 -3.061 0.00221 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 243.32 on 212 degrees of freedom
## Residual deviance: 233.87 on 211 degrees of freedom
## (2 observations deleted due to missingness)
## AIC: 237.87
##
## Number of Fisher Scoring iterations: 4
Given that “filter” was found to be significant in the chi-square test, a logistic regression model was run.
The model suggests that “filter” significantly affects the odds of the outcome:
Not having a filter (“No Filter”) is associated with lower odds of having a normal OMX_22 sample; having a filter is associated with higher odds of having a normal OMX_22 sample.
# Chi-square loop of all questionnaire variables on abnormal vs normal samples
# List of variables in quest to analyze
variables_to_analyze <- c("filter", "filter_type", "clean_tap",
"tap_running", "reduce_flow")
# Create an empty list to store significant variables
significant_variables <- c()
# Loop over each variable
for (variable in variables_to_analyze) {
# Create a contingency table
contingency_table <- table(all[[variable]], all$abnormal_37)
# Perform chi-square test
chi_sq_result <- chisq.test(contingency_table)
# Print the variable name
cat("Variable:", variable, "\n")
# Check if p-value is less than 0.05
if (chi_sq_result$p.value < 0.05) {
significant_variables <- c(significant_variables, variable)
cat("Significant\n")
} else {
cat("Not Significant\n")
}
cat("\n")
}
## Variable: filter
## Not Significant
##
## Variable: filter_type
## Not Significant
##
## Variable: clean_tap
## Not Significant
##
## Variable: tap_running
## Not Significant
##
## Variable: reduce_flow
## Not Significant
# Print significant variables
cat("Significant Variables:", paste(significant_variables, collapse = ", "), "\n")
## Significant Variables:
Given that there were no p-values <0.05, there is not enough sufficient evidence to reject the null hypothesis; none of the variables have a significant association with the OMX_37 samples.
# Fit logistic regression model for abnormal_37 and filter
model <- glm(abnormal_37 ~ filter, data = all, family = binomial)
summary(model)
##
## Call:
## glm(formula = abnormal_37 ~ filter, family = binomial, data = all)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.2205 0.2682 -4.550 5.36e-06 ***
## filterNo Filter -0.2520 0.3480 -0.724 0.469
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 214.28 on 212 degrees of freedom
## Residual deviance: 213.76 on 211 degrees of freedom
## (2 observations deleted due to missingness)
## AIC: 217.76
##
## Number of Fisher Scoring iterations: 4
The model suggests that “filter” does not have a significant effect the odds of the outcome (Abnormal/Normal OMX_37 sample).