t_seq <- seq(-4, 4, length.out = 600)
yt <- dt(t_seq, df = 29)
par(mfrow = c(2, 1), mar = c(3.5, 4, 2.5, 1))
# ---- One-tailed (right) ----
plot(t_seq, yt, type = "l", lwd = 2, col = "navy",
main = expression(paste("One-Tailed (Right): ", alpha, " = 0.05")),
xlab = "", ylab = "Density", ylim = c(0, 0.41))
t_nr <- t_seq[t_seq <= t_one]
polygon(c(t_nr, rev(t_nr)), c(dt(t_nr, df), rep(0, length(t_nr))),
col = "lightgray", border = NA)
t_rj <- t_seq[t_seq >= t_one]
polygon(c(t_rj, rev(t_rj)), c(dt(t_rj, df), rep(0, length(t_rj))),
col = rgb(1, 0, 0, 0.5), border = NA)
abline(v = t_one, lty = 2, col = "steelblue", lwd = 1.8)
text(t_one + 0.15, 0.27, paste0("t* = ", round(t_one, 2)),
col = "steelblue", cex = 0.75, adj = 0)
text(3.3, 0.04, expression(alpha), col = "red", cex = 0.9)
text(-1.5, 0.18, expression(paste("Retain ", H[0])), col = "gray40", cex = 0.8)
text(3.0, 0.15, expression(paste("Reject ", H[0])), col = "red", cex = 0.8)
# ---- Two-tailed ----
plot(t_seq, yt, type = "l", lwd = 2, col = "navy",
main = expression(paste("Two-Tailed: ", alpha, " = 0.05")),
xlab = "t-statistic", ylab = "Density", ylim = c(0, 0.41))
t_nr2 <- t_seq[t_seq >= -t_two & t_seq <= t_two]
polygon(c(t_nr2, rev(t_nr2)), c(dt(t_nr2, df), rep(0, length(t_nr2))),
col = "lightgray", border = NA)
t_L <- t_seq[t_seq <= -t_two]
polygon(c(t_L, rev(t_L)), c(dt(t_L, df), rep(0, length(t_L))),
col = rgb(1, 0, 0, 0.5), border = NA)
t_R <- t_seq[t_seq >= t_two]
polygon(c(t_R, rev(t_R)), c(dt(t_R, df), rep(0, length(t_R))),
col = rgb(1, 0, 0, 0.5), border = NA)
abline(v = -t_two, lty = 2, col = "steelblue", lwd = 1.8)
abline(v = t_two, lty = 2, col = "steelblue", lwd = 1.8)
text(-t_two - 0.15, 0.27, paste0("t* = ", round(-t_two, 2)),
col = "steelblue", cex = 0.75, adj = 1)
text( t_two + 0.15, 0.27, paste0("t* = ", round(t_two, 2)),
col = "steelblue", cex = 0.75, adj = 0)
text(-3.3, 0.04, expression(alpha/2), col = "red", cex = 0.9)
text( 3.3, 0.04, expression(alpha/2), col = "red", cex = 0.9)
text(0, 0.18, expression(paste("Retain ", H[0])), col = "gray40", cex = 0.8)
par(mfrow = c(1,1))