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
sugar <- read.csv("~/Desktop/BIN510-files/cane.csv")
How many rows does the data set have? (2 pts) # There are 180 rows in the data set.
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)
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)
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
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" ...
meandisbv <- aggregate(diseaseStems ~ block + variety, data = sugar, FUN = mean)
hist(sugar$nStems)
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.
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")
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")