Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
statlink committed Oct 24, 2023
1 parent c23e0a3 commit 99b4bba
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions R/normal.etest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
normal.etest <- function(x, R = 999) {
n <- length(x)
s <- Rfast::Var(x, std = TRUE)
y <- ( x - mean(x) ) / s
y <- sort(y)
K <- seq(1 - n, n - 1, 2)
stat <- 4 * sum( y * pnorm(y) + dnorm(y) ) - 2 * mean(K * y)

z <- Rfast::matrnorm(n, R)
z <- Rfast::standardise(z)
z <- Rfast::colSort(z)
bootstat <- 4 * Rfast::colsums( z * pnorm(z) ) +
4 * Rfast::colsums( exp(-0.5 * z^2) ) / sqrt(2 * pi) -
2 * Rfast::eachcol.apply(z, K) / n
pvalue <- ( sum(bootstat > stat) + 1 ) / (R + 1)
res <- c(stat - 2 * n / sqrt(pi), pvalue)
names(res) <- c("statistic", "p-value")
res
}



0 comments on commit 99b4bba

Please sign in to comment.