Learn R Programming

flip (version 2.0)

flip: The main function for univariate tests under permutation framework

Description

The general function for permutation (or rotation) test.

It allows for multivariate one sample, C>=2 samples and any regression tests. Also the use of covariates (to be fitted in the model but) not under test is allowed.

Usage

flip(Y, X=NULL, Z=NULL, data=NULL, tail = 0, perms = 1000, statTest=NULL, 
     Strata=NULL, flipReturn, testType=c("permutation","rotation"), ...)

flip.statTest # = c("t", "F", "ANOVA", # "Wilcoxon","Kruskal-Wallis", "kruskal", "rank", "Mann-Whitney", # "chisq","chisq.separated", "Fisher", # "McNemar", "Sign","sum")

Arguments

Y
The response vector of the regression model. May be supplied as a vector or as a formula object. In the latter case, the right hand side of Y is passed on to
X
The part of the design matrix corresponding to the alternative hypothesis. The covariates of the null model do not have to be supplied again here. May be given as a half formula
Z
The part of the design matrix corresponding to the null hypothesis. May be given as a design matrix or as a half formula object (e.g. ~a+b). The default for Z is
data
Only used when Y, X, or Z is given in formula form. An optional data frame, list or environment containing the variables used in the formula. If the variables in a formula are not found in data, the vari
tail
Vector of values -1, 0 or 1 indicating the tail to be used in the test for each column of Y. I the length of tail is smaller than number of columns of Y, the values are recycled.
perms
The number of permutations to use. The default is perms = 1000. Alternatively it can be a matrix (i.e. the permutation space) or a list with elements number and seed.
Strata
A vector, which unique values identifies strata. This option is used only with testType="permutation"; parameter Z is not considered in this case. Also note that when only two levels with one observation per each level are pres
statTest
Choose from flip.statTest. See also Details section.
flipReturn
list of objects indicating what will be included in the output.

e.g. list(permP=TRUE,permT=TRUE,data=TRUE).

testType
by default testType="permutation". In alternative you can choose "rotation" resampling is performed through random linear combinations (i.e. a rotation test is performed). This option is useful when only few permutations are avai
...
Further parameters. The followings are still valid but deprecated (use flipReturn instead):

permT.return = TRUE, permP.return = FALSE, permSpace.return = FALSE, permY.return = FALSE.

Value

  • The function returns an object of class flip.object. Several operations and plots can be made from this object. See also flip.object-class.

Details

statTest="t" use the t statistic derived from the correlation among the X and the Y. Therefore for multiple Xs, can be slight different from the t test of parametric linear models (the fitted model does not consider the other covariates). The test are valid only under the null hypothesis that all Xs are independent of the single Y. To get adequate test use use Z. The test statistic "sum" is the sum of values (or frequencies) of the given sample centered on the expected (i.e. computed on the overall sample). It performs all possible comparisons among values of X and Y (i.e. it does not produce only one test. p-values can be combined using npc).

"ANOVA" is synonyms of "F". Only valid for dependence tests (i.e. non constant X). "Mann-Whitney" is synonyms of "Wilcoxon". "rank" choose among "Wilcoxon" and "Kruskal-Wallis" depending if the samples are two or more (respectively).

The "Wilcoxon" statistic is based on the 'sum of ranks of second sample minus n1*(n+1)/2' instead of 'sum of ranks of smallest sample minus nSmallest*(n+1)/2'. Therefore the statistic is centered on 0 and allow for two sided alternatives. Despite the p-value are ok, it requires the X to be a two-levels factor in order to compute the right test statistic. When the X is not a two-levels factor, it measures the codeviance among X and ranks of Y.

For paired samples (see also the argument Strata and the example below) the Signed Rank test is performed. To perform the Sign Test use option Sign (i.e. same as Signed Rank but without using magnitude of ranks).

The "Fisher" test is allowed only with dichotomous Ys. The reported statistic is the bottom-right cell of the 2 by 2 frequencies table. The "chisq.separated" test perform cell-wise chi squared (see also Finos and Salmaso (2004) Communications in Statistics - Theory and methods).

The "McNemar" test is based on the signs of the differences, hence it can be used also with ordinal or continuous responses. Only valid for symmetry tests (i.e. X is constant or NULL). The reported statistic for "McNemar" test is the signed squared root of the McNemar statistic. Hence it allows for tailed alternatives.

For ordered X, a stochastic ordering test can be performed using "t","Wilcoxon","sum" and then combining the separated test using npc.

References

For the general framework of univariate and multivariate permutation tests see: Pesarin, F. (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, Mew York.

for Rotation tests see: Langsrud, O. (2005) Rotation tests, Statistics and Computing, 15, 1, 53-60

See Also

The permutation spaces on which the test is based: permutationSpace function and useful functions associated with that object.

Multiplicity correction and Overall test: npc.

Examples

Run this code
X=rep(0:1,5)

Y=data.frame(matrix(rnorm(50),10,5))
Y=Y+matrix(X*2,10,5)
names(Y)=LETTERS[1:5]

data=data.frame(Y,X=X, Z=rnorm(10))
#testing dependence among Y's and X
res = flip(Y,~X,data=data)
res
#same as:
res = flip(A+B+C+D+E~X,data=data)

#testing dependence among Y's and X also using covariates
res = flip(Y,~X,~Z,data=data)
res

#Using rank tests:
res = flip(Y,~X,data=data,statTest="Wilcoxon")
res


#testing symmetry of Y around 0
Y[,1:2]=Y[,1:2] +2
res = flip(Y)
res
plot(res)


#use of strata (in this case equal to paired samples)
data$S=rep(1:5,rep(2,5))
#paired t
flip(A+B+C+D+E~X,data=data,statTest="t",Strata=~S)
#signed Rank test
flip(A+B+C+D+E~X,data=data,statTest="Wilcox",Strata=~S)

Run the code above in your browser using DataLab