Learn R Programming

HelpersMG (version 3.6)

IC_threshold_matrix: Calculate correlation matrix

Description

This function calculates the matrix of correlations thresholded using partial correlation. If the threshold is not given, the object that is produced can be used later for thresholding. For model OAT: a correlation is retained if it is higher that the threshold and if all partial correlations of the two variables and any third one are all lower than the threshold. For model AAT: a correlation is retained if it is higher than the threshold and the partial correlation is lower than the threshold. In this case, no missing value is accepted. The use and method parameters are used by cor() function. The function uses by default a parallel computing in Unix or MacOSX systems. If progress is TRUE and the package pbmcapply is present, a progress bar is displayed. If debug is TRUE, some informations are shown during the process but parallel computing is not used. https://fr.wikipedia.org/wiki/Iconographie_des_corr<U+00E9>lations

Usage

IC_threshold_matrix(data = stop("A dataframe or an IconoCorel object is required"),
  threshold = NULL, use = c("pairwise.complete.obs", "everything",
  "all.obs", "complete.obs", "na.or.complete"), method = c("pearson",
  "kendall", "spearman"), model = c("OAT", "ATT"), progress = TRUE,
  debug = FALSE)

Arguments

data

A dataframe or an IconoCorel object from a previous run of IC_threshold_matrix

threshold

threshold for partial and full correlations

use

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs".

method

a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated.

model

a character string indicating if linear model uses all variables at a time (AAT) or one at a time (OAT).

progress

show a progress bar

debug

display information about progression of computing

Value

A list

Details

IC_threshold_matrix calculates correlation matrix thresholed by partial correlation

References

Lesty, M., 1999. Une nouvelle approche dans le choix des r<U+00E9>gresseurs de la r<U+00E9>gression multiple en pr<U+00E9>sence d<U+2019>interactions et de colin<U+00E9>arit<U+00E9>s. Revue de Modulad 22, 41-77.

See Also

Other Iconography of correlations: IC_clean_data, IC_correlation_simplify, plot.IconoCorel

Examples

Run this code
# NOT RUN {
library("HelpersMG")
es <- matrix(c("e1", "52", "12", "12", "5",
"e2", "59", "12.5", "9", "5",
"e3", "55", "13", "15", "9",
"e4", "58", "14.5", "5", "5",
"e5", "66", "15.5", "11", "13.5",
"e6", "62", "16", "15", "18",
"e7", "63", "17", "12", "18",
"e8", "69", "18", "9", "18"), ncol=5, byrow = TRUE)
colnames(es) <- c("<U+00C9>l<U+00E8>ve", "Poids", "<U+00C2>ge", "Assiduit<U+00E9>", "Note")
es <- as.data.frame(es, stringsasFactor=FALSE)
es[, 2] <- as.numeric(as.character(es[, 2]))
es[, 3] <- as.numeric(as.character(es[, 3]))
es[, 4] <- as.numeric(as.character(es[, 4]))
es[, 5] <- as.numeric(as.character(es[, 5]))

es

df <- IC_clean_data(es, debug = TRUE)
cor_matrix <- IC_threshold_matrix(data=df, threshold = NULL, progress=FALSE)
cor_threshold <- IC_threshold_matrix(data=cor_matrix, threshold = 0.3)
par(mar=c(1,1,1,1))
set.seed(4)
plot(cor_threshold)
cor_threshold_Note <- IC_correlation_simplify(matrix=cor_threshold, variable="Note")
plot(cor_threshold_Note)

# Using the model All at a time

cor_threshold_AAT <- IC_threshold_matrix(data=df, threshold = 0.3, model="AAT")
par(mar=c(1,1,1,1))
set.seed(4)
plot(cor_threshold_AAT, show.legend.strength="bottomleft")



############
dta <- structure(list(<U+00C9>l<U+00E8>ve = structure(1:8, .Label = c("e1", "e2", 
"e3", "e4", "e5", "e6", "e7", "e8"), class = "factor"), Poids = c(52L, 
59L, 55L, 58L, 66L, 62L, 63L, 69L), <U+00C2>ge = c(12, 12.5, 13, 14.5, 
15.5, 16, 17, 18), Assiduit<U+00E9> = c(12L, 9L, 15L, 5L, 11L, 15L, 
12L, 9L), Note = c(5, 5, 9, 5, 13.5, 18, 18, 18), e1 = c(1L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L), e2 = c(0L, 1L, 0L, 0L, 0L, 0L, 0L, 
0L), e3 = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), e4 = c(0L, 0L, 0L, 
1L, 0L, 0L, 0L, 0L), e5 = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L), 
    e6 = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L), e7 = c(0L, 0L, 0L, 
    0L, 0L, 0L, 1L, 0L), e8 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L
    )), .Names = c("<U+00C9>l<U+00E8>ve", "Poids", "<U+00C2>ge", "Assiduit<U+00E9>", 
"Note", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"), class = "data.frame", row.names = c(NA, 
-8L))

dta0 <- dta[, 2:ncol(dta)]
ic0 <- IC_threshold_matrix(data = dta0)
cor_threshold <- IC_threshold_matrix(data=ic0, threshold = 0.3)
par(mar=c(1,1,1,1))
set.seed(4)
library("igraph")

plot(cor_threshold, vertex.color="red", show.legend.strength = FALSE)
plot(IC_correlation_simplify(matrix=cor_threshold), 
     show.legend.strength = FALSE, show.legend.direction = FALSE)

# }

Run the code above in your browser using DataLab