In this exp we compare to groups, who got the VC supplement and the other who got the OJ supplement.
We consider the two groups to be Independent as theres no matching of the subjects between them and considering tooth growth may be subjected to only one subject in an experiment.
For calculating T-Intervals,we consider 95% confidence, variances as different and alpha value is 0.05.

Exploring the Data Set

head(ToothGrowth)         #view first six observations of the data set
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5
str(ToothGrowth)        #to view no. of observations of variables, with type
## '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: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
summary(ToothGrowth)    #To see statistical summary of the data set
##       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

Summarizing the Data Set

library(ggplot2)
library(dplyr)
data(ToothGrowth)
g1<-ggplot(ToothGrowth,aes(x=supp,y=len))
g1 + geom_point(size =5, pch = 21, fill = "steelblue", alpha = .5)+facet_grid(.~dose)

By quickly summarizing from the graph we see that for doses ‘0.5’ and ‘1’ the lengths of tooth growth for the supplement ‘OJ’ are relatively higher than that of the supplement ‘VC’.
Whereas, the lenghts of tooth growth for the supplement ‘VC’ are having a higher range for dose ‘2’.

Calculating the T-Confidence Intervals of the 0.5 dose data.

We load the required variables with the data. Here, vcsup and ojsup are the variables containing the VC and OJ supplements data. The vcdose and ojdose variables contain data specific to their VC and OJ supplement doses respectively.

vcsup<-filter(ToothGrowth,supp=="VC")               
vcsup<-vcsup[,c(1,3)];names(vcsup)[2]<-"VC_dose"    #only VC data
vcdose05<-filter(vcsup,VC_dose==0.5)                #0.5 dose, VC data
vcdose1<-filter(vcsup,VC_dose==1)                   #1 dose, VC data
vcdose2<-filter(vcsup,VC_dose==2)                   #2 doses, VC data

ojsup<-filter(ToothGrowth,supp=="OJ")
ojsup<-ojsup[,c(1,3)];names(ojsup)[2]<-"OJ_dose"    #only OJ data
ojdose05<-filter(ojsup,OJ_dose==0.5)                #0.5 dose, OJ data
ojdose1<-filter(ojsup,OJ_dose==1)                   #1 dose, OJ data
ojdose2<-filter(ojsup,OJ_dose==2)                   #2 doses, OJ data

We consider the groups to be independent with different variances.
For calculating the T-Interval we use the t.test().
Test Statistic here is: ((Xmean-Ymean) +/-tdf) /sqrt(Sx2/nx+Sy2/ny)
Degree of freedom equal to, df=(sx2/nx+sy2/ny)2/(sx2/nx)2/(nx-1)+(sy2/ny)^2/(ny-1)

Comparing the tooth growth based on the 0.5 dose, supplement OJ Vs VC.

We calculate the 95% t-confidence intervals for the supplements OJ and VC with dose amount 0.5.

t.test(ojdose05$len,vcdose05$len,paired=FALSE,var.equal=FALSE)$conf.int[c(1,2)]
## [1] 1.719057 8.780943

Therefore, we can be 95% confident that the mean tooth growth length by supplement OJ is between 1.719057 and 8.780943 larger than the mean tooth growth by supplement VC with dose amount 0.5.

Comparing the tooth growth based on the 1 dose, supplement OJ Vs VC.

t.test(ojdose1$len,vcdose1$len,paired=FALSE,var.equal=FALSE)$conf.int[c(1,2)]
## [1] 2.802148 9.057852

Therefore, we can be 95% confident that the mean tooth growth length by supplement OJ is between 2.802148 and 9.057852 larger than the mean tooth growth by supplement VC with dose amount 1.

Comparing tooth growth based on the 2 dose, supplement OJ Vs VC.

t.test(ojdose2$len,vcdose2$len,paired=FALSE,var.equal=FALSE)$conf.int[c(1,2)]
## [1] -3.79807  3.63807

Therefore, we can be 95% confident that the actual mean difference in the size of tooth growth is between -3.63807 and 3.79807 for dose amount 2. Because the interval contains the value 0, we cannot conclude that the population means differ.

Performing hypothesis tests on 2 dose data.

Here, our Null Hypothesis,H0, is: Difference between the means of the lengths of the two supplements for Tooth growth is zero.
Our Alternate Hypothesis is: Difference between the means of the lengths of the two supplements for Tooth growth is not equal to zero.
We use alpha as 0.05,df as in above stated formula and Test Statistic: T=(X¯???Y¯)???(??X?????Y)/???(Sx2/nx+Sy2/ny)

(mean(vcdose2$len)-mean(ojdose2$len)-0)/(sqrt(var(vcdose2$len)/30-var(ojdose2$len)/30)) #Test Statistc
## [1] 0.1096512
round(t.test(ojdose2$len,vcdose2$len,paired=FALSE,var.equal=F)$parameter) #Degrees of Freedom
## df 
## 14

Hence, there is sufficient evidence at the alpha = 0.05, df=14, to conclude that the mean of tooth growth lengths caused by supplement OJ differs from the mean of tooth growth lengths caused by supplement VC with dose amount 2.