- Homework 3 is out
- For the next two Fridays, the first hour of class will be a lecture
- Read Introduction to Statistics with R (Chapter 9: Power analysis and Chapter 7: ANOVA and Kruskal Wallis)
Patrick D. Schloss, PhD (microbialinformatics.github.io)
Department of Microbiology & Immunology
\[\bar x=\frac{\sum x_i}{n}\]
\[SD = \sqrt{\frac{\sum(x_i-\bar x)^2}{n-1}}\]
\[SE = \frac{SD}{\sqrt{n}}\]
\[\mbox{Upper 95% limit} = \bar x + (SE \times 1.96)\] \[\mbox{Lower 95% limit} = \bar x - (SE \times 1.96)\]
When you plot data with "error bars" you must indicate...
pmg.se <- sd(pmg.weights)/sqrt(length(pmg.weights))
pmg.ci <- mean(pmg.weights) + pmg.se * c(-1.95,1.95)
pmg.ci
## [1] 15.79 18.28
pl.se <- sd(pl.weights)/sqrt(length(pl.weights))
pl.ci <- mean(pl.weights) + pl.se * c(-1.95,1.95)
pl.ci
## [1] 14.82 17.23
\[t=\frac{\bar x_2 - \bar x_1}{\sqrt{SE_1^2+SE_2^2}}\]
pt
function and a two-tailed test we get a P-value of 0.2595.t.test(pl.weights, pmg.weights)
##
## Welch Two Sample t-test
##
## data: pl.weights and pmg.weights
## t = -1.133, df = 116, p-value = 0.2595
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.7686 0.7536
## sample estimates:
## mean of x mean of y
## 16.03 17.03
No.
t.test(pl.weights, pmg.weights, alternative="greater")
##
## Welch Two Sample t-test
##
## data: pl.weights and pmg.weights
## t = -1.133, df = 116, p-value = 0.8702
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## -2.482 Inf
## sample estimates:
## mean of x mean of y
## 16.03 17.03
No.
t.test(pl.weights, pmg.weights, alternative="less")
##
## Welch Two Sample t-test
##
## data: pl.weights and pmg.weights
## t = -1.133, df = 116, p-value = 0.1298
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 0.4668
## sample estimates:
## mean of x mean of y
## 16.03 17.03
No.
\[t=\frac{\bar x - x_o}{SE}\]
We can test against a t distribution with n-1 degrees of freedom
For this example, we get a t of 1.6583 and a P-value of 0.1027
t.test(pl.weights, mu=15)
##
## One Sample t-test
##
## data: pl.weights
## t = 1.658, df = 57, p-value = 0.1028
## alternative hypothesis: true mean is not equal to 15
## 95 percent confidence interval:
## 14.79 17.26
## sample estimates:
## mean of x
## 16.03
first <- pl.weights[1:40]
second <- pmg.weights[1:40]
diff <- first-second
hist(diff, main="")
\[t=\frac{\bar x}{SE}\]
diff.mean <- mean(diff)
diff.se <- sd(diff)/sqrt(length(diff))
t <- diff.mean / diff.se
df <- length(diff) - 1
p <- 2 * pt(t, df)
We get a P-value of 0.0384, which indicates the mice had a significant change in weight over the two time points
t.test(first, second, paired=TRUE)
##
## Paired t-test
##
## data: first and second
## t = -2.143, df = 39, p-value = 0.03837
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -4.1789 -0.1211
## sample estimates:
## mean of the differences
## -2.15
wilcox.test
is virutally identical to that of t.test
wilcox.test(pl.weights, pmg.weights)
##
## Wilcoxon rank sum test with continuity correction
##
## data: pl.weights and pmg.weights
## W = 1525, p-value = 0.2474
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(pl.weights, mu=15)
##
## Wilcoxon signed rank test with continuity correction
##
## data: pl.weights
## V = 867, p-value = 0.1804
## alternative hypothesis: true location is not equal to 15
wilcox.test(first, second, paired=TRUE)
## Warning: cannot compute exact p-value with ties
## Warning: cannot compute exact p-value with zeroes
##
## Wilcoxon signed rank test with continuity correction
##
## data: first and second
## V = 180.5, p-value = 0.01685
## alternative hypothesis: true location shift is not equal to 0