Study of US Craft Beer and Breweries

David Stroud, Cory Thigpen, Korey MacVittie, and Stacy Conant

February 2018

Introduction and Overview

In this report, we explore datasets for various beers and the breweries that produce them in the US. The steps and procedures taken for this analysis are detailed below.

The initial data provided were in two separate datasets, one each for beers and breweries, which were combined into a single dataset.

Repository Structure

Our Git repository {https://github.com/davestroud/BeerStudy} is relatively unstructured, with the following pertinent files contained within:

  • README.md : This is the base page for the repository, containing an introduction as well as our codebook for how we coded variable names throughout the datasets.
  • BottomsUp_DS.Rmd : This is the primary file for the analysis, and is the file you are currently reading. It contains all the relevant R code, graphics, and analysis for the project; also included are specific .docx, .html, and .pdf knitted versions of this file.
  • Beers.csv and Breweries.csv, were provided and are the original datasets from which our merged dataset is produced.

Reproduction of Analysis

It would be suggested to start with the README.md file to acquaint yourself with our nomenclature. Clone or otherwise download this repository, then run the BottomsUp_DS.Rmd file.

Analysis

We begin by setting knitr options, loading various libraries we will need for our analysis, and reading in our data.

# Read in beer and breweries data set using _csv for more tidy output
Beers <- read_csv('Beers.csv', col_types = cols())
Breweries <- read_csv('Breweries.csv', col_types = cols())

The field Brewery_id in Beers.csv and Brew_ID in Breweries.csv are the same data, but do not share a name. We remedy this by renaming the column in Beers.csv.

Research Questions

We can now address the research questions put forth on the dataset.

1. How many breweries are present in each state?

We answer this question by retrieving the value of State from the Breweries data.

BrewPerState <-table(Breweries$State)
BrewPerState
## 
## AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO 
##  7  3  2 11 39 47  8  1  2 15  7  4  5  5 18 22  3  4  5 23  7  9 32 12  9 
## MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV 
##  2  9 19  1  5  3  3  4  2 16 15  6 29 25  5  4  1  3 28  4 16 10 23 20  1 
## WY 
##  4
# Renamed Brewery_id to Brew_ID to satisfy merging requirement
Beers <- rename(Beers, Brew_ID = Brewery_id)

2. Merge beer data with the breweries data. Print the first 6 observations and the last six observations to check the merged file.

As part of our analysis, we ensured that duplicate data within each dataset shared the same variable name in both sets. We can now merge them into a single dataset, using full_join.

BrewPub <- full_join(Beers, Breweries, by="Brew_ID")
# Change variable names to more meaningful title
BrewPub <- rename(BrewPub, Beer = Name.x, Brewery = Name.y,
                  OZ = Ounces)

To retrieve the first and last six observations from the combined data, we run head and tail on BrewPub, our combined dataset.

kable(BrewPub %>% head())
Beer Beer_ID ABV IBU Brew_ID Style OZ Brewery City State
Pub Beer 1436 0.050 NA 409 American Pale Lager 12 10 Barrel Brewing Company Bend OR
Devil’s Cup 2265 0.066 NA 178 American Pale Ale (APA) 12 18th Street Brewery Gary IN
Rise of the Phoenix 2264 0.071 NA 178 American IPA 12 18th Street Brewery Gary IN
Sinister 2263 0.090 NA 178 American Double / Imperial IPA 12 18th Street Brewery Gary IN
Sex and Candy 2262 0.075 NA 178 American IPA 12 18th Street Brewery Gary IN
Black Exodus 2261 0.077 NA 178 Oatmeal Stout 12 18th Street Brewery Gary IN
kable(BrewPub %>% tail())
Beer Beer_ID ABV IBU Brew_ID Style OZ Brewery City State
Rocky Mountain Oyster Stout 1035 0.075 NA 425 American Stout 12 Wynkoop Brewing Company Denver CO
Belgorado 928 0.067 45 425 Belgian IPA 12 Wynkoop Brewing Company Denver CO
Rail Yard Ale 807 0.052 NA 425 American Amber / Red Ale 12 Wynkoop Brewing Company Denver CO
B3K Black Lager 620 0.055 NA 425 Schwarzbier 12 Wynkoop Brewing Company Denver CO
Silverback Pale Ale 145 0.055 40 425 American Pale Ale (APA) 12 Wynkoop Brewing Company Denver CO
Rail Yard Ale (2009) 84 0.052 NA 425 American Amber / Red Ale 12 Wynkoop Brewing Company Denver CO

3. Report the number of NA’s in each column.

To do this, we use a function (which returns true if a given value is NA, false otherwise, using is.na) and sapply to determine the number of missing values for each column within BrewPub.

Per the results, we find that there are a total of 62 ABV values missing, and 1005 IBU values missing. No other data is missing.

MissingValues <- sapply(BrewPub, function(x)sum(is.na(x)))
# Used kable library to make document more presentable
MissingValues %>%
  kable("html") %>%
  kable_styling()
x
Beer 0
Beer_ID 0
ABV 62
IBU 1005
Brew_ID 0
Style 5
OZ 0
Brewery 0
City 0
State 0

4. Compute the median alcohol content and international bitterness unit for each state. Plot a bar chart to compare.

We build two new datasets, Bitter and FireWater, from our BrewPub dataset, omitting NA values. We then group the relevant values by state, and summarise by the median of the relevant value.

# 4. Compute the median alcohol content unit for each state.
Firewater <- BrewPub %>%
  na.omit() %>%
group_by(State) %>%
summarise(Median = median(ABV)) %>%
arrange(Median)
# 4. a Compute the median international bitterness unit for each state.
Bitter <- BrewPub %>%
  na.omit() %>%
group_by(State) %>%
summarise(Median = median(IBU)) %>%
arrange(Median)
# 4. b Plot a bar chart to compare ABV by state
library(ggthemes)
ggplot(data=Firewater, aes(x=State, y=Median)) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_economist() + 
  scale_color_economist()+
  theme(axis.text.x=element_text(size=rel(0.8), angle=90)) +
  ggtitle("Median ABV by State") +
  labs(x="State",y="ABV")

# 4. c Plot a bar chart to compare IBU by state
ggplot(data=Bitter, aes(x=State, y=Median)) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_economist() + 
  scale_color_economist()+
  theme(axis.text.x=element_text(size=rel(0.8), angle=90))+
  ggtitle("Median IBU by State") +
  labs(x="State",y="IBU")

5. Which state has the maximum alcoholic (ABV) beer? Which state has the most bitter (IBU) beer?

We use which.max on our BrewPub dataset, seeking specifically the maximum value in the ABV and IBU columns.

From this, we identify Colorado as having the beer with the highest ABV, at .128; and we identify Oregon has having the beer with the highest IBU, at 138.

kable(BrewPub[which.max(BrewPub$ABV),])
Beer Beer_ID ABV IBU Brew_ID Style OZ Brewery City State
Lee Hill Series Vol. 5 - Belgian Style Quadrupel Ale 2565 0.128 NA 52 Quadrupel (Quad) 19.2 Upslope Brewing Company Boulder CO
kable(BrewPub[which.max(BrewPub$IBU),])
Beer Beer_ID ABV IBU Brew_ID Style OZ Brewery City State
Bitter Bitch Imperial IPA 980 0.082 138 375 American Double / Imperial IPA 12 Astoria Brewing Company Astoria OR

6. Summary statistics for the ABV variable.

We do this by calling summary on the ABV column in our BrewPub dataset.

BeerSummary <- (summary(BrewPub$ABV))
print(BeerSummary)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## 0.00100 0.05000 0.05600 0.05977 0.06700 0.12800      62

7. Is there an apparent relationship between the bitterness of the beer and its alcoholic content? Draw a scatter plot.

We utilize ggplot to plot a scatter plot of the data, using IBU and ABV as our variables.

Examination of this scatter plot and the regression line suggests that there is a positive, linear relationship between IBU and ABV.

# 7. Draw a scatter plot to compare relationship between beer 
# bitterness and alcohol content
ggplot(BrewPub, aes(x=IBU, y= ABV)) +
  geom_point(shape=1) +
   geom_smooth(method=lm) + # add linear regression line
  theme_economist() + 
  scale_color_economist()+
  theme(axis.text.x=element_text(size=rel(1.0)))+
ggtitle("Correlation between IBU and ABV ") +
  labs(x="IBU",y="ABV")

Review and Conclusion

In this analysis, we examined data gleaned from two datasets regarding beers and breweries throughout the US. We examined the structure of this data, cleaned them, and combined them. We then performed various analyses, such as calculating median values for IBU and ABV by state, and determining which states had the beers with the highest ABV and IBU values. We finished by looking for a potential relationship between IBU and ABV, and found that there is evidence to suggest that a positive correlation exists between the two.