0

I am trying to find out exactly how the test statistic is computed when performing a Shapiro-Wilk Normality Test in R. Here is the body of the function.

> shapiro.test
function (x) 
{
    DNAME <- deparse(substitute(x))
    stopifnot(is.numeric(x))
    x <- sort(x[complete.cases(x)])
    n <- length(x)
    if (is.na(n) || n < 3L || n > 5000L) 
        stop("sample size must be between 3 and 5000")
    rng <- x[n] - x[1L]
    if (rng == 0) 
        stop("all 'x' values are identical")
    if (rng < 1e-10) 
        x <- x/rng
    res <- .Call(C_SWilk, x)
    RVAL <- list(statistic = c(W = res[1]), p.value = res[2], 
        method = "Shapiro-Wilk normality test", data.name = DNAME)
    class(RVAL) <- "htest"
    return(RVAL)
}
<bytecode: 0x0603f2a8>
<environment: namespace:stats>

I cannot understand this part:

.Call(C_SWilk, x)

It seems that a function (i.e. C_SWilk) is called. Does anyone know what this function is? I tried to see but it gives me an error,

> C_SWilk
Error: object 'C_SWilk' not found
Stat
  • 671
  • 7
  • 19
  • Ask this question here: http://stats.stackexchange.com/ – andilabs Aug 21 '14 at 09:22
  • @andi This is pretty clearly a programming question, not a stats question. And, it's also a duplicate. – Thomas Aug 21 '14 at 09:26
  • 1
    @Stat This is calling compiled C code. This question will be closed as a duplicate. Read the question it is a duplicate of to see how to find the C code you're interested in. Here's one way to look at it: https://github.com/wch/r-source/blob/fbf5cdf29d923395b537a9893f46af1aa75e38f3/src/library/stats/src/swilk.c – Thomas Aug 21 '14 at 09:28

0 Answers0