Learn R Programming

netCoin (version 2.1.49)

netCorr: Networked correlations.

Description

netCorr produces a network object of correlations. Its input has to be at least one set of quantitative variables.

Usage

netCorr(variables, weight=NULL, pairwise=FALSE,
        sort=FALSE, decreasing=TRUE,
        frequency=pairwise, means=TRUE,
        method="pearson",
        criteria="p", Bonferroni=FALSE, minL=0, maxL=Inf,
        sortL=NULL, decreasingL=TRUE,
        igraph=FALSE, ...)

Value

The function creates a netCoin object and eventually a folder in the computer with an HTML document named index.html which contains the produced graph. This file can be directly opened with your browser and sent to a web server to work properly.

The links hold the value of the association, the statistic z of its test and its probability p, all of them of the first method. With pairwise=TRUE and missing values they also hold n, the number of cases of each pair. The remaining methods add their coefficient (named after the method), z(method) and p(method).

Arguments

variables

a data frame with at least two quantitative variables.

weight

weights of the cases: the name of a column of variables (which is then left out of the analysis) or a numeric vector with a weight per case. Pearson, Spearman and partial correlations are weighted; the tests use the effective sample size of Kish, \((\sum w)^2 / \sum w^2\). Kendall and dcor do not admit weights.

pairwise

Pairwise mode of handling missing values if TRUE. Listwise by default. The tests of each pair rest on the cases of that pair. Partial correlations always use the cases complete in all the variables.

sort

if TRUE, the variables (nodes, and so the rows and columns of the correlation matrix) are sorted by frequency, that is, by their number of valid cases, and by mean when the frequencies are equal. Default=FALSE.

decreasing

decreasing or increasing sort of the variables. Default=TRUE.

frequency

a logical value true if the frequency (number of valid cases) of each variable is to be shown in the nodes. By default it is TRUE only if pairwise=TRUE, the only case in which it can differ among the variables.

means

a logical value true if the mean, standard deviation, minimum and maximum of each variable are to be shown in the nodes. Default=TRUE.

method

one or several measures of association: "pearson", "spearman", "kendall", "partial" (partial correlation of each pair controlling for all the other variables) and "dcor" (bias-corrected distance correlation of Szekely and Rizzo, which also detects non-linear dependence). The first one gives the value, z and p of the links; the others are added as further columns. See details.

criteria

statistic to be used for selection criteria: "p", "z", "value", the name of a method (its coefficient), or "z(method)" and "p(method)". "p", "z" and "value" refer to the first method.

Bonferroni

Bonferroni criterium of the signification test: when criteria is a probability, maxL is divided by the number of contrasts, choose(k, 2) for k variables.

minL

minimum value of the statistic to include the edge in the list. With bipolar links (the default, see ...) the absolute value of value, z and of the coefficients is compared, so minL=.3 keeps the correlations with |r| >= .3.

maxL

maximum value of the statistic to include the edge in the list. When the criterium is a probability and it is not set, it is 0.5 (1 for bipolar links).

sortL

sort the list according to the values of a statistic. See below

decreasingL

order in a decreasing way.

igraph

Produces an igraph object instead of a netCoin object if TRUE

...

Any netCoin argument. Unless they are given, linkBipolar=TRUE (links of negative correlation are kept, and tested two-sided), lcolor="value", lwidth="value" and lweight="value".

Author

Modesto Escobar, Department of Sociology and Communication, University of Salamanca.

Details

The test of each association is two-sided by default (linkBipolar=TRUE), and one-sided (positive association) with linkBipolar=FALSE, when the links of negative association are also left out by the default minL=0.

  • Pearson and partial: \(t = r \sqrt{df/(1-r^2)}\) with \(n-2\) degrees of freedom (\(n-k\) for partial correlations of \(k\) variables), \(n\) being the number of cases of the pair.

  • Spearman: the same \(t\) (z) with \(n-2\) degrees of freedom, as cor.test does with exact=FALSE; the exact probability is used for \(n \le 9\) without ties.

  • Kendall: z is S divided by its standard deviation, corrected for ties, and p comes from the normal distribution; the exact probability is used for \(n < 50\) without ties.

  • dcor: the t-test of independence of Szekely and Rizzo (2013).

Examples

Run this code
# A character column (with separator)
data(iris)
netCorr(iris[,1:4],ltext="value",
 main="Correlations between measurements of Iris Species",
 note="Anderson, Edgar (1935) y Fisher, R. A. (1936)") # network object

# Several measures at once, selecting by the probability of Kendall's tau
netCorr(iris[,1:4], method=c("pearson", "kendall", "dcor"), criteria="p(kendall)", maxL=.01)

# Links of absolute correlation of .7 or more
netCorr(iris[,1:4], criteria="value", minL=.7)

# Only positive correlations, tested one-sided
netCorr(iris[,1:4], linkBipolar=FALSE)

Run the code above in your browser using DataLab