This function allows for computing custom network statistics for weighted adjacency matrices (partial correlations). The statistics are computed for each of the sampled matrices, resulting in a distribution.
roll_your_own( object, FUN, iter = NULL, select = FALSE, cred = 0.95, progress = TRUE, ... )
object | An object of class |
---|---|
FUN | A custom function for computing the statistic. The first argument must be a partial correlation matrix. |
iter | Number of iterations (posterior samples; defaults to the number in the object). |
select | Logical. Should the graph be selected ? The default is currently |
cred | Numeric. Credible interval between 0 and 1 (default is 0.95) that is used for selecting the graph. |
progress | Logical. Should a progress bar be included (defaults to |
... | Arguments passed to the function. |
An object defined by FUN
.
The user has complete control of this function. Hence, care must be taken as to what FUN
returns and in what format. The function should return a single number (one for the entire GGM)
or a vector (one for each node). This ensures that the print and plot.roll_your_own
will work.
When select = TRUE
, the graph is selected and then the network statistics are computed based on
the weigthed adjacency matrix. This is accomplished internally by multiplying each of the sampled
partial correlation matrices by the adjacency matrix.
# \donttest{ #################################### ###### example 1: assortment ####### #################################### # assortment library(assortnet) Y <- BGGM::bfi[,1:10] membership <- c(rep("a", 5), rep("c", 5)) # fit model fit <- estimate(Y = Y, iter = 250, progress = FALSE) # membership membership <- c(rep("a", 5), rep("c", 5)) # define function f <- function(x,...){ assortment.discrete(x, ...)$r } net_stat <- roll_your_own(object = fit, FUN = f, types = membership, weighted = TRUE, SE = FALSE, M = 1, progress = FALSE) # print net_stat#> BGGM: Bayesian Gaussian Graphical Models #> --- #> Network Stats: Roll Your Own #> Posterior Samples: 250 #> --- #> Estimates: #> #> Post.mean Post.sd Cred.lb Cred.ub #> 0.351 0.109 0.15 0.547 #> ---############################################ ###### example 2: expected influence ####### ############################################ # expected influence from this package library(networktools)#>#> #> #> #> #>#>#># define function f <- function(x,...){ expectedInf(x,...)$step1 } # compute net_stat <- roll_your_own(object = fit, FUN = f, progress = FALSE) ####################################### ### example 3: mixed data & bridge #### ####################################### # bridge from this package library(networktools) # data Y <- ptsd[,1:7] fit <- estimate(Y, type = "mixed", iter = 250)#>#>