wapply {multtest}  R Documentation 
A function to perform 'apply' on an matrix of data and corresponding matrix of weights.
wapply(X, MARGIN, FUN, W = NULL, ...)
X 
A matrix of data. 
MARGIN 
A vector giving the subscripts which the function will be applied over. 1 indicates rows, 2 indicates columns. 
FUN 
The function to be applied. In the case of functions like

W 
An optional matrix of weights. When 
... 
optional arguments to 
When weights are provided, these are passed to FUN
along with the data X
. For example, if FUN=meanX
, each data value is multiplied by the corresponding weight before the mean is applied.
If each call to FUN
returns a vector of length n
, then wapply
returns an array of dimension c(n, dim(X)[MARGIN])
if n > 1
. If n = 1
, wapply
returns a vector if MARGIN
has length 1 and an array of dimension dim(X)[MARGIN]
otherwise. If n = 0
, the result has length 0 but not necessarily the "correct" dimension.
If the calls to FUN
return vectors of different lengths, wapply
returns a list of length dim(X)[MARGIN]
.
This function is used in the package multtest
to compute weighted versions of test statistics. It is called by the function get.Tn
inside the userlevel function MTP
.
Katherine S. Pollard
data<matrix(rnorm(200),nr=20) weights<matrix(rexp(200,rate=0.1),nr=20) wapply(X=data,MARGIN=1,FUN=mean,W=weights)