colVars(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, weights = NULL, freq = NULL, n = NULL) colStdevs(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, weights = NULL, freq = NULL, n = NULL) rowVars(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, weights = NULL, freq = NULL, n = NULL) rowStdevs(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, weights = NULL, freq = NULL, n = NULL)
x | a matrix, data frame, array, or numeric vector. | |||
na.rm | a logical value that specifies how to handle missing values (NAs) in x. If FALSE (the default), missing values in the input will result in missing values in corresponding elements of the output. If TRUE, missing values are omitted from calculations. | |||
dims | an integer value that specifies the number of dimensions to treat as rows. For example, if x is an array with more than two dimensions (say five), dims determines what dimensions are summarized; if dims = 3, then rowMeans is a three-dimensional array consisting of the means across the remaining two dimensions, and colMeans is a two-dimensional array consisting of the means across the last three dimensions. | |||
unbiased |
a logical value that specifies if the values in x
are an unbiased estimate of the true variance.
| |||
SumSquares | a logical value, if TRUE, then unnormalized sums of squares are returned, with no division by either n or (n-1). If SumSquares = TRUE, the unbiased argument is ignored. | |||
weights |
a numeric vector that has the same number of observations as x.
If x is a matrix, the number of rows for rowMeans
or columns for colmeans.
If you specify a value for weights,
then the unbiased argument is ignored.
The definitions used when weights are specified are:
| |||
freq | a numeric vector that consists of positive integers with the same number of observations as x. If present, the kth row of x is repeated k times. The effect is similar to the weights argument, except this argument does not ignore the unbiased argument and division is by (sum(freq)-1) rather than (n-1) if unbiased is TRUE. | |||
n | an integer that specifies the number of rows; if supplied this overrides the actual number of rows in x. This is useful for obtaining summaries on regular subsets of the data. |
x <- matrix(1:12, 4) rowVars(x) colStdevs(x)# Summaries for regular subsets of a vector x <- 1:50 colVars(x, n=10) # groups of 5 consecutive observations
# Higher-dimensional array x <- array(runif(24), dim=c(2,3,4)) rowVars(x) # vector of length 2. rowVars(x, dims=2) # 2x3 matrix. apply(x, 1:2, var) # same as previous colVars(x) # 3x4 matrix. colVars(x, dims=2) # vector of length 4. colVars(aperm(x, c(2,1,3))) # 2x4 matrix colVars(x[1,,]) # vector of length 4 diag(var(x[1,,])) # same as previous
# Investigate the distribution of the sample mean and t-statistic # when the underlying population is not normal x <- rexp(1000 * 20) # 1000 samples of size 20 means <- colMeans(x, n=20) stdevs <- colStdevs(x, n=20) qqnorm(means) plot(means, stdevs) # These would be independent for a normal population qqnorm( (means - 1) / stdevs )
# The first three lines in that study could be replaced with x <- matrix(rexp(1000 * 20), 20) # 1000 samples of size 20 means <- colMeans(x) stdevs <- colStdevs(x)