#Example 2 # Testing hypothesis about the population mean when the # population standard deviation is unknown #Set working directory setwd("~/Dropbox/ISI SCB/Data sets") # read in csv file bc <-read.csv("hyp1example2.csv", TRUE) #assign the list of bacteria counts to the variable x x <- bc$bacteria #assumed population mean mu <- 190 #sample size n <- length(x) n #sample mean xbar <- mean(x) xbar #sample standard deviation s =sd(x) s #hypotheses #H0: mu <= 190 #H1: mu > 190 #test statistic ts <- (xbar - mu)/(s/sqrt(n)) ts #upper critical value - 95th percentile (0.95th quantile) upper_t05_9 <- qt(.95,n-1) upper_t05_9 #plot of density function of t-distribution curve(dt(x,n-1), from = -4, to = 4, main = 't-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=upper_t05_9,col="red") #p-value #plot of density function of t-distribution curve(dt(x,n-1), from = -4, to = 4, main = 't-Distribution', ylab = 'Density', xlab = '') #location of the test statistic abline(v=ts,col="blue") #p-value #P(t > ts) pvalue <-pt(ts,n-1,lower.tail = FALSE) pvalue #using t.test in Stats R package t.test(x, alternative = "greater", mu = 190, conf.level = 0.95) #check for outliers in data set boxplot(x) #check for normality of data set qqnorm(x) shapiro.test(x)