options(scipen=999)
options(digits=9)

x1=c(2.40,2.42,1.87,2.50,2.29,1.68,2.57,1.60,1.65,1.41,
     1.66,1.32,2.43,1.83,1.41)
x2=c(0.79,1.25,0.72,0.84,1.32,1.35,1.29,0.72,0.96,1.13)
xbar1=mean(x1);xbar1
xbar2=mean(x2);xbar2
s1=sd(x1);s1
s2=sd(x2);s2
n1=length(x1);n1
n2=length(x2);n2
mean_difference=xbar1-xbar2;mean_difference
standard_error=sqrt(s1^2/n1+s2^2/n2)
standard_error
df=(s1^2/n1+s2^2/n2)^2/((s1^2/n1)^2/(n1-1)+(s2^2/n2)^2/(n2-1))
df
alpha=0.05
ttable=qt(1-alpha/2,df);ttable
confi_level=ttable*standard_error;confi_level
lower_limit=(xbar1-xbar2)-confi_level;lower_limit
upper_limit=(xbar1-xbar2)+confi_level;upper_limit

df=23
alpha=0.05
ttable=qt(1-alpha/2,df);ttable
confi_level=ttable*standard_error;confi_level
lower_limit=(xbar1-xbar2)-confi_level;lower_limit
upper_limit=(xbar1-xbar2)+confi_level;upper_limit



library("TeachingDemos")
x1=c(2.40,2.42,1.87,2.50,2.29,1.68,2.57,1.60,1.65,1.41,
     1.66,1.32,2.43,1.83,1.41)
x2=c(0.79,1.25,0.72,0.84,1.32,1.35,1.29,0.72,0.96,1.13)
t.test(x1,x2,conf.level=0.95,var.equal=FALSE)

