--- output: github_document --- <!-- README.md is generated from README.Rmd. Please edit that file --> ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) ``` # multip2 The multip2 package provides a Bayesian implementation of the multiplex extension (Hong & Niezink, 2024) to the p2 (van Duijn et al., 2004) model which includes cross-layer dyadic dependencies as fixed effects and actor-specific dependencies as random effects. The influence of covariates are also considered in the analysis of cross-sectional, directed binary multiplex network data. You can read more about the multiplex p2 model in the following paper: [The Multiplex p2 Model: Mixed-Effects Modeling for Multiplex Social Networks](https://arxiv.org/abs/2405.17707) ## Installation You can install the development version of multip2 from [GitHub](https://github.com/) with: ``` r install.packages("remotes") remotes::install_github("annihong/multip2") ``` ## Example ```{r example, eval=FALSE} library(multip2) n = 5 networks = replicate(4, matrix(data=sample(c(0,1), n^2, replace=TRUE, prob=c(0.7,0.3)), nrow=n), simplify = FALSE) #self loops are ignored names(networks) <- c("network1", "network2", "network_covariate1", "network_covariate2") actor_data = data.frame(actor_attr1=1:n, actor_attr2=1:n) dep_net <- networks[c("network1", "network2")] dyad_covar <- networks[c("network_covariate1", "network_covariate2")] actor_covar <- actor_data[c("actor_attr1", "actor_attr2")] m_empty <- Mp2Model(dep_net, dyad_covar = dyad_covar, actor_covar = actor_data) m_PS <- fit(m_empty, iter=20) m_HC <- fit(m_empty, iter=200, stan_file = "multiplex_p2_HC.stan") # sim_nets <- extract_network_draws(m_empty_res, 200) # simulated_network_checks(sim_nets, m_empty_res, "multiplex_gof_random") m <- m_empty m <- update_covar(m, layer_1 = "network1", density = c("network_covariate2", "network_covariate1"), reciprocity = c("network_covariate2"), receiver = "actor_attr2") m <- update_covar(m, layer_1 = "network2", density = c("network_covariate2", "network_covariate1"), reciprocity = "network_covariate2", sender = "actor_attr1") m <- update_covar(m, layer_1 = "network1", layer_2 = "network2", cross_density = c("network_covariate2", "network_covariate1"), cross_reciprocity = "network_covariate2", sender = "actor_attr1") m2_fit <- fit(m, iter=10) m2_fit <- update_prior(model_obj=m2_fit, param="reciprocity", type="baseline", layer_lab=NULL, covar_lab=NULL, mean=99, sd=99, eta=NULL, alpha=NULL, beta=NULL) m2_fit <- update_prior(model_obj=m2_fit, param="reciprocity", type="covariate", layer_lab="network1", covar_lab="network_covariate2", mean=99, sd=99, eta=NULL, alpha=NULL, beta=NULL) m2_fit <- fit(m2_fit, iter=100, prior_sim=TRUE) summary(m2_fit) #testing missing val n = 5 dep_net = replicate(2, matrix(data=sample(c(0,1, NA), n^2, replace=TRUE, prob=c(0.7,0.2, 0.1)), nrow=n), simplify = FALSE) #self loops are ignored names(dep_net) <- c("network1", "network2") dyad_covar = replicate(2, matrix(data=sample(c(0,1), n^2, replace=TRUE, prob=c(0.7,0.3)), nrow=n), simplify = FALSE) #self loops are ignored names(dyad_covar) <- c("network_covariate1", "network_covariate2") actor_data = data.frame(actor_attr1=1:n, actor_attr2=1:n) actor_covar <- actor_data[c("actor_attr1", "actor_attr2")] m_empty <- Mp2Model(dep_net, dyad_covar = dyad_covar, actor_covar = actor_data) m_empty_res <- fit(m_empty, iter=10, prior_sim=TRUE) m_empty_res <- fit(m_empty, iter=10, prior_sim=FALSE) ```