#One Sample T Test - Comparing our current data sample with a new data sample
Suppose we are interested in whether a new manufacturing technique takes more/less time than our current system in which the mean manufacturing time is 43.4 minutes.
#dataset1
meantime1 <- c(86, 73, 50, 73, 24, 65, 84, 54, 16, 26)
meantime1
## [1] 86 73 50 73 24 65 84 54 16 26
summary(meantime1)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 16.0 32.0 59.5 55.1 73.0 86.0
#Normality Test
library(moments)
library(car)
## Warning: package 'car' was built under R version 3.6.2
## Loading required package: carData
plot(density(meantime1))
agostino.test(meantime1) #skewness test
##
## D'Agostino skewness test
##
## data: meantime1
## skew = -0.33887, z = -0.60389, p-value = 0.5459
## alternative hypothesis: data have a skewness
qqnorm(meantime1)
shapiro.test(meantime1) #is the data normally distributed
##
## Shapiro-Wilk normality test
##
## data: meantime1
## W = 0.90928, p-value = 0.2761
#data is normally distributed
res <- t.test(meantime1, mu = 43.4) #mu = mean (old average) value that we want to compare
res
##
## One Sample t-test
##
## data: meantime1
## t = 1.4452, df = 9, p-value = 0.1823
## alternative hypothesis: true mean is not equal to 43.4
## 95 percent confidence interval:
## 36.78584 73.41416
## sample estimates:
## mean of x
## 55.1
res2 <- t.test(meantime1, mu = 43.4, alternative = "less")
res2
##
## One Sample t-test
##
## data: meantime1
## t = 1.4452, df = 9, p-value = 0.9088
## alternative hypothesis: true mean is less than 43.4
## 95 percent confidence interval:
## -Inf 69.94067
## sample estimates:
## mean of x
## 55.1
res3 <- t.test(meantime1, mu = 43.4, alternative = "greater")
res3
##
## One Sample t-test
##
## data: meantime1
## t = 1.4452, df = 9, p-value = 0.09115
## alternative hypothesis: true mean is greater than 43.4
## 95 percent confidence interval:
## 40.25933 Inf
## sample estimates:
## mean of x
## 55.1
#one sample t test shows that there is a significant difference between the old and new system because p-value > 0.05 fail to reject the null hypothesis. Mean of X = 55.1 shwos that new system is taking more time than old sytem with mean of 43.4
We know the mean is 35 and we would like to know if there is any different between the new machine.
#{r starting} #dataset2 meantime2 <- c(90, 68, 57, 76, 39, 65, 84, 68, 46, 29) meantime2 summary(meantime2)
#{r assumptions} #Normality Test library(moments) library(car) plot(density(meantime2)) agostino.test(meantime2) #skewness test qqnorm(meantime2) shapiro.test(meantime2) #is the data normally distributed #data is normally distributed
#```{r one sample t test} res4 <- t.test(meantime2, mu = 35) #mu = mean (old average) value that we want to compare res4
res5 <- t.test(meantime2, mu = 35, alternative = “less”) res5
res6 <- t.test(meantime2, mu = 35, alternative = “greater”) res6
#one sample t test shows that there is a significant difference between the old and new machine because p-value < 0.05 fails to accept the null hypothesis. Mean of X = 62.2 shwos that new system is taking more time than old sytem with mean of 35 ```