ENA and ONA with RS.data
rena-demo.RmdThis article walks through fitting a standard ENA
(undirected) model and an ONA (directed) model from the
built-in RS.data dataset, then rendering both as live
interactive plots with qeviz.
Data and model setup
units_by <- c("Condition", "UserName")
codes <- c(
"Data", "Technical.Constraints", "Performance.Parameters",
"Client.and.Consultant.Requests", "Design.Reasoning", "Collaboration"
)
hoo_rules <- tma::conversation_rules(
(Condition %in% UNIT$Condition) & (GroupName %in% UNIT$GroupName)
)
context_model <- tma::contexts(
RS.data,
units_by = make.names(units_by),
hoo_rules = hoo_rules
)
multidim_arr <- tma::context_tensor(
RS.data,
sender_cols = NULL,
receiver_cols = NULL,
default_window = 8,
default_weight = 1
)
result_ena <- tma::accumulate(
tensor = multidim_arr,
codes = codes,
context_model = context_model,
ordered = FALSE
)
result_ona <- tma::accumulate(
tensor = multidim_arr,
codes = codes,
context_model = context_model,
ordered = TRUE
)
ena_set <- rENA::model(result_ena)
ona_set <- rENA::model(result_ona, directed = TRUE)Creating a plot object
qe_plot() wraps a set object in a qe_plot
that can be passed through the chain API. No rendering happens yet — the
plot is fully lazy.
Inspect what groups and units are available:
Standard ENA (undirected)
Show both group mean networks overlaid. Each chain call returns a new
qe_plot — the original is unchanged.
p <- qe_ena |>
qe_group() |> # show all group means + CI
qe_edges(qe_groups(qe_ena)[1],
also = qe_groups(qe_ena)[2]) # overlay both networks
htmltools::HTML(qe_fragment(p))Compare groups by subtraction — positive weights favour the first group, negative weights favour the second:
p_sub <- qe_ena |>
qe_group() |>
qe_edges(qe_groups(qe_ena)[1],
compare = qe_groups(qe_ena)[2])
htmltools::HTML(qe_fragment(p_sub))ONA (directed)
Directed edges are rendered as tapered arrows whose apex points toward the stronger directional contributor.
p_ona <- qe_ona |>
qe_group() |>
qe_edges(qe_groups(qe_ona)[1], also = qe_groups(qe_ona)[2])
htmltools::HTML(qe_fragment(p_ona))Individual unit networks
Use qe_units() to list unit IDs, then pass one to
qe_edges(unit = ...). The group mean markers stay visible
so the individual network can be read in context.
Plotting unit: FirstGame::steven z
p_unit <- qe_ena |>
qe_group() |> # show all group means for context
qe_edges(unit = unit_id) # individual edge network
htmltools::HTML(qe_fragment(p_unit))Adding unit points
qe_points() overlays the individual unit scatter
dots:
p_pts <- qe_ena |>
qe_group() |>
qe_edges(qe_groups(qe_ena)[1]) |>
qe_points()
htmltools::HTML(qe_fragment(p_pts))Label control
qe_labels() controls label visibility for nodes, group
means, and unit points independently. Accepted values:
"on", "off", "click",
"auto".
p_labels <- qe_ena |>
qe_group() |>
qe_edges(qe_groups(qe_ena)[1]) |>
qe_points() |>
qe_labels(nodes = "auto", means = "on", points = "click")
htmltools::HTML(qe_fragment(p_labels))Exporting standalone files
qe_export_html() writes a self-contained HTML file — no
server or internet connection required:
qe_export_html(qe_ena |> qe_group() |> qe_edges(qe_groups(qe_ena)[1]),
"ena_plot.html")
qe_export_html(qe_ona |> qe_group() |> qe_edges(qe_groups(qe_ona)[1]),
"ona_plot.html")Branching from a common base works naturally since each chain call copies the plot:
base <- qe_ena |> qe_group()
qe_export_html(qe_edges(base, qe_groups(qe_ena)[1]), "group1.html")
qe_export_html(qe_edges(base, qe_groups(qe_ena)[2]), "group2.html")
qe_export_html(qe_edges(base, unit = qe_units(qe_ena)[1]), "unit1.html")