We have to compare the average fat of 2 meat companies
library(ggplot2)
1. create 2 variables with a sample of 10 piezes. First normal being of N(100,30) and the second N(110,35)
meaters <-rnorm(10,100,30)
meatlof <-rnorm(10,110, 35)
3 Test if the means of the amount of fat in the 2 companies should be considered as similiar and interpret the output.
t.test(meaters, alternative = "two.sided", mu = 100)
##
## One Sample t-test
##
## data: meaters
## t = -0.10074, df = 9, p-value = 0.922
## alternative hypothesis: true mean is not equal to 100
## 95 percent confidence interval:
## 72.95996 124.73445
## sample estimates:
## mean of x
## 98.84721
t.test(meatlof, alternative = "two.sided", mu = 110)
##
## One Sample t-test
##
## data: meatlof
## t = -0.22382, df = 9, p-value = 0.8279
## alternative hypothesis: true mean is not equal to 110
## 95 percent confidence interval:
## 79.73793 134.81283
## sample estimates:
## mean of x
## 107.2754
t.test(meaters, alternative = "less", mu = 100)
##
## One Sample t-test
##
## data: meaters
## t = -0.10074, df = 9, p-value = 0.461
## alternative hypothesis: true mean is less than 100
## 95 percent confidence interval:
## -Inf 119.8246
## sample estimates:
## mean of x
## 98.84721
t.test(meatlof, alternative = "less", mu = 110)
##
## One Sample t-test
##
## data: meatlof
## t = -0.22382, df = 9, p-value = 0.4139
## alternative hypothesis: true mean is less than 110
## 95 percent confidence interval:
## -Inf 129.59
## sample estimates:
## mean of x
## 107.2754
t.test(meaters, alternative = "greater", mu = 100)
##
## One Sample t-test
##
## data: meaters
## t = -0.10074, df = 9, p-value = 0.539
## alternative hypothesis: true mean is greater than 100
## 95 percent confidence interval:
## 77.86978 Inf
## sample estimates:
## mean of x
## 98.84721
t.test(meatlof, alternative = "greater", mu = 110)
##
## One Sample t-test
##
## data: meatlof
## t = -0.22382, df = 9, p-value = 0.5861
## alternative hypothesis: true mean is greater than 110
## 95 percent confidence interval:
## 84.96073 Inf
## sample estimates:
## mean of x
## 107.2754
4 Repeat the previous steps with samples of 150 piezes each and compare the results.
meaters2 <-rnorm(150,100,30)
meatlof2 <-rnorm(150,110,35)
summary(meaters2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 32.09 75.86 100.74 99.38 117.18 188.35
summary(meatlof2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -18.84 88.67 108.04 112.13 137.41 222.66
The main difference that we can find in comparison with the sample of 10 is the Min, as it is way lower in both cases. We can also see differences in the mean and in the median, which seem to be closer to the original values.
t.test(meaters2, alternative = "two.sided", mu = 100)
##
## One Sample t-test
##
## data: meaters2
## t = -0.24132, df = 149, p-value = 0.8096
## alternative hypothesis: true mean is not equal to 100
## 95 percent confidence interval:
## 94.26857 104.48390
## sample estimates:
## mean of x
## 99.37623
t.test(meatlof2, alternative = "two.sided", mu = 110)
##
## One Sample t-test
##
## data: meatlof2
## t = 0.6954, df = 149, p-value = 0.4879
## alternative hypothesis: true mean is not equal to 110
## 95 percent confidence interval:
## 106.0818 118.1735
## sample estimates:
## mean of x
## 112.1276
t.test(meaters2, alternative = "greater", mu = 100)
##
## One Sample t-test
##
## data: meaters2
## t = -0.24132, df = 149, p-value = 0.5952
## alternative hypothesis: true mean is greater than 100
## 95 percent confidence interval:
## 95.09796 Inf
## sample estimates:
## mean of x
## 99.37623
t.test(meatlof2, alternative = "greater", mu = 110)
##
## One Sample t-test
##
## data: meatlof2
## t = 0.6954, df = 149, p-value = 0.2439
## alternative hypothesis: true mean is greater than 110
## 95 percent confidence interval:
## 107.0635 Inf
## sample estimates:
## mean of x
## 112.1276
t.test(meaters2, alternative = "less", mu = 100)
##
## One Sample t-test
##
## data: meaters2
## t = -0.24132, df = 149, p-value = 0.4048
## alternative hypothesis: true mean is less than 100
## 95 percent confidence interval:
## -Inf 103.6545
## sample estimates:
## mean of x
## 99.37623
t.test(meatlof2, alternative = "less", mu = 110)
##
## One Sample t-test
##
## data: meatlof2
## t = 0.6954, df = 149, p-value = 0.7561
## alternative hypothesis: true mean is less than 110
## 95 percent confidence interval:
## -Inf 117.1917
## sample estimates:
## mean of x
## 112.1276
As we can see in this comparison