1. Data

A=c(45.3, 66.3, 52.5, 51.4, 53.4, 60.1, 49.1, 64.5, 51.0, 52.7)
B=c(55.2, 40.3, 46.5, 55.6, 48.9, 46.7, 53.4, 43.2)
value=c(A,B);Group=c(rep("A",10),rep("B",8));dat=as.data.frame(cbind(Group,value))
dat$value=as.numeric(as.character(dat$value))
str(dat)
## 'data.frame':    18 obs. of  2 variables:
##  $ Group: Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
##  $ value: num  45.3 66.3 52.5 51.4 53.4 60.1 49.1 64.5 51 52.7 ...
par(mfrow=c(1,2)); plot(density(A),col="blue"); plot(density(B),col="blue")

2. Independent t-test

t.test(A,B)     # Assumption: paired=F, var.equal=F, mu=0
## 
##  Welch Two Sample t-test
## 
## data:  A and B
## t = 2.0178, df = 15.961, p-value = 0.06074
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2999224 12.1099224
## sample estimates:
## mean of x mean of y 
##    54.630    48.725
Compare Var(A) vs Var(B)
Ho is Var(A) = Var(B) if p<.05 –> Var(A) is different with Var(B) –>t.test(value~Group)
Ho is Var(A) = Var(B) if p>.05 –> Var(A)=Var(B) –>t.test(value~Group,var.equal=T)
var.test(value~Group)$p.value   
## [1] 0.6353104
t.test(dat$value~dat$Group)     # Similar with command t.test(A,B)
## 
##  Welch Two Sample t-test
## 
## data:  dat$value by dat$Group
## t = 2.0178, df = 15.961, p-value = 0.06074
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2999224 12.1099224
## sample estimates:
## mean in group A mean in group B 
##          54.630          48.725
t.test(dat$value~dat$Group,var.equal=T)
## 
##  Two Sample t-test
## 
## data:  dat$value by dat$Group
## t = 1.9742, df = 16, p-value = 0.06588
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4356878 12.2456878
## sample estimates:
## mean in group A mean in group B 
##          54.630          48.725
Result: There is no statistical evidence to reject the nun-hypothesis that mean A = mean B

3. Bootstrap

Ref: Phan tich du lieu voi R (NVT) pp:365-366

set.seed(123)                       # The random samples may different with those created by Prof. NVT
n1=length(A); n2=length(B)
difference=numeric(10000)               # Create a space to store values of "difference"
no.effect=0                         # Create a space to store values of "no.effect"
for(i in 1:10000){                      # loop 10000 times
              bt.A=sample(A,n1,replace=T)
              bt.B=sample(B,n2,replace=T)
              difference[i]=mean(bt.A)-mean(bt.B)
              if (difference [i]<0) no.effect = no.effect+1
}
no.effect/10000                     # number of samples with "difference" <0
## [1] 0.0168
quantile(difference,probs=c(0.025,0.5,0.975)) # 95% interval of "difference"
##     2.5%      50%    97.5% 
##  0.48750  5.86000 11.50269
Result:
- There is evidence to conclude that mean of A is higher than mean of B
- 95% CI of difference between mean of A and mean of B is not similar with that provided by t-test (trust bootstrap result)
plot(density(difference),col="blue")