[R-sig-teaching] t.test from summary of data
Joshua Wiley
jwiley.psych at gmail.com
Tue Nov 9 06:57:12 CET 2010
Dear Byungchul,
To my knowledge there is no built in functionality to calculate just
the t statistic using pre-calculated means and standard deviations.
Regarding teaching, I would flip your question around a bit, "is there
a pedagogical reason to have students who are using computers for the
calculations not use raw data?". Personally, if you are going to let
them use a computer, let students practice on real data. My guess is
the book author intended students to use the formula and practice "by
hand".
The functionality is essentially built in if not wrapped up in a
pretty function, a short version is: mean/(sd/sqrt(n)) . A (ever so
slightly) fancier version is:
summary.t.test <- function(mean, sd, n, mu = 0, two.tailed = TRUE) {
statistic <- (mean - mu) / (sd/sqrt(n))
p <- pt(q = statistic, df = n - 1, lower.tail = FALSE)
if(two.tailed) {p <- p * 2}
output <- list("t" = statistic, "df" = n - 1, "p" = p)
return(output)
}
After becoming quite tired of doing it by hand myself, I wrote a
function to calculate contrast ts. With lambdas (contrasts) +1 and
-1, this should be equivalent to a two-sample t-test. I was a very
new user of R when I wrote it so the implementation is crude as I
recall, but perhaps you will find some part beneficial, and you should
even be able to source() the function straight into R if your computer
has internet access: http://joshuawiley.com/R/contrast_t.R
Best Regards,
Josh
On Mon, Nov 8, 2010 at 9:25 PM, Byungchul Cha <cha at muhlenberg.edu> wrote:
> I am using R in my intro stat course, and, I myself is a R novice.
>
> We use "Intro to the practice of statistics" by Moore, McCabe, Craig as textbook. Is there an option for the command "t.test" so that it can perform t-test from the summary of sample data (that is, sample mean, sample sd, and sample size), instead of the (raw) sample data? I've been looking to find a way to do so, but, I couldn't.
>
> I believe it is possible to write codes to do this for my own use, but, I am just curious. Is there a pedagogical reason not to do so? This is a bit annoying when all the exercises problems in the book needs such a functionality, and I can't figure out how to do it in R, especially when many other major stat packages (including TI calculators) have that capability. What am I missing here?
>
> --
> Byungchul Cha
> Muhlenberg College
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-sig-teaching
mailing list