Homework 1

Enter your name and EID here

This homework is due on Jan. 27, 2020 at 12:00pm. Please submit as a pdf file on Canvas.

This homework uses the InsectSprays data set available in R. This data set contains counts of insects in agricultural experimental units (count) treated with different insecticides (spray). There are six different types of insect sprays tested in the data set (labeled A-F), each with 12 observations.

head(InsectSprays)
##   count spray
## 1    10     A
## 2     7     A
## 3    20     A
## 4    14     A
## 5    14     A
## 6    12     A

Question 1: (4 pts) We are interested in testing the effect of insect spray type on the number of insects observed. Since there are six different types of insect sprays in the data set, and therefore six groups of insect counts, we will use an analysis of variance (ANOVA) test. Conduct an ANOVA test and interpret your results in 1-2 sentences. HINT: You will first need to create a linear model object using the lm() function before you can use the anova() function.

spray.mod <- lm(count ~ spray, data = InsectSprays)
anova(spray.mod)
## Analysis of Variance Table
## 
## Response: count
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## spray      5 2668.8  533.77  34.702 < 2.2e-16 ***
## Residuals 66 1015.2   15.38                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The insect count means from each type of insect spray are not equal, i.e., at least one spray must be more effective than the others at controlling insect counts.

Question 2: (3 pts) Create a boxplot of the insect count data, separated by spray type. Based on this plot, is the mean insect count of Spray B the same or different from that of Spray D? Explain your answer.

boxplot(count ~ spray, data = InsectSprays, xlab="Insect Spray", ylab="Insect Count")

With one exception, the insect counts under spray D are all lower than the lowest insect count under spray F. Thus, we expect that the means will be different.

Question 3: (3 pts) Use a t test to determine if the mean insect count of Spray B is the same or different from that of Spray D. Interperet and explain your results in 1-2 sentences.

t.test(InsectSprays$count[InsectSprays$spray == 'B'], InsectSprays$count[InsectSprays$spray == 'D'])
## 
##  Welch Two Sample t-test
## 
## data:  InsectSprays$count[InsectSprays$spray == "B"] and InsectSprays$count[InsectSprays$spray == "D"]
## t = 7.289, df = 17.758, p-value = 9.744e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   7.411331 13.422003
## sample estimates:
## mean of x mean of y 
## 15.333333  4.916667

The mean insect count of Spray D is significantly smaller than that of Spray B, i.e., Spray D is a more effective insecticide.