fakedata <- function(size, xbar, sd) { if(sd<=0) stop("sd must > 0") if(!is.numeric(xbar)) stop("xbar must be a real number") fake1 <- rnorm(size) fake2 <- fake1 - mean(fake1) fake2 * (sd/sd(fake2)) + xbar } # In statistical analysis related to student t-test, t-confidence interval, # often the data was already summurized in terms of sample mean (xbar) and # standard deviation (sd) and sample size (size), and no raw data is given. # We cannot use R (or Splus) function t.test() since it needs raw data. # # I use the function fakedata to regenerate the (fake) data that match the # 1) size, 2) xbar, and 3) sd. For t.test() purposes this will give identical # results (P-value and confidence interval) as if you had the raw data. # (Sufficiency!) Written by Mai Zhou mai@ms.uky.edu 4/2000 # # Example: Suppose a sample of size n=50 had xbar=11.8 and sd=0.6. # We can get P-value of testing Ho: mu=12 vs Ha: mu<12 by # mydata <- fakedata(size=50,xbar=11.8,sd=0.6) # t.test(mydata, mu=12, alternative="less")