simPATHy (version 0.6)

simPATHy: Simulate data from a graphical model

Description

Simulate data in two different conditions with a common structure of dependences. The two different conditions are characterized by different strengths of the links between nodes (dysregulation).

Usage

simPATHy(
  graph,
  path = NULL,
  S = NULL,
  min = 2,
  max = 3,
  prob = 1,
  n1 = 500,
  n2 = n1,
  digits = 5,
  mu1 = 0,
  mu2 = mu1,
  muRandom = FALSE
)

Arguments

graph

A graphNEL object.

path

A list of edges in edgesList format (see gRbase).

S

The sample covariance matrix.

min, max

Vectors of length 1 or of the same length as path containing the lower and upper limits of a uniform distribution. The strength of dysregulation is sampled uniformly from the interval [min, max]: a value smaller than 1 represents deactivation, a value greater than 1 represents activation. If path=NULL only the first element is used.

prob

A vector of size 1 or of the same length as path, giving the probability to change the sign of the correlation coefficient for each edge. prob=0 implying that the sign of the dysregulation should be changed, and prob=1 implying that the sign should be left unaltered (default). Values between these two extremes allow for random sign switch: the sign is changed with probability 1-prob.

n1, n2

Number of observations to generate from the two conditions.

digits

Integer indicating the number of decimal places to be used.

mu1, mu2

A vector of size 1 or of the length equal to the number of nodes in the graph. Means of the multivariate normal distributions from which observations are generated. If mu1 (and/or mu2) is a vector it has to be named in accordance with the names of the nodes of the graph.

muRandom

Logical. If muRandom=TRUE the means of the variables are randomly generated.

Value

It returns a list containing:

  • data random samples generated from multivariate normal distributions with covariance matrices S1 (reference condition) and S2 (dysregulated condition);

  • S1,S2 two covariance matrices;

  • path the dysregulated path;

  • strength the dysregulation strength for each edge in the path;

  • mu1,mu2 two mean vectors;

  • correction correction details.

Details

If the matrix S does not reflect conditional independence constraints imposed by the graph simPATHy uses the maximum likelihood estimation of covariance matrices for graphical models via internal function fitSgraph. When the dysregulation of the initial (reference condition) covariance matrix leads to a matrix that is no longer positive definite, the resulting matrix is corrected via internal function makePositiveDefinite. To avoid excessively strong dysregulations, the upper limit for the absolute value of the dysregulated correlation coefficient is set to: $$min( 0.9, 1.25*max(abs(C[upper.tri(C)])) )$$ where C is the correlation matrix of the reference condition.

See Also

easyLookDys, easyLookShiny, plotCorGraph, plotGraphNELD3

Examples

Run this code
# NOT RUN {
if(require(gRbase) & require(graph)){

  ## Directed graph
  ## sub-graph Acute Myel... Leukemia
  graph<-gRbase::dag(~867:25+867:613+5295:867+5294:867+
                       + 207:5295+207:5294+4193:207+3551:207+
                       + 4792:3551+7157:4193+3265:6654+
                       + 3845:6654+6654:2885+2885:25+2885:613)
  genes<-graph::nodes(graph)

  # covariance matrix of the reference condition
  data<-t(chimera[genes,colnames(chimera)==1])
  S<-cov(data)
  S<-fitSgraph(graph,S)

  # select path to dysregulate
  path<-list(c("613","867"),c("867","5295"),c("5295","207"),
             c("207","4193"),c("4193","7157"))
  ## ..or select the path in an interactive plot
  # path<-getPathShiny(graph)

  # select parameters of the dysregulation
  min<-c(2,8,2,0.1,0.5)
  max<-c(2,10,2,4,0.5)
  prob<-c(1,0,0,0.5,1)

  # activation, switch, switch, random, deactivation
  dys<-cbind(min,max,prob)
  rownames(dys)<-sapply(path,paste,collapse = "~")
  dys

  set.seed(123)
  # main function
  Result<-simPATHy(graph,path,S,min,max,prob)
  class(Result)
  names(Result)

  # simulated data from two conditions
  round(Result$dataset[c(1:3,501:503),1:5],3)

  # Summary
  easyLookDys(Result)
  # ..or interactive summary
  # easyLookShiny(resObj=Result,graph=graph)


  # Visualization
  plotCorGraph(S1=Result$S1,S2 = Result$S2,graph = graph,path = path,colLim = c(-0.3,0.3))
  plotGraphNELD3(S1=Result$S1,S2 = Result$S2,graph = graph,colLim = c(-0.3,0.3))


  ## Undirected graph
  graph <- gRbase::ug(~a:b, ~a:c, ~c:d, ~b:d, ~b:c)
  # when reference condition covariance matrix is not supplied simPATHy generate a random one
  Result_ug<-simPATHy(graph)
  easyLookDys(Result_ug)
  plotGraphNELD3(S1=Result_ug$S1,S2 = Result_ug$S2,graph = graph,colLim = c(-0.5,0.5))

}
# }

Run the code above in your browser using DataLab