This is the part 2 of the final project from Coursera’s statistical inference course. In this project, we perform inferential analysis on one of the data in R dataset named ToothGrowth. At the end of the analysis, we shall see the relation of between the length of tooth of guinea pigs and supplements given. The dosage effect would also be considered.
First, we load the packages need to perform analysis as well as the data set ToothGrowth.
library(ggplot2)
library(datasets)
data(ToothGrowth)
Next, we look at the first 5 rows of the data with the head function in R. Then, we summarise the whole data to view the ranges. We then assign the required class to needed for analysis. Then we take a look at the data again with the str function.
head(ToothGrowth)
summary(ToothGrowth)
## len supp dose
## Min. : 4.20 OJ:30 Min. :0.500
## 1st Qu.:13.07 VC:30 1st Qu.:0.500
## Median :19.25 Median :1.000
## Mean :18.81 Mean :1.167
## 3rd Qu.:25.27 3rd Qu.:2.000
## Max. :33.90 Max. :2.000
ToothGrowth$dose<-as.factor(ToothGrowth$dose)
str(ToothGrowth)
## 'data.frame': 60 obs. of 3 variables:
## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
## $ dose: Factor w/ 3 levels "0.5","1","2": 1 1 1 1 1 1 1 1 1 1 ...
Now, we visualise the data to get a more detailed idea of the relationship.
gtooth <-ggplot(ToothGrowth,aes(x=dose, y=len, fill=supp))
gtooth <- gtooth + geom_bar(stat = "identity") + facet_grid(.~supp)
gtooth <- gtooth + labs(title = "A graph of Tooth Length relative to Supplements and Dosage",x="Dosage",y="Tooth Length")
gtooth
First, we take the t test of tooth length relative to supplements types.
t.test(len~supp,data=ToothGrowth, paired = F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1710156 7.5710156
## sample estimates:
## mean in group OJ mean in group VC
## 20.66333 16.96333
From our t test analysis, we see that we have a p value of 0.06 which is above the 5% and confidence interval contains zero(0). This implies that we fail to reject our hypothesis.
Next, we take a t test analysis of the Tooth Length relative to each of the three different dosage given.
dose1<-subset(ToothGrowth,dose %in% c(0.5,1))
dose2<- subset(ToothGrowth,dose %in% c(0.5,2.0))
dose3<- subset(ToothGrowth,dose %in% c(1.0,2.0))
t.test(len~dose,data = dose1, paired=F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -6.4766, df = 37.986, p-value = 1.268e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.983781 -6.276219
## sample estimates:
## mean in group 0.5 mean in group 1
## 10.605 19.735
t.test(len~dose,data = dose2, paired=F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -11.799, df = 36.883, p-value = 4.398e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.15617 -12.83383
## sample estimates:
## mean in group 0.5 mean in group 2
## 10.605 26.100
t.test(len~dose,data = dose3, paired=F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -4.9005, df = 37.101, p-value = 1.906e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -8.996481 -3.733519
## sample estimates:
## mean in group 1 mean in group 2
## 19.735 26.100
As analysed above, we see that each dosage analysis relative to length has a p value of approximately zero(0) which is less than the 5% level with non-zero(0) confidence levels. Therefore we reject the hypothesis due to the low p value.
We assume that the supplements administered has no effect on the growth length of the tooth of guinea pigs.
From the analysis, we see at first that the supplements type has no effect on the tooth growth, but after a closer look, we see that the supplements dosage has an effect on the tooth growth