tidy.ackwards: Tidy an ackwards object into a long data frame

View source: R/tidy.R

tidy.ackwardsR Documentation

Tidy an ackwards object into a long data frame

Description

Returns structured data from an ackwards object in tidy format. The default (what = "edges") returns the graph edge list that drives diagrams.

Usage

## S3 method for class 'ackwards'
tidy(
  x,
  what = c("edges", "loadings", "variance", "fit", "nodes", "scores"),
  primary_only = FALSE,
  sort = c("none", "strength"),
  format = c("long", "wide"),
  conf_level = 0.95,
  ...
)

Arguments

x

An ackwards object.

what

What to extract:

  • "edges" (default) – one row per directed between-level edge: from, to, level_from, level_to, r, is_primary, above_cut. If boot_edges() has been run on the object, four bootstrap columns are appended: se, lo, hi (bootstrap standard error and percentile confidence-interval endpoints), and n_boot_ok (usable replicates).

  • "loadings" – one row per item x factor x level: level, factor, item, loading, se, ci_lower, ci_upper. se, ci_lower, and ci_upper are populated only for engine = "esem" (which produces rotation-aware loading SEs); they are NA for PCA and EFA. The confidence level is controlled by conf_level.

  • "variance" – one row per factor x level: level, factor, proportion, cumulative. Both are proportions of total item variance on a 0-1 scale (multiply by 100 for a percentage).

  • "fit" – one row per fit statistic x level: level, statistic, value. For PCA objects the statistics are eigenvalues; for EFA objects they are chi, dof, p_value, RMSEA, TLI, BIC – where chi is the likelihood-ratio chi-square (psych::fa()'s STATISTIC), so chi, dof, p_value, RMSEA, and TLI all share one statistical framing (psych's residual-based empirical chi-square is a different statistic and is not reported); for ESEM they are chi, dof, p_value, CFI, TLI, RMSEA, SRMR, BIC. For ESEM under a scaled-test estimator ("WLSMV"/"ULSMV" for ordinal data, "MLR" for continuous), the whole row – chi/dof/ p_value and CFI/TLI/RMSEA – reports lavaan's mean-and-variance-adjusted ("scaled") variant, so every quantity shares one scaling. This matters most for WLSMV/ULSMV: the naive chi-square has no valid reference distribution (lavaan's own summary() labels its p-value "Unknown"), and the naive CFI/TLI are badly optimistic for ordinal data (Xia & Yang, 2019). "ML" has no scaled variant, so it reports the naive values (the correct ones for ML). SRMR has no scaled variant and is reported as-is. BIC is NA under WLSMV/ULSMV (no proper log-likelihood for a limited-information estimator) and populated under ML/MLR. Use format = "wide" for one row per non-anchor level (k >= 2; the saturated 1-factor anchor is dropped, matching summary() and autoplot(what = "fit")), one column per statistic. Conventional fit cutoffs (Hu & Bentler 1999) are shown as reference lines in autoplot(what = "fit") and inline in summary(), but are not returned as a pass/fail column here – they are contested thresholds, report-only, and never gate anything (see those functions' docs). format is oriented to the EFA/ESEM model-fit statistics; for PCA the "statistics" are per-component eigenvalues.

  • "nodes" – Forbes-extension pruning annotations (requires prune != "none" when the object was created). One row per factor across all levels: id, level, pruned, prune_reason. Returns an empty data frame with the same columns when no pruning was applied.

  • "scores" – long-format per-observation factor scores (requires keep_scores = TRUE at fit time or use augment.ackwards() for on-the-fly computation). Columns: obs (row index), level, factor, score.

primary_only

For what = "edges" only. When TRUE, returns just each factor's primary-parent edge (is_primary == TRUE) – the lineage tree that the diagram draws as solid arrows. Default FALSE (all edges). Errors for any other value of what.

sort

For what = "edges" only. One of "none" (default, natural order) or "strength" (descending ⁠|r|⁠). Ignored for all other values of what.

format

For what = "fit" only. One of "long" (default, one row per statistic x level) or "wide" (one row per level, one column per statistic). Errors for all other values of what.

conf_level

For what = "loadings" only. Confidence level for the loading intervals; default 0.95. The intervals are computed as ⁠loading ± qnorm((1 + conf_level) / 2) * se⁠ and are NA for engines that carry no SEs (PCA, EFA). Errors for all other values of what.

...

Ignored.

Value

A data frame (class data.frame).

Factor labels

If factor labels have been attached to the object, the output gains display-only label columns: factor_label for what = "loadings", "variance", or "scores", and from_label/to_label for what = "edges". Each carries the label for a labeled factor and NA otherwise. These columns are absent when no labels are set, so an unlabeled object's output is unchanged; the ID columns (factor, from, to) are never altered.

See Also

glance.ackwards(), print.ackwards(), set_factor_labels()

Examples

x <- ackwards(sim16, k_max = 5)
tidy(x) # edges in natural order
tidy(x, sort = "strength") # strongest edges first
tidy(x, primary_only = TRUE) # just the primary-parent lineage
tidy(x, what = "loadings")
tidy(x, what = "variance")
tidy(x, what = "fit")
tidy(x, what = "fit", format = "wide")


ackwards documentation built on July 25, 2026, 1:08 a.m.