Test whether a list of factors are correlated

test_between_factors(x, y = NULL, all_factors = FALSE, verbose = FALSE)

Arguments

x

A data frame or a vector which contains discrete or continuous variables. if y is omit, pairwise testing for all columns in x is performed.

y

A data frame or a vector which contains discrete or continuous variables.

all_factors

Are all columns in x and y enforced to be factors?

verbose

Whether to print messages.

Details

Pairwise test is applied to every two columns in the data frames. Methods are:

  • two numeric variables: correlation test by cor.test is applied (Spearman method);

  • two character or factor variables: chisq.test is applied;

  • one numeric variable and one character/factor variable: oneway ANOVA test by oneway.test is applied.

This function can be used to test the correlation between the predicted classes and other known factors.

Value

A matrix of p-values. If there are NA values, basically it means there are no efficient data points to perform the test.

Author

Zuguang Gu <z.gu@dkfz.de>

Examples

df = data.frame(
    v1 = rnorm(100), 
    v2 = sample(letters[1:3], 100, replace = TRUE), 
    v3 = sample(LETTERS[5:6], 100, replace = TRUE)
)
test_between_factors(df)
#>           v1        v2        v3
#> v1 0.0000000 0.3903962 0.9980339
#> v2 0.3903962 0.0000000 0.3656077
#> v3 0.9980339 0.3656077 0.0000000
x = runif(100)
test_between_factors(x, df)
#>          v1        v2        v3
#> x 0.5647816 0.2433885 0.3891961