net: Graphical Network

View source: R/net.R

Graphical Network from a numeric matrixR Documentation

Graphical Network

Description

Obtain a Graphical Network representation from a matrix where nodes are subjects in the rows and columns, and edges are obtained from the matrix entries

Usage

net(object, Z = NULL, K = NULL,
    nsup = NULL, p.radius = 1.7,
    delta = .Machine$double.eps)

Arguments

object

Either a numeric matrix X or an object of the 'SSI' class. When the object is an 'SSI' the regression coefficients are used as X

K

(numeric matrix) Kinship relationship matrix among nodes

Z

(numeric matrix) Design matrix for random effects. When Z=NULL an identity matrix is considered (default) thus G = K; otherwise G = Z K Z' is used

nsup

(numeric) For a SSI, average number of training individuals contributing to the prediction (with non-zero regression coefficient) of testing individuals. Default nsup=NULL will use the value of nsup that yielded the optimal accuracy

p.radius

(numeric) For a Multi-trait SSI, a factor (x-folds radius) to separate each trait from the origin

delta

(numeric) Minumum value to determine nodes to be connected. Default is the machine precision (numerical zero)

Details

For a numeric matrix X={xij} with m rows and n columns, a graphical network with m + n nodes is obtained by defining edges connecting subjects in rows with those in columns. An edge between subject in row i and subject in column j is determined if the corresponding (absolute) entry matrix is larger than certain value, i.e., |xij|>δ.

For a symmetric matrix, only m=n nodes are considered with edges determined by the above diagonal entries of the matrix.

Nodes and edges are plotted in the cartesian plane according to the Fruchterman-Reingold algorithm. When a matrix K is provided, nodes are plotted according to the top 2 eigenvectors from the spectral value decomposition of Z K Z' = U D U'.

When the object is a 'SSI' object the edges are taken from the regression coefficients (associated to a specific nsup value) are used as matrix X with testing subjects in rows and training subjects in columns.

Value

Returns a plottable object of the class 'net' that can be visualized using 'plot' method

Examples

  require(SFSI)
  data(wheatHTP)
  
  #--------------------------------------
  # Net for an SSI object
  #--------------------------------------
  index = which(Y$trial %in% 1:6)     # Use only a subset of data
  Y = Y[index,]
  M = scale(M[index,])/sqrt(ncol(M))  # Subset and scale markers
  G = tcrossprod(M)                   # Genomic relationship matrix
  y = as.vector(scale(Y[,"E1"]))      # Scale response variable
  
  trn_tst = ifelse(Y$trial == 2, 0, 1)

  fm = SSI(y,K=G,trn_tst=trn_tst)
  
  tmp = net(fm)          # Get the net
  plot(tmp)              # Plot the net
  plot(tmp, i=c(1,2))    # Show the first and fifth tst elements
  plot(net(fm, nsup=10), show.names=c(TRUE,TRUE,FALSE))
  
  #--------------------------------------
  # Net for a numeric matrix
  #--------------------------------------
  B = as.matrix(coef(fm, nsup=10))
  plot(net(B), curve=TRUE, set.size=c(3.5,1.5,1))
  
  #--------------------------------------
  # Net for a symmetric numeric matrix
  #--------------------------------------
  X = X_E1[,seq(1,ncol(X_E1),by=5)]
  R2 = cor(X)^2  # An R2 matrix
  plot(net(R2, delta=0.9))
  

SFSI documentation built on Nov. 18, 2023, 9:06 a.m.