Prueba t

x<-rnorm(10)
y<-rnorm(10)
t.test(x,y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -0.078349, df = 13.835, p-value = 0.9387
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.9416336  0.8753347
## sample estimates:
##  mean of x  mean of y 
## 0.01478263 0.04793212
ttest<-t.test(x,y)
names(ttest)
##  [1] "statistic"   "parameter"   "p.value"     "conf.int"    "estimate"   
##  [6] "null.value"  "stderr"      "alternative" "method"      "data.name"
ttest$statistic
##           t 
## -0.07834856

Generación de los datos t

ts<-replicate(1000,t.test(rnorm(10),rnorm(10))$statistic)
pts<-seq(-5,5,length=100)
plot(pts,dt(pts,df=18),col="blue",type="l")
lines(density(ts))

qqplot(ts,rt(1000,df=18))
abline(0,1,col="blue",lwd=2)

probs<-c(0.90,0.95,0.99)
quantile(ts,probs)
##      90%      95%      99% 
## 1.382470 1.723801 2.458574
qt(probs,df=18)
## [1] 1.330391 1.734064 2.552380
t.potencia=function(n){
  t1=qt(0.025,df=2*n-2)
  t2=qt(0.975,df=2*n-2)
  ts=replicate(1000,
               t.test(rnorm(n,5.0,1.0),rnorm(n,4.5,1.0))$statistic
               )
  sum(ts<t1 | ts>t2)/1000
}
t.potencia(90)
## [1] 0.915
nn<-c(30,40,60,80,90,100)
res=sapply(nn,function(nn)t.potencia(nn))
plot(nn,res,type="l")