-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
117 lines (85 loc) · 3.48 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
output: github_document
bibliography: reference.bib
---
<!-- 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%"
)
```
# nethist
<!-- badges: start -->
[](https://github.com/EnigmaSong/nethist/actions/workflows/R-CMD-check.yaml)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
The goal of *nethist* is to estimate graphons by *network histogram* [@wolfe2013Nonparametric; @olhede2014Network]. It also provides extra tools for summary violin plot for networks [@maugis2017Topology] and visualizing network histogram. Use undirected and simple graphs with no self-loops (either igraph or matrix) as inputs for the functions in this package.
To install the package from source, you need C++ and Fortran compilers.
## Installation
You can install the development version of nethist from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("EnigmaSong/nethist")
```
## Example
Here are basic examples using political blog data set in the package:
### Network histogram
```{r load_library}
library(nethist)
```
We use *polblog* dataset in the package for our examples.
```{r summary, echo = FALSE}
A<- igraph::as_adj(polblog, sparse = FALSE)
heatmap(A, Rowv = NA, symm=TRUE, col = c("white","red"))
```
We can estimate a network histogram from the political blog data and plot it.
```{r example}
## Example code using polblog data set
set.seed(42)
hist_polblog <- nethist(polblog, h = 72) #using user-specified bin size.
plot(hist_polblog)
```
### Plotting option
```{r get_reorder, echo = FALSE}
#Get ratio for liberal
ratio_liberal <- table(hist_polblog$cluster, c(rep(1,586),rep(0,638)))
ratio_liberal <- ratio_liberal[,1]/rowSums(ratio_liberal)
liberal_ind <- which(ratio_liberal>=0.5)
conserv_ind <- which(ratio_liberal<0.5)
#Order by cross-party connection
liberal_cp_con <- rowSums(hist_polblog$p_mat[liberal_ind,conserv_ind])
conserv_cp_con <- colSums(hist_polblog$p_mat[liberal_ind,conserv_ind])
ind <- c(rev(liberal_ind[order(liberal_cp_con,decreasing=TRUE)]),
conserv_ind[order(conserv_cp_con,decreasing=TRUE)],use.names=FALSE);
```
#### heatmap() style
`plot()` provides 2D plot as `heatmap()`.
You can use a user-specified indices for plots. Here is an example:
```{r example2}
print(ind)
## Users can specify the index order of heatmap
plot(hist_polblog, idx_order = ind)
## Users can specify the color palette
library(RColorBrewer)
plot(hist_polblog, idx_order = ind, col = brewer.pal(9, "Greys"))
```
You can display the estimated block probabilities by setting `type = prob` and `prob=TRUE`.
```{r example3}
## Users can specify the color palette
plot(hist_polblog, idx_order = ind, type = "prob", prob= TRUE, prob.col = "blue",
col = colorRampPalette(colors=c("#FFFFFF","#000000"))(200))
```
### others
There are more types of plots in `nethist` package.
### Summary violin plot
If you want to check network summary violin plot of the data set:
```{r example4}
#User-specified subsample size.
violin_netsummary(polblog, max_cycle_order = 7, subsample_sizes = 250)
#Auto-selected subsample size.
violin_netsummary(polblog, max_cycle_order = 7)
```
## Reference