# \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
############################################
###### example 2: expected influence #######
############################################
# expected influence from this package
library(networktools)
# data
Y <- depression
# fit model
fit <- estimate(Y = Y, iter = 250)
# 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)
# clusters
communities <- substring(colnames(Y), 1, 1)
# function is slow
f <- function(x, ...){
bridge(x, ...)$`Bridge Strength`
}
net_stat <- roll_your_own(fit,
FUN = f,
select = TRUE,
communities = communities,
progress = FALSE)
# }
Run the code above in your browser using DataLab