-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
83 lines (55 loc) · 2.66 KB
/
README.Rmd
File metadata and controls
83 lines (55 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
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%"
)
```
# netglm
<!-- badges: start -->
<!--
 -->


<!-- [](https://codecov.io/gh/timonelmer/netglm?branch=master) -->
<!-- badges: end -->
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](https://github.com/) with:
``` r
# 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.
```{r}
# 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:
```{r messages = F}
library(netglm)
fit <- QAP.MG(dvs, ivs, iv.names = c("intercept",paste0("IV",1:4)), samples = 1000)
```
We can inspect the output as follows:
```{r echo = T}
fit$output # for fixed effects estimates and their distribution
fit$r.squared # for r.squared measures
```