Igraph'ing nested models

Execution, for example. cv.glmnet in the dataset gives me (by default) 100 different models. Now, if there was no data in my dataset, I could do multiple imputation (for example, 10 imputations) and run cv.glmnet for each imputation.

If I ignore the actual coefficient values ​​for each of the models and just look at the selected functions (i.e. sets of column names), some models are submodels of others.

Code like this mimics the results somewhat:

usevars<-paste("var", 1:100, sep="") mdls<-replicate(1000, { numVars<-sample.int(length(usevars), 1) sample(usevars, numVars) }) names(mdls)<-paste("mdl", 1:1000, sep="") 

Now it’s easy enough to get a parent-child relationship for submodels in this regard. It is also possible to include only “direct parenthood” (that is, if model A is a child of B and B is a child of C, then do not include the relationship between A and C).

Finally, I come to my problem: I used igraph to build these models and their (direct) relationships. However, I did not find a layout that could group nodes on the basis of another variable (in this case, the size of the model): in this parameter, it seems like a good idea to create this graph containing “bands” of models with the same size model (the number of variables in the model).

What I ended up doing more or less calculated the positions of each node myself through a piece of code (which I am too embarrassed to post here), but I always wondered if I just missed the best / ready-made solution.

My own code led to such graphs (you can ignore colors and labels - just know that the horizontal axis contains the size of the model): enter image description here

Suggestions for achieving this kind of graphs are more elegant than, well, all that you need to do yourself is greatly appreciated.

+4
source share
2 answers

The Fruchterman-Reingold layout algorithm in the version of the igraph version (i.e. 0.6, which has not yet been officially released, but you can ask Gabor about the mailing list to send you a copy) has two hidden (i.e., still undocumented) parameters: miny and maxy . They allow you to limit the Y coordinates of the nodes within the range, so you can use this to create layers.

Alternatively, I’m working on an implementation of the method of placing a multi-level Sugiyama graph for igraph right now, and I will combine it with the development tree in a day or two (if everything goes well), and then you can try this.

+1
source

You can use this option to restrict the fruchterman-reingold algorithm in qgraph for this. To show this, I first create a small adjacency matrix of nested models:

 adj <- matrix(0,9,9) adj[1,2:4] <- 1 adj[2:4,5:7] <- 1 adj[5:7,8] <- 1 adj[8,9] <- 1 mod <- c(1,rep(2,3),rep(3,3),4,5) 

Here adj is the adjacency matrix, and mods is a vector containing the level of the model (how much it is nested).

In qgraph you can plot the adjacency matrix using the qgraph() function on the adjacency matrix. By setting layout="spring" , you call Fruchterman-Reingold algortihm, and with layout.par you can provide a list of options for Fruchterman-Reingold.

With the constraints parameter, we can set constraints on the layout. It should be a matrix of 2 columns and a row for each node. The first element of each row is the x coordinate, and the second is the y coordinate. If it contains NA, it means that this coordinate moves freely, and if it is a value, it means that this coordinate is attached to a specific place.

You need to try different things at the y position scale to see what works best. Here I just multiply the mod vector by the number of nodes to get a good graph:

 library("qgraph") Lpar <- list(constraints = cbind(NA,nrow(adj)*mod)) L <- qgraph(adj,layout="spring",layout.par=Lpar)$layout 

Here we also saved the layout in the L object, which can also be used as a layout in igraph .

The model

+1
source

All Articles