(Original source: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5344309/)
These data examine the relationship between the use of soap during handwashing and washing clothes and demographic variables such as socio-economic status. All of the subjects in this data set are from a variety of regions in Bangladesh. Data were collected using a national survey.
Given these data, two questions of interest are:
Is there any association between adulthood and one’s use of soap during handwashing after defecation and the use of soap when washing clothes.
Do these habits differ across sexes?
Therefore, the variables of interest are wash1_a, which takes the value 1 if the subject used soap when washing their clothes and 0 if they did not, wash6_a, which takes the value 1 if the subject used soap when washing their hands after defecating and 0 if they did not, csex, which takes the value Male or Female, and age, which lists the subject’s age in years. For the purposes of this question, we’ll designate subjects of 18 years of age or older as adults and those younger than 18 as children.
Make sure to install the following packages using the install.packages() function, then load the corresponding libraries.
library(readxl) #Reads in Excel files
library(dplyr) #Adds extra data cleaning functionality
library(epitools) #Adds odds ratio and relative risk functions
Next, read in the data set, which we’ll call washing.
washing <- read_xls("SES_Wash.xls")
head(washing) ## Shows the first six rows of the data set
## # A tibble: 6 x 24
## zone seasonality resi_type wash1_a wash2_a wash3_a wash4_a wash5_a
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Rang~ post_aman rural Yes 0 0 0 0
## 2 Rang~ post_aman rural No 1 0 0 0
## 3 Rang~ post_aman rural Yes 1 0 0 0
## 4 Rang~ post_aman rural Yes 1 0 0 0
## 5 Rang~ post_aman rural Yes 0 1 1 0
## 6 Rang~ post_aman rural Yes 0 1 1 0
## # ... with 16 more variables: wash6_a <chr>, wash7_a <chr>, wash8_a <chr>,
## # wash9_a <chr>, wash10_a <chr>, hygienic <dbl>, csex <chr>, age <dbl>,
## # ASSEL <chr>, ASSRTV <chr>, ASSFAN <chr>, ASSAL <chr>, ASSRE <chr>,
## # ASSWC <chr>, MUWALL <chr>, hfias <chr>
Let’s begin by collapsing the data set into the three variables of interest: wash6_a, csex, and age. We’ll use the select() function from the dplyr library to achieve this.
washing.subset <- washing %>%
select(wash1_a, wash6_a, csex, age)
Next, we’ll individually explore the three variables of interest to determine if there are any missing values or irregularities. Since washing clothes with soap (wash1_a), washing with soap after defecation (wash6_a), and sex assigned at birth (csex) are categorical variables, we’ll use the table function to create contingency tables telling us the number of times the given variable took each of the possible values. Since age is quantitative, we’ll use the summary function to calculate the five number summary (min, median, max, etc.) of ages.
table(washing.subset$wash1_a)
##
## No Yes
## 1916 8562
table(washing.subset$wash6_a)
##
## 0 1
## 4617 5861
table(washing.subset$csex)
##
## Female Male
## 5117 5361
summary(washing.subset$age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.10 15.30 29.40 29.67 44.00 59.90
There appear to be significantly more people who wash their clothes with soap than those who do not. There appear to be slightly more people who wash their hands after defecating than those who do not. Additionally, there are an approximately equal number of males and females in this data set. Ages seem to range from newborn (\(\text{age} = 0.10\)) to older adult (\(\text{age} = 59.90\)). There does not appear to be anyone over the age of 60 in this data set.
The age variable is currently quantitative. As part of our questions of interest, we are interested in investigating a possible association between handwashing and adulthood. Thus, we need to change the age variable into a categorical variable. To add a new variable to our dataset, we will use the mutate() function.
washing.subset <- washing.subset %>%
mutate(adulthood = ifelse(age < 18, #Checks if subject age is < 18.
"Child", #If it is, label them child.
"Adult")) #Else, label them adult.
Our new variable, adulthood, takes the value Child if the subject is below the age of 18, and Adult otherwise. We will use this new adulthood variable later in our analysis.
Next, in order to make the wash6_a variable easier to interpret at a glance (and to match the coding of the wash1_a variable), we will use the recode function to change the values of 0 to No and change the value of 1 to Yes.
washing.subset$wash6_a <- recode(washing.subset$wash6_a,
`0` = "No",
`1` = "Yes")
Finally, we’ll rename all of the variables to make them easier to identify.
names(washing.subset) <- c("Soap.With.Clothes",
"Soap.After.Defecating",
"Sex",
"Age",
"Adulthood")
Let’s construct a contingency table of sex and soap use after deficating to examine any possible patterns. The resulting table is below.
soap.use.defecation.by.sex <- table(washing.subset$Sex, washing.subset$Soap.After.Defecating)
soap.use.defecation.by.sex
##
## No Yes
## Female 2236 2881
## Male 2381 2980
Across both sexes, subjects are likely to wash their hands with soap after defecating. It is not immediately clear from the table if there is any association between sex and washing with soap. In order to determine if there is any association between sex and wash with soap, we can utilize a Chi-square contingency test (also known as a Chi-square test for association or correlation).
chisq.test(soap.use.defecation.by.sex)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: soap.use.defecation.by.sex
## X-squared = 0.5157, df = 1, p-value = 0.4727
The resulting p-value is large, and there is therefore little evidence of an association between sex and whether or not the subject washes their hands with soap after defecating. A corresponding mosaic plot helps visualize this lack of association.
mosaicplot(t(soap.use.defecation.by.sex), #Flip the table so sex is row and wash is column
shade = TRUE, #Color the table according to standardized residuals
ylab = "Sex", #Label y-axis
xlab = "Soap Status", #Label x-axis
main = "")#Remove title
Next, using the same approach, we’ll examine a possible association between our new age variable, Adulthood, and washing habits.
soap.use.defecation.by.age <- table(washing.subset$Adulthood,
washing.subset$Soap.After.Defecating)
soap.use.defecation.by.age
##
## No Yes
## Adult 3269 4090
## Child 1348 1771
chisq.test(soap.use.defecation.by.age)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: soap.use.defecation.by.age
## X-squared = 1.2375, df = 1, p-value = 0.266
The contingency table demonstrates—and the chi-square contingency test confirms—that there is little evidence of an association between adulthood and washing habits after defecating. That is, there appears to be no difference in the proportion of adults who wash their hands with soap after defecating and the proportion of children who wash their hands with soap after defecating. A mosaic plot again highlights this lack of association.
mosaicplot(t(soap.use.defecation.by.age), #Flip the table so sex is row and soap is column
shade = TRUE, #Color the table according to standardized residuals
ylab = "Adulthood", #Label y-axis
xlab = "Soap Status", #Label x-axis
main = "")#Remove title
Thus, there appears to be no evidence of an association between adulthood, sex, and the use of soap after defecation.
We’ll now take a similar approach to identifying a possible association between sex, adulthood, and the use of soap when washing clothes. First, we’ll investigate whether different sexes are more likely to use soap when washing clothes.
soap.use.clothes.by.sex <- table(washing.subset$Sex,
washing.subset$Soap.With.Clothes)
soap.use.clothes.by.sex
##
## No Yes
## Female 915 4202
## Male 1001 4360
chisq.test(soap.use.clothes.by.sex)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: soap.use.clothes.by.sex
## X-squared = 1.0421, df = 1, p-value = 0.3073
There appears to be little evidence of an association between sex and using soap when washing clothes. Finally, we’ll investigate a potential association between adulthood and washing clothes with soap.
soap.use.clothes.by.age <- table(washing.subset$Adulthood,
washing.subset$Soap.With.Clothes)
soap.use.clothes.by.age
##
## No Yes
## Adult 1436 5923
## Child 480 2639
chisq.test(soap.use.clothes.by.age)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: soap.use.clothes.by.age
## X-squared = 24.658, df = 1, p-value = 6.847e-07
Given the small p-value, there appears to be very strong evidence of an association between adulthood and the use of soap when washing clothes. To better understand the direction of this association, we’ll construct a mosaic plot.
mosaicplot(t(soap.use.clothes.by.age), #Flip the table so sex is row and soap is column
shade = TRUE, #Color the table according to standardized residuals
ylab = "Adulthood", #Label y-axis
xlab = "Soap Status", #Label x-axis
main = "")#Remove title
Perhaps surprisingly, the mosaic plot demonstrates that children are significantly more likely to wash their clothes with soap than one would expect, and adults are significant less likely to wash their clothes with soap. To better quantify this association, we’ll next calculate the odds ratio and relative risk of using soap to wash clothes.
oddsratio(soap.use.clothes.by.age,
method = "wald")$measure[-1,] #Extracts only the ouput necessary to identify odds ratio
## estimate lower upper
## 1.332941 1.190447 1.492491
The odds ratio here of approximately 1.33 is a comparison of the proportion of children who wash their clothes with soap to the proportion of adults who wash their clothes with soap. An odds ratio of 1 would indicate that the two proportions are equal. Since this odds ratio is larger than 1 and the value 1 does not fall in the confidence interval provided, there is strong evidence that children are more likely (i.e., have higher odds) to wash their clothes with soap.
Relative risk is another method of quantifying the association seen here. The relative risk here is the ratio of the probability of an adult not using soap to wash their clothes to the probability of a child not using soap to wash their clothes.
riskratio(soap.use.clothes.by.age,
method = "wald",
rev = "both")$measure[-1,] #Extracts only the ouput necessary to identify relative risk
## estimate lower upper
## 1.267972 1.153671 1.393598
The relative risk here is approximately 1.27. Thus, adults are 1.27 times as likely to not wash their clothes with soap as compared to children.