[R] Beginner's question about t.test()

pallier pallier at lscp.ehess.fr
Sun Feb 15 10:51:39 CET 2004


Pramote Khuwijitjaru wrote:

> Is it possible to use t.test() do t-test when I have only two means, 
> sample size, two standard deviations ? (no raw data).


When you type 't.test.default', you get the source code of the t.test 
function.

If you are conducting a t.test with var.equal=T, paired=F, 
alternative=two.sided,
the following commands are executed:

       df <- nx + ny - 2
       v <- ((nx - 1) * vx + (ny - 1) * vy)/df
       stderr <- sqrt(v * (1/nx + 1/ny))
       tstat <- (mx - my - mu)/stderr
       pval <- 2 * pt(-abs(tstat), df)


You could write your own function taking nx, mx, vx and ny, my and vy as 
args.
(vx=var(x))

my.t.test <- function (nx,mx,vx,ny,my,vy) {
       df <- nx + ny - 2
       v <- ((nx - 1) * vx + (ny - 1) * vy)/df
       stderr <- sqrt(v * (1/nx + 1/ny))
       tstat <- (mx - my)/stderr
       pval <- 2 * pt(-abs(tstat), df)

       cat("df=",df)
       cat("\nT=",tstat)
       cat("\np=",pval)
}

Christophe Pallier
www.pallier.org




More information about the R-help mailing list