| Title: | Heterogeneous Transition Network Analysis |
|---|---|
| Description: | Implements the Heterogeneous Transition Network Analysis (HTNA) method described by López-Pernas et al. (2026) <doi:10.1002/jcal.70285>. The method is an extension of transition network analysis (TNA) where actions or events belong to two or more distinct actor types (e.g. Human and AI),preserving the actor type partition on the resulting network. Provides a thin, focused API on top of the 'Nestimate' estimation engine and the 'cograph' rendering engine, so downstream bootstrap, permutation, reliability, centrality, and plotting functions treat each actor's codes as a distinct node group. |
| Authors: | Sonsoles López-Pernas [aut, cre, cph], Kamila Misiejuk [aut, cph], Mohammed Saqr [aut, cph] |
| Maintainer: | Sonsoles López-Pernas <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-07 11:03:49 UTC |
| Source: | https://github.com/sonsoleslp/htna |
The AI-only slice of human_ai, in a long-format data
frame ready to feed the named-list form of build_htna().
Codes have already been collapsed into the simplified AI alphabet;
see human_ai for the remapping rules.
ai_simplifiedai_simplified
A data frame with 8551 rows and 10 columns. Schema matches
human_ai minus the phase column; every value
in actor_type is "AI".
Derived from Nestimate::ai_long; see
data-raw/human_ai.R for the build script.
human_ai, human_simplified,
human_ai_codebook.
data(human_simplified, ai_simplified) net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) plot_htna(net)data(human_simplified, ai_simplified) net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) plot_htna(net)
htna-named alias of Nestimate::association_rules(). Mines
frequent itemsets and association rules over a transition-count
matrix under support / confidence / lift thresholds.
association_rules_htna( x, min_support = 0.1, min_confidence = 0.5, min_lift = 1, max_length = 5L )association_rules_htna( x, min_support = 0.1, min_confidence = 0.5, min_lift = 1, max_length = 5L )
x |
Input data. Accepts:
|
min_support |
Numeric. Minimum support threshold. Default: 0.1. |
min_confidence |
Numeric. Minimum confidence threshold. Default: 0.5. |
min_lift |
Numeric. Minimum lift threshold. Default: 1.0. |
max_length |
Integer. Maximum itemset size. Default: 5. |
Foundation function in the htna-aware exploratory family. Works on
transition-count input produced by frequencies_htna() or
Nestimate::build_network(); the rules carry over to htna networks
since the underlying transition counts are the same.
Suffixed _htna to avoid clashing with
Nestimate::association_rules() when both packages are loaded.
A list with the discovered rules and frequent itemsets. See
Nestimate::association_rules() for details.
frequencies_htna(), mosaic_plot_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") association_rules_htna(net, max_length = 3L)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") association_rules_htna(net, max_length = 3L)
S3 generic dispatched on the class of x. Provided so bootstrap(net)
works directly on an htna network (see bootstrap_htna()).
bootstrap(x, ...)bootstrap(x, ...)
x |
An object to bootstrap. |
... |
Arguments forwarded to the method. |
An object whose structure is method-defined.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") bootstrap(net, iter = 50)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") bootstrap(net, iter = 50)
Thin wrapper around Nestimate::bootstrap_network() that runs the standard
state-level edge bootstrap on an htna network and tags the result so it is
identifiable as an htna bootstrap. The bootstrap inference itself is
Nestimate's: per-edge mean, sd, p-value, significance, and confidence /
credibility intervals across iter resamples. State-level granularity is
the correct level for edge-stability analysis - aggregating up to actor
pairs would smear over real edge-by-edge differences.
bootstrap_htna(x, ...) ## S3 method for class 'htna' bootstrap(x, ...)bootstrap_htna(x, ...) ## S3 method for class 'htna' bootstrap(x, ...)
x |
[ |
... |
Arguments forwarded to |
What this wrapper adds is identity and downstream class continuity:
The returned object has class "htna_bootstrap" ahead of
"net_bootstrap", so inherits(boot, "htna_bootstrap") works.
The actor partition ($nodes$groups, $node_groups) is restored on
boot$model from the input network so cograph's auto-detect still
recognizes the heterogeneous schema downstream.
boot$model is re-tagged with "htna" at the front of its class chain
so the chain is c("htna", "netobject", "cograph_network") - identical
to what build_htna() returns.
An object of class c("htna_bootstrap", "net_bootstrap"). All
slots produced by Nestimate::bootstrap_network() are preserved
verbatim ($summary, $mean, $sd, $p_values, $significant,
$ci_lower/$ci_upper, $cr_lower/$cr_upper, $model, $original,
etc.).
Nestimate::bootstrap_network() for the underlying algorithm
and slot documentation. build_htna() for constructing the input.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") boot <- bootstrap_htna(net, iter = 50) inherits(boot, "htna_bootstrap") # TRUE inherits(boot$model, "htna") # TRUE head(boot$summary) # state-level edge stabilitydata(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") boot <- bootstrap_htna(net, iter = 50) inherits(boot, "htna_bootstrap") # TRUE inherits(boot$model, "htna") # TRUE head(boot$summary) # state-level edge stability
Builds a transition network over a combined sequence of two or more actor groups (e.g. Human and AI) and preserves the actor partition on the result so downstream plotting and analysis can treat each actor's codes as a distinct node group.
build_htna( data, actor_type = NULL, actor = NULL, node_groups = NULL, action = "code", session = "session_id", order = "order_in_session", method = "relative", group = NULL, disambiguate = FALSE, ... )build_htna( data, actor_type = NULL, actor = NULL, node_groups = NULL, action = "code", session = "session_id", order = "order_in_session", method = "relative", group = NULL, disambiguate = FALSE, ... )
data |
Either:
|
actor_type |
Character. Name of the column tagging each row's
actor type / group (e.g. |
actor |
Character. Name of an optional column identifying the
individual actor that performed each event (e.g. a learner / user id).
Forwarded to |
node_groups |
Node-to-actor-type lookup, in either of two forms:
Use |
action |
Character. Name of the action/code column. Default
|
session |
Character. Name of the session column. Default
|
order |
Character. Name of the within-session order column. Default
|
method |
Character. Transition method passed to
|
group |
Character. Optional name of a column in |
disambiguate |
Logical. If |
... |
Additional arguments forwarded to
|
A netobject with the actor partition stored in cograph's
canonical schema, so cograph::plot_htna(net) auto-detects the
groups with no further arguments:
$nodes$groups - actor label per node (the column name
cograph::plot_htna auto-detects).
$node_groups - data frame with columns node and
group (canonical cograph_network schema, also
readable by cograph::get_groups, cluster_summary, and
the print method for cograph_network).
All other slots are exactly as returned by
build_network.
build_network,
build_tna,
plot_htna
data(human_ai, human_simplified, ai_simplified) # Form 1: named list of per-actor frames net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) head(net$node_groups) # Form 2: single combined frame with a row-level actor-type tag net <- build_htna(human_ai, actor_type = "actor_type")data(human_ai, human_simplified, ai_simplified) # Form 1: named list of per-actor frames net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) head(net$node_groups) # Form 2: single combined frame with a row-level actor-type tag net <- build_htna(human_ai, actor_type = "actor_type")
htna-named alias of Nestimate::casedrop_reliability(). Computes
the CS-coefficient for the edge-weight vector of a network: the
maximum proportion of cases (rows of x$data) that can be dropped
while the flattened edge-weight vector of the re-estimated network
still correlates with the original above threshold in at least
certainty of iterations.
casedrop_reliability_htna( x, iter = 1000L, drop_prop = seq(0.1, 0.9, by = 0.1), threshold = 0.7, certainty = 0.95, method = c("spearman", "pearson", "kendall"), include_diag = FALSE, seed = NULL )casedrop_reliability_htna( x, iter = 1000L, drop_prop = seq(0.1, 0.9, by = 0.1), threshold = 0.7, certainty = 0.95, method = c("spearman", "pearson", "kendall"), include_diag = FALSE, seed = NULL )
x |
A |
iter |
Integer. Iterations per drop proportion. Default |
drop_prop |
Drop proportion at which to report the four metrics
(mean +/- sd per network). Must be one of the drop proportions the
object was built with. Defaults to the object's median grid value
(the stored grid is used, not an assumed |
threshold |
Numeric in |
certainty |
Numeric in |
method |
Correlation method: |
include_diag |
Logical. Include diagonal (self-loop) edges in the
edge vector. Default |
seed |
Optional integer for reproducibility. |
Works on htna networks and grouped htna networks directly.
Suffixed _htna to avoid clashing with
Nestimate::casedrop_reliability() when both packages are loaded.
An object of class net_casedrop_reliability (single
network) or net_casedrop_reliability_group (grouped htna). See
Nestimate::casedrop_reliability() for the full component list
and the corresponding plot() method.
reliability_htna(), centrality_stability_htna(),
bootstrap_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") casedrop_reliability_htna(net, iter = 20, seed = 1)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") casedrop_reliability_htna(net, iter = 20, seed = 1)
Computes a fixed panel of centrality measures via cograph::cograph and
returns them as a tidy data frame: one row per node, one column per
measure (plus node, an actor column when the htna partition is
set, and a group column when the input is an htna_group).
centralities_htna( x, measures = c("OutStrength", "InStrength", "ClosenessIn", "ClosenessOut", "Closeness", "Betweenness", "BetweennessRSP", "Diffusion", "Clustering"), ... )centralities_htna( x, measures = c("OutStrength", "InStrength", "ClosenessIn", "ClosenessOut", "Closeness", "Betweenness", "BetweennessRSP", "Diffusion", "Clustering"), ... )
x |
An htna network from |
measures |
Character vector of measure names. Defaults to all nine. |
... |
Forwarded to the underlying cograph centrality functions. |
The measures are: OutStrength, InStrength, ClosenessIn,
ClosenessOut, Closeness, Betweenness, BetweennessRSP,
Diffusion, Clustering. Path-based measures (closeness and
betweenness variants) are computed with invert_weights = TRUE,
since in transition networks larger weight = stronger link =
shorter distance. Strength and the closed-form measures
(Diffusion, Clustering) use raw weights.
Mapping from measure name to cograph implementation:
OutStrength → cograph::centrality_outstrength()
InStrength → cograph::centrality_instrength()
ClosenessIn → cograph::centrality_incloseness() (inverted)
ClosenessOut → cograph::centrality_outcloseness() (inverted)
Closeness → cograph::centrality_closeness() (inverted)
Betweenness → cograph::centrality_betweenness() (inverted)
BetweennessRSP → cograph::centrality_current_flow_betweenness()
Diffusion → cograph::centrality_diffusion()
Clustering → cograph::centrality_transitivity()
A data frame with one row per node.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") centralities_htna(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") centralities_htna(net)
Thin wrapper around Nestimate::centrality_stability() that
validates the input is an htna network (or htna_group), forwards
the call, and tags the result with an htna_stability class so
callers can dispatch on the htna form.
centrality_stability_htna( x, measures = c("InStrength", "OutStrength", "Betweenness"), iter = 1000L, drop_prop = seq(0.1, 0.9, by = 0.1), threshold = 0.7, certainty = 0.95, method = "pearson", centrality_fn = NULL, loops = FALSE, seed = NULL )centrality_stability_htna( x, measures = c("InStrength", "OutStrength", "Betweenness"), iter = 1000L, drop_prop = seq(0.1, 0.9, by = 0.1), threshold = 0.7, certainty = 0.95, method = "pearson", centrality_fn = NULL, loops = FALSE, seed = NULL )
x |
An htna network from |
measures |
Character vector of centrality measures to assess.
Default |
iter |
Integer. Number of resamples per drop proportion.
Default |
drop_prop |
Numeric vector. Proportions of sessions to drop.
Default |
threshold |
Numeric in [0, 1]. Correlation threshold for the
case-dropping stability coefficient. Default |
certainty |
Numeric in [0, 1]. Probability of meeting the
threshold required for a drop proportion to count as stable.
Default |
method |
Correlation method, one of |
centrality_fn |
Optional function to compute centralities.
Default |
loops |
Logical. Whether to retain self-loops. Default |
seed |
Optional integer seed for reproducibility. Default
|
For an htna_group, the call is iterated per cohort and the result
is a named list (one htna_stability per cohort), with class
c("htna_stability_group", "list").
For a single htna network, an object of class
c("htna_stability", "net_stability") with the same components
as Nestimate::centrality_stability(): cs (the stability
coefficients, one per measure), correlations (per-drop-proportion
correlation traces), and the parameters that were used.
For an htna_group, a named list of such objects with class
c("htna_stability_group", "list").
Nestimate::centrality_stability(),
bootstrap_htna(), reliability_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 30, seed = 1) cs$csdata(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 30, seed = 1) cs$cs
Computes the edge betweenness of every existing edge in an htna
network and returns a copy whose $weights slot stores those
betweenness scores instead of the original transition weights. The
actor partition is preserved, so the result can be plotted with
plot_htna() to visualise which edges carry the most shortest-path
traffic.
edge_betweenness_htna(x, directed = TRUE, invert = TRUE)edge_betweenness_htna(x, directed = TRUE, invert = TRUE)
x |
An htna network from |
directed |
If |
invert |
If |
Mirrors tna::betweenness_network(): edge weights are inverted to
costs by default (invert = TRUE) – in transition networks a
larger transition probability means the edge is "easier" and so the
equivalent path cost is smaller.
A copy of x whose $weights matrix entries are
edge-betweenness scores at every position where the original
network had a non-zero transition. Class is
c("htna_edge_betweenness", class(x)).
centralities_htna() for node-level centrality measures,
tna::betweenness_network() for the tna equivalent.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") eb <- edge_betweenness_htna(net) plot_htna(eb) # edge thickness = betweenness scoredata(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") eb <- edge_betweenness_htna(net) plot_htna(eb) # edge thickness = betweenness score
Discovers recurring patterns in the actor-typed sequences that produced a heterogeneous transition network. Operates at two levels:
extract_meta_paths( x, level = c("state", "type"), length = 2:4, schema = NULL, type = c("contiguous", "gapped"), gap = 1L, min_count = 1L, min_support = 0, min_lift = 0, start = NULL, end = NULL, contain = NULL )extract_meta_paths( x, level = c("state", "type"), length = 2:4, schema = NULL, type = c("contiguous", "gapped"), gap = 1L, min_count = 1L, min_support = 0, min_lift = 0, start = NULL, end = NULL, contain = NULL )
x |
[ |
level |
[ |
length |
[ |
schema |
[ |
type |
[ |
gap |
[ |
min_count |
[ |
min_support |
[ |
min_lift |
[ |
start, end, contain
|
[ |
level = "state" (default) - enumerate concrete state-level patterns
(e.g. Command->Execute->Command) and annotate each row with the
type-level template it instantiates (e.g. Human->AI->Human).
level = "type" - enumerate type-level meta-paths only (one row per
actor-type pattern, summed over its concrete instances).
At either level, a schema can filter the search. Schema parts can be
type names (expand to every concrete code in that group), concrete
states, or "*" (any element). Parts can be mixed freely - e.g.
"Human->Ask->Human" means "any Human code, then Ask, then any Human
code". At level = "type" concrete codes resolve to their type, so the
same schema becomes Human->AI->Human.
Operates on the actor partition stored on the network by build_htna().
An object of class c("htna_meta_paths", "htna_paths", "data.frame"). At level = "state" the columns are schema,
meta_schema, length, gap, count, n_sequences, support,
frequency, lift. At level = "type" the meta_schema column is
omitted (the schema column already holds the type pattern).
Attributes: n_sequences, alphabet, level, and (when supplied)
schema.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") # Concrete state-level patterns of length 2..4 (default) extract_meta_paths(net) # Type-level meta-path summary extract_meta_paths(net, level = "type") # Concrete instances of a type-level template extract_meta_paths(net, schema = "Human->AI->Human") # Mix types, concrete codes, and wildcards extract_meta_paths(net, schema = "Human->Ask->Human") extract_meta_paths(net, schema = "Human->*->Human") # Gapped patterns; lift threshold extract_meta_paths(net, length = 3, type = "gapped", gap = 1:2) extract_meta_paths(net, length = 3, min_lift = 1.2)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") # Concrete state-level patterns of length 2..4 (default) extract_meta_paths(net) # Type-level meta-path summary extract_meta_paths(net, level = "type") # Concrete instances of a type-level template extract_meta_paths(net, schema = "Human->AI->Human") # Mix types, concrete codes, and wildcards extract_meta_paths(net, schema = "Human->Ask->Human") extract_meta_paths(net, schema = "Human->*->Human") # Gapped patterns; lift threshold extract_meta_paths(net, length = 3, type = "gapped", gap = 1:2) extract_meta_paths(net, length = 3, min_lift = 1.2)
Returns the within-network state frequency table, partitioned by
actor. One row per (actor, state) pair, with count and
proportion columns. The data side of plot_frequencies_htna().
frequencies_htna(x)frequencies_htna(x)
x |
An htna network from |
Internally a thin wrapper around the htna S3 method shipped by
Nestimate (state_distribution.htna); exposed under the
frequencies_htna() name as the canonical "give me the frequency
table for this network" entry point.
Suffixed _htna to avoid clashing with Nestimate::frequencies()
(which takes raw long-format data and a column-name spec) when
both packages are loaded. If you have raw data rather than an htna
network, call Nestimate::frequencies() directly.
A data frame with columns group (actor), state,
count, proportion.
plot_frequencies_htna() for the rendered version,
state_distribution_htna() (same function under the upstream
name), mosaic_plot_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") frequencies_htna(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") frequencies_htna(net)
A colour palette for up to 6 actor groups, used by plot_htna() when
no explicit colours are supplied.
htna_palettehtna_palette
An object of class character of length 6.
A character vector of 6 hex colour codes.
htna_palettehtna_palette
A long-format heterogeneous sequence dataset built from
Nestimate::human_long and Nestimate::ai_long by
collapsing several near-synonym codes into a smaller, more
interpretable alphabet. Suitable as a teaching example for
build_htna().
human_aihuman_ai
A data frame with 19347 rows and 11 columns:
Integer. Source message identifier.
Character. Project label (e.g. "Project_1").
Character. Session identifier — pass to
build_htna() as the session key.
Integer. Unix timestamp of the message.
Character. Date of the session
(YYYY-MM-DD).
Character. Simplified action code; the
code-column value passed to build_htna().
Character. Original cluster label from the source data, retained for reference (see Details).
Integer. Order of the code within the message.
Integer. Order of the row within the
session — pass as the order key to build_htna().
Character. "AI" or "Human" — the
actor partition for build_htna(actor_type = "actor_type").
Factor with levels "Early" and "Late".
Session-level cohort tag from a chronological split: sessions
ordered by their first session_date (with session_id
as a deterministic tiebreak), then split in half. Suitable for
build_htna(group = "phase").
Code remapping (all other codes pass through unchanged):
AI: Investigate, Ask, Inquire
Ask; Explain, Report Report.
Human: Command, Request Request;
Correct, Verify Check;
Interrupt, Frustrate Frustrate.
Resulting alphabets:
AI (6): Ask, Delegate, Execute,
Plan, Repair, Report.
Human (6): Check, Frustrate, Inquire,
Refine, Request, Specify.
Because two source codes can map to the same simplified code while
originally belonging to different cluster values, a single
simplified code may appear with more than one cluster
label across rows. The cluster column is preserved verbatim
from the source data and should be treated as informational only.
Derived from Nestimate::human_long and
Nestimate::ai_long; see data-raw/human_ai.R for the
build script.
human_simplified, ai_simplified,
human_ai_codebook.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_htna(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_htna(net)
human_ai
A tidy two-column lookup tagging every simplified code in
human_ai with its actor type. Ready to pass as
node_groups to build_htna() (Form 3b in the
vignette("input-formats", package = "htna")).
human_ai_codebookhuman_ai_codebook
A data frame with 12 rows and 2 columns:
Character. Simplified action code (one of the 12
Human + AI codes in human_ai).
Character. "Human" or "AI".
Derived from human_simplified and
ai_simplified; see data-raw/human_ai.R for
the build script.
human_ai, human_simplified,
ai_simplified.
data(human_ai, human_ai_codebook) net <- build_htna(human_ai, node_groups = human_ai_codebook) plot_htna(net)data(human_ai, human_ai_codebook) net <- build_htna(human_ai, node_groups = human_ai_codebook) plot_htna(net)
The Human-only slice of human_ai, in a long-format
data frame ready to feed the named-list form of
build_htna(). Codes have already been collapsed into
the simplified Human alphabet; see human_ai for the
remapping rules.
human_simplifiedhuman_simplified
A data frame with 10796 rows and 10 columns. Schema matches
human_ai minus the phase column; every value
in actor_type is "Human".
Derived from Nestimate::human_long; see
data-raw/human_ai.R for the build script.
human_ai, ai_simplified,
human_ai_codebook.
data(human_simplified, ai_simplified) net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) plot_htna(net)data(human_simplified, ai_simplified) net <- build_htna(list(Human = human_simplified, AI = ai_simplified)) plot_htna(net)
htna-named alias of Nestimate::markov_order_test(). Tests
whether a first-order Markov model is adequate for the observed
sequences, or whether a higher order is required, by comparing the
empirical transition structure against orders 1..max_order via
permutation.
markov_order_test_htna( data, max_order = 3L, n_perm = 500L, alpha = 0.05, parallel = FALSE, n_cores = 2L, seed = NULL )markov_order_test_htna( data, max_order = 3L, n_perm = 500L, alpha = 0.05, parallel = FALSE, n_cores = 2L, seed = NULL )
data |
A data.frame (wide format, one sequence per row) or list of character vectors (one per trajectory). NAs are treated as end of sequence. |
max_order |
Integer. Highest Markov order to test. Default 3. |
n_perm |
Integer. Number of within- |
alpha |
Numeric. Significance level for order selection. Default 0.05. |
parallel |
Logical. Use |
n_cores |
Integer. Cores for parallel execution. Default 2. |
seed |
Optional integer seed for reproducibility. |
Operates on raw sequence data (a list of character vectors or a
wide-format data frame), not on an htna network object. Use
alongside reliability_htna() and casedrop_reliability_htna()
when assessing whether a Markov-1 transition network is
appropriate before trusting downstream htna analyses.
Suffixed _htna to avoid clashing with
Nestimate::markov_order_test() when both packages are loaded.
An object of class markov_order_test with components
test_table, optimal_order, and the inputs. See
Nestimate::markov_order_test() for full details and the
corresponding plot() method.
reliability_htna(), casedrop_reliability_htna(),
centrality_stability_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") markov_order_test_htna(net$data, max_order = 2, n_perm = 50, seed = 1)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") markov_order_test_htna(net$data, max_order = 2, n_perm = 50, seed = 1)
htna-named alias of Nestimate::mosaic_plot(). Renders a
chi-square mosaic where row x column area equals the joint share
of (from, to) transitions and fill encodes the standardized
residual (blue = over-represented, red = under-represented,
white = at-expected).
mosaic_plot_htna(x, ...)mosaic_plot_htna(x, ...)
x |
One of the four data-bearing Nestimate classes:
|
... |
Ignored. |
Designed with htna in mind: Nestimate ships an explicit
mosaic_plot.htna S3 method that recognises the actor partition
on htna networks. Pass an htna network from build_htna()
directly. The underlying transition matrix must be integer-weighted
(build with method = "frequency"), since the chi-square test
needs counts.
Axis tick labels are coloured by actor group using the htna
palette (htna_palette), matching the colours used elsewhere in
htna (e.g. plot_htna()).
Suffixed _htna to avoid clashing with Nestimate::mosaic_plot()
when both packages are loaded.
A ggplot or gtable, depending on input shape. See
Nestimate::mosaic_plot() for full details and the per-class S3
methods.
plot_frequencies_htna() for the marginal-frequency
companion view.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type", method = "frequency") mosaic_plot_htna(net, n_perm = 50, seed = 1)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type", method = "frequency") mosaic_plot_htna(net, n_perm = 50, seed = 1)
htna-named alias of Nestimate::permutation(). Tests whether
observed edge-weight differences between two networks (or all
pairwise differences within a netobject_group) exceed what would
be expected under a null of identical generating processes.
permutation_htna( x, y = NULL, iter = 1000L, alpha = 0.05, paired = FALSE, adjust = "none", nlambda = 50L, seed = NULL )permutation_htna( x, y = NULL, iter = 1000L, alpha = 0.05, paired = FALSE, adjust = "none", nlambda = 50L, seed = NULL )
x |
A |
y |
A |
iter |
Integer. Number of permutation iterations (default: 1000). |
alpha |
Numeric. Significance level (default: 0.05). |
paired |
Logical. If |
adjust |
Character. p-value adjustment method passed to
|
nlambda |
Integer. Number of lambda values for the |
seed |
Integer or NULL. RNG seed for reproducibility. |
Works on htna networks: the actor partition ($node_groups,
$actor_levels, htna class) is preserved on result$x /
result$y, so plot_htna_diff() can render the result with
htna's colour and layout conventions.
Suffixed _htna to avoid clashing with Nestimate::permutation()
when both packages are loaded.
An object of class net_permutation (single pair) or
net_permutation_group (multiple pairs). See
Nestimate::permutation() for the full slot list.
plot_htna_diff() to plot the result.
data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") permutation_htna(grp$Early, grp$Late, iter = 50)data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") permutation_htna(grp$Early, grp$Late, iter = 50)
Faceted bar plot of node-level centralities, one panel per measure.
Mirrors the look of tna::plot.tna_centralities().
plot_centralities( x, measures = c("OutStrength", "InStrength", "ClosenessIn", "ClosenessOut", "Closeness", "Betweenness", "BetweennessRSP", "Diffusion", "Clustering"), by = c("state", "group"), reorder = TRUE, ncol = 3, scales = c("free_x", "fixed"), colors = NULL, labels = TRUE, ... )plot_centralities( x, measures = c("OutStrength", "InStrength", "ClosenessIn", "ClosenessOut", "Closeness", "Betweenness", "BetweennessRSP", "Diffusion", "Clustering"), by = c("state", "group"), reorder = TRUE, ncol = 3, scales = c("free_x", "fixed"), colors = NULL, labels = TRUE, ... )
x |
An htna network, |
measures |
Centralities to plot. Default: all nine. |
by |
|
reorder |
If |
ncol |
Number of facet columns. Default |
scales |
Facet scaling: |
colors |
Optional fill colours, recycled per group/node. |
labels |
If |
... |
Forwarded to |
Accepts an htna network, an htna_group, or a data frame produced by
centralities_htna(). For groups, bars are coloured by group within each
panel.
A ggplot object.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_centralities(net) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") plot_centralities(grp)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_centralities(net) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") plot_centralities(grp)
Computes edge_betweenness_htna() and renders it with the htna
actor styling (multi-actor circular layout, htna_palette node
colours, actor legend). Edges are scaled by their betweenness
score, so the most-traveled shortest-path edges stand out.
plot_edge_betweenness_htna(x, directed = TRUE, invert = TRUE, ...)plot_edge_betweenness_htna(x, directed = TRUE, invert = TRUE, ...)
x |
An htna network from |
directed, invert
|
Forwarded to |
... |
Forwarded to |
The value returned by plot_htna() (invisibly).
edge_betweenness_htna(), plot_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_edge_betweenness_htna(net) plot_edge_betweenness_htna(net, minimum = 5)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_edge_betweenness_htna(net) plot_edge_betweenness_htna(net, minimum = 5)
Renders one of three views of an htna network's state frequencies: the upstream treemap (default), a combined actor-coloured bar chart, or a per-actor faceted bar chart.
plot_frequencies_htna(x, view = c("treemap", "bars", "facet"), ...)plot_frequencies_htna(x, view = c("treemap", "bars", "facet"), ...)
x |
An htna network from |
view |
One of
|
... |
Forwarded to |
Suffixed _htna to avoid clashing with
Nestimate::plot_state_frequencies() when both packages are loaded.
For view = "treemap": the state_freq object invisibly.
For "bars" / "facet": a ggplot, returned visibly so the
chart auto-prints and standard + composition works.
frequencies_htna() for the underlying tidy table,
state_frequencies_htna(), state_distribution_htna(),
mosaic_plot_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_frequencies_htna(net, view = "treemap") if (requireNamespace("ggplot2", quietly = TRUE)) { plot_frequencies_htna(net, view = "bars") }data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_frequencies_htna(net, view = "treemap") if (requireNamespace("ggplot2", quietly = TRUE)) { plot_frequencies_htna(net, view = "bars") }
Wrapper around cograph::plot_htna() with defaults suited for HTNA
networks built by build_htna(). When layout = "circular", a custom
layout is computed so that the first actor group appears on the left.
plot_htna( x, layout = "circular", group_colors = htna_palette, group_shapes = htna_shape_palette, minimum = 0.05, ... ) ## S3 method for class 'htna' plot(x, ...) ## S3 method for class 'htna_group' plot(x, ...)plot_htna( x, layout = "circular", group_colors = htna_palette, group_shapes = htna_shape_palette, minimum = 0.05, ... ) ## S3 method for class 'htna' plot(x, ...) ## S3 method for class 'htna_group' plot(x, ...)
x |
A network object produced by |
layout |
Character. Layout algorithm. Default |
group_colors |
Character vector of colours, one per actor group. Defaults to the built-in htna_palette. |
group_shapes |
Character vector of node shapes, one per actor group.
Defaults to the built-in |
minimum |
Numeric. Minimum absolute edge weight to display.
Edges below this threshold are hidden. Default |
... |
Additional arguments passed to |
Called for its side effect (a plot). Returns x invisibly.
cograph::plot_htna(), build_htna()
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_htna(net) plot_htna(net, layout = "auto", minimum = 0.1)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_htna(net) plot_htna(net, layout = "auto", minimum = 0.1)
Renders the bootstrap result via cograph::splot.net_bootstrap() so the
CI / significance / dashed-edge overlay is preserved, but overrides the
layout and node styling to match plot_htna() (multi-group circular
layout, warm htna_palette, darkened donut).
plot_htna_bootstrap(boot, group_colors = htna_palette, ...) ## S3 method for class 'htna_bootstrap' plot(x, ...)plot_htna_bootstrap(boot, group_colors = htna_palette, ...) ## S3 method for class 'htna_bootstrap' plot(x, ...)
boot |
An object from |
group_colors |
Character vector of colours, one per actor group. Defaults to the built-in htna_palette. |
... |
Forwarded to |
x |
Same as |
For an htna_bootstrap_group (i.e. the result of running
bootstrap_htna() on a build_htna(..., group = ...) output), each
element is plotted individually with its name as the title - this
function does not manage par(mfrow=...).
The value returned by cograph::splot.net_bootstrap()
(invisibly), or the input group invisibly.
bootstrap_htna(), plot_htna(),
cograph::splot.net_bootstrap().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") boot <- bootstrap_htna(net, iter = 50) plot_htna_bootstrap(boot) plot_htna_bootstrap(boot, display = "significant")data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") boot <- bootstrap_htna(net, iter = 50) plot_htna_bootstrap(boot) plot_htna_bootstrap(boot, display = "significant")
Renders the elementwise edge-weight difference x - y as a heterogeneous
transition network. Accepts:
plot_htna_diff( x, y = NULL, pos_color = "#009900", neg_color = "#C62828", group_colors = htna_palette, ... )plot_htna_diff( x, y = NULL, pos_color = "#009900", neg_color = "#C62828", group_colors = htna_palette, ... )
x |
One of: an htna network, a |
y |
htna network (only used when |
pos_color |
Edge colour for positive differences. Default
|
neg_color |
Edge colour for negative differences. Default
|
group_colors |
Character vector of colours, one per actor group. Defaults to the built-in htna_palette. |
... |
Forwarded to the underlying splot dispatcher
( |
Two htna networks (x, y): plots x - y via cograph::splot() with
positive/negative edge coloring.
A net_permutation result: routes through
cograph::splot.net_permutation() so the significance overlay
(significant pos/neg edges, dashed non-significant edges, stars) is
drawn upstream.
A net_permutation_group: iterates over all pairwise comparisons and
plots each (no par(mfrow=...) management - user controls layout).
In all cases the layout, node colours and donut match plot_htna().
The value of the underlying splot call (invisibly).
plot_htna(), build_htna(), Nestimate::permutation().
data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") plot_htna_diff(grp$Early, grp$Late) perm <- permutation_htna(grp$Early, grp$Late, iter = 50) plot_htna_diff(perm) plot_htna_diff(perm, show_nonsig = TRUE)data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") plot_htna_diff(grp$Early, grp$Late) perm <- permutation_htna(grp$Early, grp$Late, iter = 50) plot_htna_diff(perm) plot_htna_diff(perm, show_nonsig = TRUE)
S3 generic dispatched on x. Calling plot_sequences(net) on an htna
network forwards to sequence_plot_htna().
plot_sequences(x, ...)plot_sequences(x, ...)
x |
An object to plot. |
... |
Forwarded to the method. |
Method-defined.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_sequences(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") plot_sequences(net)
S3 method for plotting htna centrality stability results. Dispatches to cograph's plotting method with htna-specific styling.
## S3 method for class 'htna_stability' plot(x, ...)## S3 method for class 'htna_stability' plot(x, ...)
x |
An object of class |
... |
Additional arguments passed to the plotting method. |
A ggplot object or plot output, depending on the underlying method.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 20, seed = 1) plot(cs)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 20, seed = 1) plot(cs)
S3 method for plotting grouped htna stability results.
## S3 method for class 'htna_stability_group' plot(x, ...)## S3 method for class 'htna_stability_group' plot(x, ...)
x |
An object of class |
... |
Additional arguments passed to the plotting method. |
A combined plot or list of plots for each group.
data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") cs <- centrality_stability_htna(grp, iter = 20, seed = 1) plot(cs)data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") cs <- centrality_stability_htna(grp, iter = 20, seed = 1) plot(cs)
S3 method for printing htna centrality stability results.
## S3 method for class 'htna_stability' print(x, ...)## S3 method for class 'htna_stability' print(x, ...)
x |
An object of class |
... |
Additional arguments passed to the print method. |
Invisibly returns the object, prints stability information.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 20, seed = 1) print(cs)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") cs <- centrality_stability_htna(net, iter = 20, seed = 1) print(cs)
S3 method for printing grouped htna stability results.
## S3 method for class 'htna_stability_group' print(x, ...)## S3 method for class 'htna_stability_group' print(x, ...)
x |
An object of class |
... |
Additional arguments passed to the print method. |
Invisibly returns the object, prints group stability information.
data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") cs <- centrality_stability_htna(grp, iter = 20, seed = 1) print(cs)data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") cs <- centrality_stability_htna(grp, iter = 20, seed = 1) print(cs)
Thin wrapper around Nestimate::network_reliability() that preserves
the htna actor partition on every model in the returned $models
slot, so downstream htna-aware code (plotting, centralities, etc.)
keeps working on the reliability output.
reliability_htna(..., iter = 1000L, split = 0.5, scale = "none", seed = NULL)reliability_htna(..., iter = 1000L, split = 0.5, scale = "none", seed = NULL)
... |
One or more htna networks built by |
iter |
Integer. Number of split-half iterations. Default |
split |
Numeric in (0, 1). Proportion of sessions used for the
first half-network. Default |
scale |
One of |
seed |
Optional integer seed for reproducibility. Default |
Mirrors the signature of the underlying function: pass one or more
networks via ... plus the optional iter, split, scale, and
seed arguments. All networks passed through ... must be htna
networks built by build_htna().
An object of class c("htna_reliability", "net_reliability"),
with the same components as Nestimate::network_reliability() —
iterations, summary, models, iter, split, scale — and
each entry of $models carrying the htna actor partition
($nodes$groups, $node_groups, $actor_levels).
Nestimate::network_reliability(), bootstrap_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") rel <- reliability_htna(net, iter = 30, seed = 1) rel$summarydata(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") rel <- reliability_htna(net, iter = 30, seed = 1) rel$summary
Extends Nestimate::sequence_compare() with a level argument that
lets the comparison run on type-level (meta-path) sequences as well
as state-level sequences.
sequence_compare_htna( x, group = NULL, level = c("state", "type"), sub = 3:5, min_freq = 5L, test = c("permutation", "chisq", "none"), iter = 1000L, adjust = "fdr" )sequence_compare_htna( x, group = NULL, level = c("state", "type"), sub = 3:5, min_freq = 5L, test = c("permutation", "chisq", "none"), iter = 1000L, adjust = "fdr" )
x |
A |
group |
Character or vector. Column name or vector of group labels.
Not needed for |
level |
Character. |
sub |
Integer vector. Pattern lengths to analyze. Default: |
min_freq |
Integer. Minimum frequency in each group for a pattern to be included. Default: 5. |
test |
Character. Inference method: one of |
iter |
Integer. Permutation iterations. Only used when
|
adjust |
Character. P-value correction method (see
|
Extracts all k-gram patterns (subsequences of length k) from the
sequences in each cohort, computes standardised residuals against
the independence model, and optionally runs a permutation or
chi-square test for differences in pattern rates between cohorts.
Operates on grouped htna networks (built via
build_htna(..., group = ...)), single htna networks paired with a
group argument, or wide-format sequence data with an explicit
group argument. The actor partition itself is not consumed when
level = "state" — sequence comparison is between cohorts of
sessions, not between actors. When level = "type", concrete codes
are folded into their actor type before pattern enumeration, so the
comparison runs on meta-paths.
An object of class net_sequence_compare. See
Nestimate::sequence_compare() for full details and the
corresponding plot() method.
permutation_htna() for whole-network differences,
mosaic_plot_htna() for single-step transition residuals,
extract_meta_paths() for descriptive meta-path enumeration.
data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") # State-level comparison (default) sequence_compare_htna(grp, iter = 50) # Meta-path comparison sequence_compare_htna(grp, level = "type", iter = 50)data(human_ai) grp <- build_htna(human_ai, actor_type = "actor_type", group = "phase") # State-level comparison (default) sequence_compare_htna(grp, iter = 50) # Meta-path comparison sequence_compare_htna(grp, level = "type", iter = 50)
Extracts each actor's events from the combined wide sequence in
net$data (using net$node_groups as the node-to-actor lookup),
compresses each session into the actor's own ordered events, pads to a
common width, and renders with Nestimate::sequence_plot() grouped by
actor. Each session contributes one row per actor that had at least one
event in it.
sequence_plot_htna( net, by = c("state", "group"), type = c("index", "heatmap", "distribution"), grouped_legend = TRUE, ... ) ## S3 method for class 'htna' plot_sequences(x, ...)sequence_plot_htna( net, by = c("state", "group"), type = c("index", "heatmap", "distribution"), grouped_legend = TRUE, ... ) ## S3 method for class 'htna' plot_sequences(x, ...)
net |
An htna network from |
by |
|
type |
Sequence plot layout: |
grouped_legend |
Logical. If |
... |
Forwarded to |
x |
Same as |
Invisibly, the list returned by Nestimate::sequence_plot().
Nestimate::sequence_plot(), build_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") sequence_plot_htna(net) # index, faceted sequence_plot_htna(net, type = "heatmap") # single carpet, white gulf sequence_plot_htna(net, type = "distribution")data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") sequence_plot_htna(net) # index, faceted sequence_plot_htna(net, type = "heatmap") # single carpet, white gulf sequence_plot_htna(net, type = "distribution")
htna-named alias of Nestimate::state_distribution(). Returns the
per-timestep distribution of states across sequences, suitable for
driving stacked-area or bar plots.
state_distribution_htna(x, ...)state_distribution_htna(x, ...)
x |
A |
... |
Currently unused. |
Designed with htna in mind: Nestimate ships an explicit
state_distribution.htna S3 method that uses the actor partition
carried by build_htna() networks.
Suffixed _htna to avoid clashing with
Nestimate::state_distribution() when both packages are loaded.
A data frame with one row per (timestep, state). See
Nestimate::state_distribution() for full details.
state_frequencies_htna() for the within-network summary.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") state_distribution_htna(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") state_distribution_htna(net)
htna-named alias of Nestimate::state_frequencies(). Returns a
tidy data frame with state, count, and proportion columns
summarising the within-network state vocabulary.
state_frequencies_htna(data)state_frequencies_htna(data)
data |
A list of character vectors (trajectories) or a data.frame. |
Companion to plot_frequencies_htna() (which is htna-aware
via an explicit S3 method). state_frequencies_htna() itself
operates on the raw sequence data and is the data side of the same
family used by the htna tutorials.
Suffixed _htna to avoid clashing with
Nestimate::state_frequencies() when both packages are loaded.
A data frame. See Nestimate::state_frequencies() for
details.
plot_frequencies_htna(), state_distribution_htna().
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") state_frequencies_htna(net$data)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") state_frequencies_htna(net$data)
Prints a per-actor summary of an htna network: which nodes belong to which actor type and how the non-zero edges distribute across the actor partition. The result is also returned invisibly as a list so callers can inspect the structured summary programmatically.
## S3 method for class 'htna' summary(object, max_nodes = 12L, ...) ## S3 method for class 'htna_group' summary(object, max_nodes = 12L, ...)## S3 method for class 'htna' summary(object, max_nodes = 12L, ...) ## S3 method for class 'htna_group' summary(object, max_nodes = 12L, ...)
object |
An htna network from |
max_nodes |
Integer. Maximum number of nodes to list per actor
type before truncating with an ellipsis. Default |
... |
Forwarded for compatibility; currently unused. |
Invisibly, a list with components:
actors - data frame with one row per actor type (actor,
n_nodes, nodes).
edges_by_actor - integer matrix of non-zero edge counts,
rows are source actor, columns are target actor.
n_nodes, n_edges, n_sessions, n_timesteps,
method.
data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") summary(net)data(human_ai) net <- build_htna(human_ai, actor_type = "actor_type") summary(net)