Skip to content

Commit

Permalink
Merge pull request #273 from snlab-ch/develop
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
jhollway authored Jul 20, 2023
2 parents 6ee6e54 + f396830 commit 088e17f
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prchecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
config:
- {os: macOS-latest, r: 'release', artifact_name: '*.tar.gz', asset_name: macOS}
- {os: windows-latest, r: 'release', artifact_name: '*.zip', asset_name: winOS}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", artifact_name: '*.tar.gz', asset_name: linuxOS}
- {os: ubuntu-latest, r: 'release', artifact_name: '*.tar.gz', asset_name: linuxOS}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pushrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
config:
- {os: macOS-latest, r: 'release', artifact_name: '*.tar.gz', asset_name: macOS}
- {os: windows-latest, r: 'release', artifact_name: '*.zip', asset_name: winOS}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", artifact_name: '*.tar.gz', asset_name: linuxOS}
- {os: ubuntu-latest, r: 'release', artifact_name: '*.tar.gz', asset_name: linuxOS}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Package: migraph
Title: Multimodal Network Analysis and More
Version: 1.0.0
Date: 2023-06-13
Version: 1.0.1
Date: 2023-07-20
Description: A set of tools for analysing multimodal networks.
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.
It includes functions for measuring
centrality, centralization, cohesion, closure, and constraint,
centrality, centralization, cohesion, closure, constraint and diversity,
as well as for network block-modelling, regression, and diffusion models.
The package is released as a complement to
'Multimodal Political Networks' (2021, ISBN:9781108985000),
and includes various datasets used in the book in addition to other network data.
and includes various datasets used in the book.
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
BugReports: https://github.com/snlab-ch/migraph/issues
License: MIT + file LICENSE
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ importFrom(network,as.network)
importFrom(network,is.network)
importFrom(purrr,flatten)
importFrom(rlang,.data)
importFrom(rlang,`%||%`)
importFrom(rlang,enquo)
importFrom(rlang,eval_tidy)
importFrom(sna,brokerage)
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.0.1

## Measures

- Fixed backends in `node_closeness()` and `node_betweenness()` in preparation for an `{igraph}` deprecation (merci @maelle)

## Models

- Fixed #272 by making `test_random()` and `test_permutation()` rely on graph dimensions rather than graph order (thank you finding this @rabenton)

## Tutorials

- Fixed some defunct function names

# migraph 1.0.0

