Accumulate Connections from a Multidimensional Array and Context Model
accumulate.RdThis function processes a context model and a multidimensional array of window/weight parameters to compute connection counts for each unit of analysis. It applies the context model to the array, using sender, receiver, and mode columns (as defined in the array attributes), and accumulates co-occurrence or adjacency matrices for each unit. The result is a set of connection counts and row-level connection matrices, suitable for network analysis (e.g., ENA/ONA).
Usage
accumulate(
context_model,
codes,
tensor = context_tensor(context_model$model$raw.input),
time_column = NULL,
ordered = FALSE,
binary = TRUE,
weight_by = NULL,
misses = TRUE,
self_connections = FALSE
)Arguments
- context_model
A context model object (as produced by `tma::contexts`) containing contexts for each unit of analysis.
- codes
Character vector of code names to use for constructing adjacency matrices.
- tensor
A multidimensional array (see `context_tensor`) containing window and weight values for each sender/receiver/mode combination. Defaults to an array generated from the context model's raw input.
- time_column
Character string giving the name of the time column in the context model. If NULL, uses the default context column ID.
- ordered
Logical; if TRUE (default), computes ordered adjacency matrices (ONA); if FALSE, computes unordered (ENA-style) matrices.
- binary
Logical; if TRUE (default), binarizes each line's connection counts before they are summed per unit (unordered only; ordered counts are always summed raw). Ignored when `weight_by` is given.
- weight_by
Weight model applied to each line's connection counts before they are summed into the unit network (= rENA's `weight.by`): `"binary"` (unordered: each positive count becomes 1; ordered: raw directed counts), `"product"` (the raw, non-binarized counts), `"sqrt"`, or `"log1p"` (alias `"log"`). For unordered networks the weight is applied after each line is folded to the upper triangle; for ordered networks, to each directed cell. Defaults to `"binary"` when `binary = TRUE`, otherwise `"product"`. `model$row.connection.counts` always holds the raw, unweighted line counts.
- misses
Logical; if TRUE, also accumulate missed co-occurrences: for each response line, the (window-weighted) ground count of code i when code j is absent from the response, with no response self-term. Misses follow the connection counts through the same steps: ordered models keep the directed layout (ground i -> response j); unordered models fold each line to the upper triangle (i & j = i -> j + j -> i, self-misses dropped), and `weight_by` is applied per line. Defaults to TRUE; set FALSE to skip them (less memory for many codes or long data).
- self_connections
Logical, default FALSE. Unordered networks only: also include each code's self-connection (ground i x response i, weighted per line like the other columns) as a column of `connection.counts` (and of `miss.counts`, the self-misses), so the model's line weights, rotation and nodes include them. Columns then run A & A, A & B, B & B, A & C, ... (the upper triangle with the diagonal; see the adjacency key). Ordered networks always include the diagonal, so it has no effect there. `self.connection.counts` is kept separately either way.
Value
The input `context_model` with additional fields:
- connection.counts
A data.table of accumulated connection counts for each unit.
- model$row.connection.counts
A data.table of row-level connection matrices for each unit.
- self.connection.counts
A data.table of each unit's self-connections, one column per code: each line's ground count of the code times its response count (the ordered network's diagonal, which unordered networks fold away), weighted per line by `weight_by` and summed per unit. Kept for ordered and unordered models; not used in the model.
- model$row.self.connection.counts
A data.table of raw, unweighted per-line self-connections.
- miss.counts
With `misses = TRUE`: a data.table of accumulated missed co-occurrences for each unit.
- self.miss.counts, model$row.self.miss.counts
With `misses = TRUE`: self-misses (the code in the ground, absent from the response), per unit and per line, as for self-connections.
- model$row.miss.counts
With `misses = TRUE`: a data.table of raw, unweighted row-level missed co-occurrences.
- meta.data
A data.table of metadata columns for each unit.
The class of the returned object is updated to reflect the type of accumulation (ordered or unordered).