magnitude_difference: Magnitude difference between the frequency and probability...

View source: R/magnitude_difference.R

magnitude_differenceR Documentation

Magnitude difference between the frequency and probability views

Description

Quantifies, per edge, how much row-normalization moves a transition network between its two natural summaries: raw transition counts (frequency / FTNA, build_network(method = "frequency")) and row-conditional probabilities (TNA, build_network(method = "relative")). The two matrices rank edges differently - an edge that is large in counts can be modest in probability, and a rare-source edge can dominate its row in probability. The per-edge discrepancy on a common scale is the magnitude difference.

Usage

magnitude_difference(
  data,
  actor = "Actor",
  action = "Action",
  time = NULL,
  metric = c("abs_diff", "chord_dist", "atanh_diff", "geom_norm_diff", "cv_inflation"),
  scale = c("tna_range", "rank_minmax", "minmax", "none"),
  format = c("auto", "long", "wide")
)

## S3 method for class 'magnitude_difference'
print(x, ...)

## S3 method for class 'magnitude_difference'
plot(x, type = c("stacked", "circular"), min_show = 0.01, title = NULL, ...)

Arguments

data

Long- or wide-format event log (data.frame).

actor, action, time

Column names in data (long format). time may be NULL.

metric

Discrepancy metric. One of "abs_diff" (default; absolute difference, simplest and most robust), "chord_dist" (chord distance on the unit sphere), "atanh_diff" (Fisher z-style on a bounded scale), "geom_norm_diff" (geometric-mean normalized; amplifies small edges), "cv_inflation" (per-vector SD-standardized then absolute difference).

scale

How the two weight matrices are placed on a common scale before differencing. "tna_range" (default) rescales FTNA linearly into TNA's ⁠[min, max]⁠ range and leaves TNA untouched, so the difference is in TNA probability units. "rank_minmax" converts each matrix's values to ranks scaled to ⁠[0, 1]⁠ (ordinal). "minmax" scales each matrix's raw values to ⁠[0, 1]⁠ separately (asymmetric - TNA's max and FTNA's max map to the same value despite differing native ranges). "none" uses raw weights.

format

Input format passed through to build_network(); "auto" (default) treats the data as wide when action is not a column.

x

A magnitude_difference object.

...

Passed to plotting helpers (ignored by print).

type

Plot style, "stacked" (default) or "circular".

min_show

For type = "circular", drop edges whose magnitude is below this fraction of the maximum.

title

Plot title. NULL generates one from the metric and scale.

Value

An object of class "magnitude_difference": a list with ⁠$edges⁠ (per-edge data.frame with columns from, to, ftna, tna, signed = tna - ftna, and value = the chosen metric), ⁠$metric⁠, ⁠$scale⁠, ⁠$weights_ftna⁠, ⁠$weights_tna⁠, and ⁠$states⁠.

print invisibly returns x.

plot returns a ggplot object.

Methods (by generic)

  • print(magnitude_difference): Print a compact summary of the per-edge magnitude-difference distribution.

  • plot(magnitude_difference): Plot the per-edge magnitude difference as a polar portrait. type = "stacked" (default) draws one sector per from-state with stacked wedges (grey base = shared value, colored tip = magnitude difference); type = "circular" draws a chord-style diagram with signed differences on a diverging blue-orange scale.

See Also

build_network(), compare_model()

Examples

data(group_regulation_long, package = "Nestimate")
fit <- magnitude_difference(group_regulation_long,
                            actor = "Actor", action = "Action",
                            time = "Time")
print(fit)
# Edges most promoted by row-normalization (rare-source transitions):
head(fit$edges[order(-fit$edges$signed), c("from", "to", "ftna", "tna")])

plot(fit)                       # stacked polar portrait
plot(fit, type = "circular")    # chord-style diagram


Nestimate documentation built on July 11, 2026, 1:09 a.m.