Title: | Multivariate Permutation Tests |
---|---|
Description: | It implements many univariate and multivariate permutation (and rotation) tests. Allowed tests: the t one and two samples, ANOVA, linear models, Chi Squared test, rank tests (i.e. Wilcoxon, Mann-Whitney, Kruskal-Wallis), Sign test and Mc Nemar. Test on Linear Models are performed also in presence of covariates (i.e. nuisance parameters). The permutation and the rotation methods to get the null distribution of the test statistics are available. It also implements methods for multiplicity control such as Westfall & Young minP procedure and Closed Testing (Marcus, 1976) and k-FWER. Moreover, it allows to test for fixed effects in mixed effects models. |
Authors: | Livio Finos, with contributions by Florian Klinglmueller, Dario Basso, Aldo Solari, Lucia Benetazzo, Jelle Goeman and Marco Rinaldo. |
Maintainer: | Livio Finos <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.5.0 |
Built: | 2024-12-05 06:48:10 UTC |
Source: | CRAN |
The library is devoted to permutation-based inferential methods.
It implements many univariate and multivariate permutation (and rotation) tests.
The tests comprised are: the one and two samples, ANOVA, linear models, Chi Squared test, rank tests (i.e. Wilcoxon, Mann-Whitney, Kruskal-Wallis), Kolmogorov-Smirnov and Anderson-Darling.
Test on Linear Models are performed also in presence of covariates (i.e. nuisance parameters).
The permutation and the rotation method to get the null distribution of the test statistic(s) are available.
It also implements methods for multiplicity control such as Westfall-Young min-p procedure and Closed Testing (Marcus, 1976).
Package: | flip |
Type: | Package |
Version: | 1.1 |
Date: | 2012-02-05 |
License: | GPL <=2 |
LazyLoad: | yes |
Depends: | methods, e1071, someMTP, cherry |
Livio Finos, with contributions by Florian Klinglmueller, Dario Basso, Aldo Solari, Lucia Benetazzo, Jelle Goeman and Marco Rinaldo. Special thanks are due to Ivan Marin-Franch and Fredrik Nilsson for the debugging and the good questions.
Maintainer: livio finos <[email protected]>
For the general framework of univariate and multivariate permutation tests see: Pesarin, F. (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
#' @references For the general framework of univariate and multivariate permutation tests see: Pesarin, F. (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
Livio Finos and Fortunato Pesarin (2018) On zero-inflated permutation testing and some related problems. Statistical Papers.
For analysis of mixed-models see: L. Finos and D. Basso (2014) Permutation Tests for Between-Unit Fixed Effects in Multivariate Generalized Linear Mixed Models. Statistics and Computing. Vo- lume 24, Issue 6, pp 941-952. DOI: 10.1007/s11222-013-9412-6 J. J. Goeman and
D. Basso, L. Finos (2011) Exact Multivariate Permutation Tests for Fixed Effec- ts in Mixed-Models. Communications in Statistics - Theory and Methods. DOI 10.1080/03610926.2011.627103
For Rotation tests see: Langsrud, O. (2005) Rotation tests, Statistics and Computing, 15, 1, 53-60
A. Solari, L. Finos, J.J. Goeman (2014) Rotation-based multiple testing in the multivariate linear model. Biometrics, 70 (4), 954-961.
Y=data.frame(matrix(rnorm(50),10,5)) names(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] x=rep(0:1,5) data=data.frame(x=x, Z=rnorm(10)) res = flip(Y+matrix(x*2,10,5),~x,~Z,data=data) res plot(res) p2=npc(res,"fisher",subsets=list(c1=c("A","B"),c2=names(Y))) p2
Y=data.frame(matrix(rnorm(50),10,5)) names(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] x=rep(0:1,5) data=data.frame(x=x, Z=rnorm(10)) res = flip(Y+matrix(x*2,10,5),~x,~Z,data=data) res plot(res) p2=npc(res,"fisher",subsets=list(c1=c("A","B"),c2=names(Y))) p2
It concatenates flip objects warning("More than one test statistic is imputed, only the first perms space will be stored.")
cFlip(...)
cFlip(...)
... |
arguments |
a flip.object
The main function for univariate and multivariate testing under a permutation (and rotation) framework + some utilities.
flip
is the main 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.
statTest="t"
is the t statistic derived from the correlation among
each Xs and each Ys (i.e. a linear model for each couples of Xs and Ys).
This is different from the fit of a multiple (multivariate) linear models,
since the correlation does not consider the other covariates). The test
t
is valid only under the assumption that each variable in X is
independent of each variable in Y. To get adequate test while adjusting for
covariates, use Z
(see example below) 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). "coeff"
is the
statistic based on the estimated coefficient of an lm
. It produces a
test for every possible combination of (columns of) X
and Y
(p-values can be combined using npc
). "cor"
is the correlation
(i.e. not partial correlation) between each column of X
and each of
Y
. "cor.Spearman"
(or "cor.rank"
) is the analogous for
Spearman's rank correlation coefficient.
"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 Y
s. 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
.
When statTest
is a function
, the first argument must be
Y
. This same function is ran to observed data Y
and to a
number of permuted rows of Y
. The returned value must be a vector of
test statistics. Please note that argument tail
must be defined
accordingly. The default way the rows of Y
are rearranged is through
permutation (without strata). More complex permutation strategies can be
defined through proper definition of argument perm
(see also
permutationSpace
).
For testType="rotation"
: As long as the number of orthogonalized
residuals (i.e. the number of observations minus the number of columns in
Z
) is lower than 50, the function rom
is used. The the number
is larger, the faster version romFast
is used instead. Although the
latter is less accurate, for such a big sample size, it is not expected to
affect the control of the type I error.
flip(Y, X = NULL, Z = NULL, data = NULL, tail = 0, perms = 1000, statTest = NULL, Strata = NULL, flipReturn, testType = NULL, returnGamma = TRUE, ...)
flip(Y, X = NULL, Z = NULL, data = NULL, tail = 0, perms = 1000, statTest = NULL, Strata = NULL, flipReturn, testType = NULL, returnGamma = TRUE, ...)
Y |
The response vector of the regression model. May be supplied as a
vector or as a |
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 |
Z |
The part of the design matrix corresponding to the null hypothesis.
May be given as a design matrix or as a half
|
data |
Only used when |
tail |
Vector of values -1, 0 or 1 indicating the tail to be used in
the test for each column of |
perms |
The number of permutations to use. The default is |
statTest |
Choose a test statistic from |
Strata |
A vector, which unique values identifies strata. This option
is used only with |
flipReturn |
list of objects indicating what will be included in the output. e.g. |
testType |
by default |
returnGamma |
logical. Should be the eigenvectors (with corresponding
non-null eigenvalues) of the anti-projection matrix of |
... |
Further parameters. The followings are still valid but deprecated:
|
An object of class flip.object
. Several operations and plots
can be made from this object. See also flip.object-class
.
livio finos, Florian Klinglmueller
For the general framework of univariate and multivariate permutation tests see: Pesarin, F. (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
For Rotation tests see: Langsrud, O. (2005) Rotation tests, Statistics and Computing, 15, 1, 53-60
A. Solari, L. Finos, J.J. Goeman (2014) Rotation-based multiple testing in the multivariate linear model. Biometrics, 70 (4), 954-961.
Livio Finos and Fortunato Pesarin (2018) On zero-inflated permutation testing and some related problems. Statistical Papers.
The permutation spaces on which the test is based:
permutationSpace
function and useful functions associated with
that object.
Multiplicity correction: flip.adjust
and Global test:
npc
.
Y=matrix(rnorm(50),10,5) colnames(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] +1 res = flip(Y) res plot(res[[1]]) plot(res[2:3]) plot(res) X=rep(0:1,5) Y=Y+matrix(X*2,10,5) data=data.frame(Y,X=X, Z=rnorm(10)) #testing dependence among Y's and X (res = flip(Y,~X,data=data)) #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 #Note that #flip(Y,X=~X,Z=~1,data=data) #is different from #flip(Y,~X,data=data) #since the former is based on orthogonalized residuals of Y and X by Z. ## Not run: #Rotation tests: rot=flip(Y,X,Z=~1,testType="rotation") # note the use Z=~1. ## End(Not run) #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) # tests for categorical data data=data.frame(X=rep(0:2,10)) data=data.frame(X=factor(data$X),Y=factor(rbinom(30,2,.2+.2*data$X))) flip(~Y,~X,data=data,statTest="chisq") # separated chisq (Finos and Salmaso, 2004. Nonparametric multi-focus analysis # for categorical variables. CommStat - T.M.) (res.sep=flip(~Y,~X,data=data,statTest="chisq.separated")) npc(res.sep,"sumT2") #note that combined test statistic is the same as chisq ## Not run: # User-defined test statistic: my.fun <- function(Y){ summary(lm(Y~X))$coeff[2,"Estimate"] } X <- matrix(rep(0:2,5)) Y <- matrix(rnorm(mean=X,n=15)) res=flip(Y=Y,X=X,statTest=my.fun,tail=0) res hist(res) ## End(Not run)
Y=matrix(rnorm(50),10,5) colnames(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] +1 res = flip(Y) res plot(res[[1]]) plot(res[2:3]) plot(res) X=rep(0:1,5) Y=Y+matrix(X*2,10,5) data=data.frame(Y,X=X, Z=rnorm(10)) #testing dependence among Y's and X (res = flip(Y,~X,data=data)) #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 #Note that #flip(Y,X=~X,Z=~1,data=data) #is different from #flip(Y,~X,data=data) #since the former is based on orthogonalized residuals of Y and X by Z. ## Not run: #Rotation tests: rot=flip(Y,X,Z=~1,testType="rotation") # note the use Z=~1. ## End(Not run) #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) # tests for categorical data data=data.frame(X=rep(0:2,10)) data=data.frame(X=factor(data$X),Y=factor(rbinom(30,2,.2+.2*data$X))) flip(~Y,~X,data=data,statTest="chisq") # separated chisq (Finos and Salmaso, 2004. Nonparametric multi-focus analysis # for categorical variables. CommStat - T.M.) (res.sep=flip(~Y,~X,data=data,statTest="chisq.separated")) npc(res.sep,"sumT2") #note that combined test statistic is the same as chisq ## Not run: # User-defined test statistic: my.fun <- function(Y){ summary(lm(Y~X))$coeff[2,"Estimate"] } X <- matrix(rep(0:2,5)) Y <- matrix(rnorm(mean=X,n=15)) res=flip(Y=Y,X=X,statTest=my.fun,tail=0) res hist(res) ## End(Not run)
npc
provides overall tests (i.e. weak FWER control), while
flip.adjust
provides adjusted p-values (i.e. strong FWER control).
flip.adjust(permTP, method = flip.npc.methods, maxalpha = 1, weights = NULL, stdSpace = FALSE, ...) npc(permTP, comb.funct = c(flip.npc.methods, p.adjust.methods), subsets = NULL, weights = NULL, stdSpace = FALSE, ...)
flip.adjust(permTP, method = flip.npc.methods, maxalpha = 1, weights = NULL, stdSpace = FALSE, ...) npc(permTP, comb.funct = c(flip.npc.methods, p.adjust.methods), subsets = NULL, weights = NULL, stdSpace = FALSE, ...)
permTP |
A permutation space (B times m matrix) or an
|
method |
A method among |
maxalpha |
Adjusted p-values greater than |
weights |
Optional argument that can be used to give certain variables
greater weight in the combined test. Can be a vector or a list of vectors.
In the latter case, a separate test will be performed for each weight
vector. If both |
stdSpace |
Ask if the permutation distribution of the test statistic
should be standardized or not. The default is |
... |
further arguments. Among them, |
comb.funct |
A combining function |
subsets |
Optional argument that can be used to test one or more
subsets of variables. Can be a vector of column names or indices of a
|
npc
combines the p-values using the combining functions (and the
method) described in Pesarin (2001). It makes use of the join space of the
permutations. This is usually derived from a call of flip
function or
flipMixWithin
.
Very shortly: "Fisher"
=-sum log(p-values) "Liptak"
=sum
qnorm(p-values) "MahalanobisT"
= Mahalanobis distance of centered
matrix permTP
(or permTP@permT
) "MahalanobisP"
= same
as above, but using scores defined by qnorm(p-values) (tails are forced to
be one-sided) "minP"
= "Tippett"
= min(p-values) \
"maxT"
= max(test statistics) "maxTstd"
= max(standardized
test statistics) "sumT"
= sum (test statistics) "sumTstd"
= sum (standardized test statistics) "sumT2"
= sum (test
statistics)^2
. The followings have to be used carefully and only with
objects from function flipMix
: "data.sum"
= sum of all columns of
Y, "data.linComb"
= sum of all columns of Y (includes a vector or
matrix linComb
among the arguments), "data.pc"
= extracts the
first Principal component from the covariance matrix (you may also include a
vector whichPCs
indicating which PCs you want to consider)\
"data.trace"
= Extends the Pillai Trace, use parametric bootstrap to
asses the significance."kfwer"
= can be only used with
flip.adjust
(not in npc
). It requires an extra parameter
k
(k=11
by default).
flip.adjust
adjusts the p-value for multiplicity (FamilyWise Error
Rate -FWER- and kFWER). When method
is equal to "maxT"
,
"maxTstd"
(i.e. max T on scale(permTP)
) or "minP" (i.e.
Tippett) it performs the step-down method of Westfall and Young (1993). For
any other element of flip.npc.methods
(i.e. "Fisher", "Liptak",
"sumT" (i.e. direct) or "sumT2" (sum of T^2)) a call to npc
together
with a closed testing procedure is used (it make use of
cherry:closed
). When method
is any
among p.adjust.methods
the function stats:p.adjust
or -if
weights are provided- someMTP:p.adjust.w
is used. To perform control
of the kFWER use flip.adjust
with method="kfwer"
and extra
parameter k
.
The function returns an object of class
flip.object-class
(and the use of
getFlip(obj,"Adjust")
.
livio finos, Florian Klinglmueller and Aldo Solari.
Pesarin (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
P. H. Westfall and S. S. Young (1993). Resampling-based multiple testing: Examples and methods for p-value adjustment. John Wiley & Sons.
Y=data.frame(matrix(rnorm(50),10,5)) names(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2]+1.5 res = flip(Y,perms=10000) ########npc p2=npc(res) # same as p2=npc(res,"Fisher") summary(p2) p2=npc(res,"minP") summary(p2) p2=npc(res,"Fisher",subsets=list(c1=c("A","B"),c2=names(Y))) summary(p2) p2=npc(res,"Fisher",subsets=list(c1=c("A","B"),c2=names(Y)),weights=1:5) summary(p2) res=flip.adjust(res, method="maxT") #res=flip.adjust(res,"BH") ##same as #p.adjust(res,"BH") ## now try getFlip(res,"Adjust")
Y=data.frame(matrix(rnorm(50),10,5)) names(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2]+1.5 res = flip(Y,perms=10000) ########npc p2=npc(res) # same as p2=npc(res,"Fisher") summary(p2) p2=npc(res,"minP") summary(p2) p2=npc(res,"Fisher",subsets=list(c1=c("A","B"),c2=names(Y))) summary(p2) p2=npc(res,"Fisher",subsets=list(c1=c("A","B"),c2=names(Y)),weights=1:5) summary(p2) res=flip.adjust(res, method="maxT") #res=flip.adjust(res,"BH") ##same as #p.adjust(res,"BH") ## now try getFlip(res,"Adjust")
The class flip.object is the output of a call to flip
, flipMix
, npc
, flip.adjust
etc.
The following are functions to extract and manipulate relevant information from
a flip.object
.
show
prints the flip.object.
summary
: Prints information about the flip-object.
dim
: Size of permutation space, i.e. the number of permutations X number of variables.
[
and [[
: Extract parts of flip.object
names
: it deals the names of the tests (the variables, usually)
sort
: it sorts the tests stored in flip.objects
by their p-values.
hist
: it produces the histogram of the distribution of the test statistic.
When there are more test, it produces one histogram for each test statistic.
plot
: it produces the scatter plot of the (joint)
distribution of the test statistics.
When there are more than 2 tests, the plot is based on the first two principal components.
## S4 method for signature 'flip.object' show(object) summary(object, ...) ## S4 method for signature 'flip.object' summary(object, star.signif = TRUE, only.p.leq = NULL, ...) ## S4 method for signature 'flip.object' dim(x) ## S4 method for signature 'flip.object,ANY,ANY,ANY' x[i] ## S4 method for signature 'flip.object' x[[i]] ## S4 method for signature 'flip.object' length(x) ## S4 method for signature 'flip.object' names(x) ## S4 replacement method for signature 'flip.object' names(x) <- value ## S4 method for signature 'flip.object' sort(x, decreasing = FALSE) ## S4 method for signature 'flip.object' hist(x, ...) ## S4 method for signature 'flip.object' plot(x, y, ...)
## S4 method for signature 'flip.object' show(object) summary(object, ...) ## S4 method for signature 'flip.object' summary(object, star.signif = TRUE, only.p.leq = NULL, ...) ## S4 method for signature 'flip.object' dim(x) ## S4 method for signature 'flip.object,ANY,ANY,ANY' x[i] ## S4 method for signature 'flip.object' x[[i]] ## S4 method for signature 'flip.object' length(x) ## S4 method for signature 'flip.object' names(x) ## S4 replacement method for signature 'flip.object' names(x) <- value ## S4 method for signature 'flip.object' sort(x, decreasing = FALSE) ## S4 method for signature 'flip.object' hist(x, ...) ## S4 method for signature 'flip.object' plot(x, y, ...)
object |
a flip-object |
... |
additional arguments to be passed |
star.signif |
If |
only.p.leq |
Shows only tests with a p-value lower than |
x |
a |
i |
indices specifying elements to extract or replace. Indices are |
value |
|
decreasing |
logical. Should the sort be increasing or decreasing? |
y |
not used. |
Y=matrix(rnorm(50),10,5) colnames(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] +2 res = flip(Y) res summary(res) sort(res) names(res) length(res) dim(res) res=res[2:3] res hist(res) plot(res)
Y=matrix(rnorm(50),10,5) colnames(Y)=LETTERS[1:5] Y[,1:2]=Y[,1:2] +2 res = flip(Y) res summary(res) sort(res) names(res) length(res) dim(res) res=res[2:3] res hist(res) plot(res)
It allows to test fixed effect in mixed models. You can test within-unit effects, between-unit and interactions of the two. The response can be uni- or multi-variate. See also examples below.
flipMix(modelWithin, X = NULL, Z = NULL, units, perms = 1000, data = NULL, tail = 0, statTest = NULL, flipReturn, testType = "permutation", Su = NULL, equal.se = FALSE, se = NA, replaceNA.coeffWithin = "coeffMeans", replaceNA.coeffWithin.se = replaceNA.coeffWithin, ...)
flipMix(modelWithin, X = NULL, Z = NULL, units, perms = 1000, data = NULL, tail = 0, statTest = NULL, flipReturn, testType = "permutation", Su = NULL, equal.se = FALSE, se = NA, replaceNA.coeffWithin = "coeffMeans", replaceNA.coeffWithin.se = replaceNA.coeffWithin, ...)
modelWithin |
When it is a |
X |
The part of the design matrix corresponding to the between-unit
effect that are not null under the alternative hypothesis. If it is a matrix
or a data.frame it must have a number of rows equal to the number of units
or equal to the total number of observations (in the latest case all
elements of the same units must have the same values since they are
between-unit effects). The non-null between-unit covariates of null model
are defined in NOTE: When called from |
Z |
The part of the design matrix corresponding to the non-null
between-unit covariates of the model under the null hypothesis. May be given
as a design matrix or as a half |
units |
Vector of units IDs. May be given as a vector or as a half
|
perms |
The number of permutations to use. The default is |
data |
Same as in the function |
tail |
Same as in the function |
statTest |
For function Both functions allow for vector arguments. |
flipReturn |
Same as in the function |
testType |
See also the function |
Su |
Usually |
equal.se |
Logical. If |
se |
Usually |
replaceNA.coeffWithin |
deafult is |
replaceNA.coeffWithin.se |
deafult is |
... |
Further parameters. See also the function |
flipMix
and flipMixWithin
return an object of class
flip.object
. Several operations and plots can be made from this
object. See also flip.object-class
.
Note that function flipMix
with statTest="t"
or "F"
provides tests for each effect between (and interaction) and also provides
the overall test PC1
and sum
(i.e. all effects ar null, same
as npc
does).
Use npc
with any
comb.funct=c("data.sum","data.linComb","data.pc","data.trace")
to
combine results.
obs2coeffWithin
return a list of objects that can be used as argument
of data
in the function flipMix
and flipMixWithin
.
Livio Finos and Dario Basso
L. Finos and D. Basso (2013) Permutation Tests for Between-Unit Fixed Effects in Multivariate Generalized Linear Mixed Models. Statistics and Computing.
D. Basso, L. Finos (2011) Exact Multivariate Permutation Tests for Fixed Effects in Mixed-Models. Communications in Statistics - Theory and Methods.
N=10 toyData= data.frame(subj=rep(1:N,rep(4,N)), Within=rep(1:2,N*2), XBetween= rep(1:2,rep(N/2*4,2)),ZBetween= rep(rnorm(N/2),rep(8,N/2))) toyData= cbind(Y1=rnorm(n=N*4,mean=toyData$subj+toyData$ZBetween+toyData$XBetween), Y2=rnorm(n=N*4,mean=toyData$subj+toyData$ZBetween+toyData$Within*2),toyData) (toyData) ##################### ###Testing Between-unit effects (res=flipMix(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, X=~XBetween,Z=~ZBetween,units=~subj,perms=1000,testType="permutation",statTest="t")) #same as: modelWithin <- lm(as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData) (flipMix(modelWithin=modelWithin,data=toyData, X=~XBetween,Z=~ZBetween,units= ~subj, perms=1000,testType="permutation",statTest="t")) ### Note that this is different from: modelWithin <- list(Y1=lm(Y1~Within,data=toyData),Y2=lm(Y2~Within,data=toyData)) (flipMix(modelWithin=modelWithin,data=toyData, X=~XBetween,Z=~ZBetween,units= ~subj, perms=1000,testType="permutation",statTest="t")) ### combining results (npc(res,"data.pc")) (npc(res,"data.trace")) ################################ ###Testing Within-unit effects ## The resulting test is approximated. The estimate of the variance within units ## takes in account the presence of effects between units. (flipMix(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, units= ~subj, perms=1000,testType="permutation",statTest="t")) ###The resulting tests are exact. If effects between are presents, ## statTest="Tnaive" or "TBTWest" are more suitable: (res=flipMixWithin(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, units= ~subj, perms=1000,statTest=c("TH1est"))) npc(res)
N=10 toyData= data.frame(subj=rep(1:N,rep(4,N)), Within=rep(1:2,N*2), XBetween= rep(1:2,rep(N/2*4,2)),ZBetween= rep(rnorm(N/2),rep(8,N/2))) toyData= cbind(Y1=rnorm(n=N*4,mean=toyData$subj+toyData$ZBetween+toyData$XBetween), Y2=rnorm(n=N*4,mean=toyData$subj+toyData$ZBetween+toyData$Within*2),toyData) (toyData) ##################### ###Testing Between-unit effects (res=flipMix(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, X=~XBetween,Z=~ZBetween,units=~subj,perms=1000,testType="permutation",statTest="t")) #same as: modelWithin <- lm(as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData) (flipMix(modelWithin=modelWithin,data=toyData, X=~XBetween,Z=~ZBetween,units= ~subj, perms=1000,testType="permutation",statTest="t")) ### Note that this is different from: modelWithin <- list(Y1=lm(Y1~Within,data=toyData),Y2=lm(Y2~Within,data=toyData)) (flipMix(modelWithin=modelWithin,data=toyData, X=~XBetween,Z=~ZBetween,units= ~subj, perms=1000,testType="permutation",statTest="t")) ### combining results (npc(res,"data.pc")) (npc(res,"data.trace")) ################################ ###Testing Within-unit effects ## The resulting test is approximated. The estimate of the variance within units ## takes in account the presence of effects between units. (flipMix(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, units= ~subj, perms=1000,testType="permutation",statTest="t")) ###The resulting tests are exact. If effects between are presents, ## statTest="Tnaive" or "TBTWest" are more suitable: (res=flipMixWithin(modelWithin=as.matrix(toyData[,c("Y1","Y2")])~Within,data=toyData, units= ~subj, perms=1000,statTest=c("TH1est"))) npc(res)
It returns a given element of a flip.object.
getFlip(obj, element)
getFlip(obj, element)
obj |
a |
element |
element to the returned |
values of the element requested.
make.permSpace
computes the perms
x n matrix of ids used for
test of dependence. make.signSpace
computes the perms
x n
vector of +1 and -1 used for symmetry test.
IDs |
vector of IDs to be permuted. If |
return.permIDs |
logical. If |
N |
number of elements of the sample. It is also the dimention of the
random orthogonal matrix in |
Y |
a vector of data. It can also be a vector 1:N referring to the IDs of observations. |
perms |
number of random permutations. If it is a list, it has two
elements |
T |
the (possibly multivariate) permutation space as returned, for
example by |
obs.only |
logical. If |
tail |
Tail of the distribution being significant for H1. See also
argument |
testType |
See argument |
Strata |
See argument |
X |
A vector of length |
... |
other parameters |
rom
computes a Random Orthogonal Matrix of size n
Xn
(C-compiled function, very fast). implements the algorithm of Stewart (1980). The function is
compiled in C++. NOTE: this option is not available in the newest versions. This is now equivalent to romFast
romFast
computes a Random Orthogonal Matrix of size n
Xn
using the qr.Q
decomposition. romFast
is faster than
rom
but can be inaccurate (i.e. providing inaccurate type I error
control when used in testing), specially for very small n
(i.e.
sample size).
allpermutations
computes all permutations of a vector Y
. Is is
based on the function permutations
of the library(e1071)
.
t2p
computes the (possibily multivariate) space of p-values from the
space of test statistic.
Pesarin (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
Stewart, G. W. (1980). The efficient generation of random orthogonal matrices with an application to condition estimators. SIAM Journal on Numerical Analysis 17, 403-409.
#10 random elements of the orbit of a one-sample test make.signSpace(5, 10) #All elements of the orbit of a one-sample test (the size of the space is 2^5 < 1000) make.signSpace(5, 1000) ## Not run: #A random rotation matrix of size 3 (r=rom(3)) #verify that it is orthogonal: r%*%t(r) ## End(Not run)
#10 random elements of the orbit of a one-sample test make.signSpace(5, 10) #All elements of the orbit of a one-sample test (the size of the space is 2^5 < 1000) make.signSpace(5, 1000) ## Not run: #A random rotation matrix of size 3 (r=rom(3)) #verify that it is orthogonal: r%*%t(r) ## End(Not run)
Famous seeds growing data from Pesarin, F. (2001) Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York.
the data.frame contains the three columns: grs, x, y