rowCors: Rowwise Correlation with a Vector

Description Usage Arguments Value Author(s) References See Also Examples

Description

Computes Pearson's correlation coefficient of a vector with each row of a matrix.

Usage

1
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 ncol(X).

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 TRUE, then it is assumed that all variables in X and the variable represented by y are ordinal, and the values in X and y represent scores for the different levels.

use.n

should the squared values of the correlation coefficient be multiplied by ncol(X)? Ignored if trendStat = FALSE. If FALSE, the squared values are multiplied by ncol(X) - 1. By default, the squared values are multiplied by ncol(X) if y shows two levels, leading to the Cochran-Armitage test of trend. Otherwise, they are multiplied by ncol(X) - 1.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## 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)

scrime documentation built on May 2, 2019, 10:24 a.m.

Related to rowCors in scrime...