###***### ONE SAMPLE ###***###
## generate standard normal data
n <- 100
set.seed(0)
x <- rnorm(n)
## Example 1: Fn = norm, F0 = norm
# Anderson-Darling test of H0: Fx = pnorm
set.seed(1)
np.cdf.test(x, y = "norm")
if (FALSE) {
# Cramer-von Mises test of H0: Fx = pnorm
set.seed(1)
np.cdf.test(x, y = "norm", method = "CVM")
# Kolmogorov-Smirnov test of H0: Fx = pnorm
set.seed(1)
np.cdf.test(x, y = "norm", method = "KS")
## Example 2: Fn = norm, F0 = t3
# user-defined distribution (Student's t with df = 3)
pt3 <- function(q) pt(q, df = 3) # cdf = paste("p", y)
rt3 <- function(n) rt(n, df = 3) # sim = paste("r", y)
# Anderson-Darling test of H0: Fx = t3
set.seed(1)
np.cdf.test(x, y = "t3")
# Cramer-von Mises test of H0: Fx = t3
set.seed(1)
np.cdf.test(x, y = "t3", method = "CVM")
# Kolmogorov-Smirnov test of H0: Fx = t3
set.seed(1)
np.cdf.test(x, y = "t3", method = "KS")
###***### TWO SAMPLE ###***###
# generate N(0, 1) and N(2/3, 1) data
m <- 25
n <- 25
set.seed(0)
x <- rnorm(m)
y <- rnorm(n, mean = 2/3)
# Anderson-Darling test of H0: Fx = Fy
set.seed(1)
np.cdf.test(x, y)
# Cramer-von Mises test of H0: Fx = Fy
set.seed(1)
np.cdf.test(x, y, method = "CVM")
# Kolmogorov-Smirnov test of H0: Fx = Fy
set.seed(1)
np.cdf.test(x, y, method = "KS")
}
Run the code above in your browser using DataLab