# load the packages we will need
library(data.table)
library(ggplot2)

# clean session
rm(list=ls())

# 1
# Assume X ~ Normal(mu_x, sig_x)
# Then Null and alternative H's are:
# H0: mu_x = 58
# H1: mu_x > 58

# type I error (alpha) = 0.05
type_I_error <- 0.05

# estimate mu_x with mu_x_hat = x_bar
x <- c(63.97,
      60.29,
      85.60,
      72.57,
      54.65,
      53.74,
      69.13,
      70.07,
      67.19,
      53.95
     )

n <- length(x)
x_bar_obs <- mean(x)

# define the sampling distribution of x_bar:
#
# X ~ Normal(mu_x, sig_x)
# X_bar ~ Normal(mu_x_bar, sig_x_bar)
#
# mu_x_bar = mu_x
# sig_x_bar = sig_x / sqrt(n)

mu_x = 58
sig_x = sqrt(10) # given in the problem

mu_x_bar <- mu_x # from central limit theorem
sig_x_bar <- sig_x / sqrt(n) # from central limit theorem

# critical value
critical_value <- qnorm(type_I_error, mu_x_bar, sig_x_bar, lower.tail=F)

# p-value
p_value <- pnorm(x_bar_obs, mu_x_bar, sig_x_bar, lower.tail=F)

ans_1_test_stat_obs <- x_bar_obs
ans_1_critical_value <- critical_value
ans_1_p_value <- p_value

# 2
theta_hat_obs <- 8 # read off of the plot
p_value <- 0.138240 + 0.036864 + 0.004096 # what you observed plus more extreme outcomes
critical_value <- 10 # because at this value and beyond the p-val would be < 0.05 and we would reject H0

ans_3_critical_value <- critical_value
ans_3_p_value <- p_value

# 3
ans_4a <- "alpha"
ans_4b <- "confidence"
ans_4c <- "power"
ans_4d <- "beta"
ans_4e <- 0.5
ans_4f <- 0.95
ans_4g <- "NO"