In: Statistics and Probability
Using the Iris dataset in R;
PLEASE CREATE YOUR OWN FUNCTION USING FORMULAS INTEAD OF FUNCTIONS THAT ARE BUILT IN R ,,,,,PLEASE TRY PLEASE
a Carry out a hypothesis to test if the population sepal length mean is 6.2 at α = 0.05. Interpret your results.
b Carry out a hypothesis to test if the population sepal width mean is 4 at α = 0.05. Interpret your results.
c Carry out a hypothesis to test if the population sepal width mean is 3 for the Versicolor species at α = 0.05. Interpret your results. d Carry out a hypothesis to test if the population sepal length mean is 6 for the Setosa species at α = 0.05. Interpret your results. d Carry out a hypothesis to test if there is any statistical difference sepal lengths of the Setosa and Versicolor species at α = 0.05. Interpret your results. e Carry out a hypothesis to test if there is any statistical difference petal widths of the Versicolor and the Verginica species at α = 0.05. Interpret your results.
Solution:
R CODE and OUTPUT with INTERPRETATION
(a)
> x=iris$Sepal.Length;t.test(x,mu=6.2,alternative="two.sided",conf.level=0.95)
One Sample t-test
data: x
t = -5.2753, df = 149, p-value = 4.589e-07
alternative hypothesis: true mean is not equal to 6.2
95 percent confidence interval:
5.709732 5.976934
sample estimates:
mean of x
5.843333
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that the mean sepal length is not equal to 6.2.
(b)
> y=iris$Sepal.Width;t.test(y,mu=4,alternative="two.sided",conf.level=0.95)
One Sample t-test
data: y
t = -26.488, df = 149, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 4
95 percent confidence interval:
2.987010 3.127656
sample estimates:
mean of x
3.057333
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that the mean sepal width is not equal to 4.
(c)
>z=iris$Sepal.Width[which(Species=="versicolor")];t.test(z,mu=3,alternative="two.sided",conf.level=0.95)
One Sample t-test
data: z
t = -5.1828, df = 49, p-value = 4.121e-06
alternative hypothesis: true mean is not equal to 3
95 percent confidence interval:
2.68082 2.85918
sample estimates:
mean of x
2.77
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that the mean sepal width for versicolor species is not equal to 3.
(d)
>w1=iris$Sepal.Length[which(Species=="setosa")];t.test(w1,mu=6,alternative="two.sided",conf.level=0.95)
One Sample t-test
data: w1
t = -19.94, df = 49, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 6
95 percent confidence interval:
4.905824 5.106176
sample estimates:
mean of x
5.006
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that the mean sepal length for setosa is not equal to 6.
(e)
>w2=iris$Sepal.Length[which(Species=="versicolor")];t.test(w1,w2,mu=0,alternative="two.sided",conf.level=0.95)
Welch Two Sample t-test
data: w1 and w2
t = -10.521, df = 86.538, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to
0
95 percent confidence interval:
-1.1057074 -0.7542926
sample estimates:
mean of x mean of y
5.006 5.936
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that there is significant difference between sepal length of versicolor and setosa.
(f)
>
u1=iris$Petal.Width[which(Species=="versicolor")];u2=iris$Petal.Width[which(Species=="virginica")]
> t.test(u1,u2,mu=0,alternative="two.sided",conf.level=0.95)
Welch Two Sample t-test
data: u1 and u2
t = -14.625, df = 89.043, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to
0
95 percent confidence interval:
-0.7951002 -0.6048998
sample estimates:
mean of x mean of y
1.326 2.026
CONCLUSION:
p-value is quite low indicating there is strong evidence to claim that there is significant difference between petal width of versicolor and virginica.
Please give upvote.
Thank you.