Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.2 #277

Merged
merged 12 commits into from
Oct 18, 2023
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: migraph
Title: Multimodal Network Analysis and More
Version: 1.1.1
Date: 2023-10-11
Version: 1.1.2
Date: 2023-10-18
Description: A set of tools for analysing multimodal networks.
It includes functions for measuring
centrality, centralization, cohesion, closure, constraint and diversity,
Expand All @@ -12,7 +12,7 @@ Description: A set of tools for analysing multimodal networks.
Built on the 'manynet' package, all functions operate with matrices, edge lists,
and 'igraph', 'network', and 'tidygraph' objects,
and on one-mode, two-mode (bipartite), and sometimes three-mode networks.
URL: https://github.com/snlab-ch/migraph
URL: https://snlab-ch.github.io/migraph/
BugReports: https://github.com/snlab-ch/migraph/issues
License: MIT + file LICENSE
Language: en-GB
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# migraph 1.1.2

2023-10-11

## Package

- Added more code annotations in 'tutorial4' (Community)
- Elaborated 'tutorial5' (was named Equivalence, now Position)
- Chunks in tutorials that are incremental now hidden upon extraction using `purl = FALSE` argument

## Members

- Improved printing of node_members and node_measures objects

# migraph 1.1.1

2023-10-11
Expand Down
3 changes: 2 additions & 1 deletion R/class_measures.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
make_node_measure <- function(out, .data) {
if(manynet::is_labelled(.data)) names(out) <- manynet::node_names(.data)
class(out) <- c("node_measure", class(out))
attr(out, "mode") <- manynet::node_mode(.data)
out
Expand Down Expand Up @@ -154,6 +155,6 @@ print_tblvec <- function(y, names){
print(body)
cat(pillar::style_subtle(paste("# ... with",
setup$extra_cols_total,
"more from this nodeset in the vector.")))
"more values from this nodeset not printed but in the vector.")))
} else print(body)
}
8 changes: 5 additions & 3 deletions R/class_members.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
make_node_member <- function(out, .data) {
if(manynet::is_labelled(.data)) names(out) <- manynet::node_names(.data)
class(out) <- c("node_member", class(out))
attr(out, "mode") <- manynet::node_mode(.data)
out
Expand All @@ -24,13 +25,14 @@ print.node_member <- function(x, ...,
}
} else {
for (i in names(table(x))) {
if (i == names(table(x))[1]) cat(i, "\n")
else cat("\n", i, "\n")
if (i == names(table(x))[1]) cat("Class ", i, ":", sep = "")
else cat("Class ", i, ":", sep = "")
if (!is.null(names(x)))
y <- paste(names(x[x == i]), collapse = ", ")
else
y <- paste(which(x == i), collapse = ", ")
cat(" ", y)
cat(" ", y)
if (i != names(table(x))[length(table(x))]) cat("\n")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion R/member_community.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ node_kernighanlin <- function(.data){

# extract names of vertices in each group after swaps
out <- ifelse(manynet::node_names(.data) %in% g1.newnames, 1, 2)
if(manynet::is_labelled(.data)) names(out) <- manynet::node_names(.data)
make_node_member(out, .data)
}

Expand Down
50 changes: 28 additions & 22 deletions inst/tutorials/tutorial3/centrality.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@
by renaming the nodal attribute "twomode_type" to just "type".
Let's begin by graphing these datasets using `manynet::autographr()`.

```{r coercion, exercise = TRUE}
```{r coercion, exercise = TRUE, purl = FALSE}

```

```{r coercion-hint-1}
```{r coercion-hint-1, purl = FALSE}
# Let's graph the one-mode version
autographr(____)

Check warning on line 35 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=35,col=13,[error] unexpected input

Check warning on line 35 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=35,col=13,[error] unexpected input
```

```{r coercion-hint-2}
```{r coercion-hint-2, purl = FALSE}
# Now, let's create a two-mode version 'ison_brandes2' and graph it.
ison_brandes2 <- ison_brandes %>% rename(type = twomode_type)
autographr(____)
```

```{r coercion-solution}
```{r coercion-solution, purl = FALSE}
# plot the one-mode version
autographr(ison_brandes)
ison_brandes2 <- ison_brandes %>% rename(type = twomode_type)
# plot the two-mode version
autographr(ison_brandes2)
```

Expand All @@ -52,17 +54,18 @@
Luckily, `{manynet}` has a function for this.
This makes plotting the network just a wee bit more accessible and interpretable:

```{r addingnames, exercise = TRUE}
```{r addingnames, exercise = TRUE, purl = FALSE}
ison_brandes <- to_named(ison_brandes)
```

```{r addingnames-hint-1}
```{r addingnames-hint-1, purl = FALSE}
# Now, let's graph using the object names: "ison_brandes"
autographr(____)
```

```{r addingnames-solution}
ison_brandes <- to_named(ison_brandes)
# plot network with names
autographr(ison_brandes)
```

Expand All @@ -74,36 +77,37 @@
Let's start with calculating degree, as it is easy to calculate yourself.
Just sum the rows or columns of the matrix!

```{r degreesum, exercise = TRUE, exercise.setup = "addingnames"}
```{r degreesum, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

```{r degreesum-hint-1}
```{r degreesum-hint-1, purl = FALSE}
# We can calculate degree centrality like this:
(mat <- as_matrix(ison_brandes))
(degrees <- rowSums(mat))
rowSums(mat) == colSums(mat)
```

```{r degreesum-hint-2}
```{r degreesum-hint-2, purl = FALSE}
# Or by using a built in command in migraph like this:
node_degree(ison_brandes, normalized = FALSE)
```

```{r degreesum-solution}
# manually calculate degree centrality
mat <- as_matrix(ison_brandes)
degrees <- rowSums(mat)
rowSums(mat) == colSums(mat)
# You can also just use a built in command in migraph though:
node_degree(ison_brandes, normalized = FALSE)
```

```{r degreesum-Q, echo=FALSE}
```{r degreesum-Q, echo=FALSE, purl = FALSE}
question("Are the row sums the same as the column sums?",
answer("Yes",

Check warning on line 107 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=107,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.

Check warning on line 107 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=107,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.
correct = TRUE,

Check warning on line 108 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=108,col=9,[indentation_linter] Indentation should be 0 spaces but is 9 spaces.

Check warning on line 108 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=108,col=9,[indentation_linter] Indentation should be 0 spaces but is 9 spaces.
message = "That's right, that's because this is an undirected network."),

Check warning on line 109 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=109,col=81,[line_length_linter] Lines should not be more than 80 characters.

Check warning on line 109 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=109,col=81,[line_length_linter] Lines should not be more than 80 characters.
answer("No"),

Check warning on line 110 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=110,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.

Check warning on line 110 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=110,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.
allow_retry = FALSE
)
```
Expand All @@ -112,11 +116,12 @@
`{migraph}` offers a way to get a pretty good first look at this distribution,
though there are more elaborate ways to do this in base and grid graphics.

```{r distrib, exercise = TRUE, exercise.setup = "addingnames"}
```{r distrib, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

```{r distrib-solution}
# distribution of degree centrality scores of nodes
plot(node_degree(ison_brandes))
```

Expand All @@ -131,24 +136,24 @@
betweenness, closeness, and eigenvector centralities for each node in the network.
Let's collect the vectors of these centralities for the `ison_brandes` dataset:

```{r micent, exercise = TRUE, exercise.setup = "addingnames"}
```{r micent, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

```{r micent-hint-1}
```{r micent-hint-1, purl = FALSE}
# Use the node_betweenness() function to calculate the
# betweenness centralities of nodes in a network
node_betweenness(ison_brandes)
```

```{r micent-hint-2}
```{r micent-hint-2, purl = FALSE}
# Use the node_closeness() function to calculate the

Check warning on line 150 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=150,col=53,[trailing_whitespace_linter] Trailing whitespace is superfluous.

Check warning on line 150 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=150,col=53,[trailing_whitespace_linter] Trailing whitespace is superfluous.
# closeness centrality of nodes in a network
node_closeness(ison_brandes)
```

```{r micent-hint-3}
```{r micent-hint-3, purl = FALSE}
# Use the node_eigenvector() function to calculate

Check warning on line 156 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=156,col=51,[trailing_whitespace_linter] Trailing whitespace is superfluous.

Check warning on line 156 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=156,col=51,[trailing_whitespace_linter] Trailing whitespace is superfluous.
# the eigenvector centrality of nodes in a network
node_eigenvector(ison_brandes)
```
Expand Down Expand Up @@ -186,17 +191,18 @@
By passing this attribute to the `autographr()` argument "node_color"
we can highlight which node or nodes hold the maximum score in red.

```{r ggid, exercise = TRUE, exercise.setup = "addingnames"}
```{r ggid, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

```{r ggid-solution}
# plot the network, highlighting the node with the highest centrality score with a different colour

Check warning on line 199 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=199,col=81,[line_length_linter] Lines should not be more than 80 characters.

Check warning on line 199 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=199,col=81,[line_length_linter] Lines should not be more than 80 characters.
ison_brandes %>%
add_node_attribute("color", node_is_max(node_degree(ison_brandes))) %>%

Check warning on line 201 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=201,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.

Check warning on line 201 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=201,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.
autographr(node_color = "color")

ison_brandes %>%
add_node_attribute("color", node_is_max(node_betweenness(ison_brandes))) %>%

Check warning on line 205 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for macOS-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=205,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.

Check warning on line 205 in inst/tutorials/tutorial3/centrality.Rmd

View workflow job for this annotation

GitHub Actions / Build for ubuntu-latest

file=inst/tutorials/tutorial3/centrality.Rmd,line=205,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.
autographr(node_color = "color")

ison_brandes %>%
Expand All @@ -211,7 +217,7 @@
How neat! Try it with the two-mode version.
What can you see?

```{r ggid_twomode, exercise = TRUE}
```{r ggid_twomode, exercise = TRUE, purl = FALSE}
# Instead of "ison_brandes", use "ison_brandes2"

```
Expand All @@ -234,7 +240,7 @@
autographr(node_color = "color")
```

```{r brandes2quiz}
```{r brandes2quiz, purl = FALSE}
question("Select all that are true for the two-mode Brandes network.",
answer("Only one node is selected in each plot."),
answer("The maximum degree square has a higher degree than the maximum degree circle(s).",
Expand All @@ -251,7 +257,7 @@
but in the level of the whole network,
so the syntax replaces `node_` with `network_`:

```{r centzn, exercise = TRUE, exercise.setup = "addingnames"}
```{r centzn, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

Expand All @@ -277,7 +283,7 @@
This can be a little tricky with gg-based plots,
but fortunately the `{patchwork}` package is here to help.

```{r multiplot, exercise = TRUE, exercise.setup = "addingnames"}
```{r multiplot, exercise = TRUE, exercise.setup = "addingnames", purl = FALSE}

```

Expand All @@ -304,7 +310,7 @@
```


```{r centzdq}
```{r centzdq, purl = FALSE}
question("How centralized is the ison_brandes network? Select all that apply.",
answer("It is more degree centralised than betweenness centralised.",
message = "Degree centralisation is at 0.18 for this network whereas betweenness centralisation is at 0.32. In other words, the network is better characterised as having 1 or 2 nodes lying on the shortest paths between others than one where 1 or 2 nodes have many more ties than the others."),
Expand All @@ -317,7 +323,7 @@
allow_retry = TRUE)
```

```{r centvcent, echo=FALSE}
```{r centvcent, echo=FALSE, purl = FALSE}
question("What is the difference between centrality and centralisation according to the literature?",
answer("Centrality is for nodes and centralisation is for networks",
correct = TRUE),
Expand Down
Loading
Loading