Dear All, I am doing some exercise in statistics textbook on comparison of two experimental means. Is it possible to use t.test() do t-test when I have only two means, sample size, two standard deviations ? (no raw data). Thanks. Pramote
"Pramote Khuwijitjaru" <kmote at hotmail.com> writes:> Dear All, > I am doing some exercise in statistics textbook on comparison of two > experimental means. Is it possible to use t.test() do t-test when I > have only two means, sample size, two standard deviations ? (no raw > data).Only if you "cheat". fake.data <- function(n,mu,sigma) mu + sigma*scale(rnorm(n)) x1 <- fake.data(20, 12.345, .678) x2 <- fake.data(20, 13.456, .789) mean(x1) sd(x1) mean(x2) sd(x2) t.test(x1,x2) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Dear Peter Dalgaard Thank you very much.>From: <p.dalgaard at biostat.ku.dk>> >"Pramote Khuwijitjaru" <kmote at hotmail.com> writes: > > > Dear All, > > I am doing some exercise in statistics textbook on comparison of two > > experimental means. Is it possible to use t.test() do t-test when I > > have only two means, sample size, two standard deviations ? (no raw > > data). > >Only if you "cheat". > >fake.data <- function(n,mu,sigma) mu + sigma*scale(rnorm(n)) >x1 <- fake.data(20, 12.345, .678) >x2 <- fake.data(20, 13.456, .789) >mean(x1) >sd(x1) >mean(x2) >sd(x2) > >t.test(x1,x2) >-- > O__ ---- Peter Dalgaard Blegdamsvej 3 > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 >~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
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
>From: pallier <pallier at lscp.ehess.fr> >To: Pramote Khuwijitjaru <kmote at hotmail.com> >Subject: Re: [R] Beginner's question about t.test() >Date: Sun, 15 Feb 2004 10:48:05 +0100 > >Pramote Khuwijitjaru wrote: > >>Dear All, >>I am doing some exercise in statistics textbook on comparison of two >>experimental means. 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. > >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 > >Thanks for your advice. Writing my own function should be the best way. But when I type t.test, I got>t.testfunction (x, ...) UseMethod("t.test") <environment: namespace:ctest> and>t.test.defaultError: Object "t.test.default" not found I tried other couple of functions and found that only some functions (sd, var) will show their source when type the name. Could you point out the way to see function's source again ? Pramote
(a) You don't really need/want to look at t.test.default; your own code --- to do t tests based on summary statistics rather than data --- will have little or nothing to do with the code in t.test.default. Just write code to do the t test ``as if you were doing it by hand'' which is very simple and straightforward. (b) The reason that you can't ``see'' the t.test.default code is the namespace business on which I recently wrote a perhaps ill-advised rant to this list. It was gently pointed out to me that the namespace idea certainly does have its uses and advantages. It was also pointed out that you CAN get at functions which are ``hidden away'' by the namespace mechanism. Three ways (of which I was kindly informed by Andy Liaw and Duncan Murdoch) are: > ctest:::t.test.default > getAnywhere("t.test.default") > getS3method("t.test","default") Hope this helps. cheers, Rolf Turner rolf at math.unb.ca
>From: Rolf Turner <rolf at math.unb.ca> >To: kmote at hotmail.com >CC: r-help at stat.math.ethz.ch >Subject: Re: [R] Beginner's question about t.test() >Date: Sun, 15 Feb 2004 11:23:26 -0400 (AST) > >(a) You don't really need/want to look at t.test.default; your own >code --- to do t tests based on summary statistics rather than data >--- will have little or nothing to do with the code in >t.test.default. Just write code to do the t test ``as if you were >doing it by hand'' which is very simple and straightforward. > >(b) The reason that you can't ``see'' the t.test.default code is the >namespace business on which I recently wrote a perhaps ill-advised >rant to this list. > >It was gently pointed out to me that the namespace idea certainly >does have its uses and advantages. It was also pointed out that you >CAN get at functions which are ``hidden away'' by the namespace >mechanism. Three ways (of which I was kindly informed by Andy Liaw >and Duncan Murdoch) are: > > > ctest:::t.test.default > > getAnywhere("t.test.default") > > getS3method("t.test","default") > >Hope this helps. > > cheers, > > Rolf Turner > rolf at math.unb.caYou are right, I really don't want to correct the function code because it seems too complex for me to understand it right now. :) Thanks for advice how to see the code. Pramote