lpcor {metan} | R Documentation |
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")
Arguments
.data |
The data to be analyzed. It must be a symmetric correlation
matrix or a data frame, possible with grouped data passed from
|
... |
Variables to use in the correlation. If |
by |
One variable (factor) to compute the function by. It is a shortcut
to |
n |
If a correlation matrix is provided, then |
method |
a character string indicating which correlation coefficient is to be computed. One of 'pearson' (default), 'kendall', or 'spearman'. |
Value
If .data
is a grouped data passed from
dplyr::group_by()
then the results will be returned into a
list-column of data frames, containing:
-
linear.mat The matrix of linear correlation.
-
partial.mat The matrix of partial correlations.
-
results Hypothesis testing for each pairwise comparison.
Author(s)
Tiago Olivoto tiagoolivoto@gmail.com
Examples
library(metan)
partial1 <- lpcor(iris)
# Alternatively using the pipe operator %>%
partial2 <- iris %>% lpcor()
# Using a correlation matrix
partial3 <- cor(iris[1:4]) %>%
lpcor(n = nrow(iris))
# Select all numeric variables and compute the partial correlation
# For each level of Species
partial4 <- lpcor(iris, by = Species)