Aim of this exercise
An exploratory data analysis is a crucial step in a data analysis to get insight in the nature and distribution of the data, and to assess the assumptions of the downstream data analysis.
In this exercise you will acquired the skills to conduct a data exploration for a two group comparison in R and to interpret the results.
Background
Researchers wanted to study the immune response on pertussis. They have set up an experiments with 40 rats. 16 rats were infected with pertussis and 24 rats received a control treatment. Researchers measured the white blood cell concentration (WBC) in each rat (count per mm\(^3\).
De data consists of two variables:
Load the libraries
Import the dataset
Data path:
https://raw.githubusercontent.com/statOmics/PSLSData/main/wbcon.csv
Aim of the study
The overarching goal of this study was to assess if the white blood cell count changes upon pertussis infection. To this end, researchers randomized 40 rats to two treatments: A control treatment and a treatment in which the rat was infected with pertussis.
We will explore the data to get insight on the impact of the pertussis infection on the white blood cell count.
A secondary goal of the data exploration is to assess assumptions that will be required to use a formal statistical test to assess if the white blood cell count is on average different between infected and control rats (see later exercises).
For this test to be valid, we have to assess following assumptions:
The data in each treatment group are normally distributed.
The data from the two treatment groups has the same variance.
Data visualization
A crucial first step in a data analysis is to visualize and to explore the raw data.
Histogram
First, make a histogram of the data. Fill in the missing parts in the chunk of code below:
wbcon %>%
ggplot(aes(x=...,fill=...)) + ## fill in the correct values for x and fill
geom_histogram() +
facet_grid(rows = vars(...)) + ## fill in to put the histograms for both treatment conditions in a separate row
theme_bw() +
xlab("relative abundance (%)")
Based on this plot, it seems that the white blood cell count is … for rats that were randomized to the pertussis infection than rats that received the control treatment.
Boxplot
However, given the small sample size a better option to visualize these data are boxplots
:
wbcon %>%
ggplot(aes(x=...,y=...,fill=...)) +
What do you observe?
QQ-plots
To assess the assumption that the data are normally distributed in each treatment group, we will use QQ plots.
wbcon %>%
ggplot(aes(sample=...)) +
... +
... +
facet_grid(...)
What do you observe?
Descriptive statistics
Here, we will generate some informative descriptive statistics for the dataset.
We first summarize the data and calculate the mean, standard deviation, number of observations and standard error and store the result in an object wbcSum via ’wbcSum<-`
- We pipe the
wbcon
dataframe to the group_by function to group the data by treatment groep group_by(trt)
- We pipe the result to the
summarize()
function to summarize the “WBC” variable and calculate the mean, standard deviation and the number of observations
- We pipe the result to the
mutate
function to make a new variable in the data frame that is named se
for which we calculate the standard error (\(\sigma / n\))
## Use the instructions from above to generate the summary statistics
...
This concludes the data exploration. In the next exercise sessions, we will learn how to formally test if the observed difference in WBC between rats that were infected with pertussis and those receiving the control treatment is statistically significant.
LS0tCnRpdGxlOiAiRXhlcmNpc2UgNC4yOiBFeHBsb3JpbmcgdGhlIHBlcnR1c3NpcyBkYXRhc2V0IgphdXRob3I6ICJMaWV2ZW4gQ2xlbWVudCwgYW5kIE1pbGFuIE1hbGZhaXQiCmRhdGU6ICJzdGF0T21pY3MsIEdoZW50IFVuaXZlcnNpdHkgKGh0dHBzOi8vc3RhdG9taWNzLmdpdGh1Yi5pbykiCi0tLQoKIyBBaW0gb2YgdGhpcyBleGVyY2lzZQoKQW4gZXhwbG9yYXRvcnkgZGF0YSBhbmFseXNpcyBpcyBhIGNydWNpYWwgc3RlcCBpbiBhIGRhdGEgYW5hbHlzaXMgdG8gZ2V0Cmluc2lnaHQgaW4gdGhlIG5hdHVyZSBhbmQgZGlzdHJpYnV0aW9uIG9mIHRoZSBkYXRhLCBhbmQgdG8gYXNzZXNzIHRoZQphc3N1bXB0aW9ucyBvZiB0aGUgZG93bnN0cmVhbSBkYXRhIGFuYWx5c2lzLgoKSW4gdGhpcyBleGVyY2lzZSB5b3Ugd2lsbCBhY3F1aXJlZCB0aGUgc2tpbGxzIHRvIGNvbmR1Y3QgYSBkYXRhIGV4cGxvcmF0aW9uIGZvciBhIHR3byBncm91cCBjb21wYXJpc29uIGluIFIgYW5kIHRvIGludGVycHJldCB0aGUgcmVzdWx0cy4KCiMgQmFja2dyb3VuZAoKUmVzZWFyY2hlcnMgd2FudGVkIHRvIHN0dWR5IHRoZSBpbW11bmUgcmVzcG9uc2Ugb24gcGVydHVzc2lzLgpUaGV5IGhhdmUgc2V0IHVwIGFuIGV4cGVyaW1lbnRzIHdpdGggNDAgcmF0cy4KMT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