goftest/0000755000175100001440000000000013070364354011750 5ustar hornikusersgoftest/src/0000755000175100001440000000000013070346173012536 5ustar hornikusersgoftest/src/AnDarl.c0000755000175100001440000000731613070346173014055 0ustar hornikusers/* AnDarl.c $Revision: 1.1 $ $Date: 2014/06/09 07:53:21 $ Original C code by G. and J. Marsaglia R interface by Adrian Baddeley */ #include /* Anderson-Darling test for uniformity. Given an ordered set x_10. */ double adinf(double z) { if(z<2.) return ( exp(-1.2337141/z)/sqrt(z) )*( 2.00012+(.247105- (.0649821- (.0347962- (.011672-.00168691*z) *z)*z)*z)*z); /* max |error| < .000002 for z<2, (p=.90816...) */ return exp( -exp(1.0776-(2.30695-(.43424-(.082433-(.008056 -.0003146*z) *z)*z)*z)*z)); /* max |error|<.0000008 for 4.8) return (-130.2137+ (745.2337- (1705.091- (1950.646- (1116.360-255.7844*x)*x)*x)*x)*x)/n; c=.01265+.1757/n; if(x.8) { v=(-130.2137+(745.2337-(1705.091-(1950.646-(1116.360-255.7844*x) *x)*x)*x)*x)/n; return x+v; } c=.01265+.1757/n; if(x double ADinf(double z); /* A procedure for evaluating the limiting distribution of the Anderson-Darling statistic A_n=-n-(1/n)[ln(x_1(1-x_n)+3ln(x_2(1-x_{n-1})+5ln(x_3(1-x_{n-2})+... +(2n-1)ln(x_n(1-x_1))] where x_1infty} Pr[A_n150.) return 0.; a=2.22144146907918*exp(-t)/sqrt(t); b=3.93740248643060*2.*cPhi(sqrt(2*t));/* initialization requires cPhi */ /*if you have erfc(), replace 2*cPhi(sqrt(2*t)) with erfc(sqrt(t))*/ r=z*.125; f=a+b*r; for(i=1;i<200;i++) { c=((i-.5-t)*b+t*a)/i; a=b; b=c; r*=z/(8*i+8); if(fabs(r)<1e-40 || fabs(c)<1.e-40) return f; fnew=f+c*r; if(f==fnew) return f; f=fnew; } return f; } double ADinf(double z){ int j; double ad,adnew,r; if(z<.01) return 0.; /* avoids exponent limits; ADinf(.01)=.528e-52 */ r=1./z; ad=r*ADf(z,0); for(j=1;j<100;j++){ r*=(.5-j)/j; adnew=ad+(4*j+1)*r*ADf(z,j); if(ad==adnew) {return ad;} ad=adnew; } return ad; } /* Complementary normal distribution function cPhi(x) = integral from x to infinity of phi(x)=exp(-.5*t^2)/sqrt(2*pi) 13-15 digit accuracy for abs(x)<16. Stores R(0),R(2),R(4),...,R(16), with cPhi(x)=R(x)*phi(x), phi normal density, then uses Taylor series for R(z+h)=R(z)+hR'(z)+(1/2)h^2R''(z)+... with -10) ? s: 1-s); } } /* end i loop */ /* If not converged, return last estimate */ return ((x>0) ? s: 1-s); } /* R interface */ void ADprobExactInf(double *a, int *na, double *prob) { int i, m; m = *na; for(i = 0; i < m; i++) prob[i] = ADinf(a[i]); } goftest/src/init.c0000644000175100001440000000155013070346173013646 0ustar hornikusers/* Native symbol registration table for goftest package */ #include #include #include // for NULL #include void ADprobExactInf(double *, int *, double *); void ADprobN(double *, int *, int *, double *); void ADprobApproxInf(double *, int *, double *); void ADtestR(double *, int *, double *, double *); static const R_CMethodDef CEntries[] = { {"ADprobExactInf", (DL_FUNC) &ADprobExactInf, 3}, {"ADprobN", (DL_FUNC) &ADprobN, 4}, {"ADprobApproxInf", (DL_FUNC) &ADprobApproxInf, 3}, {"ADtestR", (DL_FUNC) &ADtestR, 4}, {NULL, NULL, 0} }; static const R_CallMethodDef CallEntries[] = { {NULL, NULL, 0} }; void R_init_goftest(DllInfo *dll) { R_registerRoutines(dll, CEntries, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } goftest/src/RCS/0000755000175100001440000000000013070330425013156 5ustar hornikusersgoftest/src/RCS/ADinf.c,v0000755000175100001440000000652413070330425014557 0ustar hornikusershead 1.1; access; symbols; locks adrian:1.1; strict; comment @ * @; 1.1 date 2014.06.09.10.18.10; author adrian; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @/* ADinf.c $Revision: 1.1 $ $Date: 2014/06/09 07:53:21 $ Original C code by G. and J. Marsaglia R interface by Adrian Baddeley */ #include double ADinf(double z); /* A procedure for evaluating the limiting distribution of the Anderson-Darling statistic A_n=-n-(1/n)[ln(x_1(1-x_n)+3ln(x_2(1-x_{n-1})+5ln(x_3(1-x_{n-2})+... +(2n-1)ln(x_n(1-x_1))] where x_1infty} Pr[A_n150.) return 0.; a=2.22144146907918*exp(-t)/sqrt(t); b=3.93740248643060*2.*cPhi(sqrt(2*t));/* initialization requires cPhi */ /*if you have erfc(), replace 2*cPhi(sqrt(2*t)) with erfc(sqrt(t))*/ r=z*.125; f=a+b*r; for(i=1;i<200;i++) { c=((i-.5-t)*b+t*a)/i; a=b; b=c; r*=z/(8*i+8); if(fabs(r)<1e-40 || fabs(c)<1.e-40) return f; fnew=f+c*r; if(f==fnew) return f; f=fnew; } return f; } double ADinf(double z){ int j; double ad,adnew,r; if(z<.01) return 0.; /* avoids exponent limits; ADinf(.01)=.528e-52 */ r=1./z; ad=r*ADf(z,0); for(j=1;j<100;j++){ r*=(.5-j)/j; adnew=ad+(4*j+1)*r*ADf(z,j); if(ad==adnew) {return ad;} ad=adnew; } return ad; } /* Complementary normal distribution function cPhi(x) = integral from x to infinity of phi(x)=exp(-.5*t^2)/sqrt(2*pi) 13-15 digit accuracy for abs(x)<16. Stores R(0),R(2),R(4),...,R(16), with cPhi(x)=R(x)*phi(x), phi normal density, then uses Taylor series for R(z+h)=R(z)+hR'(z)+(1/2)h^2R''(z)+... with -10) ? s: 1-s); } } /* end i loop */ /* If not converged, return last estimate */ return ((x>0) ? s: 1-s); } /* R interface */ void ADprobExactInf(double *a, int *na, double *prob) { int i, m; m = *na; for(i = 0; i < m; i++) prob[i] = ADinf(a[i]); } @ goftest/src/RCS/AnDarl.c,v0000755000175100001440000000755413070330425014743 0ustar hornikusershead 1.1; access; symbols; locks adrian:1.1; strict; comment @ * @; 1.1 date 2014.06.09.07.53.21; author adrian; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @/* AnDarl.c $Revision$ $Date$ Original C code by G. and J. Marsaglia R interface by Adrian Baddeley */ #include /* Anderson-Darling test for uniformity. Given an ordered set x_10. */ double adinf(double z) { if(z<2.) return ( exp(-1.2337141/z)/sqrt(z) )*( 2.00012+(.247105- (.0649821- (.0347962- (.011672-.00168691*z) *z)*z)*z)*z); /* max |error| < .000002 for z<2, (p=.90816...) */ return exp( -exp(1.0776-(2.30695-(.43424-(.082433-(.008056 -.0003146*z) *z)*z)*z)*z)); /* max |error|<.0000008 for 4.8) return (-130.2137+ (745.2337- (1705.091- (1950.646- (1116.360-255.7844*x)*x)*x)*x)*x)/n; c=.01265+.1757/n; if(x.8) { v=(-130.2137+(745.2337-(1705.091-(1950.646-(1116.360-255.7844*x) *x)*x)*x)*x)/n; return x+v; } c=.01265+.1757/n; if(x 1)) stop("null distribution function returned values outside [0,1]") U <- sort(U) k <- seq_len(n) ## call Marsaglia C code z <- .C(CgofADtestR, x = as.double(U), n = as.integer(n), adstat = as.double(numeric(1)), pvalue = as.double(numeric(1)), PACKAGE="goftest" ) STATISTIC <- z$adstat names(STATISTIC) <- "An" PVAL <- z$pvalue METHOD <- c("Anderson-Darling test of goodness-of-fit", paste("Null hypothesis:", nullname)) extras <- list(...) parnames <- intersect(names(extras), names(formals(F0))) if(length(parnames) > 0) { pars <- extras[parnames] pard <- character(0) for(i in seq_along(parnames)) pard[i] <- paste(parnames[i], "=", paste(pars[[i]], collapse=" ")) pard <- paste("with", ngettext(length(pard), "parameter", "parameters"), " ", paste(pard, collapse=", ")) METHOD <- c(METHOD, pard) } out <- list(statistic = STATISTIC, p.value = PVAL, method = METHOD, data.name = xname) class(out) <- "htest" return(out) } pAD <- function(q, n=Inf, lower.tail=TRUE, fast=TRUE) { q <- as.numeric(q) p <- rep(NA_real_, length(q)) if(any(ones <- is.infinite(q) & (q == Inf))) p[ones] <- 1 if(any(zeroes <- (is.finite(q) & q <= 0) | (is.infinite(q) & (q == -Inf)))) p[zeroes] <- 0 ok <- is.finite(q) & (q > 0) nok <- sum(ok) if(nok > 0) { if(is.finite(n)) { z <- .C(CgofADprobN, a = as.double(q[ok]), na = as.integer(nok), nsample = as.integer(n), prob = as.double(numeric(nok)), PACKAGE="goftest") p[ok] <- z$prob } else if(fast) { ## fast version adinf() z <- .C(CgofADprobApproxInf, a = as.double(q[ok]), na = as.integer(nok), prob = as.double(numeric(nok)), PACKAGE="goftest") p[ok] <- z$prob } else { ## slow, accurate version ADinf() z <- .C(CgofADprobExactInf, a = as.double(q[ok]), na = as.integer(nok), prob = as.double(numeric(nok)), PACKAGE="goftest") p[ok] <- z$prob } } if(!lower.tail) p <- 1 - p return(p) } qAD <- local({ f <- function(x, N, P, Fast) { pAD(x, N, fast=Fast) - P } qAD <- function(p, n=Inf, lower.tail=TRUE, fast=TRUE) { ## quantiles of null distribution of Anderson-Darling test statistic stopifnot(all(p >= 0)) stopifnot(all(p <= 1)) if(!lower.tail) p <- 1-p ans <- rep(NA_real_, length(p)) for(i in which(p >= 0 & p < 1)) ans[i] <- uniroot(f, c(0, 1), N=n, P=p[i], Fast=fast, extendInt="up")$root return(ans) } qAD }) goftest/R/cramer.R0000755000175100001440000000701713070330425013545 0ustar hornikusers## ## cramer.R ## ## Distribution of the Cramer-Von Mises test statistic ## ## $Revision: 1.2 $ $Date: 2014/06/09 04:34:49 $ ## ## .................................................................. ## ## From Matlab code written by Julian Faraway (faraway@umich.edu) ## Translated to R by Adrian Baddeley ## ## Reference: S. Csorgo and J.J. Faraway, ## The exact and asymptotic distributions of Cramer-von Mises statistics ## Journal of the Royal Statistical Society, Series B ## 58 (1996) 221-234. ## pCvM <- local({ ## all functions are vectorised D2 <- function(x) { z <- (x^2)/4 b <- besselK(x=z, nu=1/4) + besselK(x=z, nu=3/4) b * sqrt((x^3)/(8*pi)) } D3 <- function(x) { z <- (x^2)/4 b <- 2*besselK(z, nu=1/4) + 3*besselK(z, nu=3/4) - besselK(z, nu=5/4) b * sqrt((x^5)/(32 * pi)) } ED2 <- function(x) { exp(-(x^2)/4) * D2(x) } ED3 <- function(x) { exp(-(x^2)/4) * D3(x) } Ak <- function(k, x) { twosqrtx <- 2 * sqrt(x) x34 <- x^(3/4) x54 <- x^(5/4) (2*k+1)*gamma(k+1/2)*ED2((4*k+3)/twosqrtx)/(9*x34) + gamma(k+1/2)*ED3((4*k+1)/twosqrtx)/(72*x54) + 2*(2*k+3)*gamma(k+3/2)*ED3((4*k+5)/twosqrtx)/(12*x54) + 7*(2*k+1)*gamma(k+1/2)*ED2((4*k+1)/twosqrtx)/(144*x34) + 7*(2*k+1)*gamma(k+1/2)*ED2((4*k+5)/twosqrtx)/(144*x34) } psi1 <- function(x) { ## Leading term in expansion of small-sample cdf of Cramer-Von Mises m <- length(x) tot <- numeric(m) active <- rep(TRUE, m) for(k in 0:20) { z <- -Ak(k,x[active])/(pi*factorial(k)) tot[active] <- tot[active] + z active[active] <- (abs(z) >= 1e-7) if(!any(active)) break } return(tot + Vinf(x)/12) } Vinf <- function(x) { ## cdf of asymptotic distribution of Cramer-von Mises m <- length(x) tot <- numeric(m) active <- rep(TRUE, m) for(k in 0:10) { q <- (4*k+1)^2/(16*x[active]) z <- ((-1)^k)*choose(-1/2,k)*sqrt(4*k+1)* exp(-q)*besselK(q, nu=1/4)/sqrt(x[active]) tot[active] <- tot[active] + z active[active] <- (abs(z) >= 1e-7) if(!any(active)) break } return(tot/pi) } Vn <- function(x, n) { ## cdf of small-sample distribution of Cramer-von Mises statistic ## First order approximation, Csorgo and Faraway equation (1.8) Vinf(x) + psi1(x)/n } pCvM <- function(q, n=Inf, lower.tail=TRUE) { ## cdf of null distribution of Cramer-von Mises test statistic if(is.finite(n)) { lower <- 1/(12 * n) upper <- n/3 } else { lower <- 0 upper <- Inf } m <- length(q) p <- numeric(m) unknown <- rep(TRUE, m) if(any(zeroes <- (q <= lower))) { p[zeroes] <- 0 unknown[zeroes] <- FALSE } if(any(ones <- (q >= upper))) { p[ones] <- 1 unknown[ones] <- FALSE } if(any(unknown)) p[unknown] <- if(is.infinite(n)) Vinf(q[unknown]) else Vn(q[unknown], n) return(if(lower.tail) p else 1-p) } pCvM }) qCvM <- local({ f <- function(x, N, P) { pCvM(x, N) - P } qCvM <- function(p, n=Inf, lower.tail=TRUE) { ## quantiles of null distribution of Cramer-von Mises test statistic stopifnot(all(p >= 0)) stopifnot(all(p <= 1)) if(!lower.tail) p <- 1-p lower <- if(is.finite(n)) (1/(12 * n)) else 0 upper <- if(is.finite(n)) n/3 else Inf ans <- numeric(length(p)) ans[p == 0] <- lower ans[p == 1] <- upper for(i in which(p > 0 & p < 1)) ans[i] <- uniroot(f, c(lower, 1), N=n, P=p[i], extendInt="up")$root return(ans) } qCvM }) goftest/R/cvmtest.R0000755000175100001440000000330313070330425013753 0ustar hornikusers## ## cvmtest.R ## ## Cramer-von Mises test ## ## $Revision: 1.4 $ $Date: 2014/06/24 02:13:27 $ ## cvm.test <- function(x, null="punif", ..., nullname) { xname <- deparse(substitute(x)) nulltext <- deparse(substitute(null)) if(is.character(null)) nulltext <- null if(missing(nullname) || is.null(nullname)) { reco <- recogniseCdf(nulltext) nullname <- if(!is.null(reco)) reco else paste("distribution", sQuote(nulltext)) } stopifnot(is.numeric(x)) x <- as.vector(x) n <- length(x) F0 <- if(is.function(null)) null else if(is.character(null)) get(null, mode="function") else stop("Argument 'null' should be a function, or the name of a function") U <- F0(x, ...) if(any(U < 0 | U > 1)) stop("null distribution function returned values outside [0,1]") U <- sort(U) k <- seq_len(n) omega2 <- 1/(12 * n) + sum((U - (2*k - 1)/(2*n))^2) PVAL <- pCvM(omega2, n=n, lower.tail=FALSE) names(omega2) <- "omega2" METHOD <- c("Cramer-von Mises test of goodness-of-fit", paste("Null hypothesis:", nullname)) extras <- list(...) parnames <- intersect(names(extras), names(formals(F0))) if(length(parnames) > 0) { pars <- extras[parnames] pard <- character(0) for(i in seq_along(parnames)) pard[i] <- paste(parnames[i], "=", paste(pars[[i]], collapse=" ")) pard <- paste("with", ngettext(length(pard), "parameter", "parameters"), " ", paste(pard, collapse=", ")) METHOD <- c(METHOD, pard) } out <- list(statistic = omega2, p.value = PVAL, method = METHOD, data.name = xname) class(out) <- "htest" return(out) } goftest/R/oldRCS/0000755000175100001440000000000013070330425013267 5ustar hornikusersgoftest/R/oldRCS/recog.R,v0000755000175100001440000000420313070330425014755 0ustar hornikusershead 1.4; access; symbols; locks adrian:1.4; strict; comment @# @; 1.4 date 2014.06.24.02.13.35; author adrian; state Exp; branches; next 1.3; 1.3 date 2014.06.24.01.55.53; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.24.01.49.05; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.24.01.48.14; author adrian; state Exp; branches; next ; desc @@ 1.4 log @neatened @ text @## recog.R ## ## $Revision: 1.3 $ $Date: 2014/06/24 01:55:53 $ ## recogniseCdf <- function(s="punif") { if(!is.character(s) || length(s) != 1) return(NULL) if(nchar(s) <= 1 || substr(s,1,1) != "p") return(NULL) root <- substr(s, 2, nchar(s)) a <- switch(root, beta = "beta", binom = "binomial", birthday = "birthday coincidence", cauchy = "Cauchy", chisq = "chi-squared", exp = "exponential", f = "F", gamma = "Gamma", geom = "geometric", hyper = "hypergeometric", lnorm = "log-normal", logis = "logistic", nbinom = "negative binomial", norm = "Normal", pois = "Poisson", t = "Student's t", tukey = "Tukey (Studentized range)", unif = "uniform", weibull = "Weibull", NULL) if(!is.null(a)) return(paste(a, "distribution")) b <- switch(root, AD = "Anderson-Darling", CvM = "Cramer-von Mises", wilcox = "Wilcoxon Rank Sum", NULL) if(!is.null(b)) return(paste("null distribution of", b, "Test Statistic")) return(NULL) } @ 1.3 log @minor @ text @d3 1 a3 1 ## $Revision: 1.2 $ $Date: 2014/06/24 01:49:05 $ d6 1 a6 1 recogniseCdf <- function(s) { @ 1.2 log @bug fix @ text @d3 1 a3 1 ## $Revision: 1.1 $ $Date: 2014/06/24 01:48:14 $ d35 1 a35 1 CvM = "Cramer-von Mises" @ 1.1 log @Initial revision @ text @d3 1 a3 1 ## $Revision$ $Date$ d8 1 a8 1 if(substr(s,1,1) != "p" || nchar(s) > 1) return(NULL) @ goftest/R/oldRCS/cramer.R,v0000755000175100001440000001015413070330425015131 0ustar hornikusershead 1.2; access; symbols; locks adrian:1.2; strict; comment @# @; 1.2 date 2014.06.09.04.34.49; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.08.10.20.20; author adrian; state Exp; branches; next ; desc @@ 1.2 log @renamed @ text @## ## cramer.R ## ## Distribution of the Cramer-Von Mises test statistic ## ## $Revision: 1.1 $ $Date: 2014/06/08 10:20:20 $ ## ## .................................................................. ## ## From Matlab code written by Julian Faraway (faraway@@umich.edu) ## Translated to R by Adrian Baddeley ## ## Reference: S. Csorgo and J.J. Faraway, ## The exact and asymptotic distributions of Cramer-von Mises statistics ## Journal of the Royal Statistical Society, Series B ## 58 (1996) 221-234. ## pCvM <- local({ ## all functions are vectorised D2 <- function(x) { z <- (x^2)/4 b <- besselK(x=z, nu=1/4) + besselK(x=z, nu=3/4) b * sqrt((x^3)/(8*pi)) } D3 <- function(x) { z <- (x^2)/4 b <- 2*besselK(z, nu=1/4) + 3*besselK(z, nu=3/4) - besselK(z, nu=5/4) b * sqrt((x^5)/(32 * pi)) } ED2 <- function(x) { exp(-(x^2)/4) * D2(x) } ED3 <- function(x) { exp(-(x^2)/4) * D3(x) } Ak <- function(k, x) { twosqrtx <- 2 * sqrt(x) x34 <- x^(3/4) x54 <- x^(5/4) (2*k+1)*gamma(k+1/2)*ED2((4*k+3)/twosqrtx)/(9*x34) + gamma(k+1/2)*ED3((4*k+1)/twosqrtx)/(72*x54) + 2*(2*k+3)*gamma(k+3/2)*ED3((4*k+5)/twosqrtx)/(12*x54) + 7*(2*k+1)*gamma(k+1/2)*ED2((4*k+1)/twosqrtx)/(144*x34) + 7*(2*k+1)*gamma(k+1/2)*ED2((4*k+5)/twosqrtx)/(144*x34) } psi1 <- function(x) { ## Leading term in expansion of small-sample cdf of Cramer-Von Mises m <- length(x) tot <- numeric(m) active <- rep(TRUE, m) for(k in 0:20) { z <- -Ak(k,x[active])/(pi*factorial(k)) tot[active] <- tot[active] + z active[active] <- (abs(z) >= 1e-7) if(!any(active)) break } return(tot + Vinf(x)/12) } Vinf <- function(x) { ## cdf of asymptotic distribution of Cramer-von Mises m <- length(x) tot <- numeric(m) active <- rep(TRUE, m) for(k in 0:10) { q <- (4*k+1)^2/(16*x[active]) z <- ((-1)^k)*choose(-1/2,k)*sqrt(4*k+1)* exp(-q)*besselK(q, nu=1/4)/sqrt(x[active]) tot[active] <- tot[active] + z active[active] <- (abs(z) >= 1e-7) if(!any(active)) break } return(tot/pi) } Vn <- function(x, n) { ## cdf of small-sample distribution of Cramer-von Mises statistic ## First order approximation, Csorgo and Faraway equation (1.8) Vinf(x) + psi1(x)/n } pCvM <- function(q, n=Inf, lower.tail=TRUE) { ## cdf of null distribution of Cramer-von Mises test statistic if(is.finite(n)) { lower <- 1/(12 * n) upper <- n/3 } else { lower <- 0 upper <- Inf } m <- length(q) p <- numeric(m) unknown <- rep(TRUE, m) if(any(zeroes <- (q <= lower))) { p[zeroes] <- 0 unknown[zeroes] <- FALSE } if(any(ones <- (q >= upper))) { p[ones] <- 1 unknown[ones] <- FALSE } if(any(unknown)) p[unknown] <- if(is.infinite(n)) Vinf(q[unknown]) else Vn(q[unknown], n) return(if(lower.tail) p else 1-p) } pCvM }) qCvM <- local({ f <- function(x, N, P) { pCvM(x, N) - P } qCvM <- function(p, n=Inf, lower.tail=TRUE) { ## quantiles of null distribution of Cramer-von Mises test statistic stopifnot(all(p >= 0)) stopifnot(all(p <= 1)) if(!lower.tail) p <- 1-p lower <- if(is.finite(n)) (1/(12 * n)) else 0 upper <- if(is.finite(n)) n/3 else Inf ans <- numeric(length(p)) ans[p == 0] <- lower ans[p == 1] <- upper for(i in which(p > 0 & p < 1)) ans[i] <- uniroot(f, c(lower, 1), N=n, P=p[i], extendInt="up")$root return(ans) } qCvM }) @ 1.1 log @Initial revision @ text @d6 1 a6 1 ## $Revision$ $Date$ d19 1 a19 1 pcramer <- local({ d85 1 a85 1 pcramer <- function(q, n=Inf, lower.tail=TRUE) { d110 1 a110 1 pcramer d113 1 a113 1 qcramer <- local({ d116 1 a116 1 pcramer(x, N) - P d119 1 a119 1 qcramer <- function(p, n=Inf, lower.tail=TRUE) { d134 1 a134 1 qcramer @ goftest/R/oldRCS/andarl.R,v0000755000175100001440000001241113070330425015117 0ustar hornikusershead 1.6; access; symbols; locks adrian:1.6; strict; comment @# @; 1.6 date 2014.06.24.02.12.20; author adrian; state Exp; branches; next 1.5; 1.5 date 2014.06.24.01.54.16; author adrian; state Exp; branches; next 1.4; 1.4 date 2014.06.09.05.07.09; author adrian; state Exp; branches; next 1.3; 1.3 date 2014.06.09.05.02.30; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.09.04.34.57; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.09.04.26.35; author adrian; state Exp; branches; next ; desc @@ 1.6 log @polished output @ text @## ## andarl.R ## ## Anderson-Darling test and null distribution ## ## $Revision: 1.5 $ $Date: 2014/06/24 01:54:16 $ ## ad.test <- function(x, null="punif", ..., nullname) { xname <- deparse(substitute(x)) nulltext <- deparse(substitute(null)) if(is.character(null)) nulltext <- null if(missing(nullname) || is.null(nullname)) { reco <- recogniseCdf(nulltext) nullname <- if(!is.null(reco)) reco else paste("distribution", sQuote(nulltext)) } stopifnot(is.numeric(x)) x <- as.vector(x) n <- length(x) F0 <- if(is.function(null)) null else if(is.character(null)) get(null, mode="function") else stop("Argument 'null' should be a function, or the name of a function") U <- F0(x, ...) if(any(U < 0 | U > 1)) stop("null distribution function returned values outside [0,1]") U <- sort(U) k <- seq_len(n) ## call Marsaglia C code z <- .C("ADtestR", x = as.double(U), n = as.integer(n), adstat = as.double(numeric(1)), pvalue = as.double(numeric(1)) ) STATISTIC <- z$adstat names(STATISTIC) <- "An" PVAL <- z$pvalue METHOD <- c("Anderson-Darling test of goodness-of-fit", paste("Null hypothesis:", nullname)) extras <- list(...) parnames <- intersect(names(extras), names(formals(F0))) if(length(parnames) > 0) { pars <- extras[parnames] pard <- character(0) for(i in seq_along(parnames)) pard[i] <- paste(parnames[i], "=", paste(pars[[i]], collapse=" ")) pard <- paste("with", ngettext(length(pard), "parameter", "parameters"), " ", paste(pard, collapse=", ")) METHOD <- c(METHOD, pard) } out <- list(statistic = STATISTIC, p.value = PVAL, method = METHOD, data.name = xname) class(out) <- "htest" return(out) } pAD <- function(q, n=Inf, lower.tail=TRUE, fast=TRUE) { q <- as.numeric(q) p <- rep(NA_real_, length(q)) if(any(ones <- is.infinite(q) & (q == Inf))) p[ones] <- 1 if(any(zeroes <- (is.finite(q) & q <= 0) | (is.infinite(q) & (q == -Inf)))) p[zeroes] <- 0 ok <- is.finite(q) & (q > 0) nok <- sum(ok) if(nok > 0) { if(is.finite(n)) { z <- .C("ADprobN", a = as.double(q[ok]), na = as.integer(nok), nsample = as.integer(n), prob = as.double(numeric(nok)) ) p[ok] <- z$prob } else if(fast) { ## fast version adinf() z <- .C("ADprobApproxInf", a = as.double(q[ok]), na = as.integer(nok), prob = as.double(numeric(nok)) ) p[ok] <- z$prob } else { ## slow, accurate version ADinf() z <- .C("ADprobExactInf", a = as.double(q[ok]), na = as.integer(nok), prob = as.double(numeric(nok)) ) p[ok] <- z$prob } } if(!lower.tail) p <- 1 - p return(p) } qAD <- local({ f <- function(x, N, P, Fast) { pAD(x, N, fast=Fast) - P } qAD <- function(p, n=Inf, lower.tail=TRUE, fast=TRUE) { ## quantiles of null distribution of Anderson-Darling test statistic stopifnot(all(p >= 0)) stopifnot(all(p <= 1)) if(!lower.tail) p <- 1-p ans <- rep(NA_real_, length(p)) for(i in which(p >= 0 & p < 1)) ans[i] <- uniroot(f, c(0, 1), N=n, P=p[i], Fast=fast, extendInt="up")$root return(ans) } qAD }) @ 1.5 log @recognises standard distributions @ text @d6 1 a6 1 ## $Revision: 1.4 $ $Date: 2014/06/09 05:07:09 $ d39 15 a53 2 METHOD <- paste("Anderson-Darling test of", nullname) ALTERN <- paste("Not the", nullname) a55 1 alternative = ALTERN, @ 1.4 log @tweak @ text @d6 1 a6 1 ## $Revision: 1.3 $ $Date: 2014/06/09 05:02:30 $ d13 3 a15 2 if(missing(nullname)) nullname <- if(identical(null, "punif")) "uniform distribution" else d17 1 d50 1 a50 1 pAD <- function(q, n=Inf, lower.tail=TRUE) { d68 8 d77 2 a78 1 z <- .C("ADprobInf", d85 1 d94 2 a95 2 f <- function(x, N, P) { pAD(x, N) - P d98 1 a98 1 qAD <- function(p, n=Inf, lower.tail=TRUE) { d105 1 a105 1 ans[i] <- uniroot(f, c(0, 1), N=n, P=p[i], extendInt="up")$root @ 1.3 log @buglet fix @ text @d6 1 a6 1 ## $Revision: 1.2 $ $Date: 2014/06/09 04:34:57 $ d35 1 d91 2 a92 1 for(i in which(p > 0 & p < 1)) @ 1.2 log @tweaked @ text @d6 1 a6 1 ## $Revision: 1.1 $ $Date: 2014/06/09 04:26:35 $ d52 1 a52 1 if(any(zeroes <- (is.finite(q) & q < 0) | (is.infinite(q) & (q == -Inf)))) d54 1 a54 1 ok <- is.finite(q) & (q >= 0) @ 1.1 log @Initial revision @ text @d6 1 a6 1 ## $Revision$ $Date$ d47 1 a47 1 pAnDarl <- function(q, n=Inf, lower.tail=TRUE) { d78 23 @ goftest/R/oldRCS/cvmtest.R,v0000755000175100001440000000551413070330425015351 0ustar hornikusershead 1.4; access; symbols; locks adrian:1.4; strict; comment @# @; 1.4 date 2014.06.24.02.13.27; author adrian; state Exp; branches; next 1.3; 1.3 date 2014.06.24.01.54.26; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.08.11.32.51; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.08.11.05.58; author adrian; state Exp; branches; next ; desc @@ 1.4 log @polished output @ text @## ## cvmtest.R ## ## Cramer-von Mises test ## ## $Revision: 1.3 $ $Date: 2014/06/24 01:54:26 $ ## cvm.test <- function(x, null="punif", ..., nullname) { xname <- deparse(substitute(x)) nulltext <- deparse(substitute(null)) if(is.character(null)) nulltext <- null if(missing(nullname) || is.null(nullname)) { reco <- recogniseCdf(nulltext) nullname <- if(!is.null(reco)) reco else paste("distribution", sQuote(nulltext)) } stopifnot(is.numeric(x)) x <- as.vector(x) n <- length(x) F0 <- if(is.function(null)) null else if(is.character(null)) get(null, mode="function") else stop("Argument 'null' should be a function, or the name of a function") U <- F0(x, ...) if(any(U < 0 | U > 1)) stop("null distribution function returned values outside [0,1]") U <- sort(U) k <- seq_len(n) omega2 <- 1/(12 * n) + sum((U - (2*k - 1)/(2*n))^2) PVAL <- pCvM(omega2, n=n, lower.tail=FALSE) names(omega2) <- "omega2" METHOD <- c("Cramer-von Mises test of goodness-of-fit", paste("Null hypothesis:", nullname)) extras <- list(...) parnames <- intersect(names(extras), names(formals(F0))) if(length(parnames) > 0) { pars <- extras[parnames] pard <- character(0) for(i in seq_along(parnames)) pard[i] <- paste(parnames[i], "=", paste(pars[[i]], collapse=" ")) pard <- paste("with", ngettext(length(pard), "parameter", "parameters"), " ", paste(pard, collapse=", ")) METHOD <- c(METHOD, pard) } out <- list(statistic = omega2, p.value = PVAL, method = METHOD, data.name = xname) class(out) <- "htest" return(out) } @ 1.3 log @recognises standard distributions @ text @d6 1 a6 1 ## $Revision: 1.2 $ $Date: 2014/06/08 11:32:51 $ d33 14 a46 1 paste("to", nullname)) @ 1.2 log @minor @ text @d6 1 a6 1 ## $Revision: 1.1 $ $Date: 2014/06/08 11:05:58 $ d13 3 a15 2 if(missing(nullname)) nullname <- if(identical(null, "punif")) "uniform distribution" else d17 1 d30 1 a30 1 PVAL <- pcvm(omega2, n=n, lower.tail=FALSE) d32 2 a33 2 METHOD <- paste("Cramer-von Mises test of", nullname) ALTERN <- paste("Not the", nullname) a35 1 alternative = ALTERN, @ 1.1 log @Initial revision @ text @d6 1 a6 1 ## $Revision$ $Date$ d10 2 a11 2 xname <- short.deparse(substitute(x)) nulltext <- short.deparse(substitute(null)) @ goftest/R/recog.R0000755000175100001440000000252213070330425013367 0ustar hornikusers## recog.R ## ## $Revision: 1.4 $ $Date: 2014/06/24 02:13:35 $ ## recogniseCdf <- function(s="punif") { if(!is.character(s) || length(s) != 1) return(NULL) if(nchar(s) <= 1 || substr(s,1,1) != "p") return(NULL) root <- substr(s, 2, nchar(s)) a <- switch(root, beta = "beta", binom = "binomial", birthday = "birthday coincidence", cauchy = "Cauchy", chisq = "chi-squared", exp = "exponential", f = "F", gamma = "Gamma", geom = "geometric", hyper = "hypergeometric", lnorm = "log-normal", logis = "logistic", nbinom = "negative binomial", norm = "Normal", pois = "Poisson", t = "Student's t", tukey = "Tukey (Studentized range)", unif = "uniform", weibull = "Weibull", NULL) if(!is.null(a)) return(paste(a, "distribution")) b <- switch(root, AD = "Anderson-Darling", CvM = "Cramer-von Mises", wilcox = "Wilcoxon Rank Sum", NULL) if(!is.null(b)) return(paste("null distribution of", b, "Test Statistic")) return(NULL) } goftest/MD50000644000175100001440000000243313070364354012262 0ustar hornikusers96829f4e7b27aa7d9f4390defb84d6a7 *DESCRIPTION 15b924eea35078a33ce9a9597f352439 *NAMESPACE 887a04c0e343377d70f33fa812fcb6a5 *R/andarl.R af5331c232f97b2898a79436c9cf68ea *R/cramer.R 5cce1422f1250e4c202cf2cd22d1182e *R/cvmtest.R d3146be4396e0b2db19377e00d110794 *R/oldRCS/andarl.R,v 8052568d7f91b67ab5e8794f559b4cab *R/oldRCS/cramer.R,v 2c68dc762655bbc1958556cb1d84fa55 *R/oldRCS/cvmtest.R,v 56ce831b8afd6f55b7f7180a470226c1 *R/oldRCS/recog.R,v c1fe053fbad63706bc531caaa8d4093a *R/recog.R a7ad89d57a0f110ccea99d17ebb561c3 *man/RCS/ad.test.Rd,v 530c67ca8d74604f9c2d096806246e26 *man/RCS/cvm.test.Rd,v aa477968e4b102c4e762a1850b49589e *man/RCS/goftest-package.Rd,v 6e322a80bcf915758cf6b34edfe8c55c *man/RCS/pAD.Rd,v d0f7bb029253ac0d213e7f7be7f21690 *man/RCS/pCvM.Rd,v 68c7cd80d2d2cbdc2d7758195fa705ba *man/ad.test.Rd 964870356c0d8b2cb04faadff174a6eb *man/cvm.test.Rd 373cb9be37b8eda6eb06527113683d39 *man/goftest-package.Rd 1a4b2504f66e98b034f0665218b2c5bc *man/pAD.Rd b6294a6cc54d82ceb166326a40f07b4c *man/pCvM.Rd c01fa76d45da3dbc27e2ac171f63301d *man/recogniseCdf.Rd ca3270c176ce09cd15243bf4df918aa9 *src/ADinf.c cd2de573b9344ec28682f59b81a2789c *src/AnDarl.c db80933a3060fbea79e3fee3c0e04278 *src/RCS/ADinf.c,v 2e56696004e170d1f939ba1442e34c1d *src/RCS/AnDarl.c,v a197e1a03ae0ab8761473c5ad9bc9508 *src/init.c goftest/DESCRIPTION0000755000175100001440000000161313070364354013462 0ustar hornikusersPackage: goftest Type: Package Title: Classical Goodness-of-Fit Tests for Univariate Distributions Version: 1.1-1 Date: 2017-04-03 Authors@R: c(person("Julian", "Faraway", role = "aut"), person("George", "Marsaglia", role = "aut"), person("John", "Marsaglia", role = "aut"), person("Adrian", "Baddeley", role = c("aut", "cre"), email = "Adrian.Baddeley@curtin.edu.au")) Depends: R (>= 3.3) Imports: stats Description: Cramer-Von Mises and Anderson-Darling tests of goodness-of-fit for continuous univariate distributions, using efficient algorithms. License: GPL (>= 2) NeedsCompilation: yes Packaged: 2017-04-03 04:15:55 UTC; 214132e Author: Julian Faraway [aut], George Marsaglia [aut], John Marsaglia [aut], Adrian Baddeley [aut, cre] Maintainer: Adrian Baddeley Repository: CRAN Date/Publication: 2017-04-03 06:17:16 UTC goftest/man/0000755000175100001440000000000013070346173012522 5ustar hornikusersgoftest/man/goftest-package.Rd0000755000175100001440000000405213070330425016052 0ustar hornikusers\name{goftest-package} \alias{goftest-package} \alias{goftest} \docType{package} \title{ Classical Goodness-of-Fit Tests } \description{ \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises and Anderson-Darling tests of goodness-of-fit for continuous univariate distributions, using modern algorithms to compute the null distributions. } \details{ The \pkg{goftest} package contains implementations of the classical \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises and Anderson-Darling tests of goodness-of-fit for continuous univariate distributions. The \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test is performed by \code{\link{cvm.test}}. The cumulative distribution function of the null distribution of the test statistic is computed by \code{\link{pCvM}} using the algorithm of \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo} and Faraway (1996). The quantiles are computed by \code{\link{qCvM}} by root-finding. The Anderson-Darling test is performed by \code{\link{ad.test}}. The cumulative distribution function of the null distribution of the test statistic is computed by \code{\link{pAD}} using the algorithm of Marsaglia and Marsaglia (2004). The quantiles are computed by \code{\link{qAD}} by root-finding. } \author{ Adrian Baddeley, Julian Faraway, John Marsaglia, George Marsaglia. Maintainer: Adrian Baddeley } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \keyword{package} \keyword{htest} \seealso{ \code{\link[stats]{ks.test}} } \examples{ x <- rnorm(10, mean=2, sd=1) cvm.test(x, "pnorm", mean=2, sd=1) ad.test(x, "pnorm", mean=2, sd=1) } goftest/man/pCvM.Rd0000755000175100001440000000336313070330425013657 0ustar hornikusers\name{pCvM} \alias{pCvM} \alias{qCvM} \title{ Null Distribution of Cramer-von Mises Test Statistic } \description{ \code{pCvM} computes the cumulative distribution function, and \code{qCvM} computes the quantile function, of the null distribution of the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test statistic. } \usage{ pCvM(q, n = Inf, lower.tail = TRUE) qCvM(p, n = Inf, lower.tail = TRUE) } \arguments{ \item{q}{ Numeric vector of quantiles (values for which the cumulative probability is required). } \item{p}{ Numeric vector of probabilities. } \item{n}{ Integer. Sample size for the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test. } \item{lower.tail}{ Logical. If \code{TRUE} (the default), probabilities are \eqn{P(X \le q)}{P(X <= q)}, and otherwise they are \eqn{P(X > q)}. } } \details{ For finite \code{n} the cumulative distribution function is approximated by the first order expansion \eqn{V(x) + \psi_1(x)/n}{V(x) + psi1(x)/n}, equation (1.8) of \ifelse{latex}{\out{Cs\"org\"o}}{Csorgo} and Faraway (1996). \code{qCvM} uses \code{\link[stats]{uniroot}} to find the quantiles. } \value{ A numeric vector of the same length as \code{p} or \code{q}. } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. } \author{ Original Matlab code by Julian Faraway, translated to \R by Adrian Baddeley. } \seealso{ \code{\link{cvm.test}} } \examples{ pCvM(1.1, n=5) pCvM(1.1) qCvM(0.5, n=5) qCvM(0.5) } \keyword{distribution} \keyword{htest} goftest/man/pAD.Rd0000755000175100001440000000444313070330425013456 0ustar hornikusers\name{pAD} \alias{pAD} \alias{qAD} \title{ Null Distribution of Anderson-Darling Test Statistic } \description{ \code{pAD} computes the cumulative distribution function, and \code{qAD} computes the quantile function, of the null distribution of the Anderson-Darling test statistic. } \usage{ pAD(q, n = Inf, lower.tail = TRUE, fast=TRUE) qAD(p, n = Inf, lower.tail = TRUE, fast=TRUE) } \arguments{ \item{q}{ Numeric vector of quantiles (values for which the cumulative probability is required). } \item{p}{ Numeric vector of probabilities. } \item{n}{ Integer. Sample size for the Anderson-Darling test. } \item{lower.tail}{ Logical. If \code{TRUE} (the default), probabilities are \eqn{P(X \le q)}{P(X <= q)}, and otherwise they are \eqn{P(X > q)}. } \item{fast}{ Logical value indicating whether to use a fast algorithm or a slower, more accurate algorithm, in the case \code{n=Inf}. } } \details{ \code{pAD} uses the algorithms and C code described in Marsaglia and Marsaglia (2004). \code{qAD} uses \code{\link[stats]{uniroot}} to find the quantiles. The argument \code{fast} applies only when \code{n=Inf} and determines whether the asymptotic distribution is approximated using the faster algorithm \code{adinf} (accurate to 4-5 places) or the slower algorithm \code{ADinf} (accurate to 11 places) described in Marsaglia and Marsaglia (2004). } \value{ A numeric vector of the same length as \code{p} or \code{q}. } \references{ Anderson, T.W. and Darling, D.A. (1952) Asymptotic theory of certain 'goodness-of-fit' criteria based on stochastic processes. \emph{Annals of Mathematical Statistics} \bold{23}, 193--212. Anderson, T.W. and Darling, D.A. (1954) A test of goodness of fit. \emph{Journal of the American Statistical Association} \bold{49}, 765--769. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \author{ Original C code by G. and J. Marsaglia. \R interface by Adrian Baddeley. } \seealso{ \code{\link{ad.test}} } \examples{ pAD(1.1, n=5) pAD(1.1) pAD(1.1, fast=FALSE) qAD(0.5, n=5) qAD(0.5) } \keyword{distribution} \keyword{htest} goftest/man/cvm.test.Rd0000755000175100001440000000350213070330425014550 0ustar hornikusers\name{cvm.test} \alias{cvm.test} \title{ Cramer-Von Mises Test of Goodness-of-Fit } \description{ Performs the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test of goodness-of-fit to a specified continuous univariate probability distribution. } \usage{ cvm.test(x, null = "punif", ..., nullname) } \arguments{ \item{x}{ Numeric vector of data values. } \item{null}{ A function, or a character string giving the name of a function, to compute the cumulative distribution function for the null distribution. } \item{\dots}{ Additional arguments for the cumulative distribution function. } \item{nullname}{ Optional character string describing the null distribution. The default is \code{"uniform distribution"}. } } \details{ This command performs the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test of goodness-of-fit to the distribution specified by the argument \code{null}. It is assumed that the values in \code{x} are independent and identically distributed random values, with some cumulative distribution function \eqn{F}. The null hypothesis is that \eqn{F} is the function specified by the argument \code{null}, while the alternative hypothesis is that \eqn{F} is some other function. } \value{ An object of class \code{"htest"} representing the result of the hypothesis test. } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. } \author{ Adrian Baddeley. } \seealso{ \code{\link{pCvM}} for the null distribution of the test statistic. } \examples{ x <- rnorm(10, mean=2, sd=1) cvm.test(x, "pnorm", mean=2, sd=1) } \keyword{htest} goftest/man/recogniseCdf.Rd0000755000175100001440000000140413070330425015377 0ustar hornikusers\name{recogniseCdf} \alias{recogniseCdf} \title{ Explanatory Name of Distribution Function } \description{ Recognises many standard cumulative distribution functions and returns a string describing the distribution. } \usage{ recogniseCdf(s="punif") } \arguments{ \item{s}{ A single character string giving the \emph{name} of an \R function that calculates cumulative probabilities. } } \details{ The list of recognised distribution functions includes all those available in the \pkg{stats} package and in \pkg{goftest}. } \value{ Character string, or \code{NULL} if the name is not recognised. } \author{ Adrian Baddeley. } \seealso{ \code{\link{pAD}} } \examples{ recogniseCdf("punif") recogniseCdf("pt") } \keyword{distribution} goftest/man/RCS/0000755000175100001440000000000013070330425013142 5ustar hornikusersgoftest/man/RCS/ad.test.Rd,v0000755000175100001440000000522413070330425015243 0ustar hornikusershead 1.2; access; symbols; locks adrian:1.2; strict; comment @# @; 1.2 date 2014.06.09.08.37.42; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.09.04.48.21; author adrian; state Exp; branches; next ; desc @@ 1.2 log @minor @ text @\name{ad.test} \alias{ad.test} \title{ Anderson-Darling Test of Goodness-of-Fit } \description{ Performs the Anderson-Darling test of goodness-of-fit to a specified continuous univariate probability distribution. } \usage{ ad.test(x, null = "punif", ..., nullname) } \arguments{ \item{x}{ Numeric vector of data values. } \item{null}{ A function, or a character string giving the name of a function, to compute the cumulative distribution function for the null distribution. } \item{\dots}{ Additional arguments for the cumulative distribution function. } \item{nullname}{ Optional character string describing the null distribution. The default is \code{"uniform distribution"}. } } \details{ This command performs the Anderson-Darling test of goodness-of-fit to the distribution specified by the argument \code{null}. It is assumed that the values in \code{x} are independent and identically distributed random values, with some cumulative distribution function \eqn{F}. The null hypothesis is that \eqn{F} is the function specified by the argument \code{null}, while the alternative hypothesis is that \eqn{F} is some other function. } \value{ An object of class \code{"htest"} representing the result of the hypothesis test. } \references{ Anderson, T.W. and Darling, D.A. (1952) Asymptotic theory of certain 'goodness-of-fit' criteria based on stochastic processes. \emph{Annals of Mathematical Statistics} \bold{23}, 193--212. Anderson, T.W. and Darling, D.A. (1954) A test of goodness of fit. \emph{Journal of the American Statistical Association} \bold{49}, 765--769. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \author{ Original C code by George Marsaglia and John Marsaglia. \R interface by Adrian Baddeley. } \seealso{ \code{\link{pAD}} for the null distribution of the test statistic. } \examples{ x <- rnorm(10, mean=2, sd=1) ad.test(x, "pnorm", mean=2, sd=1) } \keyword{htest} @ 1.1 log @Initial revision @ text @d47 1 a47 1 Asymptotic theory of certain `goodness-of-fit’ criteria based d53 1 a53 1 \emph{Journal of the American Statistical Association} \bold{49}, 765-–769. d62 1 a62 1 C code by G. and J. Marsaglia. d69 2 a70 2 x <- runif(10) ad.test(x) a72 1 @ goftest/man/RCS/pCvM.Rd,v0000755000175100001440000000372613070330425014553 0ustar hornikusershead 1.1; access; symbols; locks adrian:1.1; strict; comment @# @; 1.1 date 2014.06.08.11.23.35; author adrian; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @\name{pcramer} \alias{pcramer} \alias{qcramer} \title{ Null Distribution of Cramer-von Mises Test Statistic } \description{ \code{pcramer} computes the cumulative distribution function, and \code{qcramer} computes the quantile function, of the null distribution of the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test statistic. } \usage{ pcramer(q, n = Inf, lower.tail = TRUE) qcramer(p, n = Inf, lower.tail = TRUE) } \arguments{ \item{q}{ Numeric vector of quantiles (values for which the cumulative probability is required). } \item{p}{ Numeric vector of probabilities. } \item{n}{ Integer. Sample size for the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test. } \item{lower.tail}{ Logical. If \code{TRUE} (the default), probabilities are \eqn{P(X \le q)}{P(X <= q)}, and otherwise they are \eqn{P(X > q)}. } } \details{ For finite \code{n} the cumulative distribution function is approximated by the first order expansion \eqn{V(x) + \psi_1(x)/n}{V(x) + psi1(x)/n}, equation (1.8) of \ifelse{latex}{\out{Cs\"org\"o}}{Csorgo} and Faraway (1996). \code{qcramer} uses \code{\link[stats]{uniroot}} to find the quantiles. } \value{ A numeric vector of the same length as \code{p} or \code{q}. } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. } \author{ Original Matlab code by Julian Faraway, translated to \R by Adrian Baddeley. } \seealso{ \code{\link{cvm.test}} } \examples{ pcramer(1.1) pcramer(1.1, n=5) qcramer(0.5) qcramer(0.5, n=5) } \keyword{distribution} \keyword{htest} @ goftest/man/RCS/pAD.Rd,v0000755000175100001440000000552213070330425014346 0ustar hornikusershead 1.3; access; symbols; locks adrian:1.3; strict; comment @# @; 1.3 date 2014.06.09.08.37.37; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.09.05.02.24; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.09.04.40.36; author adrian; state Exp; branches; next ; desc @@ 1.3 log @minor @ text @\name{pAD} \alias{pAD} \alias{qAD} \title{ Null Distribution of Anderson-Darling Test Statistic } \description{ \code{pAD} computes the cumulative distribution function, and \code{qAD} computes the quantile function, of the null distribution of the Anderson-Darling test statistic. } \usage{ pAD(q, n = Inf, lower.tail = TRUE, fast=TRUE) qAD(p, n = Inf, lower.tail = TRUE, fast=TRUE) } \arguments{ \item{q}{ Numeric vector of quantiles (values for which the cumulative probability is required). } \item{p}{ Numeric vector of probabilities. } \item{n}{ Integer. Sample size for the Anderson-Darling test. } \item{lower.tail}{ Logical. If \code{TRUE} (the default), probabilities are \eqn{P(X \le q)}{P(X <= q)}, and otherwise they are \eqn{P(X > q)}. } \item{fast}{ Logical value indicating whether to use a fast algorithm or a slower, more accurate algorithm, in the case \code{n=Inf}. } } \details{ \code{pAD} uses the algorithms and C code described in Marsaglia and Marsaglia (2004). \code{qAD} uses \code{\link[stats]{uniroot}} to find the quantiles. The argument \code{fast} applies only when \code{n=Inf} and determines whether the asymptotic distribution is approximated using the faster algorithm \code{adinf} (accurate to 4-5 places) or the slower algorithm \code{ADinf} (accurate to 11 places) described in Marsaglia and Marsaglia (2004). } \value{ A numeric vector of the same length as \code{p} or \code{q}. } \references{ Anderson, T.W. and Darling, D.A. (1952) Asymptotic theory of certain 'goodness-of-fit' criteria based on stochastic processes. \emph{Annals of Mathematical Statistics} \bold{23}, 193--212. Anderson, T.W. and Darling, D.A. (1954) A test of goodness of fit. \emph{Journal of the American Statistical Association} \bold{49}, 765--769. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \author{ Original C code by G. and J. Marsaglia. \R interface by Adrian Baddeley. } \seealso{ \code{\link{ad.test}} } \examples{ pAD(1.1, n=5) pAD(1.1) pAD(1.1, fast=FALSE) qAD(0.5, n=5) qAD(0.5) } \keyword{distribution} \keyword{htest} @ 1.2 log @minor @ text @d14 2 a15 2 pAD(q, n = Inf, lower.tail = TRUE) qAD(p, n = Inf, lower.tail = TRUE) d33 4 d44 6 d78 1 d80 3 a82 1 pAD(1.1, n=5) a83 1 qAD(0.5, n=5) @ 1.1 log @Initial revision @ text @d45 9 @ goftest/man/RCS/cvm.test.Rd,v0000755000175100001440000000452313070330425015445 0ustar hornikusershead 1.3; access; symbols; locks adrian:1.3; strict; comment @# @; 1.3 date 2014.06.09.08.37.47; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.09.04.42.32; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.08.11.23.23; author adrian; state Exp; branches; next ; desc @@ 1.3 log @minor @ text @\name{cvm.test} \alias{cvm.test} \title{ Cramer-Von Mises Test of Goodness-of-Fit } \description{ Performs the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test of goodness-of-fit to a specified continuous univariate probability distribution. } \usage{ cvm.test(x, null = "punif", ..., nullname) } \arguments{ \item{x}{ Numeric vector of data values. } \item{null}{ A function, or a character string giving the name of a function, to compute the cumulative distribution function for the null distribution. } \item{\dots}{ Additional arguments for the cumulative distribution function. } \item{nullname}{ Optional character string describing the null distribution. The default is \code{"uniform distribution"}. } } \details{ This command performs the \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test of goodness-of-fit to the distribution specified by the argument \code{null}. It is assumed that the values in \code{x} are independent and identically distributed random values, with some cumulative distribution function \eqn{F}. The null hypothesis is that \eqn{F} is the function specified by the argument \code{null}, while the alternative hypothesis is that \eqn{F} is some other function. } \value{ An object of class \code{"htest"} representing the result of the hypothesis test. } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. } \author{ Adrian Baddeley. } \seealso{ \code{\link{pCvM}} for the null distribution of the test statistic. } \examples{ x <- rnorm(10, mean=2, sd=1) cvm.test(x, "pnorm", mean=2, sd=1) } \keyword{htest} @ 1.2 log @name change @ text @d61 2 a62 2 x <- runif(10) cvm.test(x) @ 1.1 log @Initial revision @ text @d58 1 a58 1 \code{\link{pcramer}} for the null distribution of the test statistic. @ goftest/man/RCS/goftest-package.Rd,v0000755000175100001440000000562013070330425016745 0ustar hornikusershead 1.3; access; symbols; locks adrian:1.3; strict; comment @# @; 1.3 date 2014.06.09.08.37.32; author adrian; state Exp; branches; next 1.2; 1.2 date 2014.06.09.05.19.07; author adrian; state Exp; branches; next 1.1; 1.1 date 2014.06.09.05.11.00; author adrian; state Exp; branches; next ; desc @@ 1.3 log @minor @ text @\name{goftest-package} \alias{goftest-package} \alias{goftest} \docType{package} \title{ Classical Goodness-of-Fit Tests } \description{ \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises and Anderson-Darling tests of goodness-of-fit for continuous univariate distributions, using modern algorithms to compute the null distributions. } \details{ The \pkg{goftest} package contains implementations of the classical \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises and Anderson-Darling tests of goodness-of-fit for continuous univariate distributions. The \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises test is performed by \code{\link{cvm.test}}. The cumulative distribution function of the null distribution of the test statistic is computed by \code{\link{pCvM}} using the algorithm of \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo} and Faraway (1996). The quantiles are computed by \code{\link{qCvM}} by root-finding. The Anderson-Darling test is performed by \code{\link{ad.test}}. The cumulative distribution function of the null distribution of the test statistic is computed by \code{\link{pAD}} using the algorithm of Marsaglia and Marsaglia (2004). The quantiles are computed by \code{\link{qAD}} by root-finding. } \author{ Adrian Baddeley, Julian Faraway, John Marsaglia, George Marsaglia. Maintainer: Adrian Baddeley } \references{ \ifelse{latex}{\out{Cs\"org\H{o}}}{Csorgo}, S. and Faraway, J.J. (1996) The exact and asymptotic distributions of \ifelse{latex}{\out{Cram\'er}}{Cramer}-von Mises statistics. \emph{Journal of the Royal Statistical Society, Series B} \bold{58}, 221--234. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \keyword{package} \keyword{htest} \seealso{ \code{\link[stats]{ks.test}} } \examples{ x <- rnorm(10, mean=2, sd=1) cvm.test(x, "pnorm", mean=2, sd=1) ad.test(x, "pnorm", mean=2, sd=1) } @ 1.2 log @prettified. @ text @d22 2 a23 1 function of the null distribution is computed by \code{\link{pCvM}} d30 2 a31 1 function of the null distribution is computed by \code{\link{pAD}} d59 3 a61 2 x <- rnorm(10) cvm.test(x, "pnorm") @ 1.1 log @Initial revision @ text @d15 17 a31 7 \tabular{ll}{ Package: \tab goftest\cr Type: \tab Package\cr Version: \tab 1.0-0\cr Date: \tab 2014-06-08\cr License: \tab GPL\cr } d34 1 a34 1 Adrian Baddeley, Julian Faraway, John Marsaglia, George Marsaglia @ goftest/man/ad.test.Rd0000755000175100001440000000415013070330425014347 0ustar hornikusers\name{ad.test} \alias{ad.test} \title{ Anderson-Darling Test of Goodness-of-Fit } \description{ Performs the Anderson-Darling test of goodness-of-fit to a specified continuous univariate probability distribution. } \usage{ ad.test(x, null = "punif", ..., nullname) } \arguments{ \item{x}{ Numeric vector of data values. } \item{null}{ A function, or a character string giving the name of a function, to compute the cumulative distribution function for the null distribution. } \item{\dots}{ Additional arguments for the cumulative distribution function. } \item{nullname}{ Optional character string describing the null distribution. The default is \code{"uniform distribution"}. } } \details{ This command performs the Anderson-Darling test of goodness-of-fit to the distribution specified by the argument \code{null}. It is assumed that the values in \code{x} are independent and identically distributed random values, with some cumulative distribution function \eqn{F}. The null hypothesis is that \eqn{F} is the function specified by the argument \code{null}, while the alternative hypothesis is that \eqn{F} is some other function. } \value{ An object of class \code{"htest"} representing the result of the hypothesis test. } \references{ Anderson, T.W. and Darling, D.A. (1952) Asymptotic theory of certain 'goodness-of-fit' criteria based on stochastic processes. \emph{Annals of Mathematical Statistics} \bold{23}, 193--212. Anderson, T.W. and Darling, D.A. (1954) A test of goodness of fit. \emph{Journal of the American Statistical Association} \bold{49}, 765--769. Marsaglia, G. and Marsaglia, J. (2004) Evaluating the Anderson-Darling Distribution. \emph{Journal of Statistical Software} \bold{9} (2), 1--5. February 2004. \url{http://www.jstatsoft.org/v09/i02} } \author{ Original C code by George Marsaglia and John Marsaglia. \R interface by Adrian Baddeley. } \seealso{ \code{\link{pAD}} for the null distribution of the test statistic. } \examples{ x <- rnorm(10, mean=2, sd=1) ad.test(x, "pnorm", mean=2, sd=1) } \keyword{htest}