For this exam you will be using the “cane.csv” file found on Canvas:

The “cane.csv” file looks at data from an experiment looking at the disease risk of different varieties of sugar cane and how different treatments could impact the levels of disease. The file contains several columns of data:

“nStems” = total number of stems “diseaseStems” = total number of stems with disease “variety” = the type of sugar cane “block” = treatment

  1. bring in the dataset and name it “sugar” (1 pt)
sugar <- read.csv("~/Desktop/BIN510-files/cane.csv")
  1. How many rows does the data set have? (2 pts) # There are 180 rows in the data set.

  2. What are the types of variables contained in the dataset? (2 pts) # There are 4 data types in the dataset 1.nStems(total number of stems) 2. diseaseStems(diseased stems) 3. variety(sugarcane type) 4. block (treatment)

  3. Calculate the mean and standard deviation of the “diseaseStems” column (4 pts)

meandiseased <- mean(sugar$diseaseStems, na.rm = TRUE)
stdvdiseased <- sd(sugar$diseaseStems, na.rm = TRUE)
  1. Calculate the mean of the “diseaseStems” column for each “block” (3 pts)
aggregate(diseaseStems ~ block, data = sugar, FUN = mean)
##   block diseaseStems
## 1     A     18.57778
## 2     B     25.48889
## 3     C     17.44444
## 4     D     19.51111
  1. Convert the “variety” column from a number to a factor - YOU MAY NEED TO LOOK THIS UP! (2 pts)
sugar$variety <- as.factor(sugar$variety)
str(sugar)
## 'data.frame':    180 obs. of  4 variables:
##  $ nStems      : int  87 119 94 95 134 92 118 70 128 85 ...
##  $ diseaseStems: int  76 8 74 11 0 0 11 32 33 14 ...
##  $ variety     : Factor w/ 45 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ block       : chr  "A" "A" "A" "A" ...
  1. Calculate the mean of the “diseaseStems” column for each “block” AND “variety” - YOU CANNOT DO THIS WITHOUT COMPLETING 6 (4 points)
meandisbv <- aggregate(diseaseStems ~ block + variety, data = sugar, FUN = mean) 
  1. Plot a histogram of “nStems” (2 pts)
hist(sugar$nStems)

  1. Does the histogram of “nStems” appear to be normally distributed? (2 pts) # The data on the histogram seems to be normally distributed, there is a clear bell-shaped curve.

  2. Create a boxplot for “diseaseStems” by “block” - create the plot so that each block has a different color box (6 pts)

boxplot(diseaseStems ~ block,
        data = sugar,
        col = c("pink", "orange", "turquoise", "grey"),
        xlab = "Block",
        ylab = "Disease Stems",
        main = "Disease Stems by Block")

  1. Does it appear that “block” influences the number of diseases stems? Why or why not? (2 pts) # Yes, it does appear that the block influences the number of diseased stems. This is shown by each block having a higher/lower number on the graph.

BONUS: 5 pts total (3 for A, 2 for B) A. Create a new column for your dataset that creates the proportion or percentage of diseased stems for each plot

propordise <- sugar$proportionDiseased <- sugar$diseaseStems / sugar$nStems
percentdis <- sugar$percentDiseased <- (sugar$diseaseStems / sugar$nStems) * 100
head(sugar)
##   nStems diseaseStems variety block proportionDiseased percentDiseased
## 1     87           76       1     A         0.87356322       87.356322
## 2    119            8       2     A         0.06722689        6.722689
## 3     94           74       3     A         0.78723404       78.723404
## 4     95           11       4     A         0.11578947       11.578947
## 5    134            0       5     A         0.00000000        0.000000
## 6     92            0       6     A         0.00000000        0.000000

B. Create a boxplot for the new column by “block”

boxplot(proportionDiseased ~ block,
        data = sugar,
        col = c("royalblue", "darkgray", "hotpink", "black"),
        xlab = "Block",
        ylab = "Proportion of Diseased Stems",
        main = "Proportion of Diseased Stems by Block")