| Title: | Create a Language Network from Neighborhoods of Words |
| Version: | 1.0.0 |
| Description: | Input a list of words and/or their phonological transcriptions and this package creates a language network based on their neighborhood structure. First, the phonological/orthographic neighbors for each item in the list are identified based on various definitions of a neighbor (e.g., edit-distance (substitution, deletion, or addition), substitution-only; distance size (1-edit or more); based on single characters or segments indicated by separators) and summarizes this information in an 'igraph' network object for subsequent analyses. For more details see Luce & Pisoni (1998) <doi:10.1097/00003446-199802000-00001> and Vitevitch (2008) <doi:10.1044/1092-4388(2008/030)>. Helper functions for extracting network metrics, neighbors, and other information from the language network are provided. This package is intended for psycholinguists interested in modeling language networks and word neighborhoods in various languages. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Imports: | igraph, Rcpp, stringdist |
| Depends: | R (≥ 4.1.0) |
| LazyData: | true |
| LinkingTo: | Rcpp |
| NeedsCompilation: | yes |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| VignetteBuilder: | knitr |
| URL: | https://csqsiew.github.io/hood2net/ |
| Packaged: | 2026-07-09 07:24:39 UTC; cynthia |
| Author: | Cynthia Siew [aut, cre, cph] |
| Maintainer: | Cynthia Siew <cynthia.siew@mailfence.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-17 14:10:07 UTC |
Returns the neighborhood clustering (i.e., local transitivity or local clustering coefficient) for all or a subset of nodes in the language network.
Description
Returns the neighborhood clustering (i.e., local transitivity or local clustering coefficient) for all or a subset of nodes in the language network.
Usage
get_neighbor_clustering(network, node_name = NULL)
Arguments
network |
An |
node_name |
A vector containing node names to obtain values for. Node names must be found in |
Value
A named numeric vector.
Examples
# Use the demo data for executing examples
test <- make_network(sample1)
get_neighbor_clustering(network = test) # all nodes
get_neighbor_clustering(network = test, node_name = "cat") # for 1 node
Returns the mean of a neighborhood's attribute for all or a subset of nodes in the language network.
Description
Returns the mean of a neighborhood's attribute for all or a subset of nodes in the language network.
Usage
get_neighbor_mean(network, node_name = NULL, attribute)
Arguments
network |
An |
node_name |
A vector containing node names to obtain values for. Node names must be found in |
attribute |
A string stating the node attribute to obtain the mean values for. The attribute must be found in |
Value
A named numeric vector.
Examples
# Use the demo data for executing examples
test <- make_network(sample1)
get_neighbor_mean(network = test, attribute = "length") # all nodes
get_neighbor_mean(network = test, node_name = "cat", attribute = "length") # for 1 node
Returns the neighborhood size (i.e., degree) for all or a subset of nodes in the language network.
Description
Returns the neighborhood size (i.e., degree) for all or a subset of nodes in the language network.
Usage
get_neighbor_size(network, node_name = NULL)
Arguments
network |
An |
node_name |
A vector containing node names to obtain values for. Node names must be found in |
Value
A named numeric vector.
Examples
# Use the demo data for executing examples
test <- make_network(sample1)
get_neighbor_size(network = test) # all nodes
get_neighbor_size(network = test, node_name = "cat") # for 1 node
Returns a summary of global network characteristics of the language network.
Description
Returns a summary of global network characteristics of the language network.
Usage
get_network_info(network)
Arguments
network |
An |
Value
A named vector of global network metrics. For more information about these metrics, refer to the package vignette.
Examples
#' # Use the demo data for executing examples
test <- make_network(sample1)
get_network_info(network = test)
To check if edit_size is a whole number or not. Internal function used by make_network() and make_network_sep().
Description
To check if edit_size is a whole number or not. Internal function used by make_network() and make_network_sep().
Usage
is.wholenumber(x, tol = .Machine$double.eps^0.5)
Value
TRUE or FALSE.
Create a language network from a list of items. This version takes each single character as an individual segment when specifying neighbors.
Description
Create a language network from a list of items. This version takes each single character as an individual segment when specifying neighbors.
Usage
make_network(
item_df,
neighbor_type = "lv",
network_name = "test",
edit_size = 1
)
Arguments
item_df |
A data frame containing the list of items and other node-level attributes that are appended to the network (optional). Must minimally contain one character class column labeled "item". |
neighbor_type |
A string indicating neighbor type: "lv" (default) is 1-edit neighbors by substitution, deletion, or addition; "osa" is 1-edit neighbors by substitution, deletion, addition, or transposition; "hamming" is 1-edit neighbors by substitution only. |
network_name |
A string, the name of the network. Becomes a network-level attribute. |
edit_size |
An integer that indicates the maximum edit distance allowed between word pairs that are connected in the network. Default value is 1. |
Value
An igraph network object.
Examples
# Use the demo data for executing examples
g <- make_network(item_df = sample1) # substitution, addition, deletion
summary(g)
g_sub <- make_network(item_df = sample1, neighbor_type = 'hamming') # substitution only
summary(g_sub)
Create a language network from a list of items. This version segments items based on a specified separator when specifying neighbors.
Description
Create a language network from a list of items. This version segments items based on a specified separator when specifying neighbors.
Usage
make_network_sep(
item_df,
separator = ".",
neighbor_type = "lv",
network_name = "test",
edit_size = 1
)
Arguments
item_df |
A data frame containing the list of items and other node-level attributes that are appended to the network (optional). Must minimally contain one character class column labeled "item". |
separator |
A single character. The default is '.'. This is used to segment items into sub-units to base the neighborhood computation on. |
neighbor_type |
A string indicating neighbor type: "lv" (default) is 1-edit neighbors by substitution, deletion, or addition; "hamming" is 1-edit neighbors by substitution only. |
network_name |
A string, the name of the network. Becomes a network-level attribute. |
edit_size |
An integer that indicates the maximum edit distance allowed between word pairs that are connected in the network. Default value is 1. |
Value
An igraph network object.
Examples
#' # Use the demo data for executing examples
g_sep <- make_network_sep(item_df = sample2) # substitution, addition, deletion
summary(g_sep)
# substitution only
g_sep_sub <- make_network_sep(item_df = sample2, neighbor_type = 'hamming')
summary(g_sep_sub)
sample1 data
Description
for testing make_network.R
Usage
sample1
Format
sample1
A data frame with 9 rows and 2 columns:
- item
word transcriptions
- length
number of letters, node attribute
sample2 data
Description
for testing make_network_sep.R with period separator, single characters
Usage
sample2
Format
sample2
A data frame with 9 rows and 2 columns:
- item
word transcriptions
- length
number of letters, node attribute
sample3 data
Description
for testing make_network_sep.R with space separator, multiple characters
Usage
sample3
Format
sample3
A data frame with 8 rows and 3 columns:
- item
word transcriptions
- ortho
node label
- length
number of "chunks", node attribute
Helper function to compute edit distance between two strings using the vecLeven_C function, which is written in C to optimize performance. This is the substitution, deletion, or addition version.
Description
Helper function to compute edit distance between two strings using the vecLeven_C function, which is written in C to optimize performance. This is the substitution, deletion, or addition version.
Usage
sepLeven_C(s, t, sep = ".")
Arguments
s |
A string. |
t |
A character vector. |
sep |
A character separator by which |
Value
A numeric element indicating the edit distance of the target string to all other strings.
Helper function to compute edit distance between two strings using the vecSub_C function, which is written in C to optimize performance. This is the substitution only version.
Description
Helper function to compute edit distance between two strings using the vecSub_C function, which is written in C to optimize performance. This is the substitution only version.
Usage
sepSub_C(s, t, sep = ".")
Arguments
s |
A string. |
t |
A character vector. |
sep |
A character separator by which |
Value
A numeric element indicating the edit distance of the target string to all other strings.