I wish the t.test function in stats would return the standard error.
It would be nicer for students if R simply reported the standard error
used to calculate the t value. I trolled for this in r-help and got
no answers, which I interpreted to mean that this is boring but
possibly not wrong. Hopefully.
I believe only simple changes are needed.
In the source code src/library/stats/t.test.R file:
at the bottom of the first function, where the return value list is set:
rval <- list(statistic = tstat, parameter = df, p.value = pval,
conf.int = cint, estimate = estimate, null.value = mu,
alternative = alternative, method = method, data.name = dname)
I wish that "stderr = stderr" could be inserted after "estimate = estimate".
I *believe* after studying the source code it is necessary to
introduce a name for the stderr element in the list.
names(stderr) <- "standard error"
If I could get that much put in, I would be happy. But to make this
really helpful, the htest.R file's "print.htest" function needs to
check for the presence of stderr. Based on what htest.R has now, I
think it needs:
if(!is.null(x$stderr))
out <- c(out, paste(names(x$stderr), "=",
format(round(x$stderr, 3))))
I am attaching a patch file that will make these changes if it is
applied to the R-2.9.0 tree.
pj
--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas
diff -rc R-2.9.0/src/library/stats/R/htest.R R-2.9.0-new/src/library/stats/R/htest.R
*** R-2.9.0/src/library/stats/R/htest.R 2009-03-19 18:05:13.000000000 -0500
--- R-2.9.0-new/src/library/stats/R/htest.R 2009-05-14 16:04:33.000000000 -0500
***************
*** 27,32 ****
--- 27,35 ----
if(!is.null(x$parameter))
out <- c(out, paste(names(x$parameter), "=",
format(round(x$parameter, 3))))
+ if(!is.null(x$stderr))
+ out <- c(out, paste(names(x$stderr), "=",
+ format(round(x$stderr, 3))))
if(!is.null(x$p.value)) {
fp <- format.pval(x$p.value, digits = digits)
out <- c(out, paste("p-value",
diff -rc R-2.9.0/src/library/stats/R/t.test.R R-2.9.0-new/src/library/stats/R/t.test.R
*** R-2.9.0/src/library/stats/R/t.test.R 2009-03-19 18:05:13.000000000 -0500
--- R-2.9.0-new/src/library/stats/R/t.test.R 2009-05-14 16:00:07.000000000 -0500
***************
*** 109,119 ****
}
cint <- mu + cint * stderr
names(tstat) <- "t"
names(df) <- "df"
names(mu) <- if(paired || !is.null(y)) "difference in means" else "mean"
attr(cint,"conf.level") <- conf.level
rval <- list(statistic = tstat, parameter = df, p.value = pval,
! conf.int=cint, estimate=estimate, null.value = mu,
alternative=alternative,
method=method, data.name=dname)
class(rval) <- "htest"
--- 109,120 ----
}
cint <- mu + cint * stderr
names(tstat) <- "t"
+ names(stderr) <- "standard error"
names(df) <- "df"
names(mu) <- if(paired || !is.null(y)) "difference in means" else "mean"
attr(cint,"conf.level") <- conf.level
rval <- list(statistic = tstat, parameter = df, p.value = pval,
! conf.int=cint, estimate=estimate, stderr=stderr, null.value = mu,
alternative=alternative,
method=method, data.name=dname)
class(rval) <- "htest"
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel