Compute a wilcox test for control vs. the “Bglu” treatment group
wilcox.test(total_shedding ~ treatment, data = final_shed,subset = treatment %in%c("control", "Bglu"))
Wilcoxon rank sum exact test
data: total_shedding by treatment
W = 23, p-value = 0.04326
alternative hypothesis: true location shift is not equal to 0
Basics
Using the R Reference Card (and the Help pages, if needed), do the following:
Find out how many rows and columns the `iris’ data set has. Figure out at least 2 ways to do this. Hint: “Variable Information” section on the first page of the reference card!
nrow(iris)
[1] 150
ncol(iris)
[1] 5
dim(iris)
[1] 150 5
Use the rep function to construct the following vector: 1 1 2 2 3 3 4 4 5 5 Hint: “Data Creation” section of the reference card
rep(1:5, each =2)
[1] 1 1 2 2 3 3 4 4 5 5
Use rep to construct this vector: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
rep(1:5, times =3)
[1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Find out how many pigs had a total shedding value of less than 30 log10 CFUs. Hint: if you use the sum function on a logical vector, it’ll return how many TRUEs are in the vector:
sum(c(TRUE, TRUE, FALSE, TRUE, FALSE))
[1] 3
sum(shed$total_shedding < .30)
[1] 66
More Challenging: Calculate the sum of the total shedding log10 CFUs of all pigs with a total shedding value of less than 30 log10 CFUs
sum(shed$total_shedding[shed$total_shedding <30])
[1] 1930.403
Which pigs have a shedding value less than or equal to 30 OR is in the Acid treatment group?
Step Further. Create a data frame of observations where Sepal Length is greater than 6. Then create another column in the this data frame, that is the sum of Sepal Width and Sepal Length
How many rows are in iris data set? (try finding this using dim or indexing + length)
dim(iris)
[1] 150 5
Summarize the values in each column in iris data set
summary(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
Median :5.800 Median :3.000 Median :4.350 Median :1.300
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
Species
setosa :50
versicolor:50
virginica :50
Packages and Programming
Create a function that takes numeric input and provides the mean and a 95% confidence interval for the mean for the data (the t.test function could be useful)