knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

netglm

GitHub issues GitHub All Releases

The goal of netglm is to provide a software which allows to model (multi-group) network data in a general linear regression framework.

Installation

You can install the development version of netglm from GitHub with:

# install.packages("devtools")
devtools::install_github("timonelmer/netglm")

Example

This is a basic example which shows you how to estimate a multi-group QAP model. But first, let us create some test data (inspired by the example in function sna::netlm) we will imagine that we have two independently measured networks (dependent variables) with four predictor variables each (i.e. four networks). For example, friendship networks in two different school classes as dependent variables.

# create two sets of random networks as independent variables
ivnet1<-sna::rgraph(20,4) 
ivnet2<-sna::rgraph(20,4)

# create dependent variables as functions of the independent variables
dv1<-ivnet1[1,,]+4*ivnet1[2,,]+2*ivnet1[3,,]   # Note that the fourth graph  is unrelated
dv1 <- dv1 + rnorm(400,mean = 1, sd = 1)

dv2 <- 2*ivnet2[1,,]+3*ivnet2[2,,]+3*ivnet2[3,,]
dv2 <- dv2 + rnorm(400,mean = 1, sd = 1)
dvs <- list(dv1, dv2) # put the two dependent variables in a list

iv1 <- list(ivnet1[1,,],ivnet1[2,,],ivnet1[3,,], ivnet1[4,,]) #put all independent variables in a list
iv2 <- list(ivnet2[1,,],ivnet2[2,,],ivnet2[3,,], ivnet2[4,,])
ivs <- list(iv1, iv2) # put the two lists of independent variables in a list

Now that we have created some test data, we can estimate a multi-group QAP model with the QAP.MG function:

library(netglm)
fit <- QAP.MG(dvs, ivs, iv.names = c("intercept",paste0("IV",1:4)), samples = 1000)

We can inspect the output as follows:

fit$output # for fixed effects estimates and their distribution

fit$r.squared # for r.squared measures


timonelmer/netglm documentation built on Aug. 14, 2024, 9:39 p.m.