set.seed(7595)
n = 100
one_sample = sample(marbles, n)
p_hat = mean(one_sample == red_marble)
print(str_glue("Percentage of red marbles: {p_hat * 100}%"))
Percentage of red marbles: 58%
z-score: 1.6
p-value: 0.11
Unveiling the Truth Behind Statistical Decisions
\[H_0: p = 0.5\] \[H_a: p \neq 0.5\]
set.seed(7595)
n = 100
one_sample = sample(marbles, n)
p_hat = mean(one_sample == red_marble)
print(str_glue("Percentage of red marbles: {p_hat * 100}%"))
Percentage of red marbles: 58%
z-score: 1.6
p-value: 0.11
Since \(-1.96 < 1.6 < 1.96\) or \(0.11 > 0.05\), we fail to reject the null hypothesis at the 0.05 level and conclude that the proportion of red marbles is 50%.
\(H_0\) is true | \(H_0\) is false | |
---|---|---|
Reject \(H_0\) | Type I error | Correct decision |
Fail to reject \(H_0\) | Correct decision | Type II error |
\[\text{Prob}(\text{Reject } H_0 \mid H_0 \text{ is true}) = \alpha\]
\[\text{Prob}(\text{Do not reject } H_0 \mid \mu = \hat p)\]
ls = 0.5 - 1.96 * 0.05
rs = 0.5 + 1.96 * 0.05
p2=p1 + stat_function(fun = dnorm, args = list(mean = p_hat, sd = se), color = "blue") +
stat_function(fun = function(x) dnorm(x, p_hat, se),
xlim = c(ls, rs), fill = "gray50", geom = "area") +
geom_vline(xintercept = p_hat, color = "blue", linetype = "dashed") +
geom_point(x = p_hat, y = 0, color = "blue", size = 3) +
annotate("text", x = 0.545, y = 2, label = "Type II Error", color = "white")
p2
The Power of a test is the probability of rejecting a false null hypothesis.
\[\text{Power} = \text{Prob}(\text{Reject } H_0 \mid \mu = \hat p) = 1 - \text{Prob(Type II Error)}\]
p_hat = 0.69; se = sqrt(p_hat * (1 - p_hat) / n)
p3 = p + stat_function(fun = dnorm, args = list(mean = p_hat, sd = se), color = "blue") +
stat_function(fun = function(x) dnorm(x, p_hat, se),
xlim = c(ls, rs), fill = "gray50", geom = "area") +
geom_vline(xintercept = 0.69, color = "blue", linetype = "dashed") +
geom_point(x = 0.69, y = 0, color = "blue", size = 3)
p3
\[\bar X \sim \mathcal{N}(\mu, \frac{\sigma^2}{n})\]
n = 400
p_hat = 0.58
se = sqrt(p_hat * (1 - p_hat) / n)
ls = 0.5 - 1.96 * sqrt(0.5 * (1 - 0.5) / n)
rs = 0.5 + 1.96 * sqrt(0.5 * (1 - 0.5) / n)
p4 = critical_region_plot(0.5, sqrt(0.5 * (1 - 0.5) / n)) +
geom_vline(xintercept = 0.5, color = "black", linetype="dashed") +
geom_point(x = 0.58, y = 0, color = "blue", size = 3) +
stat_function(fun = dnorm, args = list(mean = p_hat, sd = se), color = "blue") +
stat_function(fun = function(x) dnorm(x, p_hat, se),
xlim = c(ls, rs), fill = "gray50", geom = "area") +
geom_vline(xintercept = p_hat, color = "blue", linetype = "dashed") +
geom_point(x = p_hat, y = 0, color = "blue", size = 3) +
annotate("text", x = 0.535, y = 0.5, label = "Type II Error", color = "white")
p4