diff --git a/DESCRIPTION b/DESCRIPTION index 7fb33fc4..52fc7327 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: migraph Title: Tools for Multimodal Network Analysis -Version: 0.10.3 +Version: 0.10.4 Date: 2022-07-03 Description: A set of tools for analysing multimodal networks. All functions operate with matrices, edge lists, diff --git a/NEWS.md b/NEWS.md index 0c3d2396..d57d9d70 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# migraph 0.10.4 + +## Package + +- Fixed some URL issues + +## Manipulation + +- Split `to_*()` functions into reformatting (changing properties) and transforming (changing dimensions) documentation + # migraph 0.10.3 ## Package diff --git a/R/data_mpn.R b/R/data_mpn.R index 5fe42f45..e67ef6e5 100644 --- a/R/data_mpn.R +++ b/R/data_mpn.R @@ -308,7 +308,7 @@ NULL #' \href{https://correlatesofwar.org/data-sets/bilateral-trade}{\emph{Trade}}. #' #' Barbieri, Katherine and Omar Keshk. 2012. -#' \href{https://correlatesofwar.org.}{\emph{Correlates of War Project Trade Data Set Codebook, Version 3.0.}}. +#' Correlates of War Project Trade Data Set Codebook, Version 3.0. #' @format #' ```{r, echo = FALSE} #' mpn_cow_trade diff --git a/R/manip_to.R b/R/manip_to.R index 744dc0d4..06070ac9 100644 --- a/R/manip_to.R +++ b/R/manip_to.R @@ -1,13 +1,14 @@ +# Reformatting #### + #' Tools for reformatting networks, graphs, and matrices #' #' @description -#' These functions offer tools for transforming certain properties -#' of migraph-consistent objects +#' These functions offer tools for reformatting migraph-consistent objects #' (matrices, igraph, tidygraph, or network objects). #' Unlike the `as_*()` group of functions, #' these functions always return the same object type as they are given, #' only transforming these objects' properties. -#' +#' @details #' Since some modifications are easier to implement for some objects than others, #' here are the currently implemented modifications: #' @@ -21,12 +22,9 @@ #' | unnamed | X | X | X | X | X | #' | named | X | X | X | X | X | #' | simplex | | X | X | X | | -#' | main_component | | | X | X | X | #' | onemode | | | X | X | | #' | multilevel | | X | X | X | | -#' | mode1 | | X | X | X | | -#' | mode2 | | X | X | X | | -#' @name to +#' @name reformat #' @family manipulations #' @inheritParams is #' @param edge Character string naming an edge attribute to retain from a graph. @@ -41,7 +39,7 @@ #' with certain modifications as outlined for each function. NULL -#' @describeIn to Returns an object that includes only a single type of tie +#' @describeIn reformat Returns an object that includes only a single type of tie #' @importFrom igraph delete_edges edge_attr_names delete_edge_attr #' @importFrom igraph E get.edge.attribute edge_attr_names #' @examples @@ -77,31 +75,7 @@ to_uniplex.igraph <- function(object, edge){ out } -#' @describeIn to Returns an object that includes only the main component -#' without any smaller components or isolates -#' @export -to_main_component <- function(object) UseMethod("to_main_component") - -#' @export -to_main_component.tbl_graph <- function(object) { - as_tidygraph(to_main_component(as_igraph(object))) -} - -#' @export -to_main_component.igraph <- function(object) { - comps <- igraph::components(object) - max.comp <- which.max(comps$csize) - igraph::delete.vertices(object, comps$membership != max.comp) -} - -#' @export -to_main_component.network <- function(object) { - network::delete.vertices(object, - which(!sna::component.largest(object, - result = "membership"))) -} - -#' @describeIn to Returns an object that has any edge direction removed, +#' @describeIn reformat Returns an object that has any edge direction removed, #' so that any pair of nodes with at least one directed edge will be #' connected by an undirected edge in the new network. #' This is equivalent to the "collapse" mode in `{igraph}`. @@ -132,7 +106,7 @@ to_undirected.matrix <- function(object) { } else ((object + t(object)) > 0) * 1 } -#' @describeIn to Returns an object that has any edge direction transposed, +#' @describeIn reformat Returns an object that has any edge direction transposed, #' or flipped, so that senders become receivers and receivers become senders. #' This essentially has no effect on undirected networks or reciprocated ties. #' @export @@ -168,7 +142,7 @@ to_redirected.matrix <- function(object) { t(object) } -#' @describeIn to Returns an object that has all edge weights removed +#' @describeIn reformat Returns an object that has all edge weights removed #' @export to_unweighted <- function(object, threshold = 1) UseMethod("to_unweighted") @@ -205,7 +179,7 @@ to_unweighted.data.frame <- function(object, threshold = 1) { else stop("Not an edgelist") } -#' @describeIn to Returns a network with either just the "positive" ties +#' @describeIn reformat Returns a network with either just the "positive" ties #' or just the "negative" ties #' @export to_unsigned <- function(object, @@ -266,7 +240,7 @@ to_unsigned.igraph <- function(object, } else object } -#' @describeIn to Returns an object with all vertex names removed +#' @describeIn reformat Returns an object with all vertex names removed #' @export to_unnamed <- function(object) UseMethod("to_unnamed") @@ -306,7 +280,7 @@ to_unnamed.data.frame <- function(object) { dplyr::as_tibble(out) } -#' @describeIn to Returns an object that has random vertex names added +#' @describeIn reformat Returns an object that has random vertex names added #' @export to_named <- function(object, names = NULL) UseMethod("to_named") @@ -360,7 +334,7 @@ to_named.matrix <- function(object, names = NULL) { object } -#' @describeIn to Returns an object that has all loops or self-ties removed +#' @describeIn reformat Returns an object that has all loops or self-ties removed #' @importFrom igraph simplify #' @export to_simplex <- function(object) UseMethod("to_simplex") @@ -382,7 +356,84 @@ to_simplex.matrix <- function(object) { out } -#' @describeIn to Results in a weighted one-mode object +#' @describeIn reformat Returns an object that has any type/mode attributes removed, +#' but otherwise includes all the same nodes and ties. +#' Note that this is not the same as `to_mode1()` or `to_mode2()`, +#' which return only some of the nodes and new ties established by coincidence. +#' @importFrom igraph delete_vertex_attr +#' @export +to_onemode <- function(object) UseMethod("to_onemode") + +#' @export +to_onemode.tbl_graph <- function(object) { + as_tidygraph(to_onemode(as_igraph(object))) +} + +#' @export +to_onemode.igraph <- function(object) { + if ("type" %in% igraph::vertex_attr_names(object)) object <- igraph::delete_vertex_attr(object, "type") + object +} + +#' @describeIn reformat Returns a network that is not divided into two mode types +#' but embeds two or more modes into a multimodal network structure. +#' @export +to_multilevel <- function(object) UseMethod("to_multilevel") + +#' @export +to_multilevel.tbl_graph <- function(object) { + as_tidygraph(to_multilevel(as_igraph(object))) +} + +#' @export +to_multilevel.igraph <- function(object) { + if(is_twomode(object)){ + igraph::V(object)$lvl <- ifelse(igraph::V(object)$type, 2, 1) + object <- igraph::delete_vertex_attr(object, "type") + } + object +} + +#' @export +to_multilevel.matrix <- function(object) { + top <- cbind(matrix(0, nrow(object), nrow(object)), object) + bottom <- cbind(t(object), matrix(0, ncol(object), ncol(object))) + out <- rbind(top, bottom) + colnames(out) <- rownames(out) + out +} + +# Transforming #### + +#' Tools for transforming networks, graphs, and matrices +#' +#' @description +#' These functions offer tools for transforming migraph-consistent objects +#' (matrices, igraph, tidygraph, or network objects). +#' Transforming means that the returned object may have different dimensions +#' than the original object. +#' @details +#' Since some modifications are easier to implement for some objects than others, +#' here are the currently implemented modifications: +#' +#' | to_ | edgelists | matrices |igraph |tidygraph |network | +#' | ------------- |:-----:|:-----:|:-----:|:-----:|:-----:| +#' | mode1 | | X | X | X | | +#' | mode2 | | X | X | X | | +#' | main_component | | | X | X | X | +#' | subgraph | X | X | X | X | X | +#' | ties | X | X | X | X | X | +#' | blocks | X | X | X | X | X | +#' +#' Note that `to_subgraph()` returns a 'tidygraph' object, +#' `to_ties()` returns an 'igraph' object, +#' and `to_blocks()` returns a 'matrix' object. +#' @name transform +#' @family manipulations +#' @inheritParams reformat +NULL + +#' @describeIn transform Results in a weighted one-mode object #' that retains the row nodes from a two-mode object, #' and weights the ties between them on the basis of #' their joint ties to nodes in the second mode (columns) @@ -409,7 +460,7 @@ to_mode1.tbl_graph <- function(object) { as_tidygraph(igraph::bipartite.projection(object)$proj1) } -#' @describeIn to Results in a weighted one-mode object +#' @describeIn transform Results in a weighted one-mode object #' that retains the column nodes from a two-mode object, #' and weights the ties between them on the basis of #' their joint ties to nodes in the first mode (rows). @@ -431,54 +482,41 @@ to_mode2.tbl_graph <- function(object) { as_tidygraph(igraph::bipartite.projection(object)$proj2) } -#' @describeIn to Returns an object that has any type/mode attributes removed, -#' but otherwise includes all the same nodes and ties. -#' Note that this is not the same as `to_mode1()` or `to_mode2()`, -#' which return only some of the nodes and new ties established by coincidence. -#' @importFrom igraph delete_vertex_attr -#' @export -to_onemode <- function(object) UseMethod("to_onemode") - +#' @describeIn transform Returns an object that includes only the main component +#' without any smaller components or isolates #' @export -to_onemode.tbl_graph <- function(object) { - as_tidygraph(to_onemode(as_igraph(object))) -} +to_main_component <- function(object) UseMethod("to_main_component") #' @export -to_onemode.igraph <- function(object) { - if ("type" %in% igraph::vertex_attr_names(object)) object <- igraph::delete_vertex_attr(object, "type") - object +to_main_component.tbl_graph <- function(object) { + as_tidygraph(to_main_component(as_igraph(object))) } -#' @describeIn to Returns a network that is not divided into two mode types -#' but embeds two or more modes into a multimodal network structure. -#' @export -to_multilevel <- function(object) UseMethod("to_multilevel") - #' @export -to_multilevel.tbl_graph <- function(object) { - as_tidygraph(to_multilevel(as_igraph(object))) +to_main_component.igraph <- function(object) { + comps <- igraph::components(object) + max.comp <- which.max(comps$csize) + igraph::delete.vertices(object, comps$membership != max.comp) } #' @export -to_multilevel.igraph <- function(object) { - if(is_twomode(object)){ - igraph::V(object)$lvl <- ifelse(igraph::V(object)$type, 2, 1) - object <- igraph::delete_vertex_attr(object, "type") - } - object +to_main_component.network <- function(object) { + network::delete.vertices(object, + which(!sna::component.largest(object, + result = "membership"))) } +#' @describeIn transform Returns a network subgraph filtered +#' on the basis of some node-related logical statement. +#' @param ... Arguments passed on to dplyr::filter +#' @importFrom dplyr filter #' @export -to_multilevel.matrix <- function(object) { - top <- cbind(matrix(0, nrow(object), nrow(object)), object) - bottom <- cbind(t(object), matrix(0, ncol(object), ncol(object))) - out <- rbind(top, bottom) - colnames(out) <- rownames(out) - out +to_subgraph <- function(object, ...){ + dplyr::filter(.data = as_tidygraph(object), ..., + .preserve = FALSE) } -#' @describeIn to Returns a matrix (named if possible) +#' @describeIn transform Returns a matrix (named if possible) #' where the edges are the nodes #' @importFrom igraph make_line_graph E #' @examples @@ -492,18 +530,7 @@ to_ties <- function(object){ out } - -#' @describeIn to Returns a network subgraph filtered -#' on the basis of some node-related logical statement. -#' @param ... Arguments passed on to dplyr::filter -#' @importFrom dplyr filter -#' @export -to_subgraph <- function(object, ...){ - dplyr::filter(.data = as_tidygraph(object), ..., - .preserve = FALSE) -} - -#' @describeIn to Returns a reduced graph from a given +#' @describeIn transform Returns a reduced graph from a given #' partition membership vector #' @param membership A vector of partition memberships #' @param FUN A function for summarising block content. @@ -543,3 +570,6 @@ to_blocks <- function(object, membership, FUN = mean){ } out } + + + diff --git a/R/mark_is.R b/R/mark_is.R index 7fe59a1e..280b487c 100644 --- a/R/mark_is.R +++ b/R/mark_is.R @@ -1,4 +1,4 @@ -#' Logical tests of network properties +#' Marking networks based on their properties #' #' These functions implement logical tests for various network #' properties. diff --git a/R/mark_nodes.R b/R/mark_nodes.R index 0efa9bdd..6d1a20fa 100644 --- a/R/mark_nodes.R +++ b/R/mark_nodes.R @@ -1,4 +1,4 @@ -#' Logical tests of nodal properties +#' Marking nodes based on their properties #' #' @description #' These functions return logical vectors the length of the diff --git a/R/mark_ties.R b/R/mark_ties.R index b902314b..8fb57db9 100644 --- a/R/mark_ties.R +++ b/R/mark_ties.R @@ -1,4 +1,4 @@ -#' Logical tests of tie properties +#' Marking ties based on their properties #' #' @description #' These functions return logical vectors the length of the ties diff --git a/README.Rmd b/README.Rmd index 20d484eb..47de5ff0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -65,7 +65,7 @@ All `{migraph}` measures and models work with data in base formats: as well as with objects constructed from the following packages: - [`{igraph}`](https://igraph.org/r/) -- [`{network}`](http://statnet.org) +- [`{network}`](https://statnet.org) - [`{tidygraph}`](https://tidygraph.data-imaginist.com/index.html) `{migraph}`'s `as_*()` functions can be used to translate objects diff --git a/README.md b/README.md index 7b2a4b9c..dbafd28b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ and models work with data in base formats: as well as with objects constructed from the following packages: - [`{igraph}`](https://igraph.org/r/) -- [`{network}`](http://statnet.org) +- [`{network}`](https://statnet.org) - [`{tidygraph}`](https://tidygraph.data-imaginist.com/index.html) `{migraph}`’s `as_*()` functions can be used to translate objects from @@ -83,10 +83,11 @@ properties, e.g.: `{migraph}`’s `to_*()` functions can be used on any class object to transform networks into networks with other properties, e.g.: -- `to_blocks()`, `to_main_component()`, `to_mode1()`, `to_mode2()`, - `to_multilevel()`, `to_named()`, `to_onemode()`, `to_redirected()`, - `to_simplex()`, `to_subgraph()`, `to_ties()`, `to_undirected()`, - `to_uniplex()`, `to_unnamed()`, `to_unsigned()`, `to_unweighted()` +- `to_blocks()`, `to_edges()`, `to_main_component()`, `to_mode1()`, + `to_mode2()`, `to_multilevel()`, `to_named()`, `to_onemode()`, + `to_redirected()`, `to_simplex()`, `to_subgraph()`, `to_ties()`, + `to_undirected()`, `to_uniplex()`, `to_unnamed()`, `to_unsigned()`, + `to_unweighted()` #### Making @@ -108,14 +109,15 @@ generative mechanisms, e.g.: multimodal and multiplex examples for demonstrating more advanced methods. -- `mpn_bristol`, `mpn_DE_1990`, `mpn_DE_2008`, `mpn_DemSxP`, - `mpn_elite_mex`, `mpn_elite_usa_advice`, `mpn_elite_usa_money`, - `mpn_IT_1990`, `mpn_IT_2008`, `mpn_OverSxP`, `mpn_RepSxP`, - `mpn_ryanair`, `mpn_UK_1990`, `mpn_UK_2008` +- `mpn_bristol`, `mpn_cow_igo`, `mpn_cow_trade`, `mpn_DE_1990`, + `mpn_DE_2008`, `mpn_DemSxP`, `mpn_elite_mex`, + `mpn_elite_usa_advice`, `mpn_elite_usa_money`, `mpn_IT_1990`, + `mpn_IT_2008`, `mpn_OverSxP`, `mpn_RepSxP`, `mpn_ryanair`, + `mpn_UK_1990`, `mpn_UK_2008` - `ison_adolescents`, `ison_algebra`, `ison_bb`, `ison_bm`, - `ison_brandes`, `ison_karateka`, `ison_marvel_relationships`, - `ison_marvel_teams`, `ison_mb`, `ison_mm`, `ison_networkers`, - `ison_southern_women` + `ison_brandes`, `ison_brandes2`, `ison_karateka`, + `ison_marvel_relationships`, `ison_marvel_teams`, `ison_mb`, + `ison_mm`, `ison_networkers`, `ison_southern_women` `{migraph}` can also import and export to Excel edgelists and nodelists, [UCINET](http://www.analytictech.com/archive/ucinet.htm) and diff --git a/cran-comments.md b/cran-comments.md index 047997cb..71420594 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -11,3 +11,4 @@ 0 errors | 0 warnings | 0 notes - Using "\donttest" to deal with examples in versions 0.10.x that took too long +- Fixed a URL redirect and a SSL certificate issue diff --git a/man/add.Rd b/man/add.Rd index 98f73516..c927da83 100644 --- a/man/add.Rd +++ b/man/add.Rd @@ -65,6 +65,7 @@ autographr(to_uniplex(both, "orig")) Other manipulations: \code{\link{as}()}, \code{\link{grab}}, -\code{\link{to}} +\code{\link{reformat}}, +\code{\link{transform}()} } \concept{manipulations} diff --git a/man/as.Rd b/man/as.Rd index 374b03ee..fba373f6 100644 --- a/man/as.Rd +++ b/man/as.Rd @@ -97,6 +97,7 @@ as_network(test) Other manipulations: \code{\link{add}}, \code{\link{grab}}, -\code{\link{to}} +\code{\link{reformat}}, +\code{\link{transform}()} } \concept{manipulations} diff --git a/man/grab.Rd b/man/grab.Rd index 963038d3..38b25aa3 100644 --- a/man/grab.Rd +++ b/man/grab.Rd @@ -103,6 +103,7 @@ graph_tie_attributes(mpn_elite_mex) Other manipulations: \code{\link{add}}, \code{\link{as}()}, -\code{\link{to}} +\code{\link{reformat}}, +\code{\link{transform}()} } \concept{manipulations} diff --git a/man/is.Rd b/man/is.Rd index f33df0cc..a4eaf342 100644 --- a/man/is.Rd +++ b/man/is.Rd @@ -15,7 +15,7 @@ \alias{is_multiplex} \alias{is_uniplex} \alias{is_acyclic} -\title{Logical tests of network properties} +\title{Marking networks based on their properties} \usage{ is_migraph(object) diff --git a/man/mark_nodes.Rd b/man/mark_nodes.Rd index a79dae00..f2ca8548 100644 --- a/man/mark_nodes.Rd +++ b/man/mark_nodes.Rd @@ -6,7 +6,7 @@ \alias{node_is_isolate} \alias{node_is_max} \alias{node_is_min} -\title{Logical tests of nodal properties} +\title{Marking nodes based on their properties} \usage{ node_is_cutpoint(object) diff --git a/man/mark_ties.Rd b/man/mark_ties.Rd index 4b2a3717..9eece6c3 100644 --- a/man/mark_ties.Rd +++ b/man/mark_ties.Rd @@ -8,7 +8,7 @@ \alias{tie_is_bridge} \alias{tie_is_max} \alias{tie_is_min} -\title{Logical tests of tie properties} +\title{Marking ties based on their properties} \usage{ tie_is_multiple(object) diff --git a/man/mpn_cow.Rd b/man/mpn_cow.Rd index 403b36a1..11929a6b 100644 --- a/man/mpn_cow.Rd +++ b/man/mpn_cow.Rd @@ -60,7 +60,7 @@ The Correlates of War Project. 2012. \href{https://correlatesofwar.org/data-sets/bilateral-trade}{\emph{Trade}}. Barbieri, Katherine and Omar Keshk. 2012. -\href{https://correlatesofwar.org.}{\emph{Correlates of War Project Trade Data Set Codebook, Version 3.0.}}. +Correlates of War Project Trade Data Set Codebook, Version 3.0. The Correlates of War Project. 2019. \href{https://correlatesofwar.org/data-sets/IGOs}{\emph{Intergovernmental Organization v3}}. diff --git a/man/to.Rd b/man/reformat.Rd similarity index 68% rename from man/to.Rd rename to man/reformat.Rd index e7928f55..4b72806d 100644 --- a/man/to.Rd +++ b/man/reformat.Rd @@ -1,9 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/manip_to.R -\name{to} -\alias{to} +\name{reformat} +\alias{reformat} \alias{to_uniplex} -\alias{to_main_component} \alias{to_undirected} \alias{to_redirected} \alias{to_unweighted} @@ -11,19 +10,12 @@ \alias{to_unnamed} \alias{to_named} \alias{to_simplex} -\alias{to_mode1} -\alias{to_mode2} \alias{to_onemode} \alias{to_multilevel} -\alias{to_ties} -\alias{to_subgraph} -\alias{to_blocks} \title{Tools for reformatting networks, graphs, and matrices} \usage{ to_uniplex(object, edge) -to_main_component(object) - to_undirected(object) to_redirected(object) @@ -38,19 +30,9 @@ to_named(object, names = NULL) to_simplex(object) -to_mode1(object) - -to_mode2(object) - to_onemode(object) to_multilevel(object) - -to_ties(object) - -to_subgraph(object, ...) - -to_blocks(object, membership, FUN = mean) } \arguments{ \item{object}{An object of a migraph-consistent class: @@ -70,15 +52,6 @@ to_blocks(object, membership, FUN = mean) the "positive" or "negative" ties.} \item{names}{Character vector of the node names. NULL by default.} - -\item{...}{Arguments passed on to dplyr::filter} - -\item{membership}{A vector of partition memberships} - -\item{FUN}{A function for summarising block content. -By default \code{mean}. -Other recommended options include \code{median}, \code{sum}, -\code{min} or \code{max}.} } \value{ All \code{to_} functions return an object of the same class as that provided. @@ -87,13 +60,13 @@ and passing it a network object will return a network object, with certain modifications as outlined for each function. } \description{ -These functions offer tools for transforming certain properties -of migraph-consistent objects +These functions offer tools for reformatting migraph-consistent objects (matrices, igraph, tidygraph, or network objects). Unlike the \verb{as_*()} group of functions, these functions always return the same object type as they are given, only transforming these objects' properties. - +} +\details{ Since some modifications are easier to implement for some objects than others, here are the currently implemented modifications:\tabular{lccccc}{ to_ \tab edgelists \tab matrices \tab igraph \tab tidygraph \tab network \cr @@ -105,20 +78,14 @@ here are the currently implemented modifications:\tabular{lccccc}{ unnamed \tab X \tab X \tab X \tab X \tab X \cr named \tab X \tab X \tab X \tab X \tab X \cr simplex \tab \tab X \tab X \tab X \tab \cr - main_component \tab \tab \tab X \tab X \tab X \cr onemode \tab \tab \tab X \tab X \tab \cr multilevel \tab \tab X \tab X \tab X \tab \cr - mode1 \tab \tab X \tab X \tab X \tab \cr - mode2 \tab \tab X \tab X \tab X \tab \cr } } \section{Functions}{ \itemize{ \item \code{to_uniplex}: Returns an object that includes only a single type of tie -\item \code{to_main_component}: Returns an object that includes only the main component -without any smaller components or isolates - \item \code{to_undirected}: Returns an object that has any edge direction removed, so that any pair of nodes with at least one directed edge will be connected by an undirected edge in the new network. @@ -139,16 +106,6 @@ or just the "negative" ties \item \code{to_simplex}: Returns an object that has all loops or self-ties removed -\item \code{to_mode1}: Results in a weighted one-mode object -that retains the row nodes from a two-mode object, -and weights the ties between them on the basis of -their joint ties to nodes in the second mode (columns) - -\item \code{to_mode2}: Results in a weighted one-mode object -that retains the column nodes from a two-mode object, -and weights the ties between them on the basis of -their joint ties to nodes in the first mode (rows). - \item \code{to_onemode}: Returns an object that has any type/mode attributes removed, but otherwise includes all the same nodes and ties. Note that this is not the same as \code{to_mode1()} or \code{to_mode2()}, @@ -156,15 +113,6 @@ which return only some of the nodes and new ties established by coincidence. \item \code{to_multilevel}: Returns a network that is not divided into two mode types but embeds two or more modes into a multimodal network structure. - -\item \code{to_ties}: Returns a matrix (named if possible) -where the edges are the nodes - -\item \code{to_subgraph}: Returns a network subgraph filtered -on the basis of some node-related logical statement. - -\item \code{to_blocks}: Returns a reduced graph from a given -partition membership vector }} \examples{ @@ -177,19 +125,12 @@ a <- to_undirected(a) autographr(a) a <- to_unweighted(a) autographr(a) -autographr(ison_southern_women) / -(autographr(to_mode1(ison_southern_women)) | -autographr(to_mode2(ison_southern_women))) -autographr(ison_adolescents) + -autographr(to_ties(ison_adolescents)) -(adolblock <- to_blocks(ison_adolescents, - node_regular_equivalence(ison_adolescents, k = 3))) -autographr(adolblock) } \seealso{ Other manipulations: \code{\link{add}}, \code{\link{as}()}, -\code{\link{grab}} +\code{\link{grab}}, +\code{\link{transform}()} } \concept{manipulations} diff --git a/man/transform.Rd b/man/transform.Rd new file mode 100644 index 00000000..1252f693 --- /dev/null +++ b/man/transform.Rd @@ -0,0 +1,109 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/manip_to.R +\name{transform} +\alias{transform} +\alias{to_mode1} +\alias{to_mode2} +\alias{to_main_component} +\alias{to_subgraph} +\alias{to_ties} +\alias{to_blocks} +\title{Tools for transforming networks, graphs, and matrices} +\usage{ +to_mode1(object) + +to_mode2(object) + +to_main_component(object) + +to_subgraph(object, ...) + +to_ties(object) + +to_blocks(object, membership, FUN = mean) +} +\arguments{ +\item{object}{An object of a migraph-consistent class: +\itemize{ +\item matrix (adjacency or incidence) from \code{{base}} R +\item edgelist, a data frame from \code{{base}} R or tibble from \code{{tibble}} +\item igraph, from the \code{{igraph}} package +\item network, from the \code{{network}} package +\item tbl_graph, from the \code{{tidygraph}} package +}} + +\item{...}{Arguments passed on to dplyr::filter} + +\item{membership}{A vector of partition memberships} + +\item{FUN}{A function for summarising block content. +By default \code{mean}. +Other recommended options include \code{median}, \code{sum}, +\code{min} or \code{max}.} +} +\description{ +These functions offer tools for transforming migraph-consistent objects +(matrices, igraph, tidygraph, or network objects). +Transforming means that the returned object may have different dimensions +than the original object. +} +\details{ +Since some modifications are easier to implement for some objects than others, +here are the currently implemented modifications:\tabular{lccccc}{ + to_ \tab edgelists \tab matrices \tab igraph \tab tidygraph \tab network \cr + mode1 \tab \tab X \tab X \tab X \tab \cr + mode2 \tab \tab X \tab X \tab X \tab \cr + main_component \tab \tab \tab X \tab X \tab X \cr + subgraph \tab X \tab X \tab X \tab X \tab X \cr + ties \tab X \tab X \tab X \tab X \tab X \cr + blocks \tab X \tab X \tab X \tab X \tab X \cr +} + + +Note that \code{to_subgraph()} returns a 'tidygraph' object, +\code{to_ties()} returns an 'igraph' object, +and \code{to_blocks()} returns a 'matrix' object. +} +\section{Functions}{ +\itemize{ +\item \code{to_mode1}: Results in a weighted one-mode object +that retains the row nodes from a two-mode object, +and weights the ties between them on the basis of +their joint ties to nodes in the second mode (columns) + +\item \code{to_mode2}: Results in a weighted one-mode object +that retains the column nodes from a two-mode object, +and weights the ties between them on the basis of +their joint ties to nodes in the first mode (rows). + +\item \code{to_main_component}: Returns an object that includes only the main component +without any smaller components or isolates + +\item \code{to_subgraph}: Returns a network subgraph filtered +on the basis of some node-related logical statement. + +\item \code{to_ties}: Returns a matrix (named if possible) +where the edges are the nodes + +\item \code{to_blocks}: Returns a reduced graph from a given +partition membership vector +}} + +\examples{ +autographr(ison_southern_women) / +(autographr(to_mode1(ison_southern_women)) | +autographr(to_mode2(ison_southern_women))) +autographr(ison_adolescents) + +autographr(to_ties(ison_adolescents)) +(adolblock <- to_blocks(ison_adolescents, + node_regular_equivalence(ison_adolescents, k = 3))) +autographr(adolblock) +} +\seealso{ +Other manipulations: +\code{\link{add}}, +\code{\link{as}()}, +\code{\link{grab}}, +\code{\link{reformat}} +} +\concept{manipulations}