<- 30; n2 <- 30
n1 <- 20; mu2 <- 20
mu1 <- 5; sigma2 <- 5
sigma1
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2), type = "l")
lines(dnorm(x_range, mu2, sigma2), col = "red")
p-values
p-values
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2/sqrt(n1)), type = "l")
lines(dnorm(x_range, mu2, sigma2/sqrt(n2)), col = "red")
<- 1
B
<- rnorm(n1, mean = mu1, sd = sigma1)
x <- rnorm(n2, mean = mu2, sd = sigma2)
y
hist(x)
hist(y)
t.test(x, y, var.equal = FALSE)
Welch Two Sample t-test
data: x and y
t = 2.0308, df = 57.751, p-value = 0.04688
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.04186283 5.83338647
sample estimates:
mean of x mean of y
21.88547 18.94785
<- 20; mu2 <- 20
mu1
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2), type = "l")
lines(dnorm(x_range, mu2, sigma2), col = "red")
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2/sqrt(n1)), type = "l")
lines(dnorm(x_range, mu2, sigma2/sqrt(n2)), col = "red")
<- 1000
B
<- replicate(B, t.test( rnorm(n1, mean = mu1, sd = sigma1), rnorm(n2, mean = mu2, sd = sigma2), var.equal = FALSE)$p.value)
p_values
hist(p_values)
plot(p_values, type = "l")
abline(a = 0.05, b = 0, col = "purple")
<- 20; mu2 <- 22
mu1
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2), type = "l")
lines(dnorm(x_range, mu2, sigma2), col = "red")
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2/sqrt(n1)), type = "l")
lines(dnorm(x_range, mu2, sigma2/sqrt(n2)), col = "red")
<- 1000
B
<- replicate(B, t.test( rnorm(n1, mean = mu1, sd = sigma1), rnorm(n2, mean = mu2, sd = sigma2), var.equal = FALSE)$p.value)
p_values
hist(p_values)
plot(p_values, type = "l")
abline(a = 0.05, b = 0, col = "purple")
<- 20; mu2 <- 24
mu1
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2), type = "l")
lines(dnorm(x_range, mu2, sigma2), col = "red")
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2/sqrt(n1)), type = "l")
lines(dnorm(x_range, mu2, sigma2/sqrt(n2)), col = "red")
<- 1000
B
<- replicate(B, t.test( rnorm(n1, mean = mu1, sd = sigma1), rnorm(n2, mean = mu2, sd = sigma2), var.equal = FALSE)$p.value)
p_values
hist(p_values)
plot(p_values, type = "l")
abline(a = 0.05, b = 0, col = "purple")
<- 20; mu2 <- 26
mu1
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2), type = "l")
lines(dnorm(x_range, mu2, sigma2), col = "red")
<- seq(mu1 - 3*sigma1, mu1 + 3*sigma1, length.out = 100)
x_range plot(dnorm(x_range, mu1, sigma2/sqrt(n1)), type = "l")
lines(dnorm(x_range, mu2, sigma2/sqrt(n2)), col = "red")
<- 1000
B
<- replicate(B, t.test( rnorm(n1, mean = mu1, sd = sigma1), rnorm(n2, mean = mu2, sd = sigma2), var.equal = FALSE)$p.value)
p_values
hist(p_values)
plot(p_values, type = "l")
abline(a = 0.05, b = 0, col = "purple")