exactRankTests/0000755000175100001440000000000014231675202013235 5ustar hornikusersexactRankTests/NAMESPACE0000644000175100001440000000111314172231232014443 0ustar hornikusersuseDynLib(exactRankTests, .registration = TRUE) import(utils) import(stats) exportPattern("\\.exact$") exportPattern("\\.exact.default$") exportPattern("\\.exact.formula$") export(dperm, qperm, pperm, rperm, perm.test, perm.test.default, perm.test.formula, cscores, cscores.default, cscores.factor, cscores.Surv, irank) S3method(ansari.exact, default) S3method(ansari.exact, formula) S3method(cscores, Surv) S3method(cscores, default) S3method(cscores, factor) S3method(perm.test, default) S3method(perm.test, formula) S3method(wilcox.exact, default) S3method(wilcox.exact, formula)exactRankTests/data/0000755000175100001440000000000014172231232014141 5ustar hornikusersexactRankTests/data/glioma.rda0000644000175100001440000000104414231470523016104 0ustar hornikusersOAg-U/FHDj|@>Px4Yf[ޛu5 =3{3'NuU 婢4FeTQ͛ ۅl5,mWS Cjq-~-h@4K=wmAuyh К} {v2W/R/0Лi;dqԗ΢`Ep6msmnRl7OФ.ݦ&)LI | GdG*MM{&/T4VJOO= B=/g"59*w]Q>$8-'_-O8 Ԕyq0d9&8hbypFx'lOo%Գޛ|,4 âŢ͢âbEljҢ=QC-Z\>a^u!ThБdcGmZسھqZGߍ kh*p9#7m"}͎[{D=:wV P^8*a T**@U p`p`p`p`p`p`p`p`p`p`pppppbxh exactRankTests/data/sal.rda0000644000175100001440000000043114231470523015412 0ustar hornikusers r0b```b`a@& s0X 8$-` tT*K tNk@U àYP t=T *U$f؝p<̯@&` P܃՝X{AݓtUT';*۴u\vS)hqq(n"nEPC-srg 0n< zvZ10`n-xuKd[U{b/?nws_}ZU04imd#&xXGez{StIGqZ*J=\&糖t[k)h/[_眳PG|uqwěd}7Egcb?>.`۳}khpjDz]`h$ZI_*@}ܚ_-<9t(}[~M̡M:yeLn?,6y:U3?5MdRk]ЇV}f{ӆ+VGڶQ_Ž*#:f$QFqXYm}n2.&: ߹{_|52U FPj$igJE@7"]Z iÃqVZ&lrLT#jV&r$MB'~]`-8|6p$drlȵ!φ| $ R@9\Ppp88CCCCCCCCCCCCCCCCCCCCCCCCCCCCC3[6 -"exactRankTests/data/bloodp.rda0000644000175100001440000000036014231470523016113 0ustar hornikusers0 QŸEORH2'*DS@Bo%5,C%'p<[pZ ;hzs ^L8$Y®l4ͳotSNf96zɉrLǫ,m'nr:u,}'gqjɊ?|wͥy,}}2)]y0~䐗,r]Q>3N=\,ؗ{q01Mg"&u\g 糀8b=o~=Gqyn7u~ͺzgO[FkMwc4nGn:yj_ 0} denote real valued scores in reverse ordering and \eqn{f} a positive factor (this is the \code{fact} argument). Let \eqn{R_i = f \cdot a_i - round(f \cdot a_i)}. Then \deqn{ \sum_{i=1}^m f \cdot a_i = \sum_{i=1}^m round(f \cdot a_i) - R_i. } Clearly, the maximum difference between \eqn{1/f \sum_{i=1}^m f \cdot a_i} and \eqn{1/f \sum_{i=1}^n round(f \cdot a_i)} is given by \eqn{|\sum_{i=1}^m R_i|}. Therefore one searches for \eqn{f} with \deqn{ |\sum_{i=1}^m R_i| \le \sum_{i=1}^m |R_i| \le tol.} If \eqn{f} induces more that 100.000 columns in the Shift-Algorithm by Streitberg & R\"ohmel, \eqn{f} is restricted to the largest integer that does not. The second idea is to map the scores into integers by taking the integer part of \eqn{a_i N / \max(a_i)} (Hothorn & Lausen, 2002). This induces additional ties, but the shape of the scores is very similar. That means we do not try to approximate something but use a different test (with integer valued scores), serving for the same purpose (due to a similar shape of the scores). However, this has to be done prior to calling \code{pperm} (see the examples). Exact two-sided p-values are computed as suggested in the StatXact-5 manual, page 225, equation (9.31) and equation (8.18), p. 179 (paired case). In detail: For the paired case the two-sided p-value is just twice the one-sided one. For the independent sample case the two sided p-value is defined as \deqn{p_2 = P( |T - E(T)| \ge | q - E(T) |)} where \eqn{q} is the quantile passed to \code{pperm}. } \value{ \code{dperm} gives the density, \code{pperm} gives the distribution function and \code{qperm} gives the quantile function. If \code{pprob} is true, \code{pperm} returns a list with elements \item{PVALUE}{the probability specified by \code{alternative}.} \item{PPROB}{the probability \eqn{P(T = q)}.} \code{rperm} is a wrapper to \code{\link{sample}}. } \references{ Bernd Streitberg & Joachim R\"ohmel (1986), Exact distributions for permutations and rank tests: An introduction to some recently published algorithms. \emph{Statistical Software Newsletter} \bold{12}(1), 10--17. Bernd Streitberg & Joachim R\"ohmel (1987), Exakte Verteilungen f\"ur Rang- und Randomisierungstests im allgemeinen $c$-Stichprobenfall. \emph{EDV in Medizin und Biologie} \bold{18}(1), 12--19. Torsten Hothorn (2001), On exact rank tests in \R. \emph{R News} \bold{1}(1), 11--12. Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA Torsten Hothorn & Berthold Lausen (2003), On the exact distribution of maximally selected rank statistics. \emph{Computational Statistics & Data Analysis}, \bold{43}(2), 121-137. } \examples{ # exact one-sided p-value of the Wilcoxon test for a tied sample x <- c(0.5, 0.5, 0.6, 0.6, 0.7, 0.8, 0.9) y <- c(0.5, 1.0, 1.2, 1.2, 1.4, 1.5, 1.9, 2.0) r <- cscores(c(x,y), type="Wilcoxon") pperm(sum(r[seq(along=x)]), r, 7) # Compare the exact algorithm as implemented in ctest and the # Shift-Algorithm by Streitberg & Roehmel for untied samples # Wilcoxon: n <- 10 x <- rnorm(n, 2) y <- rnorm(n, 3) r <- cscores(c(x,y), type="Wilcoxon") # exact distribution using the Shift-Algorithm dwexac <- dperm((n*(n+1)/2):(n^2 + n*(n+1)/2), r, n) sum(dwexac) # should be something near 1 :-) # exact distribution using dwilcox dw <- dwilcox(0:(n^2), n, n) # compare the two distributions: plot(dw, dwexac, main="Wilcoxon", xlab="dwilcox", ylab="dperm") # should give a "perfect" line # Wilcoxon signed rank test n <- 10 x <- rnorm(n, 5) y <- rnorm(n, 5) r <- cscores(abs(x - y), type="Wilcoxon") pperm(sum(r[x - y > 0]), r, length(r)) wilcox.test(x,y, paired=TRUE, alternative="less") psignrank(sum(r[x - y > 0]), length(r)) # Ansari-Bradley n <- 10 x <- rnorm(n, 2, 1) y <- rnorm(n, 2, 2) # exact distribution using the Shift-Algorithm sc <- cscores(c(x,y), type="Ansari") dabexac <- dperm(0:(n*(2*n+1)/2), sc, n) sum(dabexac) # real scores are allowed (but only result in an approximation) # e.g. v.d. Waerden test n <- 10 x <- rnorm(n) y <- rnorm(n) scores <- cscores(c(x,y), type="NormalQuantile") X <- sum(scores[seq(along=x)]) # <- v.d. Waerden normal quantile statistic # critical value, two-sided test abs(qperm(0.025, scores, length(x))) # p-values p1 <- pperm(X, scores, length(x), alternative="two.sided") # generate integer valued scores with the same shape as normal quantile # scores, this no longer v.d.Waerden, but something very similar scores <- cscores(c(x,y), type="NormalQuantile", int=TRUE) X <- sum(scores[seq(along=x)]) p2 <- pperm(X, scores, length(x), alternative="two.sided") # compare p1 and p2 p1 - p2 } \keyword{distribution} exactRankTests/man/lungcancer.Rd0000644000175100001440000000261214172231230016412 0ustar hornikusers\name{lungcancer} \alias{lungcancer} \docType{data} \title{ Lung Cancer Clinical Trial } \description{ Survival times for patients suffering lung cancer for a treatment and control group. } \usage{data(lungcancer)} \format{ A data frame with 14 observations on the following 3 variables. \describe{ \item{time}{survival time in days.} \item{cens}{censoring indicator: 0 censored, 1 event.} \item{group}{a factor with levels \code{control} and \code{newdrug}.} } } \details{ The data is given in Table 9.19, page 293, of Metha and Pathel (2001). The two-sided p-value for the log-rank test is 0.001 (page 295). } \references{ Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA } \examples{ data(lungcancer) attach(lungcancer) # round logrank scores scores <- cscores.Surv(cbind(time, cens)) T <- sum(scores[group=="newdrug"]) mobs <- sum(group=="newdrug") (prob <- pperm(T, scores, m=mobs, al="le")) pperm(T, scores, m=mobs, al="tw") pperm(T, scores, m=mobs, al="tw", simulate=TRUE) # map into integers, faster scores <- cscores.Surv(cbind(time, cens), int=TRUE) T <- sum(scores[group=="newdrug"]) mobs <- sum(group=="newdrug") (prob <- pperm(T, scores, m=mobs, al="le")) pperm(T, scores, m=mobs, al="tw") pperm(T, scores, m=mobs, al="tw", simulate=TRUE) detach(lungcancer) } \keyword{datasets} exactRankTests/man/ASAT.Rd0000644000175100001440000000316114172231230015021 0ustar hornikusers\name{ASAT} \alias{ASAT} \docType{data} \title{ Toxicological Study on Female Wistar Rats } \description{ ASAT-Values for a new compound and a control group of 34 female Wistar rats. } \usage{data(ASAT)} \format{ A data frame with 34 observations on the following 2 variables. \describe{ \item{asat}{the ASAT-values (a liver enzyme)} \item{group}{a factor with levels \code{Compound} and \code{Control}.} } } \details{ The aim of this toxicological study is the proof of safety for the new compound. The data are originally given in Hothorn (1992) and reproduced in Hauschke et al. (1999). } \source{ Ludwig A. Hothorn (1992), Biometrische Analyse toxikologischer Untersuchungen. In: J. Adams (ed.): \emph{Statistisches Know how in der medizinischen Forschung.} Ullstein-Mosby, Berlin, 475--590. } \references{ Dieter Hauschke, Meinhard Kieser & Ludwig A. Hothorn (1999), Proof of safety in toxicology based on the ratio of two means for normally distributed data. \emph{Biometrical Journal}, \bold{41}(3), 295--304. Rafael Pfl\"uger & Torsten Hothorn (2002), Assessing Equivalence Tests with Respect to their Expected $p$-Value. \emph{Biometrical Journal}, \bold{44}(8), 1002--1027. } \examples{ set.seed(29) data(ASAT) # does not really look symmetric plot(asat ~ group, data=ASAT) # proof-of-safety based on ration of medians pos <- wilcox.exact(I(log(asat)) ~ group, data = ASAT, alternative = "less", conf.int=TRUE) # one-sided confidence set. Safety cannot be concluded since the effect of # the compound exceeds 20\% of the control median exp(pos$conf.int) } \keyword{datasets} exactRankTests/man/bloodp.Rd0000644000175100001440000000410514172231230015547 0ustar hornikusers\name{bloodp} \alias{bloodp} \docType{data} \title{ Diastolic Blood Pressure } \description{ Diastolic blood pressure for a two groups of patients. } \usage{data(bloodp)} \format{ A data frame with 15 observations on the following 2 variables. \describe{ \item{bp}{the diastolic blood pressure.} \item{group}{a factor with levels \code{group1} and \code{group2}.} } } \details{ The data is given in Table 9.6, page 227, of Metha and Pathel (2001). Note that there are some tied observations. The permutation test using the raw blood pressure values does not lead to a rejection of the null hypothesis of exchangeability: p-value = 0.1040 (two-sided) and p-value = 0.0564 (one-sided). The asymptotic two-sided p-value is 0.1070. For the Wilcoxon-Mann-Whitney test, the one-sided p-value is 0.0542 and the two-sided one is 0.0989 (Metha & Patel, 2001, page 229). The one-sided p-value for the v.d.Waeren test is 0.0462 (Metha & Patel, 2001, page 241) and the two-sided p-value is 0.0799. } \references{ Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA } \examples{ data(bloodp) # Permutation test perm.test(bp ~ group, data=bloodp) perm.test(bp ~ group, data=bloodp, alternative="greater") perm.test(bp ~ group, data=bloodp, exact=FALSE) # Wilcoxon-Mann-Whitney test wilcox.exact(bp ~ group, data=bloodp, conf.int=TRUE, alternative="l") wilcox.exact(bp ~ group, data=bloodp, conf.int=TRUE) # compute the v.d. Waerden test sc <- cscores(bloodp$bp, type="NormalQuantile") X <- sum(sc[bloodp$group == "group2"]) round(pperm(X, sc, 11), 4) ## IGNORE_RDIFF_BEGIN round(pperm(X, sc, 11, simulate=TRUE), 4) round(pperm(X, sc, 11, alternative="two.sided"), 4) round(pperm(X, sc, 11, alternative="two.sided", simulate=TRUE), 4) ## IGNORE_RDIFF_END # use scores mapped into integers (cf. dperm) sc <- cscores(bloodp$bp, type="NormalQuantile", int=TRUE) X <- sum(sc[bloodp$group == "group2"]) round(pperm(X, sc, 11), 4) round(pperm(X, sc, 11, alternative="two.sided"), 4) } \keyword{datasets} exactRankTests/man/irank.Rd0000644000175100001440000000072214172231230015375 0ustar hornikusers\name{irank} \alias{irank} \title{ Integer Ranks } \description{ Compute the number of elements less or equal the elements in a given vector. } \usage{ irank(x, ox = NULL) } \arguments{ \item{x}{a numeric vector. } \item{ox}{\code{order(x)}, optionally (for efficiency in case \code{order(x)} is already known). } } \value{ A vector of integers. } \examples{ x <- rnorm(10) irank(x) rank(x) x <- c(1,2,3,3,0) irank(x) rank(x) } \keyword{univar} exactRankTests/man/perm.test.Rd0000644000175100001440000001156614231244750016231 0ustar hornikusers\name{perm.test} \alias{perm.test} \alias{perm.test.default} \alias{perm.test.formula} \title{One and Two Sample Permutation Test } \description{ Performs the permutation test for the one and two sample problem. } \usage{ \method{perm.test}{default}(x, y, paired=FALSE, alternative=c("two.sided", "less", "greater"), mu=0, exact=NULL, conf.int=FALSE, conf.level=0.95, tol=NULL, \dots) \method{perm.test}{formula}(formula, data, subset, na.action, \dots) } \arguments{ \item{x}{numeric vector of integer data values.} \item{y}{numeric vector of integer data values.} \item{paired}{a logical indicating whether you want a paired test.} \item{alternative}{the alternative hypothesis must be one of \code{"two.sided"} (default), \code{"greater"} or \code{"less"}. You can specify just the initial letter.} \item{mu}{a number specifying an optional location parameter.} \item{exact}{a logical indicating whether an exact p-value should be computed.} \item{conf.int}{a logical indicating whether a confidence interval should be computed.} \item{conf.level}{confidence level of the interval.} \item{tol}{real. real valued scores are mapped into integers by multiplication. Make sure that the absolute difference between the "true" quantile and the approximated quantile is less than \code{tol}. This might not be possible due to memory/time limitations. See \code{\link{pperm}}.} \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} is a numeric variable giving the data values and \code{rhs} a factor with two levels giving the corresponding groups.} \item{data}{an optional data frame containing the variables in the model formula.} \item{subset}{an optional vector specifying a subset of observations to be used.} \item{na.action}{a function which indicates what should happen when the data contain \code{NA}s. Defaults to \code{getOption("na.action")}.} \item{\dots}{further arguments to be passed to or from methods.} } \details{ The permutation test is performed for integer valued observations or scores. If real values \code{x} or \code{y} are passed to this function the following applies: if \code{exact} is true (i.e. the sample size is less than 50 observations) and \code{tol} is not given, the scores are mapped into \eqn{\{1,\dots,N\}}, see \code{\link{pperm}} for the details. Otherwise the p-values are computed using \code{tol}. If the sample size exceeds $50$ observations, the usual normal approximation is used. P-values are computed according to the StatXact-manual, see \code{\link{pperm}}. For (in principle) continuous variables the confidence sets represent the "largest shift in location being consistent with the observations". For discrete variables with only a few categories they are hard to interpret. In the case of binary data (e.g. success / failure) the confidence sets can be interpreted as the differences of two success-rates covered by the data. For a detailed description see R\"ohmel (1996). Confidence intervals are only available for independent samples. When the sample sizes are unbalanced, \code{length(x)} needs to be smaller than \code{length(y)}. } \value{ A list with class \code{"htest"} containing the following components: \item{statistic}{the value of the test statistic with a name describing it.} \item{p.value}{the p-value for the test.} \item{pointprob}{this gives the probability of observing the test statistic itself.} \item{null.value}{the location parameter \code{mu}.} \item{alternative}{a character string describing the alternative hypothesis.} \item{method}{the type of test applied.} \item{data.name}{a character string giving the names of the data.} \item{conf.int}{a confidence interval for the location parameter. (Only present if argument \code{conf.int = TRUE}.)} } \references{ Joachim R\"ohmel (1996), Precision intervals for estimates of the difference in success rates for binary random variables based on the permutation principle. \emph{Biometrical Journal}, \bold{38}(8), 977--993. Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA } \note{ Confidence intervals may need some cpu-time ... } \examples{ # Example from Gardner & Altman (1989), p. 30 # two treatments A and B, 1 means improvement, 0 means no improvement # confidence sets cf. R\"ohmel (1996) A <- c(rep(1, 61), rep(0, 19)) B <- c(rep(1, 45), rep(0, 35)) perm.test(A, B, conf.int=TRUE, exact=TRUE) # one-sample AIDS data (differences only), Methta and Patel (2001), # Table 8.1 page 181 data(sal) attach(sal) ppdiff <- pre - post detach(sal) # p-values in StatXact == 0.0011 one-sided, 0.0021 two.sided, page 183 perm.test(ppdiff) perm.test(ppdiff, alternative="less") perm.test(ppdiff, exact=FALSE) } \keyword{htest} exactRankTests/man/neuropathy.Rd0000644000175100001440000000211314172231230016463 0ustar hornikusers\name{neuropathy} \alias{neuropathy} \docType{data} \title{ Acute Painful Diabetic Neuropathy } \description{ The logarithm of the ratio of pain scores at baseline and after four weeks for a control and treatment group. } \usage{data(neuropathy)} \format{ A data frame with 58 observations on the following 2 variables. \describe{ \item{pain}{Pain scores: ln(baseline/final).} \item{group}{a factor with levels \code{control} and \code{treat}.} } } \details{ Data from Table 1 of Conover & Salsburg (1988). } \source{ William J. Conover and David S. Salsburg (1988), Locally most powerful tests for detecting treatment effects when only a subset of patients can be expected to "respond" to treatment. \emph{Biometrics}, \bold{44}, 189--196. } \examples{ data(neuropathy) # compare with Table 2 of Conover & Salsburg (1988) wilcox.exact(pain ~ group, data=neuropathy, alternative="less") css <- cscores(neuropathy$pain, type="ConSal") pperm(sum(css[neuropathy$group=="control"]),css, m=sum(neuropathy$group=="control")) } \keyword{datasets} exactRankTests/man/rotarod.Rd0000644000175100001440000000326614172231230015751 0ustar hornikusers\name{rotarod} \alias{rotarod} \docType{data} \title{ Rotating Rats Data} \description{ The endurance time of 24 rats in two groups in a rotating cylinder. } \usage{data(rotarod)} \format{ A data frame with 24 observations on the following 2 variables. \describe{ \item{time}{the endurance time} \item{group}{a factor with levels \code{control} and \code{treatment}.}} } \details{ The 24 rats received a fixed oral dose of a centrally acting muscle relaxant (treatment) or a saline solvent (control). They were placed on a rotating cylinder and the length of time each rat remains on the cylinder is measured, up to a maximum of 300 seconds. The rats were randomly assigned to the control and treatment group. Note that the empirical variance in the control group is 0 and that the group medians are identical. This dataset serves as the basis of an comparision of the results of the Wilcoxon-Mann-Whitney test computed by 11 statistical packages in Bergmann et al. (2000). The exact conditional p-value is $0.0373$ (two-sided) and $0.0186$ (one-sided). The asymptotic two-sided p-value (corrected for ties) is reported as $0.0147$. } \source{ Reinhard Bergmann, John Ludbrook & Will P.J.M. Spooren (2000), Different outcomes of the Wilcoxon-Mann-Whitney test from different statistics packages. \emph{The American Statistician}, \bold{54}(1), 72--77. } \examples{ data(rotarod) wilcox.exact(time ~ group, data=rotarod, alternative="g") wilcox.exact(time ~ group, data=rotarod, conf.int=TRUE) wilcox.exact(time ~ group, data=rotarod, exact=FALSE) # the permutation test perm.test(time ~ group, data=rotarod) perm.test(time ~ group, data=rotarod, exact=FALSE) } \keyword{datasets} exactRankTests/man/wilcox.exact.Rd0000644000175100001440000001400514172231230016700 0ustar hornikusers\name{wilcox.exact} \alias{wilcox.exact} \alias{wilcox.exact.default} \alias{wilcox.exact.formula} \title{Wilcoxon Rank Sum and Signed Rank Tests} \description{ Performs one and two sample Wilcoxon tests on vectors of data for possibly tied observations. } \usage{ \method{wilcox.exact}{default}(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, exact = NULL, conf.int = FALSE, conf.level = 0.95, \dots) \method{wilcox.exact}{formula}(formula, data, subset, na.action, \dots) } \arguments{ \item{x}{numeric vector of data values.} \item{y}{an optional numeric vector of data values.} \item{alternative}{the alternative hypothesis must be one of \code{"two.sided"} (default), \code{"greater"} or \code{"less"}. You can specify just the initial letter.} \item{mu}{a number specifying an optional location parameter.} \item{paired}{a logical indicating whether you want a paired test.} \item{exact}{a logical indicating whether an exact p-value should be computed.} \item{conf.int}{a logical indicating whether a confidence interval should be computed.} \item{conf.level}{confidence level of the interval.} \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} is a numeric variable giving the data values and \code{rhs} a factor with two levels giving the corresponding groups.} \item{data}{an optional data frame containing the variables in the model formula.} \item{subset}{an optional vector specifying a subset of observations to be used.} \item{na.action}{a function which indicates what should happen when the data contain \code{NA}s. Defaults to \code{getOption("na.action")}.} \item{\dots}{further arguments to be passed to or from methods.} } \details{ This version computes exact conditional (on the data) p-values and quantiles using the Shift-Algorithm by Streitberg & R\"ohmel for both tied and untied samples. If only \code{x} is given, or if both \code{x} and \code{y} are given and \code{paired} is \code{TRUE}, a Wilcoxon signed rank test of the null that the median of \code{x} (in the one sample case) or of \code{x-y} (in the paired two sample case) equals \code{mu} is performed. Otherwise, if both \code{x} and \code{y} are given and \code{paired} is \code{FALSE}, a Wilcoxon rank sum test (equivalent to the Mann-Whitney test) is carried out. In this case, the null hypothesis is that the location of the distributions of \code{x} and \code{y} differ by \code{mu}. By default (if \code{exact} is not specified), an exact p-value is computed if the samples contain less than 50 finite values and there are no ties. Otherwise, a normal approximation is used. Optionally (if argument \code{conf.int} is true), a nonparametric confidence interval for the median (one-sample case) or for the difference of the location parameters \code{x-y} is computed. If exact p-values are available, an exact confidence interval is obtained by the algorithm described in Bauer (1972). Otherwise, an asymptotic confidence interval is returned. } \value{ A list with class \code{"htest"} containing the following components: \item{statistic}{the value of the test statistic with a name describing it.} \item{p.value}{the p-value for the test.} \item{pointprob}{this gives the probability of observing the test statistic itself (called \code{point-prob}).} \item{null.value}{the location parameter \code{mu}.} \item{alternative}{a character string describing the alternative hypothesis.} \item{method}{the type of test applied.} \item{data.name}{a character string giving the names of the data.} \item{conf.int}{a confidence interval for the location parameter. (Only present if argument \code{conf.int = TRUE}.)} \item{estimate}{Hodges-Lehmann estimate of the location parameter. (Only present if argument \code{conf.int = TRUE}.)} } \references{ Myles Hollander & Douglas A. Wolfe (1973), \emph{Nonparametric statistical inference}. New York: John Wiley & Sons. Pages 27--33 (one-sample), 68--75 (two-sample). David F. Bauer (1972), Constructing confidence sets using rank statistics. \emph{Journal of the American Statistical Association} \bold{67}, 687--690. Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA } \seealso{ \code{\link{perm.test}} for the one and two sample permutation test. } \examples{ ## One-sample test. ## Hollander & Wolfe (1973), 29f. ## Hamilton depression scale factor measurements in 9 patients with ## mixed anxiety and depression, taken at the first (x) and second ## (y) visit after initiation of a therapy (administration of a ## tranquilizer). x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30) y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29) wilcox.exact(x, y, paired = TRUE, alternative = "greater") wilcox.exact(y - x, alternative = "less") # The same. ## Two-sample test. ## Hollander & Wolfe (1973), 69f. ## Permeability constants of the human chorioamnion (a placental ## membrane) at term (x) and between 12 to 26 weeks gestational ## age (y). The alternative of interest is greater permeability ## of the human chorioamnion for the term pregnancy. x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) y <- c(1.15, 0.88, 0.90, 0.74, 1.21) wilcox.exact(x, y, alternative = "g") # greater ## Formula interface. data(airquality) boxplot(Ozone ~ Month, data = airquality) wilcox.exact(Ozone ~ Month, data = airquality, subset = Month \%in\% c(5, 8)) # Hollander & Wolfe, p. 39, results p. 40 and p. 53 x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30) y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29) wilcox.exact(y,x, paired=TRUE, conf.int=TRUE) # Hollander & Wolfe, p. 110, results p. 111 and p. 126 x <- c(0.8, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) y <- c(1.15, 0.88, 0.90, 0.74, 1.21) wilcox.exact(y,x, conf.int=TRUE) } \keyword{htest} exactRankTests/man/cscores.Rd0000644000175100001440000000451014231244706015741 0ustar hornikusers\name{cscores} \alias{cscores} \alias{cscores.default} \alias{cscores.Surv} \alias{cscores.factor} \title{ Computation of Scores } \description{ This function can be used to compute several scores for a data vector. } \usage{ \method{cscores}{default}(y, type=c("Data", "Wilcoxon", "NormalQuantile", "AnsariBradley", "Median", "Savage", "ConSal"), int=FALSE, maxs=length(y), \dots ) \method{cscores}{factor}(y, \dots) \method{cscores}{Surv}(y, type="LogRank", int=FALSE, maxs=nrow(y), \dots) } \arguments{ \item{y}{ a numeric, factor or logical vector or an object of class \code{Surv}. } \item{type}{a character string which specifies the type of the scores to be computed. \code{Data} just returns \code{y} if \code{y} is numeric.} \item{int}{a logical, forcing integer valued scores. } \item{maxs}{an integer defining the maximal value of the scores if \code{int=TRUE}.} \item{\dots}{ additional arguments, not passed to anything at the moment. } } \details{ This function will serve as the basis for a more general framework of rank and permutation tests in future versions of this package. Currently, it is only used in the examples. The logrank scores are computed as given in Hothorn & Lausen (2002). If integer valued scores are requested (\code{int = TRUE}), the \code{scores} are mapped into integers by \code{round(scores*length(scores)/max(scores))}. See \code{\link{dperm}} for more details. \code{type} is self descriptive, except for \code{ConSal} which implements scores suggested by Conover & Salsburg (1988). } \value{ A vector of scores for \code{y} with an attribute \code{scores} indicating the kind of scores used is returned. } \references{ Torsten Hothorn & Berthold Lausen (2003), On the exact distribution of maximally selected rank statistics. \emph{Computational Statistics & Data Analysis}, \bold{43}(2), 121-137. William J. Conover & David S. Salsburg (1988), Locally most powerful tests for detecting treatment effects when only a subset of patients can be expected to "respond" to treatment. \emph{Biometrics}, \bold{44}, 189-196. } \examples{ y <- rnorm(50) # v.d. Waerden scores nq <- cscores(y, type="Normal", int=TRUE) # quantile for m=20 observations in the first group qperm(0.1, nq, 20) } \keyword{misc} exactRankTests/man/glioma.Rd0000644000175100001440000000616514172231230015550 0ustar hornikusers\name{glioma} \alias{glioma} \docType{data} \title{ Malignant Glioma Pilot Study} \description{ A non-randomized pilot study on malignant glioma patients with pretargeted adjuvant radioimmunotherapy using Yttrium-90-biotin. } \usage{data(glioma)} \format{ A data frame with 37 observations on the following 7 variables. \describe{ \item{No.}{patient number.} \item{Age}{patients ages in years.} \item{Sex}{a factor with levels \code{F}(emale) and \code{M}(ale). } \item{Histology}{a factor with levels \code{GBM} (grade IV) and \code{Grade3} (grade III)} \item{Survival}{survival times in month.} \item{Cens}{censoring indicator: \code{0} censored and \code{1} dead.} \item{Group}{a factor with levels \code{Control} and \code{RIT}.} } } \details{ The primary endpoint of this small pilot study is survival. Survival times are tied, the usual asymptotic log-rank test may be inadequate in this setup. Therefore, a permutation test (via Monte-Carlo sampling) was conducted in the original paper. The data are taken from Tables 1 and 2 of Grana et al. (2002). } \source{ C. Grana, M. Chinol, C. Robertson, C. Mazzetta, M. Bartolomei, C. De Cicco, M. Fiorenza, M. Gatti, P. Caliceti & G. Paganelli (2002), Pretargeted adjuvant radioimmunotherapy with Yttrium-90-biotin in malignant glioma patients: A pilot study. \emph{British Journal of Cancer}, \bold{86}(2), 207--212. } \examples{ data(glioma) if(require(survival, quietly = TRUE)) { par(mfrow=c(1,2)) # Grade III glioma g3 <- glioma[glioma$Histology == "Grade3",] # Plot Kaplan-Meier curves plot(survfit(Surv(Survival, Cens) ~ Group, data=g3), main="Grade III Glioma", lty=c(2,1), legend.text=c("Control", "Treated"), legend.bty=1, ylab="Probability", xlab="Survival Time in Month") # log-rank test survdiff(Surv(Survival, Cens) ~ Group, data=g3) # permutation test with integer valued log-rank scores lsc <- cscores(Surv(g3$Survival, g3$Cens), int=TRUE) perm.test(lsc ~ Group, data=g3) # permutation test with real valued log-rank scores lsc <- cscores(Surv(g3$Survival, g3$Cens), int=FALSE) tr <- (g3$Group == "RIT") T <- sum(lsc[tr]) pperm(T, lsc, sum(tr), alternative="tw") pperm(T, lsc, sum(tr), alternative="tw", simulate=TRUE) # Grade IV glioma gbm <- glioma[glioma$Histology == "GBM",] # Plot Kaplan-Meier curves plot(survfit(Surv(Survival, Cens) ~ Group, data=gbm), main="Grade IV Glioma", lty=c(2,1), legend.text=c("Control", "Treated"), legend.bty=1, legend.pos=1, ylab="Probability", xlab="Survival Time in Month") # log-rank test survdiff(Surv(Survival, Cens) ~ Group, data=gbm) # permutation test with integer valued log-rank scores lsc <- cscores(Surv(gbm$Survival, gbm$Cens), int=TRUE) perm.test(lsc ~ Group, data=gbm) # permutation test with real valued log-rank scores lsc <- cscores(Surv(gbm$Survival, gbm$Cens), int=FALSE) tr <- (gbm$Group == "RIT") T <- sum(lsc[tr]) pperm(T, lsc, sum(tr), alternative="tw") pperm(T, lsc, sum(tr), alternative="tw", simulate=TRUE) } } \keyword{datasets} exactRankTests/man/ocarcinoma.Rd0000644000175100001440000000332314172231230016404 0ustar hornikusers\name{ocarcinoma} \alias{ocarcinoma} \docType{data} \title{ Ovarian Carcinoma } \description{ Survival times of 35 women suffering ovarian carcinoma at stadium II and IIA. } \usage{data(ocarcinoma)} \format{ A data frame with 35 observations on the following 3 variables. \describe{ \item{time}{time in days.} \item{cens}{censoring indicator: 0 censored, 1 event.} \item{stadium}{a factor with levels \code{II} and \code{IIA}. } } } \details{ Data from Fleming et al. (1980, 1984), reanalysed in Schumacher and Schulgen (2002). } \source{ Thomas R. Fleming, Judith R. O'Fallon, Peter C. O'Brien & David P. Harrington (1980), Modified Kolmogorov-Smirnov test procedures with applications to arbitrarily censored data. \emph{Biometrics}, \bold{36}, 607--625. Thomas R. Fleming, Stephanie J. Green & David P. Harrington (1984), Considerations of monitoring and evaluating treatment effects in clinical trials. \emph{Controlled Clinical Trials}, \bold{5}, 55--66. } \references{ Martin Schumacher & Gabi Schulgen (2002), \emph{Methodik klinischer Studien: methodische Grundlagen der Planung, Durchf\"uhrung und Auswertung.} Springer, Heidelberg. } \examples{ data(ocarcinoma) attach(ocarcinoma) # compute integer valued logrank scores logrsc <- cscores.Surv(cbind(time, cens), int=TRUE) # the test statistic lgT <- sum(logrsc[stadium == "II"]) # p-value round(pperm(lgT, logrsc, m=sum(stadium=="II"), al="tw"), 4) # compute logrank scores and simulate p-value logrsc <- cscores.Surv(cbind(time, cens), int=FALSE) # the test statistic lgT <- sum(logrsc[stadium == "II"]) # p-value round(pperm(lgT, logrsc, m=sum(stadium=="II"), al="tw", simulate=TRUE), 4) } \keyword{datasets} exactRankTests/man/sal.Rd0000644000175100001440000000155314172231230015053 0ustar hornikusers\name{sal} \alias{sal} \docType{data} \title{ Serum Antigen Level } \description{ The response of serum antigen level to AZT in 20 patients suffering AIDS. } \usage{data(sal)} \format{ A data frame with 20 observations on the following 2 variables. \describe{ \item{pre}{level pre treatment.} \item{post}{level post treatment.} } } \details{ The data is given in Metha and Patel (2001), Table 8.1, page 181. Two-sided p-value for the Wilcoxon-Signed Rank Test: 0.0021 (page 183) or 0.0038 (asymptotically). } \references{ Cyrus R. Mehta & Nitin R. Patel (2001), \emph{StatXact-5 for Windows.} Manual, Cytel Software Cooperation, Cambridge, USA } \examples{ data(sal) attach(sal) wilcox.exact(pre, post, paired=TRUE, conf.int=TRUE) wilcox.exact(pre,post, paired=TRUE, conf.int=TRUE, exact=FALSE) detach(sal) } \keyword{datasets} exactRankTests/man/ansari.exact.Rd0000644000175100001440000001175414172231230016660 0ustar hornikusers\name{ansari.exact} \alias{ansari.exact} \alias{ansari.exact.default} \alias{ansari.exact.formula} \title{Ansari-Bradley Test} \description{ Performs the Ansari-Bradley two-sample test for a difference in scale parameters for possibly tied observations. } \usage{ \method{ansari.exact}{default}(x, y, alternative = c("two.sided", "less", "greater"), exact = NULL, conf.int = FALSE, conf.level = 0.95, \dots) \method{ansari.exact}{formula}(formula, data, subset, na.action, \dots) } \arguments{ \item{x}{numeric vector of data values.} \item{y}{numeric vector of data values.} \item{alternative}{indicates the alternative hypothesis and must be one of \code{"two.sided"}, \code{"greater"} or \code{"less"}. You can specify just the initial letter.} \item{exact}{a logical indicating whether an exact p-value should be computed.} \item{conf.int}{a logical,indicating whether a confidence interval should be computed.} \item{conf.level}{confidence level of the interval.} \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} is a numeric variable giving the data values and \code{rhs} a factor with two levels giving the corresponding groups.} \item{data}{an optional data frame containing the variables in the model formula.} \item{subset}{an optional vector specifying a subset of observations to be used.} \item{na.action}{a function which indicates what should happen when the data contain \code{NA}s. Defaults to \code{getOption("na.action")}.} \item{\dots}{further arguments to be passed to or from methods.} } \details{ Suppose that \code{x} and \code{y} are independent samples from distributions with densities \eqn{f((t-m)/s)/s} and \eqn{f(t-m)}, respectively, where \eqn{m} is an unknown nuisance parameter and \eqn{s}, the ratio of scales, is the parameter of interest. The Ansari-Bradley test is used for testing the null that \eqn{s} equals 1, the two-sided alternative being that \eqn{s \ne 1}{s != 1} (the distributions differ only in variance), and the one-sided alternatives being \eqn{s > 1} (the distribution underlying \code{x} has a larger variance, \code{"greater"}) or \eqn{s < 1} (\code{"less"}). By default (if \code{exact} is not specified), an exact p-value is computed if both samples contain less than 50 finite values. Otherwise, a normal approximation is used. Optionally, a nonparametric confidence interval and an estimator for \eqn{s} are computed. If exact p-values are available, an exact confidence interval is obtained by the algorithm described in Bauer (1972), and the Hodges-Lehmann estimator is employed. Otherwise, the returned confidence interval and point estimate are based on normal approximations. } \value{ A list with class \code{"htest"} containing the following components: \item{statistic}{the value of the Ansari-Bradley test statistic.} \item{p.value}{the p-value of the test.} \item{null.value}{the ratio of scales \eqn{s} under the null, 1.} \item{alternative}{a character string describing the alternative hypothesis.} \item{method}{the string \code{"Ansari-Bradley test"}.} \item{data.name}{a character string giving the names of the data.} \item{conf.int}{a confidence interval for the scale parameter. (Only present if argument \code{conf.int = TRUE}.)} \item{estimate}{an estimate of the ratio of scales. (Only present if argument \code{conf.int = TRUE}.)} } \note{ To compare results of the Ansari-Bradley test to those of the F test to compare two variances (under the assumption of normality), observe that \eqn{s} is the ratio of scales and hence \eqn{s^2} is the ratio of variances (provided they exist), whereas for the F test the ratio of variances itself is the parameter of interest. In particular, confidence intervals are for \eqn{s} in the Ansari-Bradley test but for \eqn{s^2} in the F test. } \references{ Myles Hollander & Douglas A. Wolfe (1973), \emph{Nonparametric statistical inference}. New York: John Wiley & Sons. Pages 83--92. David F. Bauer (1972), Constructing confidence sets using rank statistics. \emph{Journal of the American Statistical Association} \bold{67}, 687--690. } \seealso{ \code{\link{fligner.test}} for a rank-based (nonparametric) \eqn{k}-sample test for homogeneity of variances; \code{\link{mood.test}} for another rank-based two-sample test for a difference in scale parameters; \code{\link{var.test}} and \code{\link{bartlett.test}} for parametric tests for the homogeneity in variance. } \examples{ ## Hollander & Wolfe (1973, p. 86f): ## Serum iron determination using Hyland control sera ramsay <- c(111, 107, 100, 99, 102, 106, 109, 108, 104, 99, 101, 96, 97, 102, 107, 113, 116, 113, 110, 98) jung.parekh <- c(107, 108, 106, 98, 105, 103, 110, 105, 104, 100, 96, 108, 103, 104, 114, 114, 113, 108, 106, 99) ansari.test(ramsay, jung.parekh) ansari.exact(ramsay, jung.parekh) ansari.exact(rnorm(20), rnorm(20, 0, 2), conf.int = TRUE) } \keyword{htest} exactRankTests/man/ears.Rd0000644000175100001440000000261514172231230015226 0ustar hornikusers\name{ears} \alias{ears} \docType{data} \title{ Survival of Ventilating Tubes } \description{ Survival times of ventilating tubes of left and right ears in 78 children with otitis media. } \usage{data(ears)} \format{ A data frame with 78 observations on the following 5 variables. \describe{ \item{left}{Survival time in month of tube in left ear.} \item{lcens}{Censoring indicator for left ear: \code{0} censored and \code{1} event.} \item{right}{Survival time in month of tube in right ear.} \item{rcens}{Censoring indicator for right ear: \code{0} censored and \code{1} event.} \item{group}{a factor with levels \code{control} and \code{treat}. }} } \source{ Sin-Ho Jung and Jong-Hyeon Jeong (2003). Rank tests for clustered survival data. \emph{Lifetime Data Analysis}, \bold{9}, 21-33. } \references{ V.M. Howie and R.H. Schwarz (1983). Acute otitis media: One year in general pediatric practice. \emph{American Journal of Diseases in Children}, \bold{137}, 155-158. D.W. Teele, J.O. Klein, B. Rosner et al. (1989). Epidemiology of otitis media during the first seven years of life in children in greater Boston. \emph{Journal of Infectious Diseases}, \bold{160}, 89-94. } \examples{ data(ears) if (require(survival, quietly=TRUE)) { ls <- cscores(Surv(ears$left, ears$lcens), int=TRUE) perm.test(ls ~ group, data=ears) } } \keyword{datasets} exactRankTests/man/globulin.Rd0000644000175100001440000000164114172231230016105 0ustar hornikusers\name{globulin} \alias{globulin} \docType{data} \title{ Differences in Globulin Fraction in Two Groups } \usage{data(globulin)} \description{ Globulin fraction of plasma (g/l) in two groups of 10 patients. } \format{ This data frame contains the following variables: \describe{ \item{gfrac}{Globulin fraction of plasma} \item{group}{a factor with levels \code{group1} and \code{group2}} } } \details{ See page 75 of Gardner & Altman (1989). } \source{ M. J. Gardner & D. G. Altman (1989), \emph{Statistics with Confidence}. Published by the British Medical Journal. } \references{ Joachim R\"ohmel (1996), Precision intervals for estimates of the difference in success rates for binary random variables based on the permutation principle. \emph{Biometrical Journal}, \bold{38}(8), 977--993. } \examples{ data(globulin) perm.test(gfrac ~ group, data=globulin, conf.int=TRUE) } \keyword{datasets} exactRankTests/DESCRIPTION0000644000175100001440000000135314231675202014745 0ustar hornikusersPackage: exactRankTests Title: Exact Distributions for Rank and Permutation Tests Date: 2022-04-25 Version: 0.8-35 Authors@R: c(person("Torsten", "Hothorn", role = c("aut", "cre"), email = "Torsten.Hothorn@R-project.org"), person("Kurt", "Hornik", role = "aut")) Description: Computes exact conditional p-values and quantiles using an implementation of the Shift-Algorithm by Streitberg & Roehmel. Depends: R (>= 2.4.0), stats, utils Suggests: survival License: GPL (>= 2) NeedsCompilation: yes Packaged: 2022-04-25 10:00:51 UTC; hothorn Author: Torsten Hothorn [aut, cre], Kurt Hornik [aut] Maintainer: Torsten Hothorn Repository: CRAN Date/Publication: 2022-04-26 04:52:18 UTC exactRankTests/tests/0000755000175100001440000000000014231470523014376 5ustar hornikusersexactRankTests/tests/Examples/0000755000175100001440000000000014172231232016150 5ustar hornikusersexactRankTests/tests/Examples/exactRankTests-Ex.Rout.save0000644000175100001440000005724414172231232023311 0ustar hornikusers R version 4.1.1 (2021-08-10) -- "Kick Things" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "exactRankTests" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('exactRankTests') Package ‘exactRankTests’ is no longer under development. Please consider using package ‘coin’ instead. > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("ASAT") > ### * ASAT > > flush(stderr()); flush(stdout()) > > ### Name: ASAT > ### Title: Toxicological Study on Female Wistar Rats > ### Aliases: ASAT > ### Keywords: datasets > > ### ** Examples > > > set.seed(29) > > data(ASAT) > # does not really look symmetric > > plot(asat ~ group, data=ASAT) > > # proof-of-safety based on ration of medians > pos <- wilcox.exact(I(log(asat)) ~ group, data = ASAT, alternative = "less", + conf.int=TRUE) > > # one-sided confidence set. Safety cannot be concluded since the effect of > # the compound exceeds 20% of the control median > exp(pos$conf.int) [1] 0.000000 1.337778 attr(,"conf.level") [1] 0.95 > > > > cleanEx() > nameEx("ansari.exact") > ### * ansari.exact > > flush(stderr()); flush(stdout()) > > ### Name: ansari.exact > ### Title: Ansari-Bradley Test > ### Aliases: ansari.exact ansari.exact.default ansari.exact.formula > ### Keywords: htest > > ### ** Examples > > ## Hollander & Wolfe (1973, p. 86f): > ## Serum iron determination using Hyland control sera > ramsay <- c(111, 107, 100, 99, 102, 106, 109, 108, 104, 99, + 101, 96, 97, 102, 107, 113, 116, 113, 110, 98) > jung.parekh <- c(107, 108, 106, 98, 105, 103, 110, 105, 104, + 100, 96, 108, 103, 104, 114, 114, 113, 108, 106, 99) > ansari.test(ramsay, jung.parekh) Warning in ansari.test.default(ramsay, jung.parekh) : cannot compute exact p-value with ties Ansari-Bradley test data: ramsay and jung.parekh AB = 185.5, p-value = 0.1815 alternative hypothesis: true ratio of scales is not equal to 1 > ansari.exact(ramsay, jung.parekh) Ansari-Bradley test data: ramsay and jung.parekh AB = 185.5, p-value = 0.1881 alternative hypothesis: true ratio of scales is not equal to 1 > > ansari.exact(rnorm(20), rnorm(20, 0, 2), conf.int = TRUE) Ansari-Bradley test data: rnorm(20) and rnorm(20, 0, 2) AB = 250, p-value = 0.03133 alternative hypothesis: true ratio of scales is not equal to 1 95 percent confidence interval: 0.2979059 0.9800937 sample estimates: ratio of scales 0.5315074 > > > > cleanEx() > nameEx("bloodp") > ### * bloodp > > flush(stderr()); flush(stdout()) > > ### Name: bloodp > ### Title: Diastolic Blood Pressure > ### Aliases: bloodp > ### Keywords: datasets > > ### ** Examples > > data(bloodp) > > # Permutation test > > perm.test(bp ~ group, data=bloodp) 2-sample Permutation Test data: bp by group T = 402, p-value = 0.104 alternative hypothesis: true mu is not equal to 0 > perm.test(bp ~ group, data=bloodp, alternative="greater") 2-sample Permutation Test data: bp by group T = 402, p-value = 0.05641 alternative hypothesis: true mu is greater than 0 > perm.test(bp ~ group, data=bloodp, exact=FALSE) Asymptotic 2-sample Permutation Test data: bp by group T = 402, p-value = 0.107 alternative hypothesis: true mu is not equal to 0 > > # Wilcoxon-Mann-Whitney test > > wilcox.exact(bp ~ group, data=bloodp, conf.int=TRUE, alternative="l") Exact Wilcoxon rank sum test data: bp by group W = 35, p-value = 0.9648 alternative hypothesis: true mu is less than 0 95 percent confidence interval: -Inf 20 sample estimates: difference in location 9.5 > wilcox.exact(bp ~ group, data=bloodp, conf.int=TRUE) Exact Wilcoxon rank sum test data: bp by group W = 35, p-value = 0.0989 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: -4 22 sample estimates: difference in location 9.5 > > # compute the v.d. Waerden test > > sc <- cscores(bloodp$bp, type="NormalQuantile") > X <- sum(sc[bloodp$group == "group2"]) > round(pperm(X, sc, 11), 4) [1] 0.0462 > ## IGNORE_RDIFF_BEGIN > round(pperm(X, sc, 11, simulate=TRUE), 4) [1] 0.0372 > round(pperm(X, sc, 11, alternative="two.sided"), 4) [1] 0.0799 > round(pperm(X, sc, 11, alternative="two.sided", simulate=TRUE), 4) [1] 0.0705 > ## IGNORE_RDIFF_END > > # use scores mapped into integers (cf. dperm) > > sc <- cscores(bloodp$bp, type="NormalQuantile", int=TRUE) > X <- sum(sc[bloodp$group == "group2"]) > round(pperm(X, sc, 11), 4) [1] 0.0462 > round(pperm(X, sc, 11, alternative="two.sided"), 4) [1] 0.0799 > > > > > cleanEx() > nameEx("cscores") > ### * cscores > > flush(stderr()); flush(stdout()) > > ### Name: cscores > ### Title: Computation of Scores > ### Aliases: cscores cscores.default cscores.Surv cscores.factor > ### Keywords: misc > > ### ** Examples > > > y <- rnorm(50) > # v.d. Waerden scores > nq <- cscores(y, type="Normal", int=TRUE) > # quantile for m=20 observations in the first group > qperm(0.1, nq, 20) [1] -102 > > > > > cleanEx() > nameEx("dperm") > ### * dperm > > flush(stderr()); flush(stdout()) > > ### Name: dperm > ### Title: Distribution of One and Two Sample Permutation Tests > ### Aliases: dperm pperm qperm rperm > ### Keywords: distribution > > ### ** Examples > > > # exact one-sided p-value of the Wilcoxon test for a tied sample > > x <- c(0.5, 0.5, 0.6, 0.6, 0.7, 0.8, 0.9) > y <- c(0.5, 1.0, 1.2, 1.2, 1.4, 1.5, 1.9, 2.0) > r <- cscores(c(x,y), type="Wilcoxon") > pperm(sum(r[seq(along=x)]), r, 7) [1] 0.004351204 > > # Compare the exact algorithm as implemented in ctest and the > # Shift-Algorithm by Streitberg & Roehmel for untied samples > > # Wilcoxon: > > n <- 10 > x <- rnorm(n, 2) > y <- rnorm(n, 3) > r <- cscores(c(x,y), type="Wilcoxon") > > # exact distribution using the Shift-Algorithm > > dwexac <- dperm((n*(n+1)/2):(n^2 + n*(n+1)/2), r, n) > sum(dwexac) # should be something near 1 :-) [1] 1 > > # exact distribution using dwilcox > > dw <- dwilcox(0:(n^2), n, n) > > # compare the two distributions: > > plot(dw, dwexac, main="Wilcoxon", xlab="dwilcox", ylab="dperm") > # should give a "perfect" line > > # Wilcoxon signed rank test > > n <- 10 > x <- rnorm(n, 5) > y <- rnorm(n, 5) > r <- cscores(abs(x - y), type="Wilcoxon") > pperm(sum(r[x - y > 0]), r, length(r)) [1] 0.2783203 > wilcox.test(x,y, paired=TRUE, alternative="less") Wilcoxon signed rank exact test data: x and y V = 21, p-value = 0.2783 alternative hypothesis: true location shift is less than 0 > psignrank(sum(r[x - y > 0]), length(r)) [1] 0.2783203 > > # Ansari-Bradley > > n <- 10 > x <- rnorm(n, 2, 1) > y <- rnorm(n, 2, 2) > > # exact distribution using the Shift-Algorithm > > sc <- cscores(c(x,y), type="Ansari") > dabexac <- dperm(0:(n*(2*n+1)/2), sc, n) > sum(dabexac) [1] 1 > > # real scores are allowed (but only result in an approximation) > # e.g. v.d. Waerden test > > n <- 10 > x <- rnorm(n) > y <- rnorm(n) > scores <- cscores(c(x,y), type="NormalQuantile") > X <- sum(scores[seq(along=x)]) # <- v.d. Waerden normal quantile statistic > > # critical value, two-sided test > > abs(qperm(0.025, scores, length(x))) Warning in findfact(scores - min(scores) + 1, m, tol) : cannot hold tol, tolerance: 0.010292 [1] 3.871345 > > # p-values > > p1 <- pperm(X, scores, length(x), alternative="two.sided") Warning in findfact(scores - min(scores) + 1, m, tol) : cannot hold tol, tolerance: 0.010292 > > # generate integer valued scores with the same shape as normal quantile > # scores, this no longer v.d.Waerden, but something very similar > > scores <- cscores(c(x,y), type="NormalQuantile", int=TRUE) > > X <- sum(scores[seq(along=x)]) > p2 <- pperm(X, scores, length(x), alternative="two.sided") > > # compare p1 and p2 > > p1 - p2 [1] -0.01441902 > > > > > cleanEx() > nameEx("ears") > ### * ears > > flush(stderr()); flush(stdout()) > > ### Name: ears > ### Title: Survival of Ventilating Tubes > ### Aliases: ears > ### Keywords: datasets > > ### ** Examples > > data(ears) > if (require(survival, quietly=TRUE)) { + ls <- cscores(Surv(ears$left, ears$lcens), int=TRUE) + perm.test(ls ~ group, data=ears) + } 2-sample Permutation Test data: ls by group T = 748, p-value = 0.01222 alternative hypothesis: true mu is not equal to 0 > > > > > cleanEx() detaching ‘package:survival’ > nameEx("glioma") > ### * glioma > > flush(stderr()); flush(stdout()) > > ### Name: glioma > ### Title: Malignant Glioma Pilot Study > ### Aliases: glioma > ### Keywords: datasets > > ### ** Examples > > data(glioma) > > if(require(survival, quietly = TRUE)) { + + par(mfrow=c(1,2)) + + # Grade III glioma + g3 <- glioma[glioma$Histology == "Grade3",] + + # Plot Kaplan-Meier curves + plot(survfit(Surv(Survival, Cens) ~ Group, data=g3), + main="Grade III Glioma", lty=c(2,1), + legend.text=c("Control", "Treated"), + legend.bty=1, ylab="Probability", + xlab="Survival Time in Month") + + # log-rank test + survdiff(Surv(Survival, Cens) ~ Group, data=g3) + + # permutation test with integer valued log-rank scores + lsc <- cscores(Surv(g3$Survival, g3$Cens), int=TRUE) + perm.test(lsc ~ Group, data=g3) + + # permutation test with real valued log-rank scores + lsc <- cscores(Surv(g3$Survival, g3$Cens), int=FALSE) + tr <- (g3$Group == "RIT") + T <- sum(lsc[tr]) + pperm(T, lsc, sum(tr), alternative="tw") + pperm(T, lsc, sum(tr), alternative="tw", simulate=TRUE) + + # Grade IV glioma + gbm <- glioma[glioma$Histology == "GBM",] + + # Plot Kaplan-Meier curves + plot(survfit(Surv(Survival, Cens) ~ Group, data=gbm), + main="Grade IV Glioma", lty=c(2,1), + legend.text=c("Control", "Treated"), + legend.bty=1, legend.pos=1, ylab="Probability", + xlab="Survival Time in Month") + + # log-rank test + survdiff(Surv(Survival, Cens) ~ Group, data=gbm) + + # permutation test with integer valued log-rank scores + lsc <- cscores(Surv(gbm$Survival, gbm$Cens), int=TRUE) + perm.test(lsc ~ Group, data=gbm) + + # permutation test with real valued log-rank scores + lsc <- cscores(Surv(gbm$Survival, gbm$Cens), int=FALSE) + tr <- (gbm$Group == "RIT") + T <- sum(lsc[tr]) + pperm(T, lsc, sum(tr), alternative="tw") + pperm(T, lsc, sum(tr), alternative="tw", simulate=TRUE) + } Warning in plot.window(...) : "legend.text" is not a graphical parameter Warning in plot.window(...) : "legend.bty" is not a graphical parameter Warning in plot.xy(xy, type, ...) : "legend.text" is not a graphical parameter Warning in plot.xy(xy, type, ...) : "legend.bty" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.text" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.bty" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.text" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.bty" is not a graphical parameter Warning in box(...) : "legend.text" is not a graphical parameter Warning in box(...) : "legend.bty" is not a graphical parameter Warning in title(...) : "legend.text" is not a graphical parameter Warning in title(...) : "legend.bty" is not a graphical parameter Warning in findfact(scores - min(scores) + 1, m, tol) : cannot hold tol, tolerance: 0.010019 Warning in plot.window(...) : "legend.text" is not a graphical parameter Warning in plot.window(...) : "legend.bty" is not a graphical parameter Warning in plot.window(...) : "legend.pos" is not a graphical parameter Warning in plot.xy(xy, type, ...) : "legend.text" is not a graphical parameter Warning in plot.xy(xy, type, ...) : "legend.bty" is not a graphical parameter Warning in plot.xy(xy, type, ...) : "legend.pos" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.text" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.bty" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.pos" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.text" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.bty" is not a graphical parameter Warning in axis(side = side, at = at, labels = labels, ...) : "legend.pos" is not a graphical parameter Warning in box(...) : "legend.text" is not a graphical parameter Warning in box(...) : "legend.bty" is not a graphical parameter Warning in box(...) : "legend.pos" is not a graphical parameter Warning in title(...) : "legend.text" is not a graphical parameter Warning in title(...) : "legend.bty" is not a graphical parameter Warning in title(...) : "legend.pos" is not a graphical parameter Warning in findfact(scores - min(scores) + 1, m, tol) : cannot hold tol, tolerance: 0.010067 [1] 1e-04 > > > > graphics::par(get("par.postscript", pos = 'CheckExEnv')) > cleanEx() detaching ‘package:survival’ > nameEx("globulin") > ### * globulin > > flush(stderr()); flush(stdout()) > > ### Name: globulin > ### Title: Differences in Globulin Fraction in Two Groups > ### Aliases: globulin > ### Keywords: datasets > > ### ** Examples > > data(globulin) > perm.test(gfrac ~ group, data=globulin, conf.int=TRUE) 2-sample Permutation Test data: gfrac by group T = 331, p-value = 0.1475 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: -8.50 1.25 > > > > cleanEx() > nameEx("irank") > ### * irank > > flush(stderr()); flush(stdout()) > > ### Name: irank > ### Title: Integer Ranks > ### Aliases: irank > ### Keywords: univar > > ### ** Examples > > x <- rnorm(10) > irank(x) [1] 3 5 1 10 6 2 7 9 8 4 > rank(x) [1] 3 5 1 10 6 2 7 9 8 4 > x <- c(1,2,3,3,0) > irank(x) [1] 2 3 5 5 1 > rank(x) [1] 2.0 3.0 4.5 4.5 1.0 > > > > cleanEx() > nameEx("lungcancer") > ### * lungcancer > > flush(stderr()); flush(stdout()) > > ### Name: lungcancer > ### Title: Lung Cancer Clinical Trial > ### Aliases: lungcancer > ### Keywords: datasets > > ### ** Examples > > data(lungcancer) > attach(lungcancer) > > # round logrank scores > scores <- cscores.Surv(cbind(time, cens)) > T <- sum(scores[group=="newdrug"]) > mobs <- sum(group=="newdrug") > (prob <- pperm(T, scores, m=mobs, al="le")) [1] 0.000999001 > pperm(T, scores, m=mobs, al="tw") [1] 0.000999001 > pperm(T, scores, m=mobs, al="tw", simulate=TRUE) [1] 0.0011 > > # map into integers, faster > scores <- cscores.Surv(cbind(time, cens), int=TRUE) > T <- sum(scores[group=="newdrug"]) > mobs <- sum(group=="newdrug") > (prob <- pperm(T, scores, m=mobs, al="le")) [1] 0.000999001 > pperm(T, scores, m=mobs, al="tw") [1] 0.000999001 > pperm(T, scores, m=mobs, al="tw", simulate=TRUE) [1] 9e-04 > > detach(lungcancer) > > > > > cleanEx() > nameEx("neuropathy") > ### * neuropathy > > flush(stderr()); flush(stdout()) > > ### Name: neuropathy > ### Title: Acute Painful Diabetic Neuropathy > ### Aliases: neuropathy > ### Keywords: datasets > > ### ** Examples > > data(neuropathy) > # compare with Table 2 of Conover & Salsburg (1988) > wilcox.exact(pain ~ group, data=neuropathy, alternative="less") Exact Wilcoxon rank sum test data: pain by group W = 357, p-value = 0.1654 alternative hypothesis: true mu is less than 0 > css <- cscores(neuropathy$pain, type="ConSal") > pperm(sum(css[neuropathy$group=="control"]),css, + m=sum(neuropathy$group=="control")) Warning in findfact(scores - min(scores) + 1, m, tol) : cannot hold tol, tolerance: 0.047123 [1] 0.0307573 > > > > > cleanEx() > nameEx("ocarcinoma") > ### * ocarcinoma > > flush(stderr()); flush(stdout()) > > ### Name: ocarcinoma > ### Title: Ovarian Carcinoma > ### Aliases: ocarcinoma > ### Keywords: datasets > > ### ** Examples > > > data(ocarcinoma) > attach(ocarcinoma) > # compute integer valued logrank scores > logrsc <- cscores.Surv(cbind(time, cens), int=TRUE) > # the test statistic > lgT <- sum(logrsc[stadium == "II"]) > # p-value > round(pperm(lgT, logrsc, m=sum(stadium=="II"), al="tw"), 4) [1] 0.0191 > > # compute logrank scores and simulate p-value > logrsc <- cscores.Surv(cbind(time, cens), int=FALSE) > # the test statistic > lgT <- sum(logrsc[stadium == "II"]) > # p-value > round(pperm(lgT, logrsc, m=sum(stadium=="II"), al="tw", simulate=TRUE), 4) [1] 0.0179 > > > > > cleanEx() detaching ‘ocarcinoma’ > nameEx("perm.test") > ### * perm.test > > flush(stderr()); flush(stdout()) > > ### Name: perm.test > ### Title: One and Two Sample Permutation Test > ### Aliases: perm.test perm.test.default perm.test.formula > ### Keywords: htest > > ### ** Examples > > > # Example from Gardner & Altman (1989), p. 30 > # two treatments A and B, 1 means improvement, 0 means no improvement > # confidence sets cf. R\"ohmel (1996) > > A <- c(rep(1, 61), rep(0, 19)) > B <- c(rep(1, 45), rep(0, 35)) > perm.test(A, B, conf.int=TRUE, exact=TRUE) 2-sample Permutation Test data: A and B T = 61, p-value = 0.0118 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: 0.05263158 0.34285714 > > # one-sample AIDS data (differences only), Methta and Patel (2001), > # Table 8.1 page 181 > > data(sal) > attach(sal) > ppdiff <- pre - post > detach(sal) > > # p-values in StatXact == 0.0011 one-sided, 0.0021 two.sided, page 183 > > perm.test(ppdiff) 1-sample Permutation Test data: ppdiff T = 4831, p-value = 0.002136 alternative hypothesis: true mu is not equal to 0 > perm.test(ppdiff, alternative="less") 1-sample Permutation Test data: ppdiff T = 4831, p-value = 0.999 alternative hypothesis: true mu is less than 0 > perm.test(ppdiff, exact=FALSE) Asymptotic 1-sample Permutation Test data: ppdiff T = 4831, p-value = 0.08779 alternative hypothesis: true mu is not equal to 0 > > > > > cleanEx() > nameEx("rotarod") > ### * rotarod > > flush(stderr()); flush(stdout()) > > ### Name: rotarod > ### Title: Rotating Rats Data > ### Aliases: rotarod > ### Keywords: datasets > > ### ** Examples > > data(rotarod) > wilcox.exact(time ~ group, data=rotarod, alternative="g") Exact Wilcoxon rank sum test data: time by group W = 102, p-value = 0.01863 alternative hypothesis: true mu is greater than 0 > wilcox.exact(time ~ group, data=rotarod, conf.int=TRUE) Exact Wilcoxon rank sum test data: time by group W = 102, p-value = 0.03727 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: 0 137 sample estimates: difference in location 14.5 > wilcox.exact(time ~ group, data=rotarod, exact=FALSE) Asymptotic Wilcoxon rank sum test data: time by group W = 102, p-value = 0.01473 alternative hypothesis: true mu is not equal to 0 > # the permutation test > perm.test(time ~ group, data=rotarod) 2-sample Permutation Test data: time by group T = 3600, p-value = 0.03727 alternative hypothesis: true mu is not equal to 0 > perm.test(time ~ group, data=rotarod, exact=FALSE) Asymptotic 2-sample Permutation Test data: time by group T = 3600, p-value = 0.0324 alternative hypothesis: true mu is not equal to 0 > > > > cleanEx() > nameEx("sal") > ### * sal > > flush(stderr()); flush(stdout()) > > ### Name: sal > ### Title: Serum Antigen Level > ### Aliases: sal > ### Keywords: datasets > > ### ** Examples > > data(sal) > attach(sal) > > wilcox.exact(pre, post, paired=TRUE, conf.int=TRUE) Exact Wilcoxon signed rank test data: pre and post V = 124, p-value = 0.002136 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: 54 292 sample estimates: (pseudo)median 137.75 > wilcox.exact(pre,post, paired=TRUE, conf.int=TRUE, exact=FALSE) Asymptotic Wilcoxon signed rank test data: pre and post V = 124, p-value = 0.003783 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: 54.49998 281.50005 sample estimates: (pseudo)median 137.2646 > > detach(sal) > > > > > cleanEx() > nameEx("wilcox.exact") > ### * wilcox.exact > > flush(stderr()); flush(stdout()) > > ### Name: wilcox.exact > ### Title: Wilcoxon Rank Sum and Signed Rank Tests > ### Aliases: wilcox.exact wilcox.exact.default wilcox.exact.formula > ### Keywords: htest > > ### ** Examples > > ## One-sample test. > ## Hollander & Wolfe (1973), 29f. > ## Hamilton depression scale factor measurements in 9 patients with > ## mixed anxiety and depression, taken at the first (x) and second > ## (y) visit after initiation of a therapy (administration of a > ## tranquilizer). > x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30) > y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29) > wilcox.exact(x, y, paired = TRUE, alternative = "greater") Exact Wilcoxon signed rank test data: x and y V = 40, p-value = 0.01953 alternative hypothesis: true mu is greater than 0 > wilcox.exact(y - x, alternative = "less") # The same. Exact Wilcoxon signed rank test data: y - x V = 5, p-value = 0.01953 alternative hypothesis: true mu is less than 0 > > ## Two-sample test. > ## Hollander & Wolfe (1973), 69f. > ## Permeability constants of the human chorioamnion (a placental > ## membrane) at term (x) and between 12 to 26 weeks gestational > ## age (y). The alternative of interest is greater permeability > ## of the human chorioamnion for the term pregnancy. > x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) > y <- c(1.15, 0.88, 0.90, 0.74, 1.21) > wilcox.exact(x, y, alternative = "g") # greater Exact Wilcoxon rank sum test data: x and y W = 35, p-value = 0.1272 alternative hypothesis: true mu is greater than 0 > > ## Formula interface. > data(airquality) > boxplot(Ozone ~ Month, data = airquality) > wilcox.exact(Ozone ~ Month, data = airquality, + subset = Month %in% c(5, 8)) Exact Wilcoxon rank sum test data: Ozone by Month W = 127.5, p-value = 6.109e-05 alternative hypothesis: true mu is not equal to 0 > > > # Hollander & Wolfe, p. 39, results p. 40 and p. 53 > > x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30) > y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29) > > wilcox.exact(y,x, paired=TRUE, conf.int=TRUE) Exact Wilcoxon signed rank test data: y and x V = 5, p-value = 0.03906 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: -0.786 -0.010 sample estimates: (pseudo)median -0.46 > > # Hollander & Wolfe, p. 110, results p. 111 and p. 126 > > x <- c(0.8, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) > y <- c(1.15, 0.88, 0.90, 0.74, 1.21) > > wilcox.exact(y,x, conf.int=TRUE) Exact Wilcoxon rank sum test data: y and x W = 15, p-value = 0.2544 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: -0.76 0.15 sample estimates: difference in location -0.305 > > > > > ### *