Calculates (correlation or distance) network adjacency from given expression data or from a similarity.

```
adjacency(datExpr,
selectCols = NULL,
type = "unsigned",
power = if (type=="distance") 1 else 6,
corFnc = "cor", corOptions = list(use = "p"),
weights = NULL,
distFnc = "dist", distOptions = "method = 'euclidean'",
weightArgNames = c("weights.x", "weights.y"))
```adjacency.fromSimilarity(similarity,
type = "unsigned",
power = if (type=="distance") 1 else 6)

datExpr

data frame containing expression data. Columns correspond to genes and rows to samples.

similarity

a (signed) similarity matrix: square, symmetric matrix with entries between -1 and 1.

selectCols

for correlation networks only (see below); can be used to select genes whose adjacencies will be calculated. Should be either a numeric vector giving the indices of the genes to be used, or a boolean vector indicating which genes are to be used.

type

network type. Allowed values are (unique abbreviations of) `"unsigned"`

,
`"signed"`

, `"signed hybrid"`

, `"distance"`

.

power

soft thresholding power.

corFnc

character string specifying the function to be used to calculate co-expression similarity for correlation networks. Defaults to Pearson correlation. Any function returning values between -1 and 1 can be used.

corOptions

character string or a list specifying additional arguments to be passed to the function given
by `corFnc`

. Use `"use = 'p', method = 'spearman'"`

or, equivalently,
`list(use = 'p', method = 'spearman')`

to obtain Spearman correlation.

weights

optional observation weights for `datExpr`

to be used in correlation calculation.
A matrix of the same dimensions as `datExpr`

, containing non-negative weights. Only used with Pearson
correlation.

distFnc

character string specifying the function to be used to calculate co-expression
similarity for distance networks. Defaults to the function `dist`

.
Any function returning non-negative values can be used.

distOptions

character string or a list specifying additional arguments to be passed to the function given
by `distFnc`

. For example, when the function `dist`

is used, the argument `method`

can be used to specify various ways of computing the distance.

weightArgNames

character vector of length 2 giving the names of the arguments to `corFnc`

that
represent weights for variable x and y. Only used if `weights`

are non-NULL.

Adjacency matrix of dimensions `ncol(datExpr)`

times `ncol(datExpr)`

(or the same dimensions
as `similarity`

). If `selectCols`

was
given, the number of columns will be the length (if numeric) or sum (if boolean) of `selectCols`

.

The argument `type`

determines whether a correlation (`type`

one of `"unsigned"`

,
`"signed"`

, `"signed hybrid"`

), or a distance network (`type`

equal `"distance"`

) will
be calculated. In correlation networks the adajcency is constructed from correlations (values between -1 and
1, with high numbers meaning high similarity). In distance networks, the adjacency is constructed from
distances (non-negative values, high values mean low similarity).

The function calculates the similarity of columns (genes) in `datExpr`

by calling the function
given in `corFnc`

(for correlation networks) or `distFnc`

(for distance networks),
transforms the similarity according to `type`

and raises it to `power`

,
resulting in a weighted network adjacency matrix. If `selectCols`

is given, the `corFnc`

function
will be given arguments `(datExpr, datExpr[selectCols], ...)`

; hence the returned adjacency will have
rows corresponding to all genes and columns corresponding to genes selected by `selectCols`

.

Correlation and distance are transformed as follows: for `type = "unsigned"`

, adjacency = |cor|^power;
for `type = "signed"`

, adjacency = (0.5 * (1+cor) )^power; for `type = "signed hybrid"`

, adjacency
= cor^power if cor>0 and 0 otherwise; and for `type = "distance"`

, adjacency =
(1-(dist/max(dist))^2)^power.

The function `adjacency.fromSimilarity`

inputs a similarity matrix, that is it skips the correlation
calculation step but is otherwise identical.

Bin Zhang and Steve Horvath (2005) A General Framework for Weighted Gene Co-Expression Network Analysis, Statistical Applications in Genetics and Molecular Biology, Vol. 4 No. 1, Article 17

Langfelder P, Horvath S (2007) Eigengene networks for studying the relationships between co-expression modules. BMC Systems Biology 2007, 1:54