#Example 1 # Testing hypothesis about the population mean when the # population standard deviation is known #assumed population mean mu <- 15 #sample size n <- 70 #sample mean xbar <- 14.18 # population standard deviation sigma <- 3 #hypotheses #H0: mu >= 15 #H1: mu < 15 #test statistic ts <- (xbar - mu)/(sigma/sqrt(n)) ts #lower critical value - 5th percentile (0.05th quantile) lower_z05 <- qnorm(.05) lower_z05 #plot of standard normal density function curve(dnorm(x), from = -4, to = 4, main = 'Standard Normal Distribution', ylab = 'Density', xlab = '') #location of the test statistic and critical value abline(v=ts,col="blue") #location of the lower critical value abline(v=lower_z05,col="red") #p-value #plot of standard normal density function curve(dnorm(x), from = -4, to = 4, main = 'Standard Normal Distribution', ylab = 'Density', xlab = '') #location of the test statistic abline(v=ts,col="blue") #p-value #P(Z < ts) pvalue <-pnorm(ts,lower.tail = TRUE) pvalue