wapply {multtest} | R Documentation

## Weighted version of the apply function

### Description

A function to perform 'apply' on an matrix of data and corresponding matrix of weights.

### Usage

    wapply(X, MARGIN, FUN, W = NULL, ...)

### Arguments

`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 `+` the function name must be quoted.
`W` | An optional matrix of weights. When `W=NULL`, the usual `apply` function is called.
`...` | optional arguments to `FUN`.

### Details

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.

### Value

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 user-level function `MTP`.

### Author(s)

Katherine S. Pollard

### See Also

`get.Tn`, `MTP`

### Examples

    data<-matrix(rnorm(200),nr=20)
    weights<-matrix(rexp(200,rate=0.1),nr=20)
    wapply(X=data,MARGIN=1,FUN=mean,W=weights)

[Package multtest version 1.22.0 Index]