- Homework 3 is out
- Have posted some guide lines to follow for Project 1
- For this Friday, the first hour of class will be a lecture
- Read Introduction to Statistics with R (Chapter 7: ANOVA and Kruskal Wallis)
Patrick D. Schloss, PhD (microbialinformatics.github.io)
Department of Microbiology & Immunology
range <- seq(12, 22, 0.5)
plot(x = range, dnorm(range, 17, 2), type = "l", ylab = "Density", xlab = "Weight (g)",
ylim = c(0, 0.6), lwd = 2)
sim1 <- rnorm(20, 17, 2)
sim2 <- rnorm(20, 17, 2)
sim1.h <- hist(sim1, breaks = 10, plot = FALSE)
points(sim1.h$mids, sim1.h$density, type = "l", col = "red", lwd = 2)
sim2.h <- hist(sim2, breaks = 10, plot = FALSE)
points(sim2.h$mids, sim2.h$density, type = "l", col = "blue", lwd = 2)
t.test(sim1, sim2)
##
## Welch Two Sample t-test
##
## data: sim1 and sim2
## t = 0.1968, df = 195.3, p-value = 0.8442
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.5347 0.6533
## sample estimates:
## mean of x mean of y
## 16.95 16.89
t.test(rnorm(20, 17, 2), rnorm(20, 17, 2))
##
## Welch Two Sample t-test
##
## data: rnorm(20, 17, 2) and rnorm(20, 17, 2)
## t = 0.9921, df = 37.68, p-value = 0.3275
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.7551 2.2057
## sample estimates:
## mean of x mean of y
## 16.98 16.25
t.test(rnorm(20, 17, 2), rnorm(20, 17, 2))$p.value
## [1] 0.7176
p <- replicate(1000, t.test(rnorm(20, 17, 2), rnorm(20, 17, 2))$p.value)
summary(p)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0002 0.2560 0.5020 0.5010 0.7450 1.0000
sum(p<0.05) / 1000
## [1] 0.064
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.349
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.335
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 18, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.867
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.358
p <- replicate(1000, t.test(rnorm(40, 16, 2), rnorm(40, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.609
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.333
p <- replicate(1000, t.test(rnorm(40, 16, 1.5), rnorm(40, 17, 1.5))$p.value)
sum(p<0.05) / 1000
## [1] 0.861
p <- replicate(1000, t.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.316
p <- replicate(1000, wilcox.test(rnorm(20, 16, 2), rnorm(20, 17, 2))$p.value)
sum(p<0.05) / 1000
## [1] 0.317
p <- replicate(1000, t.test(rnorm(58, 16, 4.8), rnorm(60, 17, 4.8))$p.value)
sum(p<0.05) / 1000
## [1] 0.21
N <- seq(50,500,10)
getPower <- function(N){
p.values <- replicate(1000, t.test(rnorm(N, 16, 4.8), rnorm(N, 17, 4.8))$p.value)
power <- sum(p.values<0.05)/1000
return(power)
}
power.curve <- sapply(N, getPower)
power.t.test(n=NULL, delta=1.0, sd=4.8, sig.level=0.05, power=0.8) #what's the required N?
power.t.test(n=60, delta=1.0, sd=4.8, sig.level=0.05, power=NULL) #what's the power?
power.t.test( n=60, delta=1.0, sd=NULL, sig.level=0.05, power=0.8) #what's the required sd?
power.t.test(n=60, delta=NULL, sd=4.8, sig.level=0.05, power=0.8) #what's the required N?
power.t.test(n=NULL, delta=1.0, sd=4.8, sig.level=0.05, power=0.8) #what's the required N?
##
## Two-sample t test power calculation
##
## n = 362.6
## delta = 1
## sd = 4.8
## sig.level = 0.05
## power = 0.8
## alternative = two.sided
##
## NOTE: n is number in *each* group
power.t.test(n=NULL, delta=0.5, sd=2, sig.level=0.05, power=0.9, type="one.sample")
power.t.test(n=NULL, delta=0.5, sd=2, sig.level=0.05, power=0.9, type="paired")
power.prop.test(power=0.80, p1=0.15, p2=0.30) #test of proportions