dion
dion

Reputation: 11

Shapiro Wilk Test

I am trying to complete a Shapiro Wilks test.

I have used this function on my data set:

shapiro.test(rdailypriceUSA500)
Shapiro-Wilk normality test
data:  rdailypriceUSA500
W = 0.85676, p-value < 2.2e-16

My data set is made up of two columns, the date and then closing daily returns.

Although the test function has generated the W & P-value output, I am just unsure if I have performed the test correctly as I did not specify a column of data.

Upvotes: 0

Views: 291

Answers (1)

Claudio Paladini
Claudio Paladini

Reputation: 1028

I hope this helps. When running the function on multiple columns I get an error. Only when one column is selected, the function seems to work.

> shapiro.test(mtcars[,1:3])
Error in shapiro.test(mtcars[, 1:3]) : is.numeric(x) is not TRUE


> shapiro.test(mtcars[,1])

    Shapiro-Wilk normality test

data:  mtcars[, 1]
W = 0.94756, p-value = 0.1229

Also, if you run ?shapiro.test you can see the function's documentation and, with just, shapiro.test the code:

function (x) 
{
    DNAME <- deparse1(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: 0x0000017a65930318>
<environment: namespace:stats>

It's good practice to use these to investigate issues.

Upvotes: 1

Related Questions