1-way ANOVA

advertisement

MBP1010 – Tutorial 5 – Linear Regression & two-way ANOVA – Hops

You’re interested in understanding the bittering properties of two wild varieties of hops that you’ve recently discovered while hiking in a small valley in Dusseldorf.

Hops add bitterness to beer and act as a preservative. You decide to brew small, separate batches of beer with the 2 new hops varieties and a standard hop variety.

Since the boil time (the amount of time the hops are boiled for in the wort stage of brewing) impacts the extraction of bitterness from the hops, you decide to make separate batches, boiling the wort beer for 30-120 minutes. After completing each batch, you measure the bitterness of the resulting beer using a spectrophotometer and scale it on the IBU scale (10 = not very bitter at all, 100 = insanely bitter).

Variables

hops = hop variety (control, type1, type2) boiltime = boiling times (30,60,90,120)

IBU = international bitterness units

Loading the data

Load the CSV format dataset into your working directory. setwd(“yourDir”) brewing <- read.csv(“brewingData.txt”)

Visualizing your data

Open up the dataset. How many replicates are there for each combination of boiltime and hop variety? Your task in this step is to create a visually appealing plot of the raw data points according to both variety of hops and the boiltime. This can be done several different ways.

One of the simplest ways of doing this is to create a scatterplot of the entire dataset, coloring each of the varieties differently. This can be done with the R plot command, specifying the hops varieties vector using the “col” option. plot(x=brewing$boiltime, y=brewing$IBU, col=brewing$hops)

Alternatively, you could specify a different symbol for each hop variety using the pch option. You may want to add some random “noise” to the values of boiltimes so that the points don’t totally overlap; this can be done using the “jitter()” function.

A second way to look at the data is to create something called a panel plot. A panel plot is a collection of plots where different groups each get a separate graph.

Automated panel-plotting options exist in the “lattice” and “ggplot2” packages, but

1

here I will ask you to make a panel plot manually, by dividing the plotting space into rows and columns using the mfrow or mfcol option in par (see ?par help page for more details).

For example, the following code would divide the plotting space into 3 rows and 1 columns, and instruct R to plot each subgroup. An improvement on this graph would use the same y axis limits in order to facilitate comparing the 3 panels. par(mfrow=c(3,1)) plot(IBU ~ boiltime, data = subset(brewing, hops == “control”)) plot(IBU ~ boiltime, data = subset(brewing, hops == “type1”)) plot(IBU ~ boiltime, data = subset(brewing, hops == “type2”))

Which plot is most helpful for understanding the data in this case? Why?

___________________________________

Data preparation

Now we will conduct ANOVAs. But first, create a dummy variable for boiltimes variable called bt120; bt120 = 1 when boiltime = 120 and 0 otherwise. Similarly, create dummy variables indicating the type1 and type2 hop varieties. brewing$bt120<-brewing$boiltime == 120 brewing$type1<-brewing$hops == “Type1”

1-way ANOVA

Run a 1-way ANOVA model for predicting the IBUs of the different hop varieties using the lm function. Are the means different? lm(IBU ~ type1 + type2, data=brewing)

Write down the formula for the statistical model this represents.

Formula: __________________________ control mean : mean of type 1 : mean of type 2 :

______

______

______ p-value of the F-test (2DF) for comparing b1=b2=0: ______

2

p-values of the three 1DF t-tests for comparing comparing type 1 versus type 2, type

1 versus control, and type 2 versus control ______ ______ ______

What is the ANOVA model R 2 ______

What is the ANOVA model SSE? ______

2-way ANOVA

Now, limit the data to the shortest and longest boiltimes and to the control hop variety and the type 2 varieties. We will conduct a 2 way ANOVA to look at the combined effects of brewing times and hop varieties. sub1<-subset(brewing, boiltime %in% c(30,120) & hops %in% c("Control","Type2")) lm (IBU ~ bt120 + type2 + bt120*type2, data = sub1)

Write down the formula for the statistical model this represents:

_________________________________

What is the mean IBU for the control hop variety when the boiltime is 30 minutes?

What is the mean IBU for the type2 hop variety when the boiltime is 30 minutes?

What is the mean IBU for the control hop variety when the boiltime is 120 minutes?

What is the mean IBU for the type2 hop variety when the boiltime is 120 minutes?

Is there a statistically significant effect of variety? Report the p-value.

Is there a statistically significant effect of boiltime? Report the p-value.

Is there a statistically significant interaction between boil time and variety?

Is the interaction effect between variety and boiltime sub-additive or above an additive effect? To answer this, give the expected mean at 120 minutes for variety 2, under the assumption of additivity.

What is the ANOVA model R 2 ______

What is the ANOVA model SSE? ______

Linear modeling approach

If time permits, we will continue to compare the association between bitterness and hop variety. This time consider the boiltime variable as a continuous linear predictor. For this modeling approach, perform a data transform to the boiltime variable so that:

3

1) the intercept variable corresponds to the bitterness level at 30 minutes

2) the coefficient of the new variable corresponds to effect of a 30 minute increase in boiltime.

Run the following model using the dataset. Limit your data to the control variety and to the type 1 variety.

IBU ~ B

0

+ B

1

boiltime.transformed + B

2

type2 + B

3

* interaction

What is the mean IBU for the type2 hop variety when the boiltime is 30 minutes?

When boiltime is 90 minutes?

Is the interaction effect between variety and boiltime sub-additive or above an additive effect? To answer this, give the expected mean under the assumption of additivity.

4

Download