metan (version 1.2.1)

lpcor: Linear and Partial Correlation Coefficients

Description

Estimates the linear and partial correlation coefficients using as input a data frame or a correlation matrix.

Usage

lpcor(.data, ..., by = NULL, n = NULL, method = "pearson", verbose = TRUE)

Arguments

.data

The data to be analyzed. Must be a symmetric correlation matrix or, a dataframe containing the predictor variables, or an object of class split_factors.

...

Variables to use in the correlation. If ... is null (Default) then all the numeric variables from .data are used. It must be a single variable name or a comma-separated list of unquoted variables names.

by

One variable (factor) to split the data into subsets. The function is then applied to each subset and returns a list where each element contains the results for one level of the variable in by. To split the data by more than one factor variable, use the function split_factors to pass subsetted data to .data.

n

If a correlation matrix is provided, then n is the number of objects used to compute the correlation coefficients.

method

a character string indicating which correlation coefficient is to be computed. One of 'pearson' (default), 'kendall', or 'spearman'.

verbose

If verbose = TRUE then some results are shown in the console.

Value

If a grouping factor is used then a list is returned with the following values.

  • linear.mat The matrix of linear correlation.

  • partial.mat The matrix of partial correlations.

  • results Hypothesis testing for each pairwise comparison.

Examples

Run this code
# NOT RUN {
library(metan)
partial1 <- pcor(iris)

# Alternatively using the pipe operator %>%
partial2 <- iris %>% lpcor()

# Using a correlation matrix
partial3 <- cor(iris[1:4]) %>%
            lpcor(n = nrow(iris),
                  verbose = FALSE)

# Select all numeric variables and compute the partial correlation
# For each level of \code{Species}

partial4 <- lpcor(iris, everithig(), by = Species)
print(partial4$summary)
# }

Run the code above in your browser using DataLab