rowCors {scrime} | R Documentation |
Rowwise Correlation with a Vector
Description
Computes Pearson's correlation coefficient of a vector with each row of a matrix.
Usage
rowCors(X, y, trendStat = FALSE, use.n = NULL)
Arguments
X |
a numeric matrix in which each row represents a variable and each column an observation. |
y |
a numeric vector of length |
trendStat |
instead of the correlation coefficients should the values of
the statistic for a test of linear trend based on this coefficient be returned?
If |
use.n |
should the squared values of the correlation coefficient be multiplied
by |
Value
A vector containing the rowwise values of Pearson's correlation coefficient (if
trendStat = FALSE
or the rowwise values of the trend statistics (if
trendStat = TRUE
.
Author(s)
Holger Schwender, holger.schwender@udo.edu
References
Agresti, A.\ (2002). Categorical Data Analysis. Wiley, Hoboken, NJ. 2nd Edition.
See Also
rowTrendStats
, rowCATTs
, rowMsquares
Examples
## Not run:
# Generate a random matrix containing 10 continuous variables
# and a vector representing a continuous variable.
mat <- matrix(runif(200, 0, 20), 10)
y <- sample(runif(20, 0, 20))
# The correlations between y and each of row of mat are
# computed by
rowCors(mat, y)
# Generate a random binary vector and a matrix consisting
# of 10 ordinal variables with levels 0, 1, 2, where these
# values can be interpreted as scores for the differ
# categories.
mat <- matrix(sample(0:2, 500, TRUE), 10)
y <- sample(0:1, 50, TRUE)
# The values of the Cochran-Armitage trend statistic are
# computed by
rowCors(mat, y, trendStat = TRUE)
# If the values of the general test of linear trend described
# on page 87 of Agresti (2002) should be computed, then call
rowCors(mat, y, trendStat = TRUE, use.n = FALSE)
## End(Not run)