Repository navigation
05. Exploratory Data Analysis
Code for the Exploratory Data Analysis can be found (EDA pt.1 here) and (EDA pt.2 here).
For the Exploratory Data Analysis (EDA), I will utilize the framework of Garret Grolemund and Hadley Wickham in their open text "R for Data Science" (free here). Specifically, I'll reference chapter 7: Exploratory Data Analysis (direct link).
This framework uses the Tidyverse (more here).
The first pass at EDA was to simply plot each field on a bar chart with ggplot. This is not the optimal method due to a number of reasons.
- Some fields have many values and other visualization methods are more appropriate.
- x-axis value labels are largely unreadable due to many possible values.
- Missing and NA values.
A second pass at the plots was to clean up the axes, labels, and titles. After this pass, this common warning was noted:
Removed [N] rows containing non-finite values (stat_count)
Additional evaluation revealed this warning is a result of NA values in the field. There are a few ways to manage this warning:
- Remove
NAvalues inside of theggplot(). This can be achieved by changing
ggplot(data = HxMx) to
ggplot(data = subset(HxMx, ~is.na(_[field_name]_)))
- Remove
NAvalues prior to theggplot(). This can be achieved by changing theletter_gradeexample from
ggplot(data = subset(HxMx, !is.na(letter_grade))) + geom_bar(mapping = aes(x = letter_grade)) + scale_x_discrete(limits = c("A","B","C","D","F")) + #,NA)) + inclue for NA scale_y_continuous(name=" ", labels = comma) + theme(axis.title.x = element_blank()) + labs(title = "Letter Grade")
to the following by incorporating subset and piping (%>%)
HxMx %>% subset(!is.na(letter_grade)) %>% ggplot() + geom_bar(mapping = aes(x = letter_grade)) + scale_x_discrete(limits = c("A","B","C","D","F")) + #,NA)) + inclue for NA scale_y_continuous(name=" ", labels = comma) + theme(axis.title.x = element_blank()) + labs(title = "Letter Grade")
A third pass continued to modify the plots within ggplot(). Some integer fields were being plotted with decimals rather than whole numbers.
The following fields were impacted: year, registered, viewed, explored, certified, nevents_ind, ndays_act_ind, nchapters_ind, nforum_posts_ind, & incomplete_flag.
This issue was fixed by adding a scale_x_discrete(breaks = c()) modification, such as:
ggplot(data = HxMx) + geom_bar(mapping = aes(x = year)) + scale_x_continuous(name = " ", breaks = c(2012, 2013)) + scale_y_continuous(name = " ", labels = comma) + theme(axis.title.x = element_blank()) + labs(title = "Year")
Summary statistics are now included with each plot to provide, at a minimum, counts. This adds context to the differences in plots, as well as identified a few inconsistencies within the data.
The pipe operator was effective and efficient in helping provide summary statistics, ranging from more simplistic to complex.
For instance, this provides counts of institution:
HxMx %>% group_by(institution) %>% summarize(n = n())
Output:
# A tibble: 2 x 2 institution n <chr> <int> 1 HarvardX 338223 2 MITx 302915
And this provides counts of groups of nevents, removing NA values, and only showing where nevents were greater than or equal to 5000:
HxMx %>% filter(!is.na(nevents) & nevents >= 5000) %>% group_by(nevents) %>% tally(sort = T) %>% arrange(n)
Output:
# A tibble: 5,676 x 2 nevents n <int> <int> 1 5000 1 2 5016 1 3 5017 1 4 5019 1 5 5021 1 6 5023 1 7 5034 1 8 5035 1 9 5041 1 10 5042 1 ... with 5,666 more rows
Additional exploration into last_event_DI revealed outliers on the extreme upper end, which were attributed to course_code = "CB22x". Further investigation shows this was only for one of the CB22x course offerings, not all.
A fourth pass is in progress to plot two fields at once to explore potential correlations.
Learning R by Doing - A Learning Experiment in RStudio and GitHub