## Package
Expand Down
18 changes: 7 additions & 11 deletions R/measure_centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ node_betweenness <- function(.data, normalized = TRUE,
directed = manynet::is_directed(graph), weights = weights,
normalized = normalized)
} else {
out <- igraph::estimate_betweenness(graph = graph, vids = igraph::V(graph),
directed = manynet::is_directed(graph),
cutoff = cutoff,
weights = weights)
out <- igraph::betweenness(graph = graph, v = igraph::V(graph),
directed = manynet::is_directed(graph),
cutoff = cutoff,
weights = weights)
}
}
out <- make_node_measure(out, .data)
Expand Down Expand Up @@ -325,13 +325,9 @@ node_closeness <- function(.data, normalized = TRUE,
set_size <- ifelse(igraph::V(graph)$type, sum(igraph::V(graph)$type), sum(!igraph::V(graph)$type))
out <- closeness/(1/(other_set_size+2*set_size-2))
} else {
if (is.null(cutoff)) {
out <- igraph::closeness(graph = graph, vids = igraph::V(graph), mode = direction,
weights = weights, normalized = normalized)
} else {
out <- igraph::estimate_closeness(graph = graph, vids = igraph::V(graph), mode = direction,
cutoff = cutoff, weights = weights, normalized = normalized)
}
cutoff <- cutoff %||% -1
out <- igraph::closeness(graph = graph, vids = igraph::V(graph), mode = direction,
cutoff = cutoff, weights = weights, normalized = normalized)
}
out <- make_node_measure(out, .data)
out
Expand Down
7 changes: 7 additions & 0 deletions R/migraph-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @importFrom rlang `%||%`
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
6 changes: 3 additions & 3 deletions R/model_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_random <- function(.data, FUN, ...,
} else {
obsd <- FUN(.data)
}
n <- manynet::network_nodes(.data)
n <- manynet::network_dims(.data)
d <- network_density(.data)
future::plan(strategy)
rands <- furrr::future_map(1:times, manynet::generate_random, n = n, p = d,
Expand Down Expand Up @@ -79,11 +79,11 @@ test_permutation <- function(.data, FUN, ...,
} else {
obsd <- FUN(.data)
}
n <- manynet::network_nodes(.data)
n <- manynet::network_dims(.data)
d <- network_density(.data)
future::plan(strategy)
rands <- furrr::future_map(1:times,
function(x) manynet::as_igraph(manynet::generate_permutation(.data)),
function(x) manynet::generate_permutation(.data),
.progress = verbose,
.options = furrr::furrr_options(seed = T))
if (!is.null(args)) {
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ learnr::available_tutorials("migraph")
```

You can then choose to begin a tutorial using the following command: e.g.
`learnr::run_tutorial("tutorial2", "migraph")`.
`learnr::run_tutorial("tutorial3", "migraph")`.
For more details on the `{learnr}` package, see [here](https://rstudio.github.io/learnr/).

## Relationship to other packages
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ suggest that you check to see which vignettes are currently available:
learnr::available_tutorials("migraph")
#> Available tutorials:
#> * migraph
#> - tutorial2 : "Visualisation"
#> - tutorial3 : "Centrality"
#> - tutorial4 : "Community"
#> - tutorial5 : "Equivalence"
Expand All @@ -241,7 +240,7 @@ learnr::available_tutorials("migraph")
```

You can then choose to begin a tutorial using the following command:
e.g. `learnr::run_tutorial("tutorial2", "migraph")`. For more details on
e.g. `learnr::run_tutorial("tutorial3", "migraph")`. For more details on
the `{learnr}` package, see [here](https://rstudio.github.io/learnr/).

## Relationship to other packages
Expand Down
13 changes: 7 additions & 6 deletions inst/tutorials/tutorial8/regression.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ $$\frac{E-I}{E+I}$$
where $E$ is the number of ties present between a variable's categories (i.e. external),
and $I$ is the number of ties present within a variable's categories (i.e. internal).
As such, an EI index of -1 suggests perfect homophily, whereas an EI index of +1 suggests perfect heterophily.
(This is why the function is called `network_heterophily()`).

Check how homophilic three variables in the network are,
"Gender", "PowerOrigin", and "Attractive".
Expand All @@ -186,7 +187,7 @@ Check how homophilic three variables in the network are,
```

```{r ei-hint}
network_homophily(____, ____)
network_heterophily(____, ____)
```

```{r ei-solution}
Expand Down Expand Up @@ -244,13 +245,13 @@ plot(rand.____)

```{r rando-solution}
rand.gender <- test_random(marvel_friends,
network_homophily, attribute = "Gender",
network_heterophily, attribute = "Gender",
times = 1000)
rand.power <- test_random(marvel_friends,
network_homophily, attribute = "PowerOrigin",
network_heterophily, attribute = "PowerOrigin",
times = 1000)
rand.attract <- test_random(marvel_friends,
network_homophily, attribute = "Attractive",
network_heterophily, attribute = "Attractive",
times = 1000)
plot(rand.gender)
plot(rand.power)
Expand Down Expand Up @@ -311,7 +312,7 @@ attributes, but it is just a single permutation.
Let's try a test that runs this over a succession of permutations,
just as we did with random graphs.

```{r testpermute, exercise=TRUE, exercise.setup = "friends-solution"}
```{r testpermute, exercise=TRUE, exercise.setup = "rando-solution"}
```

Expand All @@ -333,7 +334,7 @@ Again, we see that there is perhaps nothing so surprising that we got the homoph
for gender that we did, but the lack of power origin heterophily is surprising.
Plot the results for gender and power according to the random and permutation baselines.

```{r cugqap, exercise=TRUE, exercise.setup = "friends-solution"}
```{r cugqap, exercise=TRUE, exercise.setup = "testpermute-solution"}
```

Expand Down
32 changes: 32 additions & 0 deletions man/migraph-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-model_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cugtest <- test_random(marvel_friends,
cugtest2 <- test_random(marvel_friends,
network_betweenness,
times = 200)
cugtest3 <- test_random(ison_southern_women,
network_equivalency,
times = 200)

test_that("test_random works", {
# Set the cugtest up
Expand All @@ -23,6 +26,7 @@ test_that("test_random works", {
expect_s3_class(cugtest, "network_test")
# Test stuff cug2
expect_equal(as.numeric(cugtest2$testval), 0.238, tolerance = 0.001)
expect_equal(mean(cugtest3$testdist), 0.361, tolerance = 0.003)
expect_equal(length(cugtest2$testdist), 200) # NB: Stochastic
expect_false(cugtest2$mode)
expect_false(cugtest2$diag)
Expand Down

0 comments on commit 088e17f

Please sign in to comment.