1"pearson.test" <-
2function (x, n.classes = ceiling(2 * (n^(2/5))), adjust = TRUE)
3{
4    DNAME <- deparse(substitute(x))
5    x <- x[complete.cases(x)]
6    n <- length(x)
7    if (adjust) {
8        dfd <- 2
9    }
10    else {
11        dfd <- 0
12    }
13    num <- floor(1 + n.classes * pnorm(x, mean(x), sd(x)))
14    count <- tabulate(num, n.classes)
15    prob <- rep(1/n.classes, n.classes)
16    xpec <- n * prob
17    h <- ((count - xpec)^2)/xpec
18    P <- sum(h)
19    pvalue <- pchisq(P, n.classes - dfd - 1, lower.tail = FALSE)
20    RVAL <- list(statistic = c(P = P), p.value = pvalue, method = "Pearson chi-square normality test",
21        data.name = DNAME, n.classes = n.classes, df = n.classes -
22            1 - dfd)
23    class(RVAL) <- "htest"
24    return(RVAL)
25}
26