qgraph.animate {qgraph} | R Documentation |

This function is meant to facilitate the creation of animations based on growing networks. Networks are created based on the Fruchterman Reingold algorithm, which is constraint by limiting the maximum displacement of nodes that are already in the graph.

qgraph.animate(input, ind = NULL, ..., constraint = 10, growth = "order", titles = NULL, sleep = 0)

`input` |
A weights matrix of the graph or a list of weigths matrices with different weights of the same graph (see details). See |

`ind` |
An object that specifies which nodes ar included or excluded. See details. |

`...` |
Additional arguments sent to |

`constraint` |
The constraint factor of included nodes. See details. Defaults to 10 for an soft-constrained animation. Set to Inf for a hard-constrained animation. |

`growth` |
The way nodes are added by default. Set to "order" to include nodes in the order they appear in the weigths matrix and to "degree" to include nodes based on their degree (high degree first) |

`titles` |
Optional vector with a title for each plot |

`sleep` |
Optional value sent to Sys.sleep() for showing the animation in R |

Let n be the number of nodes in total in the graph.

This function is designed to facilitate the production of animations by constraining the Fruchterman Reingold algorithm. Several frames are plotted of (a subset of) the same graph. If a node was already in the graph its maximum displacement per iteration of Fruchterman Reingold is equal to the number of nodes times the inverse of the constraint argument (so by default n/10). The higher this constraint value the stricter nodes stay in the same place between plots.

How many and which plots are made are defined by the 'input' and 'ind' arguments. There are two ways to specify the 'input' argument, either by speficying one weigths matrix or by specifying a list of weights matrices. In the sections below is explained what both of these methods do and how they are used.

This function, since it can be seen as an expression that makes several plots, works well in combination with the animation package for saving the animation to a wide variety of filetypes.

If 'input' is a single weigths matrix then in each frame a subset of the same graph is plotted. This is especially usefull for animating the growth of a network. Which nodes are in each frame is determined by the 'ind' argument.

If 'int' is not specified an animation is created in which in each frame a single node is added. This node is either in order of apearance in the weigths matrix or by its degree, which is determined with the 'growth' argument.

If 'ind' is a logical vector of length n than the first frame will contain the nodes specified with this vector and all other frames will grow in the same way as explained above (each step one node is added).

If 'ind' is a numeric vector of length n which contains all integers between 1 and n ( a single entry per node) then the first frame starts with only the node specified in the first element of the vector and in frame i the ith element is added (each step one node is added).

If 'ind' is a list with numeric vectors as elements containing integers between 1 and n then in frame i the nodes from the ith element of the list will be added. Node numbers that occur multiple times in the list are ignored (they are already added the first time).

Finally, if 'ind' is a logical matrix with n columns and an arbitrary amount of rows, then in frame i only the nodes that are TRUE in row i are included. This is the only way to specify removal of nodes.

The 'input' argument can also be given a list of weigths matrices if all these matrices have the same dimension (i.e.\ only the weights differ). If this is done than in frame i the ith weigths matrix is used. This is especially usefull for animating the change in a graph.

In this case, the 'ind' argument behaves differently. If this argument is not specified then in each frame all nodes are included.

If 'ind' is a logical vector of length n then only one plot is made with the nodes specified with that vector, and only if the length of 'input' is one.

Other methods woth in the same way as above. However, if the 'ind' argument indicates a different number of frames than the 'input' argument the function will stop and give an error.

Sacha Epskamp (qgraph@sachaepskamp.com)

Sacha Epskamp, Angelique O. J. Cramer, Lourens J. Waldorp, Verena D. Schmittmann, Denny Borsboom (2012). qgraph: Network Visualizations of Relationships in Psychometric Data. Journal of Statistical Software, 48(4), 1-18. URL http://www.jstatsoft.org/v48/i04/.

```
## Not run:
##D
##D ## For these examples, first generate a scale free network using preferential attachment:
##D
##D # Number of nodes:
##D n <- 100
##D # Empty vector with Degrees:
##D Degs <- rep(0, n)
##D # Empty Edgelist:
##D E <- matrix(NA, n - 1, 2)
##D # Add and connect nodes 1 and 2:
##D E[1, ] <- 1:2
##D Degs[1:2] <- 1
##D # For each node, add it with probability proportional to degree:
##D for (i in 2:(n - 1))
##D {
##D E[i, 2] <- i + 1
##D con <- sample(1:i, 1, prob = Degs[1:i]/sum(Degs[1:i]),i)
##D Degs[c(con,i+1)] <- Degs[c(con,i+1)] + 1
##D E[i, 1] <- con
##D }
##D
##D # Because this is an edgelist we need a function to convert this to an adjacency matrix:
##D E2adj <- function(E,n)
##D {
##D adj <- matrix(0,n,n)
##D for (i in 1:nrow(E))
##D {
##D adj[E[i,1],E[i,2]] <- 1
##D }
##D adj <- adj + t(adj)
##D return(adj)
##D }
##D
##D
##D
##D ### EXAMPLE 1: Animation of construction algorithm: ###
##D adjs <- lapply(1:nrow(E),function(i) E2adj(E[1:i,,drop=FALSE],n))
##D qgraph.animate(adjs,color="black",labels=FALSE,sleep=0.1)
##D rm(adjs)
##D
##D ### EXAMPLE 2: Add nodes by final degree: ###
##D adj <- E2adj(E,n)
##D qgraph.animate(E2adj(E,n),color="black",labels=FALSE,constraint=100,sleep=0.1)
##D
##D ### EXAMPLE 3: Changing edge weights: ###
##D adjW <- adj*rnorm(n^2)
##D adjW <- (adjW + t(adjW))/2
##D adjs <- list(adjW)
##D for (i in 2:100)
##D {
##D adjW <- adj*rnorm(n^2)
##D adjW <- (adjW + t(adjW))/2
##D adjs[[i]] <- adjs[[i-1]] + adjW
##D }
##D qgraph.animate(adjs,color="black",labels=FALSE,constraint=100,sleep=0.1)
##D
##D
## End(Not run)
```

[Package *qgraph* version 1.2 Index]