rowGroupMeans {jamba} | R Documentation |
Calculate row group means, or other statistics
Description
Calculate row group means, or other statistics, where: rowGroupMeans()
calculates row summary stats; and rowGroupRmOutliers()
is a convenience
function to call rowGroupMeans(..., rmOutliers=TRUE, returnType="input")
.
Usage
rowGroupMeans(
x,
groups,
na.rm = TRUE,
useMedian = TRUE,
rmOutliers = FALSE,
crossGroupMad = TRUE,
madFactor = 5,
returnType = c("output", "input"),
rowStatsFunc = NULL,
groupOrder = c("same", "sort"),
keepNULLlevels = FALSE,
includeAttributes = FALSE,
verbose = FALSE,
...
)
rowGroupRmOutliers(
x,
groups,
na.rm = TRUE,
rmOutliers = TRUE,
crossGroupMad = TRUE,
madFactor = 5,
returnType = c("input"),
groupOrder = c("same", "sort"),
keepNULLlevels = FALSE,
includeAttributes = FALSE,
verbose = FALSE,
...
)
Arguments
x |
|
groups |
|
na.rm |
|
useMedian |
|
rmOutliers |
|
crossGroupMad |
|
madFactor |
|
returnType |
|
rowStatsFunc |
|
groupOrder |
|
keepNULLlevels |
|
includeAttributes |
|
verbose |
|
... |
additional parameters are passed to |
Details
This function by default calculates group mean values per row in a numeric matrix. However, the stat function can be changed to calculate row medians, row MADs, etc.
An added purpose of this function is optional outlier
filtering, via calculation of MAD values and applying
a MAD threshold cutoff. The intention is to identify
technical outliers that otherwise adversely affect the
calculated group mean or median values. To inspect the
data after outlier removal, use the parameter returnType="input"
which will return the input data matrix with NA
substituted for outlier points. Outlier detection and
removal is performed by jamba::rowRmMadOutliers()
.
Value
numeric
matrix based upon returnType
:
When
returnType="output"
the output is a numeric matrix with the same number of columns as the number of uniquegroups
labels. Whengroups
is a factor andkeepNULLlevels=TRUE
, the number of columns will be the number of factor levels, otherwise it will be the number of factor levels used ingroups
.When
returnType="input"
the output is a numeric matrix with the same dimensions as the input data. This output is intended for use withrmOutliers=TRUE
which will replace outlier points withNA
values. Therefore, this matrix can be used to see the location of outliers.
The function also returns attributes when includeAttributes=TRUE
,
although the default is FALSE. The attributes describe the
number of samples per group overall:
- attr(out, "n")
The attribute
"n"
is used to describe the number of replicates per group.- attr(out, "nLabel")
The attribute
"nLabel"
is a simple text label in the form"n=3"
.
Note that when rmOutliers=TRUE
the number of replicates per
group will vary depending upon the outliers removed. In that
case, remember that the reported "n"
is always the total
possible columns available prior to outlier removal.
See Also
Other jam numeric functions:
deg2rad()
,
noiseFloor()
,
normScale()
,
rad2deg()
,
rowRmMadOutliers()
,
warpAroundZero()
Examples
x <- matrix(ncol=9, stats::rnorm(90));
colnames(x) <- LETTERS[1:9];
use_groups <- rep(letters[1:3], each=3)
rowGroupMeans(x, groups=use_groups)
# rowGroupRmOutliers returns the input data after outlier removal
rowGroupRmOutliers(x, groups=use_groups, returnType="input")
# rowGroupMeans(..., returnType="input") also returns the input data
rowGroupMeans(x, groups=use_groups, rmOutliers=TRUE, returnType="input")
# rowGroupMeans with outlier removal
rowGroupMeans(x, groups=use_groups, rmOutliers=TRUE)