Skip to content

[Phase 1.2] Refactor build_netstats() to use g-computation predictions from joint model #62

@smjenness

Description

@smjenness

Context

Once a joint Poisson GLM is fit per layer (see #61), build_netstats() should use it via g-computation to produce internally-consistent target statistics.

Proposed approach

Step 1 — Build synthetic target population (N=10,000 default) from a single reference distribution. Attributes: age (continuous), age.grp, race, deg.casl, hiv2, etc. See #64 for post-stratification options.

Step 2 — Predict per-node expected degree using the joint model:

pred_deg <- predict(netparams\$main\$joint_model, newdata = synth_pop, type = 'response')

Step 3 — Aggregate target statistics by subsetting:

edges_target      <- sum(pred_deg) / 2
nf.age.grp[k]     <- sum(pred_deg[synth_pop\$age.grp == k])
nf.race[r]        <- sum(pred_deg[synth_pop\$race.cat.num == r])
nf.deg.casl[d]    <- sum(pred_deg[synth_pop\$deg.casl == d])
nf.diag.status[h] <- sum(pred_deg[synth_pop\$hiv2 == h])

All stats are internally consistent by construction: Σ_k nf.age.grp[k] = Σ_r nf.race[r] = 2 × edges_target.

Step 4 — Add method = c('marginal', 'joint_gcomp') argument; default 'marginal' for backward compatibility.

Tasks

  • Add method argument to build_netstats(). Default 'marginal' (current behavior).
  • Under method = 'joint_gcomp', use joint GLM predictions on synth population.
  • Refactor each target stat computation (edges, nf.*, concurrent, degrange) to use predicted per-node degrees.
  • Remove edges.avg flag when method = 'joint_gcomp' (inconsistency is resolved by construction).
  • Warn clearly when method = 'marginal' is used that joint approach may be more appropriate.
  • Regression tests: method = 'marginal' reproduces existing output byte-identically.

Acceptance criteria

  • build_netstats(method = 'joint_gcomp') returns a netstats object with internally consistent targets:
    • Σ_k nodefactor_age.grp[k] == 2 × edges within floating-point tolerance.
    • Σ_r nodefactor_race[r] == 2 × edges similarly.
  • build_netstats(method = 'marginal') produces the same output as the current function.
  • Documentation flags that method = 'marginal' may be biased when target distribution differs from ARTnet sample.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions