test_assoc: Test for association between each paired variables and...

Description Usage Arguments Details Value Author(s) Examples

View source: R/test_assoc.R

Description

Tests for association between each paired variables:

Categorical-Categorical

Using pearson's chi-squared test (chisq.test function from stats package).

Continuous-Continuous

Using correlation test (cor.test function from stats package).

Categorical-Continuous

Using analysis of variance model (aov function from stats package).

Also adjusts p.values using Benjamini & Hochberg method (p.adjust function from stats package) and constructs heatmap using heatmaply function.

Usage

1

Arguments

data

a dataframe. It is strongly recommended that the dataframe has no missing data and is preprocessed.

vars

a list including the name (or index) of columns of data.

levels

An integer value indicating the maximum number of levels of a categorical variable. To be used to distinguish the categorical variable. Defaults to NULL because it is supposed that data has been preprocessed using data_preproc and the categorical variables are specified.

plot

Logical indicating if the heatmap should be constructed. Defaults to FALSE.

Details

This provides a wrapper to chisq.test, cor.test, aov, p.adjust from stats package to test association between variables And a wrapper to heatmaply package to construct heatmap.

Value

If plot = FALSE, returns a matrix containing p.values of tests between each two variables. Otherwise returns A list which contains:

matrix

A matrix containing p.values of tests between each two variables.

heatmap

A plotly object containing heatmap related to matrix.

Author(s)

Elyas Heidari

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data("NHANES")
## Using raw data
df <- NHANES[1:1000, ]
test_matrix <- test_assoc(data = df, vars = colnames(df), plot = FALSE, levels = 15)

## Using preprocessed data
data <- data_preproc(NHANES, levels = 15)
data$SEQN <- NULL
## Outputs the heatmap too (plot = TRUE)
test_mat_heatmap <- test_assoc(data = data, vars = colnames(data[, 1:20]), plot = TRUE)

bAIo-lab/Questools documentation built on Nov. 9, 2019, 3:59 a.m.