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
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
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:
Step 3 — Aggregate target statistics by subsetting:
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
methodargument tobuild_netstats(). Default'marginal'(current behavior).method = 'joint_gcomp', use joint GLM predictions on synth population.edges.avgflag whenmethod = 'joint_gcomp'(inconsistency is resolved by construction).method = 'marginal'is used that joint approach may be more appropriate.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 × edgeswithin floating-point tolerance.Σ_r nodefactor_race[r] == 2 × edgessimilarly.build_netstats(method = 'marginal')produces the same output as the current function.method = 'marginal'may be biased when target distribution differs from ARTnet sample.Related