| wtna | R Documentation |
Computes networks from one-hot (binary indicator) data using temporal windowing. Supports transition (directed), co-occurrence (undirected), or both network types.
wtna(
data,
method = c("transition", "cooccurrence", "both"),
type = c("frequency", "relative"),
codes = NULL,
window_size = 1L,
mode = c("non-overlapping", "overlapping"),
actor = NULL
)
data |
Data frame with one-hot encoded columns (0/1 binary). |
method |
Character. Network type: |
type |
Character. Output type: |
codes |
Character vector or NULL. Names of the one-hot columns to use. If NULL, auto-detects binary columns. Default: NULL. |
window_size |
Integer. Number of consecutive rows to aggregate per window. Default: 1 (no windowing). |
mode |
Character. Window mode: |
actor |
Character or NULL. Name of the actor/ID column for per-group computation. If NULL, treats all rows as one group. Default: NULL. |
Transitions: Uses crossprod(X[-n,], X[-1,]) to count
how often state i is active at time t AND state j at time t+1.
Co-occurrence: Uses crossprod(X) to count states that are
simultaneously active in the same row.
Windowing: For window_size > 1, rows are aggregated into
windows before computing networks. Non-overlapping windows are fixed,
separate blocks; overlapping windows roll forward one row at a time.
Within each window, any active indicator (1) in any row makes that state
active for the window.
Per-actor: When actor is specified, networks are computed
per group and summed.
For method = "transition" or "cooccurrence": a
netobject (see build_network).
For method = "both": a wtna_mixed object with elements
$transition and $cooccurrence, each a netobject.
build_network, prepare_onehot
oh <- matrix(c(1,0,0, 0,1,0, 0,0,1, 1,0,0), nrow = 4, byrow = TRUE,
dimnames = list(NULL, c("A","B","C")))
w <- wtna(oh)
# Simple one-hot data
df <- data.frame(
A = c(1, 0, 1, 0, 1),
B = c(0, 1, 0, 1, 0),
C = c(0, 0, 1, 0, 0)
)
# Transition network
net <- wtna(df)
print(net)
# Both networks
nets <- wtna(df, method = "both")
print(nets$transition)
print(nets$cooccurrence)
# With windowing
net <- wtna(df, window_size = 2, mode = "non-overlapping")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.