-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
76 lines (55 loc) · 1.98 KB
/
README.Rmd
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
---
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%"
)
```
# MultiNeSS
<!-- badges: start -->
<!-- badges: end -->
The R package "multiness" implements model fitting and simulation for Gaussian and logistic inner
product MultiNeSS models for multiplex networks. The package uses
a convex fitting algorithm with fully adaptive parameter tuning,
including options for edge cross-validation. For more details see [MacDonald et al., (2022)](https://doi.org/10.1093/biomet/asab058).
## Installation
You can install "multiness" version 1.0.2 from CRAN using
``` r
install.packages("multiness")
```
You can install the development version of "multiness" from GitHub using
``` r
devtools::install_github("peterwmacd/multiness")
```
## Example
"multiness" includes an example multiplex network of agricultural trade which is studied in [MacDonald et al., (2022)](https://doi.org/10.1093/biomet/asab058). It is easy to import and to fit a Gaussian MultiNeSS model with adaptive tuning.
```{r example}
library(multiness)
# import data
data(agri_trade)
dim(agri_trade)
# log transformation for edge weights
A <- log(1+agri_trade)
# model fit
fit <- multiness_fit(A,model="gaussian",self_loops=FALSE,
tuning="adaptive",tuning_opts=list(penalty_const=3),
optim_opts=list(max_rank=100,return_posns=TRUE))
# inspect fitted latent space dimensions
# common latent space
fit$d1
# individual latent spaces
fit$d2
# plot first two common latent dimensions
plot(fit$V_hat[,1:2],main="Common latent dimensions",
xlab="v1",ylab="v2",xlim=c(0,4.5))
# label a subset of the points
countries <- dimnames(A)[[1]]
do_label <- c(4,5,8,10,11,14,17,19,20,24,25,28,33,34,35,37,39,41,54,61,75)
text(fit$V_hat[do_label,1],fit$V_hat[do_label,2],
labels=countries[do_label],pos=4,cex=.8)
```