[R] expressing functions
Remington, Richard
rnews at kernstat.com
Wed Dec 10 03:52:41 CET 2003
# Why does expressing one function
require(ctest)
t.test
# return only
function (x, ...)
UseMethod("t.test")
<environment: namespace:ctest>
# but expressing another function
shapiro.test
# returns more complete code?
function (x)
{
DNAME <- deparse(substitute(x))
x <- sort(x[complete.cases(x)])
n <- length(x)
if (n < 3 || n > 5000)
stop("sample size must be between 3 and 5000")
rng <- x[n] - x[1]
if (rng == 0)
stop("all `x[]' are identical")
if (rng < 1e-10)
x <- x/rng
n2 <- n%/%2
sw <- .C("swilk", init = FALSE, as.single(x), n, n1 = as.integer(n),
as.integer(n2), a = single(n2), w = double(1), pw = double(1),
ifault = integer(1), PACKAGE = "ctest")
if (sw$ifault && sw$ifault != 7)
stop(paste("ifault=", sw$ifault, ". This should not happen"))
RVAL <- list(statistic = c(W = sw$w), p.value = sw$pw, method =
"Shapiro-Wilk normality test",
data.name = DNAME)
class(RVAL) <- "htest"
return(RVAL)
}
<environment: namespace:ctest>
--
Richard E. Remington III
Statistician
KERN Statistical Services, Inc.
PO Box 1046
Boise, ID 83701
Tel: 208.426.0113
KernStat.com
More information about the R-help
mailing list